1 23 24 31 32 package com.sun.enterprise.server; 33 34 import java.io.File ; 35 import javax.naming.InitialContext ; 36 37 import com.sun.enterprise.Switch; 38 import com.sun.enterprise.NamingManager; 39 import com.sun.enterprise.InvocationManager; 40 41 import com.sun.enterprise.config.ConfigContext; 42 import com.sun.enterprise.config.ConfigException; 43 import com.sun.enterprise.config.serverbeans.Server; 44 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 45 import com.sun.enterprise.instance.InstanceEnvironment; 46 import com.sun.enterprise.server.pluggable.PluggableFeatureFactory; 47 import com.sun.enterprise.util.i18n.StringManager; 48 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistry; 49 50 55 public class ServerContextImpl implements ServerContext { 56 57 58 59 public final String SERVER_XML = "domain.xml"; 60 61 public final String DEFAULT_DOMAIN_NAME = "com.sun.appserv"; 62 63 public final String CONFIG_DIR = "config"; 64 65 66 private String [] cmdLineArgs; 67 68 69 private PluggableFeatureFactory featureFactory; 70 71 72 private String installRoot; 73 74 75 private String instanceName; 76 77 78 private static StringManager localStrings = 79 StringManager.getManager("com.sun.enterprise.server"); 80 81 82 private static ClassLoader commonClassLoader; 83 84 85 private static ClassLoader sharedClassLoader; 86 87 88 private ClassLoader lifeCycleClassLoader; 89 90 91 private ConfigContext configContext; 92 93 94 private Server server; 95 96 private String serverConfigPath = null; 98 99 private String serverConfigURL = null; 101 102 103 private InstanceEnvironment instanceEnvironment = null; 104 105 108 public ServerContextImpl() { 109 installRoot = System.getProperty(Constants.INSTALL_ROOT); 110 instanceName = System.getProperty("com.sun.aas.instanceName"); 111 getInstanceEnvironment(); 112 } 113 114 119 protected void setCmdLineArgs(String [] cmdLineArgs) { 120 this.cmdLineArgs = cmdLineArgs; 121 } 122 123 128 public String [] getCmdLineArgs() { 129 return cmdLineArgs; 130 } 131 132 139 public void setPluggableFeatureFactory(PluggableFeatureFactory obj) { 140 featureFactory = obj; 141 } 142 143 146 public PluggableFeatureFactory getPluggableFeatureFactory() { 147 return featureFactory; 148 } 149 150 155 protected void setInstallRoot(String installRoot) { 156 this.installRoot = installRoot; 157 } 158 159 164 public String getInstallRoot() { 165 return this.installRoot; 166 } 167 168 173 protected void setInstanceName(String instanceName) { 174 this.instanceName = instanceName; 175 } 176 177 182 public String getInstanceName() { 183 return instanceName; 184 } 185 186 189 public String getServerConfigPath() { 190 return instanceEnvironment.getConfigDirPath(); 191 } 192 193 196 public String getConfigURL(String configName) { 197 String configURI = instanceEnvironment.getConfigFilePath(); 198 199 return configURI; 201 } 206 207 212 public String getServerConfigURL() { 213 return instanceEnvironment.getConfigFilePath(); 214 } 215 216 219 public InitialContext getInitialContext() { 220 NamingManager mgr = Switch.getSwitch().getNamingManager(); 222 if (mgr == null) { 223 return null; 224 } 225 return (InitialContext )(mgr.getInitialContext()); 226 } 227 228 231 private boolean isWindows() { 232 return (File.separatorChar == '\\'); 233 } 234 235 240 public Server getConfigBean() throws ConfigException { 241 if (server != null) { 242 return server; 243 } 244 245 if (configContext != null) { 247 server = ServerBeansFactory.getServerBean(configContext); 248 } else { 249 String msg = localStrings.getString( 251 "serverContext.config_context_is_null"); 252 throw new ConfigException(msg); 253 } 254 return this.server; 255 } 256 257 262 public ConfigContext getConfigContext() { 263 return this.configContext; 264 } 265 266 274 public void setConfigContext(ConfigContext config) { 275 this.configContext = config; 276 } 277 278 284 public ClassLoader getCommonClassLoader() { 285 return this.commonClassLoader; 286 } 287 288 294 protected void setCommonClassLoader(ClassLoader cl) { 295 this.commonClassLoader = cl; 296 } 297 298 303 public ClassLoader getSharedClassLoader() { 304 return this.sharedClassLoader; 305 } 306 307 313 protected void setSharedClassLoader(ClassLoader cl) { 314 this.sharedClassLoader = cl; 315 } 316 317 322 public ClassLoader getLifecycleParentClassLoader() { 323 return this.lifeCycleClassLoader; 324 } 325 326 331 protected void setLifecycleParentClassLoader(ClassLoader cl) { 332 this.lifeCycleClassLoader = cl; 333 } 334 335 340 public InstanceEnvironment getInstanceEnvironment() { 341 if (this.instanceEnvironment == null) { 342 this.instanceEnvironment = 343 new InstanceEnvironment(this.instanceName); 344 } 345 return this.instanceEnvironment; 346 } 347 348 353 void setInstanceEnvironment(InstanceEnvironment instanceEnv) { 354 this.instanceEnvironment = instanceEnv; 355 } 356 357 362 public InvocationManager getInvocationManager() { 363 return Switch.getSwitch().getInvocationManager(); 364 } 365 366 371 public String getDefaultDomainName() { 372 return DEFAULT_DOMAIN_NAME; 373 } 374 379 public MonitoringRegistry getMonitoringRegistry() { 380 382 final String REG_IMPL_CLASS = 383 "com.sun.enterprise.admin.monitor.registry.spi.MonitoringRegistrationHelper"; 384 final String METHOD = "getInstance"; 385 try { 386 final Class c = Class.forName(REG_IMPL_CLASS); 387 final java.lang.reflect.Method m = c.getMethod(METHOD, (Class []) null); 388 final MonitoringRegistry r = (MonitoringRegistry) m.invoke(c, (Object []) null); 389 return r; 390 } 391 catch(Throwable t) { 392 throw new RuntimeException (t); 393 } 394 } 395 } 396 | Popular Tags |