1 23 package com.sun.enterprise.admin.server.core; 24 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 28 import java.net.URL ; 29 30 import javax.management.MBeanServer ; 31 32 import com.sun.enterprise.admin.AdminContext; 33 import com.sun.enterprise.admin.meta.MBeanRegistry; 34 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 35 import com.sun.enterprise.admin.meta.AdminConfigEventListener; 36 import com.sun.enterprise.admin.util.proxy.Interceptor; 37 import com.sun.enterprise.config.ConfigContext; 38 import com.sun.enterprise.config.ConfigContextEventListener; 39 import com.sun.enterprise.config.ConfigException; 40 import com.sun.enterprise.config.ConfigContextFactory; 41 import com.sun.enterprise.config.ConfigException; 42 import com.sun.enterprise.server.ServerContextImpl; 43 import com.sun.enterprise.config.pluggable.ConfigEnvironment; 44 import com.sun.enterprise.config.pluggable.EnvironmentFactory; 45 46 49 public class AdminContextImpl implements AdminContext { 50 51 private ServerContextImpl serverContext; 52 private ConfigContext runtimeConfigContext; 53 private ConfigContext adminConfigContext; 54 private MBeanServer mbeanServer; 55 private String domainName; 56 private String serverName; 57 private Logger adminLogger; 58 private Interceptor configInterceptor; 59 private URL adminMBeanRegistryURL; 60 private URL runtimeMBeanRegistryURL; 61 62 private static final String ADMIN_DESCRIPTORS_FILENAME = "/admin-mbeans-descriptors.xml"; 63 private static final String RUNTIME_DESCRIPTORS_FILENAME = "/runtime-mbeans-descriptors.xml"; 64 65 68 public AdminContextImpl() { 69 String loggerName = System.getProperty("com.sun.aas.admin.logger.name"); 70 if (loggerName != null) { 71 adminLogger = Logger.getLogger(loggerName); 72 } else { 73 adminLogger = Logger.getAnonymousLogger(); 74 } 75 domainName = "com.sun.appserv"; 77 MBeanRegistryFactory.setAdminContext(this); 79 } 80 81 public AdminContextImpl(ServerContextImpl srvCtx) { 82 this(); 83 setServerContext(srvCtx); 84 } 85 86 87 public void setServerContext(ServerContextImpl srvCtx) { 88 serverContext = srvCtx; 89 runtimeConfigContext = serverContext.getConfigContext(); 90 String configFileName = serverContext.getServerConfigURL(); 91 try { 92 adminConfigContext = ConfigContextFactory.createConfigContext( 93 getAdminConfigEnvironment(configFileName)); 94 registerValidator(); 96 registerConfigAdjustmentListener(); 97 98 } catch (RuntimeException ce) { 99 adminLogger.log(Level.SEVERE, "core.admin_config_read_error", 100 ce.getMessage()); 101 adminLogger.log(Level.WARNING, "core.admin_config_read_error_trace", 102 ce); 103 throw ce; 104 } 105 106 adminLogger.log(Level.FINEST, "core.log_config_id_runtime", 107 new Long (runtimeConfigContext.hashCode())); 108 adminLogger.log(Level.FINEST, "core.log_config_is_admin", 109 new Long (adminConfigContext.hashCode())); 110 serverName = serverContext.getInstanceName(); 111 } 112 113 protected void registerConfigAdjustmentListener() { 114 115 adminConfigContext.addConfigContextEventListener((ConfigContextEventListener)(new AdminConfigEventListener())); 117 } 118 protected void registerValidator() { 119 120 try { 122 Class cl = Class.forName("com.sun.enterprise.config.serverbeans.validation.DomainMgr"); 123 adminConfigContext.addConfigContextEventListener((ConfigContextEventListener)cl.newInstance()); 124 } catch (Exception ex) { 125 adminLogger.log(Level.WARNING, "core.admin_validator_not_registered", "Error registering validator, config validator will not be available"); 126 adminLogger.log(Level.FINE, "core.admin_validator_register_error", ex.getMessage()); 127 } 128 } 129 130 public ConfigContext getAdminConfigContext() { 131 return adminConfigContext; 132 } 133 134 public String getDomainName() { 135 return domainName; 136 } 137 138 public MBeanServer getMBeanServer() { 139 return mbeanServer; 140 } 141 142 public ConfigContext getRuntimeConfigContext() { 143 return runtimeConfigContext; 144 } 145 146 public String getServerName() { 147 return serverName; 148 } 149 150 public URL getAdminMBeanRegistryURL() { 151 if(adminMBeanRegistryURL==null) { 152 try { 153 adminMBeanRegistryURL = MBeanRegistry.class.getResource(ADMIN_DESCRIPTORS_FILENAME); 155 } catch (Throwable t) { 156 adminLogger.log(Level.WARNING, "core.adminconfig_adminregistry_not_found", 157 ADMIN_DESCRIPTORS_FILENAME); 158 } 159 } 160 return adminMBeanRegistryURL; 161 } 162 163 public URL getRuntimeMBeanRegistryURL() { 164 if(runtimeMBeanRegistryURL==null) { 165 try { 166 runtimeMBeanRegistryURL = MBeanRegistry.class.getResource(RUNTIME_DESCRIPTORS_FILENAME); 168 } catch (Throwable t) { 169 adminLogger.log(Level.WARNING, "core.adminconfig_runtimeregistry_not_found", 170 RUNTIME_DESCRIPTORS_FILENAME); 171 } 172 } 173 return runtimeMBeanRegistryURL; 174 } 175 176 public void setAdminConfigContext(ConfigContext ctx) { 177 } 178 179 public void setDomainName(String name) { 180 } 182 183 public void setMBeanServer(MBeanServer mbs) { 184 mbeanServer = mbs; 185 } 186 187 public void setRuntimeConfigContext(ConfigContext ctx) { 188 if (serverContext != null) { 189 serverContext.setConfigContext(ctx); 190 } 191 } 192 193 public void setServerName(String serverName) { 194 } 195 196 public void setAdminMBeanRegistryURL(URL url) { 197 adminMBeanRegistryURL = url; 198 } 199 200 public void setRuntimeMBeanRegistryURL(URL url) { 201 runtimeMBeanRegistryURL = url; 202 } 203 204 public Logger getAdminLogger() { 205 return adminLogger; 206 } 207 208 public void setAdminLogger(Logger logger) { 209 adminLogger = logger; 210 } 211 212 public Interceptor getMBeanServerInterceptor() { 213 if (configInterceptor == null) { 214 configInterceptor = new ConfigInterceptor(this); 215 } 216 return configInterceptor; 217 } 218 219 public void setMBeanServerInterceptor(Interceptor interceptor) { 220 } 221 222 private ConfigEnvironment getAdminConfigEnvironment(String configFileName) { 223 ConfigEnvironment ce = EnvironmentFactory.getEnvironmentFactory(). 224 getConfigEnvironment(); 225 ce.setUrl(configFileName); 226 ce.setReadOnly(false); 227 ce.setCachingEnabled(false); 228 ce.setRootClass("com.sun.enterprise.config.serverbeans.Domain"); 229 ce.setHandler("com.sun.enterprise.config.serverbeans.ServerValidationHandler"); 230 ce.getConfigBeanInterceptor().setResolvingPaths(false); 231 return ce; 232 } 233 public String getDottedNameMBeanImplClassName(){ 234 return "com.sun.enterprise.admin.mbeans.DottedNameGetSetMBeanImpl"; 235 } 236 } 237 | Popular Tags |