1 23 24 101 102 package com.sun.enterprise.admin.meta; 103 104 import java.io.InputStream ; 105 import java.io.FileInputStream ; 106 import java.io.PrintWriter ; 107 import java.io.BufferedWriter ; 108 import java.io.FileWriter ;import java.net.URL ; 109 110 import java.util.logging.Level ; 111 import java.util.logging.Logger ; 112 import com.sun.logging.LogDomains; 113 114 import com.sun.enterprise.admin.meta.naming.MBeansNaming; 115 import com.sun.enterprise.admin.AdminContext; 116 119 public class MBeanRegistryFactory 120 { 121 private static MBeanRegistry adminRegistry = null; 122 private static MBeanRegistry runtimeRegistry = null; 123 private static AdminContext adminContext = null; 124 125 static protected Logger _sLogger = LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 126 127 static public void setAdminContext(AdminContext ctx) 128 { 129 adminContext = ctx; 130 } 131 132 static public AdminContext getAdminContext() 133 { 134 return adminContext; 135 } 136 137 static public void setAdminMBeanRegistry(MBeanRegistry registry) 138 { adminRegistry = registry; 140 } 141 142 static public MBeanRegistry getAdminMBeanRegistry() 143 { 144 if(adminRegistry != null) 145 return adminRegistry; 146 try { 147 URL url = null; 148 if(adminContext!=null) 149 url = adminContext.getAdminMBeanRegistryURL(); 150 if(url==null) 151 url = MBeanRegistry.class.getResource("/admin-mbeans-descriptors.xml"); InputStream stream = url.openStream(); 153 adminRegistry = new MBeanRegistry(); 154 adminRegistry.loadMBeanRegistry(stream); 155 stream.close(); 156 try { 158 String fileName = System.getProperty("adminmbeanregistry.printfile"); 159 if(fileName!=null) 160 { 161 PrintWriter out = new PrintWriter (new BufferedWriter (new FileWriter (fileName))); 162 out.println("MBean REGISTRY (in XPath value order)"); 163 adminRegistry.sortRegistryEntries(MBeanRegistry.SORT_BY_XPATH); 164 out.print(adminRegistry.toFormatString()); 165 out.println("\n\n\nMBean REGISTRY (in Type value order)"); 166 adminRegistry.sortRegistryEntries(MBeanRegistry.SORT_BY_NAME); 167 out.print(adminRegistry.toFormatString()); 168 out.close(); 169 } 170 171 } 172 catch (Throwable t) 173 {} 174 return adminRegistry; 175 } catch (Throwable t) { 176 _sLogger.log(Level.WARNING, "core.registryfactory_adminregistry_not_found", 177 t); 178 } 179 return null; 180 } 181 182 static public MBeanRegistry getRuntimeMBeanRegistry() 183 { 184 if(runtimeRegistry != null) 185 return runtimeRegistry; 186 try { 187 URL url = null; 188 if(adminContext!=null) 189 url = adminContext.getRuntimeMBeanRegistryURL(); 190 if(url==null) 191 url = MBeanRegistry.class.getResource("/runtime-mbeans-descriptors.xml"); InputStream stream = url.openStream(); 193 runtimeRegistry = new MBeanRegistry(); 194 runtimeRegistry.loadMBeanRegistry(stream); 195 stream.close(); 196 return runtimeRegistry; 197 } catch (Throwable t) { 198 _sLogger.log(Level.WARNING, "core.registryfactory_adminregistry_not_found", 199 t); 200 } 201 return null; 202 } 203 static public MBeanRegistry getMBeanRegistry(String fileName) 205 { 206 try { 207 FileInputStream stream = new FileInputStream (fileName); 208 MBeanRegistry myRegistry = new MBeanRegistry(); 209 myRegistry.loadMBeanRegistry((InputStream )stream); 210 stream.close(); 211 return myRegistry; 212 } catch (Throwable t) { 213 _sLogger.log(Level.WARNING, "core.registryfactory_registry_not_found", 214 t); 215 } 216 return null; 217 } 218 219 } 220 | Popular Tags |