类的load过程
在Catalina中
public static void main(String args[]) {
(new Catalina()).process(args);
}
1.public class Catalina extends Embedded
2.public class Embedded extends StandardService implements Lifecycle
2.1 public class StandardService implements Lifecycle, Service, MBeanRegistration
2.2 public interface Lifecycle
2.3 public Embedded(Logger logger, Realm realm) {
super();
setLogger(logger);
setRealm(realm);
setSecurityProtection();
}
3.1 public interface Lifecycle
3.2 public interface Service
3.3 abstract public interface javax.management.MBeanRegistration extends java.lang.Object
3.4 public void setLogger(Logger logger) {
Logger oldLogger = this.logger;
this.logger = logger;
support.firePropertyChange("logger", oldLogger, this.logger);
}
3.4 public void setRealm(Realm realm) {
Realm oldRealm = this.realm;
this.realm = realm;
support.firePropertyChange("realm", oldRealm, this.realm);
}
3.5 protected void setSecurityProtection(){
SecurityConfig securityConfig = SecurityConfig.newInstance();
securityConfig.setPackageDefinition();
securityConfig.setPackageAccess();
}
4.1 protected PropertyChangeSupport support = new PropertyChangeSupport(this);
4.2 protected PropertyChangeSupport support = new PropertyChangeSupport(this);
4.3 public final class SecurityConfig
初始化
方法调用
在catalina
public static void main(String args[]) {
(new Catalina()).process(args);
}
public void process(String args[]) {
setAwait(true);
setCatalinaHome();
setCatalinaBase();
try {
if (arguments(args)) {
if (starting) {
load(args);
start();
} else if (stopping) {
stopServer();
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
public void setAwait(boolean b) {
await = b;
}
类的load过程
在Catalina中
public static void main(String args[]) {
(new Catalina()).process(args);
}
1.public class Catalina extends Embedded
2.public class Embedded extends StandardService implements Lifecycle
2.1 public class StandardService implements Lifecycle, Service, MBeanRegistration
2.2 public interface Lifecycle
2.3 public Embedded(Logger logger, Realm realm) {
super();
setLogger(logger);
setRealm(realm);
setSecurityProtection();
}
3.1 public interface Lifecycle
3.2 public interface Service
3.3 abstract public interface javax.management.MBeanRegistration extends java.lang.Object
3.4 public void setLogger(Logger logger) {
Logger oldLogger = this.logger;
this.logger = logger;
support.firePropertyChange("logger", oldLogger, this.logger);
}
3.4 public void setRealm(Realm realm) {
Realm oldRealm = this.realm;
this.realm = realm;
support.firePropertyChange("realm", oldRealm, this.realm);
}
3.5 protected void setSecurityProtection(){
SecurityConfig securityConfig = SecurityConfig.newInstance();
securityConfig.setPackageDefinition();
securityConfig.setPackageAccess();
}
4.1 protected PropertyChangeSupport support = new PropertyChangeSupport(this);
4.2 protected PropertyChangeSupport support = new PropertyChangeSupport(this);
4.3 public final class SecurityConfig
初始化
方法调用
在catalina
public static void main(String args[]) {
(new Catalina()).process(args);
}
public void process(String args[]) {
setAwait(true);
setCatalinaHome();
setCatalinaBase();
try {
if (arguments(args)) {
if (starting) {
load(args);
start();
} else if (stopping) {
stopServer();
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
public void setAwait(boolean b) {
await = b;
}
public void setCatalinaHome() {
initDirs();
}
protected void initDirs() {
String catalinaHome = System.getProperty("catalina.home");
if (catalinaHome == null) {
// Backwards compatibility patch for J2EE RI 1.3
String j2eeHome = System.getProperty("com.sun.enterprise.home");
if (j2eeHome != null) {
catalinaHome=System.getProperty("com.sun.enterprise.home");
} else if (System.getProperty("catalina.base") != null) {
catalinaHome = System.getProperty("catalina.base");
} else {
// Use IntrospectionUtils and guess the dir
catalinaHome = IntrospectionUtils.guessInstall
("catalina.home", "catalina.base", "catalina.jar");
if (catalinaHome == null) {
catalinaHome = IntrospectionUtils.guessInstall
("tomcat.install", "catalina.home", "tomcat.jar");
}
}
}
if (catalinaHome != null) {
File home = new File(catalinaHome);
if (!home.isAbsolute()) {
try {
catalinaHome = home.getCanonicalPath();
} catch (IOException e) {
catalinaHome = home.getAbsolutePath();
}
}
System.setProperty("catalina.home", catalinaHome);
}
if (System.getProperty("catalina.base") == null) {
System.setProperty("catalina.base",
System.getProperty("catalina.home"));
} else {
String catalinaBase = System.getProperty("catalina.base");
File base = new File(catalinaBase);
if (!base.isAbsolute()) {
try {
catalinaBase = base.getCanonicalPath();
} catch (IOException e) {
catalinaBase = base.getAbsolutePath();
}
}
System.setProperty("catalina.base", catalinaBase);
}
}
protected boolean arguments(String args[]) {
boolean isConfig = false;
if (args.length < 1) {
usage();
return (false);
}
for (int i = 0; i < args.length; i++) {
if (isConfig) {
configFile = args[i];
isConfig = false;
} else if (args[i].equals("-config")) {
isConfig = true;
} else if (args[i].equals("-debug")) {
debug = 1;
} else if (args[i].equals("-nonaming")) {
setUseNaming( false );
} else if (args[i].equals("-help")) {
usage();
return (false);
} else if (args[i].equals("start")) {
starting = true;
stopping = false;
} else if (args[i].equals("stop")) {
starting = false;
stopping = true;
} else {
usage();
return (false);
}
}
return (true);
}
public void load(String args[]) {
setCatalinaHome();
setCatalinaBase();
try {
if (arguments(args))
load();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
public void load() {
initDirs();
initNaming();
Digester digester = createStartDigester();
long t1 = System.currentTimeMillis();
Exception ex = null;
InputSource inputSource = null;
InputStream inputStream = null;
try {
File file = configFile();
inputStream = new FileInputStream(file);
inputSource = new InputSource("file://" + file.getAbsolutePath());
} catch (Exception e) {
;
}
if (inputStream == null) {
try {
inputStream = getClass().getClassLoader()
.getResourceAsStream(getConfigFile());
inputSource = new InputSource
(getClass().getClassLoader()
.getResource(getConfigFile()).toString());
} catch (Exception e) {
;
}
}
if (inputStream == null) {
System.out.println("Can't load server.xml");
return;
}
try {
inputSource.setByteStream(inputStream);
digester.push(this);
digester.parse(inputSource);
inputStream.close();
} catch (Exception e) {
System.out.println("Catalina.start: " + e);
e.printStackTrace(System.out);
return;
}
SystemLogHandler systemlog = new SystemLogHandler(System.out);
System.setOut(systemlog);
System.setErr(systemlog);
if (server instanceof Lifecycle) {
try {
server.initialize();
} catch (LifecycleException e) {
log.error("Catalina.start", e);
}
}
long t2 = System.currentTimeMillis();
log.info("Initialization processed in " + (t2 - t1) + " ms");
}
protected void initNaming() {
// Setting additional variables
if (!useNaming) {
log.info( "Catalina naming disabled");
System.setProperty("catalina.useNaming", "false");
} else {
System.setProperty("catalina.useNaming", "true");
String value = "org.apache.naming";
String oldValue =
System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
if (oldValue != null) {
value = value + ":" + oldValue;
}
System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
if( log.isDebugEnabled() )
log.debug("Setting naming prefix=" + value);
value = System.getProperty
(javax.naming.Context.INITIAL_CONTEXT_FACTORY);
if (value == null) {
System.setProperty
(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"org.apache.naming.java.javaURLContextFactory");
} else {
log.debug( "INITIAL_CONTEXT_FACTORY alread set " + value );
}
}
}
protected Digester createStartDigester() {
long t1=System.currentTimeMillis();
// Initialize the digester
Digester digester = new CatalinaDigester();
digester.setValidating(false);
digester.setClassLoader(StandardServer.class.getClassLoader());
// Configure the actions we will be using
digester.addObjectCreate("Server",
"org.apache.catalina.core.StandardServer",
"className");
digester.addSetProperties("Server");
digester.addSetNext("Server",
"setServer",
"org.apache.catalina.Server");
digester.addObjectCreate("Server/GlobalNamingResources",
"org.apache.catalina.deploy.NamingResources");
digester.addSetProperties("Server/GlobalNamingResources");
digester.addSetNext("Server/GlobalNamingResources",
"setGlobalNamingResources",
"org.apache.catalina.deploy.NamingResources");
digester.addObjectCreate("Server/Listener",
null, // MUST be specified in the element
"className");
digester.addSetProperties("Server/Listener");
digester.addSetNext("Server/Listener",
"addLifecycleListener",
"org.apache.catalina.LifecycleListener");
digester.addObjectCreate("Server/Service",
"org.apache.catalina.core.StandardService",
"className");
digester.addSetProperties("Server/Service");
digester.addSetNext("Server/Service",
"addService",
"org.apache.catalina.Service");
digester.addObjectCreate("Server/Service/Listener",
null, // MUST be specified in the element
"className");
digester.addSetProperties("Server/Service/Listener");
digester.addSetNext("Server/Service/Listener",
"addLifecycleListener",
"org.apache.catalina.LifecycleListener");
digester.addObjectCreate("Server/Service/Connector",
"org.apache.coyote.tomcat5.CoyoteConnector",
"className");
digester.addRule("Server/Service/Connector",
new SetAllPropertiesRule());
digester.addSetNext("Server/Service/Connector",
"addConnector",
"org.apache.catalina.Connector");
digester.addObjectCreate("Server/Service/Connector/Factory",
"org.apache.coyote.tomcat5.CoyoteServerSocketFactory",
"className");
digester.addSetProperties("Server/Service/Connector/Factory");
digester.addSetNext("Server/Service/Connector/Factory",
"setFactory",
"org.apache.catalina.net.ServerSocketFactory");
digester.addObjectCreate("Server/Service/Connector/Listener",
null, // MUST be specified in the element
"className");
digester.addSetProperties("Server/Service/Connector/Listener");
digester.addSetNext("Server/Service/Connector/Listener",
"addLifecycleListener",
"org.apache.catalina.LifecycleListener");
// Add RuleSets for nested elements
digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));
digester.addRuleSet(new EngineRuleSet("Server/Service/"));
digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Default"));
digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/DefaultContext/"));
digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/Default"));
digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/DefaultContext/"));
digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));
digester.addRuleSet(new ClusterRuleSet("Server/Service/Engine/Host/Cluster/"));
digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));
// When the 'engine' is found, set the parentClassLoader.
digester.addRule("Server/Service/Engine",
new SetParentClassLoaderRule(parentClassLoader));
long t2=System.currentTimeMillis();
log.debug("Digester for server.xml created " + ( t2-t1 ));
return (digester);
}