glenn 2003/10/20 17:22:57
Modified: webapps/tomcat-docs/config defaultcontext.xml
catalina/src/share/org/apache/catalina/startup
ContextRuleSet.java
catalina/src/share/org/apache/catalina/core
StandardContext.java StandardDefaultContext.java
StandardEngine.java StandardHost.java
Log:
The DefaultContext docs listed support for a Listener but the
code to suppor this was not implemented.
Added support for nesting a Context Listener within a
DefaultContext.
Added support for nesting a Webapp Loader within a
DefaultContext.
The importDefaultContext() had to be split into two
methods. The installDefaultContext() method was added.
This is due to sequencing issues when instantiating
a Context. Some things needed to occur earlier than
when the importDefaultContext() is called. And some
things needed to occur during the normal
importDefaultContext().
No interfaces in org.apache.catalina were changed,
though they could be in Tomcat 5 since there has
not been a final release.
Revision Changes Path
1.6 +2 -2 jakarta-tomcat-4.0/webapps/tomcat-docs/config/defaultcontext.xml
Index: defaultcontext.xml
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/config/defaultcontext.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- defaultcontext.xml 12 Jan 2003 17:26:48 -0000 1.5
+++ defaultcontext.xml 21 Oct 2003 00:22:57 -0000 1.6
@@ -113,7 +113,6 @@
</section>
-<!--
<section name="Nested Components">
<p>You can nest at most one instance of the following utility components
@@ -124,6 +123,7 @@
Configure the web application class loader that will be used to load
servlet and bean classes for each web application. Normally, the
default configuration of the class loader will be sufficient.</li>
+<!--
<li><a href="logger.html"><strong>Logger</strong></a> -
Configure a logger that will receive
and process all log messages for each <strong>Context</strong>. This
@@ -143,10 +143,10 @@
Configure the resource manager that will be used to access the static
resources associated with each web application. Normally, the
default configuration of the resource manager will be sufficient.</li>
+-->
</ul>
</section>
--->
<section name="Special Features">
1.4 +9 -6
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java
Index: ContextRuleSet.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContextRuleSet.java 8 Nov 2001 21:03:15 -0000 1.3
+++ ContextRuleSet.java 21 Oct 2003 00:22:57 -0000 1.4
@@ -303,8 +303,11 @@
public void begin(Attributes attributes) throws Exception {
// Look up the required parent class loader
- Container container = (Container) digester.peek();
- ClassLoader parentClassLoader = container.getParentClassLoader();
+ ClassLoader parentClassLoader = null;
+ Object ojb = digester.peek();
+ if (ojb instanceof Container) {
+ parentClassLoader = ((Container)ojb).getParentClassLoader();
+ }
// Instantiate a new Loader implementation object
String className = loaderClass;
1.121 +18 -4
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java
Index: StandardContext.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -r1.120 -r1.121
--- StandardContext.java 5 Aug 2003 09:32:14 -0000 1.120
+++ StandardContext.java 21 Oct 2003 00:22:57 -0000 1.121
@@ -106,6 +106,7 @@
import org.apache.catalina.Container;
import org.apache.catalina.ContainerListener;
import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.Globals;
import org.apache.catalina.HttpRequest;
@@ -3473,6 +3474,19 @@
if (!resourcesStart())
ok = false;
}
+
+ // Install DefaultContext configuration
+ if (!getOverride()) {
+ Container host = getParent();
+ if (host instanceof StandardHost) {
+ ((StandardHost)host).installDefaultContext(this);
+ Container engine = host.getParent();
+ if( engine instanceof StandardEngine ) {
+ ((StandardEngine)engine).installDefaultContext(this);
+ }
+ }
+ }
+
if (getLoader() == null) { // (2) Required by Manager
if (getPrivileged()) {
if (debug >= 1)
1.10 +68 -7
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardDefaultContext.java
Index: StandardDefaultContext.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardDefaultContext.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StandardDefaultContext.java 13 Nov 2002 14:16:24 -0000 1.9
+++ StandardDefaultContext.java 21 Oct 2003 00:22:57 -0000 1.10
@@ -66,10 +66,12 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
+import java.lang.reflect.Constructor;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.Vector;
import javax.naming.directory.DirContext;
import org.apache.naming.ContextAccessController;
import org.apache.catalina.Container;
@@ -91,6 +93,7 @@
import org.apache.catalina.deploy.ContextResourceLink;
import org.apache.catalina.deploy.NamingResources;
import org.apache.catalina.deploy.ResourceParams;
+import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.util.StringManager;
/**
@@ -261,6 +264,11 @@
/**
+ * The Context LifecycleListener's
+ */
+ protected Vector lifecycle = new Vector();
+
+ /**
* The string manager for this package.
*/
protected static StringManager sm =
@@ -491,6 +499,18 @@
}
+ // ------------------------------------------------------ Lifecycle Methods
+
+
+ /**
+ * Add a lifecycle event listener to this component.
+ *
+ * @param listener The listener to add
+ */
+ public void addLifecycleListener(LifecycleListener listener) {
+ lifecycle.add(listener);
+ }
+
// ------------------------------------------------------ Public Properties
/**
@@ -1342,12 +1362,12 @@
/**
- * Import the configuration from the DefaultContext into
- * current Context.
+ * Install the StandardContext portion of the DefaultContext
+ * configuration into current Context.
*
* @param context current web application context
*/
- public void importDefaultContext(Context context) {
+ public void installDefaultContext(Context context) {
if (context instanceof StandardContext) {
((StandardContext)context).setUseNaming(isUseNaming());
@@ -1355,7 +1375,48 @@
if (!contexts.containsKey(context)) {
((StandardContext) context).addLifecycleListener(this);
}
+ Enumeration lifecycleListeners = lifecycle.elements();
+ while (lifecycleListeners.hasMoreElements()) {
+ ((StandardContext)context).addLifecycleListener(
+ (LifecycleListener)lifecycleListeners.nextElement());
+ }
}
+
+ if (!context.getPrivileged() && loader != null) {
+ ClassLoader parentClassLoader =
context.getParent().getParentClassLoader();
+ Class clazz = loader.getClass();
+ Class types[] = { ClassLoader.class };
+ Object args[] = { parentClassLoader };
+ try {
+ Constructor constructor = clazz.getDeclaredConstructor(types);
+ Loader context_loader = (Loader) constructor.newInstance(args);
+ context_loader.setDelegate(loader.getDelegate());
+ context_loader.setReloadable(loader.getReloadable());
+ if (loader instanceof WebappLoader) {
+ ((WebappLoader)context_loader).setCheckInterval
+ (((WebappLoader)loader).getCheckInterval());
+ ((WebappLoader)context_loader).setDebug
+ (((WebappLoader)loader).getDebug());
+ ((WebappLoader)context_loader).setLoaderClass
+ (((WebappLoader)loader).getLoaderClass());
+ }
+ context.setLoader(context_loader);
+ } catch(Exception e) {
+ throw new IllegalArgumentException
+ ("DefaultContext custom Loader install failed, Exception: " +
+ e.getMessage());
+ }
+ }
+
+ }
+
+ /**
+ * Import the configuration from the DefaultContext into
+ * current Context.
+ *
+ * @param context current web application context
+ */
+ public void importDefaultContext(Context context) {
context.setCookies(getCookies());
context.setCrossContext(getCrossContext());
1.16 +20 -4
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngine.java
Index: StandardEngine.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngine.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- StandardEngine.java 2 May 2002 22:14:45 -0000 1.15
+++ StandardEngine.java 21 Oct 2003 00:22:57 -0000 1.16
@@ -279,6 +279,22 @@
/**
+ * Install the StandardContext portion of the DefaultContext
+ * configuration into current Context.
+ *
+ * @param context current web application context
+ */
+ public void installDefaultContext(Context context) {
+
+ if (defaultContext != null &&
+ defaultContext instanceof StandardDefaultContext) {
+
+ ((StandardDefaultContext)defaultContext).installDefaultContext(context);
+ }
+ }
+
+
+ /**
* Import the DefaultContext config into a web application context.
*
* @param context web application context to import default context
1.31 +20 -4
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java
Index: StandardHost.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- StandardHost.java 10 Jan 2003 15:52:18 -0000 1.30
+++ StandardHost.java 21 Oct 2003 00:22:57 -0000 1.31
@@ -525,6 +525,22 @@
/**
+ * Install the StandardContext portion of the DefaultContext
+ * configuration into current Context.
+ *
+ * @param context current web application context
+ */
+ public void installDefaultContext(Context context) {
+
+ if (defaultContext != null &&
+ defaultContext instanceof StandardDefaultContext) {
+
+ ((StandardDefaultContext)defaultContext).installDefaultContext(context);
+ }
+
+ }
+
+ /**
* Import the DefaultContext config into a web application context.
*
* @param context web application context to import default context
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]