glenn 2003/10/20 17:18:25 Modified: webapps/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.4 +2 -2 jakarta-tomcat-catalina/webapps/docs/config/defaultcontext.xml Index: defaultcontext.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/config/defaultcontext.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- defaultcontext.xml 15 Jan 2003 03:40:44 -0000 1.3 +++ defaultcontext.xml 21 Oct 2003 00:18:25 -0000 1.4 @@ -115,7 +115,6 @@ <section name="Nested Components"> -<!-- <p>You can nest at most one instance of the following utility components by nesting a corresponding element inside your <strong>DefaultContext</strong> element:</p> @@ -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,8 +143,8 @@ 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> 1.4 +9 -6 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java Index: ContextRuleSet.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/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 2 Sep 2003 21:22:00 -0000 1.3 +++ ContextRuleSet.java 21 Oct 2003 00:18:25 -0000 1.4 @@ -302,8 +302,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.97 +14 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java Index: StandardContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v retrieving revision 1.96 retrieving revision 1.97 diff -u -r1.96 -r1.97 --- StandardContext.java 15 Oct 2003 17:24:16 -0000 1.96 +++ StandardContext.java 21 Oct 2003 00:18:25 -0000 1.97 @@ -3965,6 +3965,19 @@ 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); + } + } + } + // Look for a realm - that may have been configured earlier. // If the realm is added after context - it'll set itself. if( realm == null ) { 1.7 +70 -8 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardDefaultContext.java Index: StandardDefaultContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardDefaultContext.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- StandardDefaultContext.java 2 Sep 2003 21:22:04 -0000 1.6 +++ StandardDefaultContext.java 21 Oct 2003 00:18:25 -0000 1.7 @@ -66,9 +66,12 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.lang.reflect.Constructor; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; +import java.util.Vector; import javax.management.MBeanRegistration; import javax.management.MBeanServer; @@ -91,6 +94,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.mbeans.MBeanUtils; import org.apache.catalina.util.StringManager; import org.apache.commons.modeler.ManagedBean; @@ -253,6 +257,12 @@ /** + * The Context LifecycleListener's + */ + protected Vector lifecycle = new Vector(); + + + /** * The Loader implementation with which this Container is associated. */ protected Loader loader = null; @@ -495,6 +505,19 @@ } + // ------------------------------------------------------ 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 /** @@ -1371,20 +1394,59 @@ /** - * 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()); ((StandardContext)context).setSwallowOutput(getSwallowOutput()); 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).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.22 +17 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardEngine.java Index: StandardEngine.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardEngine.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- StandardEngine.java 23 May 2003 10:54:35 -0000 1.21 +++ StandardEngine.java 21 Oct 2003 00:18:25 -0000 1.22 @@ -319,6 +319,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.26 +18 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java Index: StandardHost.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- StandardHost.java 7 Oct 2003 14:25:24 -0000 1.25 +++ StandardHost.java 21 Oct 2003 00:18:25 -0000 1.26 @@ -562,6 +562,23 @@ /** + * 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]