Author: markt
Date: Wed Sep  6 18:51:28 2006
New Revision: 440936

URL: http://svn.apache.org/viewvc?view=rev&rev=440936
Log:
Better fix for bug 39704. Port Remy's changes from TC6 but make new behaviour 
configurable with old behaviour as default.

Modified:
    
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappLoader.java
    
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml
    tomcat/container/tc5.5.x/webapps/docs/config/loader.xml
    tomcat/container/tc5.5.x/webapps/docs/developers.xml

Modified: 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappLoader.java
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappLoader.java?view=diff&rev=440936&r1=440935&r2=440936
==============================================================================
--- 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappLoader.java
 (original)
+++ 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappLoader.java
 Wed Sep  6 18:51:28 2006
@@ -152,6 +152,12 @@
 
 
     /**
+     * If not specified, should the system class loader be used as the parent.
+     */
+    private boolean useSystemClassLoaderAsParent = true;
+
+
+    /**
      * The Java class name of the ClassLoader implementation to be used.
      * This class should extend WebappClassLoader, otherwise, a different 
      * loader implementation must be used.
@@ -319,6 +325,29 @@
 
 
     /**
+     * Return the useSystemClassLoaderAsParent flag for this Loader.
+     */
+    public boolean getUseSystemClassLoaderAsParent() {
+        
+        return (this.useSystemClassLoaderAsParent);
+        
+    }
+    
+    /**
+     * Set the useSystemClassLoaderAsParent flag for this Loader.
+     * 
+     * @param useSystemClassLoaderAsParent The useSystemClassLoaderAsParent
+     *                                     flag.
+     */
+    public void setUseSystemClassLoaderAsParent(
+            boolean useSystemClassLoaderAsParent) {
+        
+        this.useSystemClassLoaderAsParent = useSystemClassLoaderAsParent;
+        
+    }
+    
+    
+    /**
      * Return the reloadable flag for this Loader.
      */
     public boolean getReloadable() {
@@ -554,6 +583,7 @@
 
     private boolean initialized=false;
 
+
     public void init() {
         initialized=true;
 
@@ -770,7 +800,11 @@
         WebappClassLoader classLoader = null;
 
         if (parentClassLoader == null) {
-            parentClassLoader = Thread.currentThread().getContextClassLoader();
+            if (useSystemClassLoaderAsParent) {
+                parentClassLoader = ClassLoader.getSystemClassLoader();
+            } else {
+                parentClassLoader = container.getParentClassLoader();
+            }
         }
         Class[] argTypes = { ClassLoader.class };
         Object[] args = { parentClassLoader };

Modified: 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java?view=diff&rev=440936&r1=440935&r2=440936
==============================================================================
--- 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java
 (original)
+++ 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java
 Wed Sep  6 18:51:28 2006
@@ -18,14 +18,8 @@
 package org.apache.catalina.startup;
 
 
-import java.lang.reflect.Constructor;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.Loader;
 import org.apache.tomcat.util.digester.Digester;
-import org.apache.tomcat.util.digester.Rule;
 import org.apache.tomcat.util.digester.RuleSetBase;
-import org.xml.sax.Attributes;
 
 
 /**
@@ -144,10 +138,9 @@
                             "addLifecycleListener",
                             "org.apache.catalina.LifecycleListener");
 
-        digester.addRule(prefix + "Context/Loader",
-                         new CreateLoaderRule
-                             ("org.apache.catalina.loader.WebappLoader",
-                              "className"));
+        digester.addObjectCreate(prefix + "Context/Loader",
+                            "org.apache.catalina.loader.WebappLoader",
+                            "className");
         digester.addSetProperties(prefix + "Context/Loader");
         digester.addSetNext(prefix + "Context/Loader",
                             "setLoader",
@@ -217,76 +210,5 @@
                                "addWrapperListener", 0);
 
     }
-
-}
-
-
-// ----------------------------------------------------------- Private Classes
-
-
-/**
- * Rule that creates a new <code>Loader</code> instance, with the parent
- * class loader associated with the top object on the stack (which must be
- * a <code>Container</code>), and pushes it on to the stack.
- */
-
-final class CreateLoaderRule extends Rule {
-
-    public CreateLoaderRule(String loaderClass, String attributeName) {
-
-        this.loaderClass = loaderClass;
-        this.attributeName = attributeName;
-
-    }
-
-    private String attributeName;
-
-    private String loaderClass;
-
-    public void begin(String namespace, String name, Attributes attributes)
-        throws Exception {
-
-        // Look up the required parent class loader
-        ClassLoader parentClassLoader = null;
-        Object ojb = digester.peek();
-        if (ojb instanceof Container) {
-            parentClassLoader = ((Container)ojb).getParentClassLoader();
-        }
-
-        // Bugzilla 36852: 
http://issues.apache.org/bugzilla/show_bug.cgi?id=36852
-        if((ojb instanceof org.apache.catalina.Context) &&
-           (((org.apache.catalina.Context) ojb).getPrivileged())) {
-            parentClassLoader = ojb.getClass().getClassLoader();
-        }
-
-        // Instantiate a new Loader implementation object
-        String className = loaderClass;
-        if (attributeName != null) {
-            String value = attributes.getValue(attributeName);
-            if (value != null)
-                className = value;
-        }
-        Class clazz = Class.forName(className);
-        Class types[] = { ClassLoader.class };
-        Object args[] = { parentClassLoader };
-        Constructor constructor = clazz.getDeclaredConstructor(types);
-        Loader loader = (Loader) constructor.newInstance(args);
-
-        // Push the new loader onto the stack
-        digester.push(loader);
-        if (digester.getLogger().isDebugEnabled())
-            digester.getLogger().debug("new " + loader.getClass().getName());
-
-    }
-
-    public void end(String namespace, String name)
-        throws Exception {
-
-        Loader loader = (Loader) digester.pop();
-        if (digester.getLogger().isDebugEnabled())
-            digester.getLogger().debug("pop " + loader.getClass().getName());
-
-    }
-
 
 }

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?view=diff&rev=440936&r1=440935&r2=440936
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Wed Sep  6 18:51:28 2006
@@ -28,7 +28,8 @@
       </fix>
       <fix>
         <bug>39704</bug>: The use of custom classloaders failed when the 
context
-        was specified in server.xml (markt)
+        was specified in server.xml. Correction of the fault will require 
setting
+        the new loader attribute useSystemClassLoaderAsParent to false.(markt)
       </fix>
     </changelog>
   </subsection> 

Modified: tomcat/container/tc5.5.x/webapps/docs/config/loader.xml
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/config/loader.xml?view=diff&rev=440936&r1=440935&r2=440936
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/config/loader.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/config/loader.xml Wed Sep  6 18:51:28 
2006
@@ -119,6 +119,17 @@
         <code>org.apache.catalina.loader.WebappClassLoader</code>.</p>
       </attribute>
 
+      <attribute name="useSystemClassLoaderAsParent" required="false">
+        <p>If no parent classloader is specified, should the system
+        classloader be used? The default of <code>true</code> mantains
+        backwards compatibility with previous releases however most
+        users will want to set this to <code>false</code> to obtain
+        the parent classloader from the associated container.</p>
+        <p>This attribute will not be present in Tomcat 6 where the
+        Loader API has changed and the parent class loader is always
+        obtained from the associated container.</p>
+      </attribute>
+
     </attributes>
 
   </subsection>

Modified: tomcat/container/tc5.5.x/webapps/docs/developers.xml
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/developers.xml?view=diff&rev=440936&r1=440935&r2=440936
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/developers.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/developers.xml Wed Sep  6 18:51:28 
2006
@@ -39,6 +39,7 @@
       <li>Jean-Francois Arcand (jfarcand): Catalina</li>
       <li>Jean-Frederic Clere (jfclere): Connectors</li>
       <li>Kin-Man Chung (kinman): Jasper</li>
+      <li>Mark Thomas (markt): CGI, SSI, WebDAV, bug fixing</li>
       <li>Mladen Turk (mturk): Connectors</li>
       <li>Peter Rossbach (pero): Catalina, Clustering, JMX</li>
       <li>Rainer Jung (rjung): Catalina, Clustering, Connectors</li>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to