Author: markt
Date: Wed Jul  4 21:20:46 2012
New Revision: 1357412

URL: http://svn.apache.org/viewvc?rev=1357412&view=rev
Log:
Move Resources and Loader from Container to Context

Modified:
    tomcat/trunk/java/org/apache/catalina/Container.java
    tomcat/trunk/java/org/apache/catalina/Context.java
    tomcat/trunk/java/org/apache/catalina/Loader.java
    tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
    tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java
    tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java
    tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java
    tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
    tomcat/trunk/java/org/apache/catalina/session/FileStore.java
    tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java
    tomcat/trunk/java/org/apache/catalina/session/StandardManager.java
    tomcat/trunk/java/org/apache/catalina/util/Introspection.java
    tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java
    
tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java

Modified: tomcat/trunk/java/org/apache/catalina/Container.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Container.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Container.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Container.java Wed Jul  4 21:20:46 
2012
@@ -20,7 +20,6 @@ import java.beans.PropertyChangeListener
 import java.io.File;
 
 import javax.management.ObjectName;
-import javax.naming.directory.DirContext;
 
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
@@ -115,22 +114,6 @@ public interface Container extends Lifec
     // ------------------------------------------------------------- Properties
 
     /**
-     * Return the Loader with which this Container is associated.  If there is
-     * no associated Loader, return the Loader associated with our parent
-     * Container (if any); otherwise, return <code>null</code>.
-     */
-    public Loader getLoader();
-
-
-    /**
-     * Set the Loader with which this Container is associated.
-     *
-     * @param loader The newly associated loader
-     */
-    public void setLoader(Loader loader);
-
-
-    /**
      * Return the Logger with which this Container is associated.  If there is
      * no associated Logger, return the Logger associated with our parent
      * Container (if any); otherwise return <code>null</code>.
@@ -300,22 +283,6 @@ public interface Container extends Lifec
     public void setRealm(Realm realm);
 
 
-    /**
-     * Return the Resources with which this Container is associated.  If there
-     * is no associated Resources object, return the Resources associated with
-     * our parent Container (if any); otherwise return <code>null</code>.
-     */
-    public DirContext getResources();
-
-
-    /**
-     * Set the Resources object with which this Container is associated.
-     *
-     * @param resources The newly associated Resources
-     */
-    public void setResources(DirContext resources);
-
-
     // --------------------------------------------------------- Public Methods
 
 

Modified: tomcat/trunk/java/org/apache/catalina/Context.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Context.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Context.java Wed Jul  4 21:20:46 2012
@@ -20,6 +20,7 @@ import java.net.URL;
 import java.util.Locale;
 import java.util.Set;
 
+import javax.naming.directory.DirContext;
 import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRegistration;
@@ -1387,5 +1388,29 @@ public interface Context extends Contain
      * part of a redirect response.
      */
     public boolean getSendRedirectBody();
+
+    /**
+     * Return the Loader with which this Context is associated.
+     */
+    public Loader getLoader();
+
+    /**
+     * Set the Loader with which this Context is associated.
+     *
+     * @param loader The newly associated loader
+     */
+    public void setLoader(Loader loader);
+
+    /**
+     * Return the Resources with which this Context is associated.
+     */
+    public DirContext getResources();
+
+    /**
+     * Set the Resources object with which this Context is associated.
+     *
+     * @param resources The newly associated Resources
+     */
+    public void setResources(DirContext resources);
 }
 

Modified: tomcat/trunk/java/org/apache/catalina/Loader.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Loader.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Loader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Loader.java Wed Jul  4 21:20:46 2012
@@ -74,17 +74,17 @@ public interface Loader {
 
 
     /**
-     * Return the Container with which this Loader has been associated.
+     * Return the Context with which this Loader has been associated.
      */
-    public Container getContainer();
+    public Context getContext();
 
 
     /**
-     * Set the Container with which this Loader has been associated.
+     * Set the Context with which this Loader has been associated.
      *
-     * @param container The associated Container
+     * @param context The associated Context
      */
-    public void setContainer(Container container);
+    public void setContext(Context context);
 
 
     /**

Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Wed Jul  4 
21:20:46 2012
@@ -24,7 +24,6 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.BlockingQueue;
@@ -41,7 +40,6 @@ import java.util.concurrent.locks.ReadWr
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import javax.management.ObjectName;
-import javax.naming.directory.DirContext;
 
 import org.apache.catalina.AccessLog;
 import org.apache.catalina.Cluster;
@@ -55,7 +53,6 @@ import org.apache.catalina.Host;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleState;
-import org.apache.catalina.Loader;
 import org.apache.catalina.Manager;
 import org.apache.catalina.Pipeline;
 import org.apache.catalina.Realm;
@@ -67,7 +64,6 @@ import org.apache.catalina.util.ContextN
 import org.apache.catalina.util.LifecycleMBeanBase;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
-import org.apache.naming.resources.ProxyDirContext;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -188,12 +184,6 @@ public abstract class ContainerBase exte
             new CopyOnWriteArrayList<ContainerListener>();
 
     /**
-     * The Loader implementation with which this Container is associated.
-     */
-    protected Loader loader = null;
-
-
-    /**
      * The Logger implementation with which this Container is associated.
      */
     protected Log logger = null;
@@ -252,11 +242,6 @@ public abstract class ContainerBase exte
      */
     private final ReadWriteLock realmLock = new ReentrantReadWriteLock();
 
-    /**
-     * The resources DirContext object with which this Container is associated.
-     */
-    protected DirContext resources = null;
-
 
     /**
      * The string manager for this package.
@@ -375,65 +360,6 @@ public abstract class ContainerBase exte
 
 
     /**
-     * Return the Loader with which this Container is associated.  If there is
-     * no associated Loader, return the Loader associated with our parent
-     * Container (if any); otherwise, return <code>null</code>.
-     */
-    @Override
-    public Loader getLoader() {
-
-        if (loader != null)
-            return (loader);
-        if (parent != null)
-            return (parent.getLoader());
-        return (null);
-
-    }
-
-
-    /**
-     * Set the Loader with which this Container is associated.
-     *
-     * @param loader The newly associated loader
-     */
-    @Override
-    public synchronized void setLoader(Loader loader) {
-
-        // Change components if necessary
-        Loader oldLoader = this.loader;
-        if (oldLoader == loader)
-            return;
-        this.loader = loader;
-
-        // Stop the old component if necessary
-        if (getState().isAvailable() && (oldLoader != null) &&
-            (oldLoader instanceof Lifecycle)) {
-            try {
-                ((Lifecycle) oldLoader).stop();
-            } catch (LifecycleException e) {
-                log.error("ContainerBase.setLoader: stop: ", e);
-            }
-        }
-
-        // Start the new component if necessary
-        if (loader != null)
-            loader.setContainer(this);
-        if (getState().isAvailable() && (loader != null) &&
-            (loader instanceof Lifecycle)) {
-            try {
-                ((Lifecycle) loader).start();
-            } catch (LifecycleException e) {
-                log.error("ContainerBase.setLoader: start: ", e);
-            }
-        }
-
-        // Report this property change to interested listeners
-        support.firePropertyChange("loader", oldLoader, this.loader);
-
-    }
-
-
-    /**
      * Return the Logger for this Container.
      */
     @Override
@@ -785,50 +711,6 @@ public abstract class ContainerBase exte
     }
 
 
-    /**
-      * Return the resources DirContext object with which this Container is
-      * associated.  If there is no associated resources object, return the
-      * resources associated with our parent Container (if any); otherwise
-      * return <code>null</code>.
-     */
-    @Override
-    public DirContext getResources() {
-        if (resources != null)
-            return (resources);
-        if (parent != null)
-            return (parent.getResources());
-        return (null);
-
-    }
-
-
-    /**
-     * Set the resources DirContext object with which this Container is
-     * associated.
-     *
-     * @param resources The newly associated DirContext
-     */
-    @Override
-    public synchronized void setResources(DirContext resources) {
-        // Called from StandardContext.setResources()
-        //              <- StandardContext.start()
-        //              <- ContainerBase.addChildInternal()
-
-        // Change components if necessary
-        DirContext oldResources = this.resources;
-        if (oldResources == resources)
-            return;
-        Hashtable<String, String> env = new Hashtable<String, String>();
-        if (getParent() != null)
-            env.put(ProxyDirContext.HOST, getParent().getName());
-        env.put(ProxyDirContext.CONTEXT, getName());
-        this.resources = new ProxyDirContext(env, resources);
-        // Report this property change to interested listeners
-        support.firePropertyChange("resources", oldResources, this.resources);
-
-    }
-
-
     // ------------------------------------------------------ Container Methods
 
 
@@ -1054,8 +936,6 @@ public abstract class ContainerBase exte
     protected synchronized void startInternal() throws LifecycleException {
 
         // Start our subordinate components, if any
-        if ((loader != null) && (loader instanceof Lifecycle))
-            ((Lifecycle) loader).start();
         logger = null;
         getLogger();
         if ((manager != null) && (manager instanceof Lifecycle))
@@ -1065,8 +945,6 @@ public abstract class ContainerBase exte
         Realm realm = getRealmInternal();
         if ((realm != null) && (realm instanceof Lifecycle))
             ((Lifecycle) realm).start();
-        if ((resources != null) && (resources instanceof Lifecycle))
-            ((Lifecycle) resources).start();
 
         // Start our child containers, if any
         Container children[] = findChildren();
@@ -1146,9 +1024,6 @@ public abstract class ContainerBase exte
         }
 
         // Stop our subordinate components, if any
-        if ((resources != null) && (resources instanceof Lifecycle)) {
-            ((Lifecycle) resources).stop();
-        }
         Realm realm = getRealmInternal();
         if ((realm != null) && (realm instanceof Lifecycle)) {
             ((Lifecycle) realm).stop();
@@ -1160,9 +1035,6 @@ public abstract class ContainerBase exte
                 ((Lifecycle) manager).getState().isAvailable() ) {
             ((Lifecycle) manager).stop();
         }
-        if ((loader != null) && (loader instanceof Lifecycle)) {
-            ((Lifecycle) loader).stop();
-        }
     }
 
     @Override
@@ -1178,9 +1050,6 @@ public abstract class ContainerBase exte
         if ((cluster != null) && (cluster instanceof Lifecycle)) {
             ((Lifecycle) cluster).destroy();
         }
-        if ((loader != null) && (loader instanceof Lifecycle)) {
-            ((Lifecycle) loader).destroy();
-        }
 
         // Stop the Valves in our pipeline (including the basic), if any
         if (pipeline instanceof Lifecycle) {
@@ -1298,13 +1167,6 @@ public abstract class ContainerBase exte
                 
log.warn(sm.getString("containerBase.backgroundProcess.cluster", cluster), e);
             }
         }
-        if (loader != null) {
-            try {
-                loader.backgroundProcess();
-            } catch (Exception e) {
-                
log.warn(sm.getString("containerBase.backgroundProcess.loader", loader), e);
-            }
-        }
         if (manager != null) {
             try {
                 manager.backgroundProcess();
@@ -1522,34 +1384,37 @@ public abstract class ContainerBase exte
                     // Ignore
                 }
                 if (!threadDone) {
-                    ClassLoader cl =
-                        Thread.currentThread().getContextClassLoader();
-                    Loader loader = getLoader();
-                    if (loader != null) {
-                        cl = loader.getClassLoader();
-                    }
-                    processChildren(ContainerBase.this, cl);
+                    processChildren(ContainerBase.this);
                 }
             }
         }
 
-        protected void processChildren(Container container, ClassLoader cl) {
+        protected void processChildren(Container container) {
+            ClassLoader originalClassLoader = null;
+
             try {
-                if (container.getLoader() != null) {
+                if (container instanceof Context) {
+                    // Ensure background processing for Contexts and Wrappers
+                    // is performed under the web app's class loader
+                    originalClassLoader =
+                            Thread.currentThread().getContextClassLoader();
                     Thread.currentThread().setContextClassLoader
-                        (container.getLoader().getClassLoader());
+                            (((Context) 
container).getLoader().getClassLoader());
                 }
                 container.backgroundProcess();
+                Container[] children = container.findChildren();
+                for (int i = 0; i < children.length; i++) {
+                    if (children[i].getBackgroundProcessorDelay() <= 0) {
+                        processChildren(children[i]);
+                    }
+                }
             } catch (Throwable t) {
                 ExceptionUtils.handleThrowable(t);
                 log.error("Exception invoking periodic operation: ", t);
             } finally {
-                Thread.currentThread().setContextClassLoader(cl);
-            }
-            Container[] children = container.findChildren();
-            for (int i = 0; i < children.length; i++) {
-                if (children[i].getBackgroundProcessorDelay() <= 0) {
-                    processChildren(children[i], cl);
+                if (originalClassLoader != null) {
+                    Thread.currentThread().setContextClassLoader(
+                            originalClassLoader);
                 }
             }
         }

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Wed Jul  
4 21:20:46 2012
@@ -64,7 +64,6 @@ asyncContextImpl.requestEnded=The reques
 containerBase.threadedStartFailed=A child container failed during start
 containerBase.threadedStopFailed=A child container failed during stop
 containerBase.backgroundProcess.cluster=Exception processing cluster {0} 
background process
-containerBase.backgroundProcess.loader=Exception processing loader {0} 
background process
 containerBase.backgroundProcess.manager=Exception processing manager {0} 
background process
 containerBase.backgroundProcess.realm=Exception processing realm {0} 
background process
 containerBase.backgroundProcess.valve=Exception processing valve {0} 
background process
@@ -87,6 +86,7 @@ naming.namingContextCreationFailed=Creat
 standardContext.invalidWrapperClass={0} is not a subclass of StandardWrapper
 standardContext.applicationListener=Error configuring application listener of 
class {0}
 standardContext.applicationSkipped=Skipped installing application listeners 
due to previous error(s)
+standardContext.backgroundProcess.loader=Exception processing loader {0} 
background process
 standardContext.cluster.noManager=No manager found. Checking if cluster 
manager should be used. Cluster configured: [{0}], Application distributable: 
[{1}]
 standardContext.duplicateListener=The listener "{0}" is already configured for 
this context. The duplicate definition has been ignored.
 standardContext.errorPage.error=Error page location {0} must start with a ''/''

Modified: tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java Wed 
Jul  4 21:20:46 2012
@@ -36,7 +36,6 @@ import javax.naming.NamingException;
 import javax.naming.Reference;
 import javax.naming.StringRefAddr;
 
-import org.apache.catalina.Container;
 import org.apache.catalina.ContainerEvent;
 import org.apache.catalina.ContainerListener;
 import org.apache.catalina.Context;
@@ -263,7 +262,7 @@ public class NamingContextListener
                 try {
                     ContextBindings.bindClassLoader
                         (container, container,
-                         ((Container) container).getLoader().getClassLoader());
+                         ((Context) container).getLoader().getClassLoader());
                 } catch (NamingException e) {
                     logger.error(sm.getString("naming.bindFailed", e));
                 }
@@ -299,7 +298,7 @@ public class NamingContextListener
             if (container instanceof Context) {
                 ContextBindings.unbindClassLoader
                     (container, container,
-                     ((Container) container).getLoader().getClassLoader());
+                     ((Context) container).getLoader().getClassLoader());
             }
 
             if (container instanceof Server) {
@@ -704,7 +703,7 @@ public class NamingContextListener
         if (container instanceof Context) {
             try {
                 compCtx.bind("Resources",
-                             ((Container) container).getResources());
+                             ((Context) container).getResources());
             } catch (NamingException e) {
                 logger.error(sm.getString("naming.bindFailed", e));
             }

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Wed Jul  4 
21:20:46 2012
@@ -420,6 +420,12 @@ public class StandardContext extends Con
 
 
     /**
+     * The Loader implementation with which this Container is associated.
+     */
+    private Loader loader = null;
+
+
+    /**
      * The login configuration descriptor for this web application.
      */
     private LoginConfig loginConfig = null;
@@ -670,6 +676,8 @@ public class StandardContext extends Con
     private String aliases = null;
 
 
+    private DirContext resources = null;
+
     /**
      * Non proxied resources.
      */
@@ -1854,16 +1862,45 @@ public class StandardContext extends Con
     }
 
 
-    /**
-     * Set the Loader with which this Context is associated.
-     *
-     * @param loader The newly associated loader
-     */
+    @Override
+    public Loader getLoader() {
+        return loader;
+    }
+
+
     @Override
     public synchronized void setLoader(Loader loader) {
 
-        super.setLoader(loader);
+        // Change components if necessary
+        Loader oldLoader = this.loader;
+        if (oldLoader == loader)
+            return;
+        this.loader = loader;
+
+        // Stop the old component if necessary
+        if (getState().isAvailable() && (oldLoader != null) &&
+            (oldLoader instanceof Lifecycle)) {
+            try {
+                ((Lifecycle) oldLoader).stop();
+            } catch (LifecycleException e) {
+                log.error("StandardContext.setLoader: stop: ", e);
+            }
+        }
+
+        // Start the new component if necessary
+        if (loader != null)
+            loader.setContext(this);
+        if (getState().isAvailable() && (loader != null) &&
+            (loader instanceof Lifecycle)) {
+            try {
+                ((Lifecycle) loader).start();
+            } catch (LifecycleException e) {
+                log.error("StandardContext.setLoader: start: ", e);
+            }
+        }
 
+        // Report this property change to interested listeners
+        support.firePropertyChange("loader", oldLoader, this.loader);
     }
 
 
@@ -2396,12 +2433,12 @@ public class StandardContext extends Con
     }
 
 
-    /**
-     * Set the resources DirContext object with which this Container is
-     * associated.
-     *
-     * @param resources The newly associated DirContext
-     */
+   @Override
+   public DirContext getResources() {
+       return resources;
+   }
+
+
     @Override
     public synchronized void setResources(DirContext resources) {
 
@@ -5479,9 +5516,28 @@ public class StandardContext extends Con
             instanceListeners = new String[0];
         }
 
+        if ((loader != null) && (loader instanceof Lifecycle)) {
+            ((Lifecycle) loader).destroy();
+        }
+
         super.destroyInternal();
     }
 
+
+    @Override
+    public void backgroundProcess() {
+        if (loader != null) {
+            try {
+                loader.backgroundProcess();
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "standardContext.backgroundProcess.loader", loader), 
e);
+            }
+        }
+        super.backgroundProcess();
+    }
+
+
     private void resetContext() throws Exception {
         // Restore the original state ( pre reading web.xml in start )
         // If you extend this - override this method and make sure to clean up

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java Wed Jul  4 
21:20:46 2012
@@ -1168,7 +1168,7 @@ public class StandardWrapper extends Con
         if (getServlet() == null) {
             Class<?> clazz = null;
             try {
-                clazz = getParent().getLoader().getClassLoader().loadClass(
+                clazz = ((Context) 
getParent()).getLoader().getClassLoader().loadClass(
                         getServletClass());
                 processServletSecurityAnnotation(clazz);
             } catch (ClassNotFoundException e) {

Modified: 
tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java 
Wed Jul  4 21:20:46 2012
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.regex.Pattern;
 
 import org.apache.catalina.Container;
+import org.apache.catalina.Context;
 import org.apache.catalina.Loader;
 import org.apache.catalina.ha.CatalinaCluster;
 import org.apache.catalina.ha.ClusterManager;
@@ -129,7 +130,9 @@ public abstract class ClusterManagerBase
     public static ClassLoader[] getClassLoaders(Container container) {
         Loader loader = null;
         ClassLoader classLoader = null;
-        if (container != null) loader = container.getLoader();
+        if (container instanceof Context) {
+            loader = ((Context) container).getLoader();
+        }
         if (loader != null) classLoader = loader.getClassLoader();
         else classLoader = Thread.currentThread().getContextClassLoader();
         if ( classLoader == Thread.currentThread().getContextClassLoader() ) {

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Wed Jul  4 
21:20:46 2012
@@ -44,7 +44,6 @@ import javax.naming.NamingException;
 import javax.naming.directory.DirContext;
 import javax.servlet.ServletContext;
 
-import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.Globals;
 import org.apache.catalina.Lifecycle;
@@ -123,9 +122,9 @@ public class WebappLoader extends Lifecy
 
 
     /**
-     * The Container with which this Loader has been associated.
+     * The Context with which this Loader has been associated.
      */
-    private Container container = null;
+    private Context context = null;
 
 
     /**
@@ -207,40 +206,30 @@ public class WebappLoader extends Lifecy
     }
 
 
-    /**
-     * Return the Container with which this Logger has been associated.
-     */
     @Override
-    public Container getContainer() {
-
-        return (container);
-
+    public Context getContext() {
+        return context;
     }
 
 
-    /**
-     * Set the Container with which this Logger has been associated.
-     *
-     * @param container The associated Container
-     */
     @Override
-    public void setContainer(Container container) {
+    public void setContext(Context context) {
 
-        // Deregister from the old Container (if any)
-        if ((this.container != null) && (this.container instanceof Context))
-            ((Context) this.container).removePropertyChangeListener(this);
+        // Deregister from the old Context (if any)
+        if (this.context != null) {
+            this.context.removePropertyChangeListener(this);
+        }
 
         // Process this property change
-        Container oldContainer = this.container;
-        this.container = container;
-        support.firePropertyChange("container", oldContainer, this.container);
+        Context oldContext = this.context;
+        this.context = context;
+        support.firePropertyChange("context", oldContext, this.context);
 
         // Register with the new Container (if any)
-        if ((this.container != null) && (this.container instanceof Context)) {
-            setReloadable( ((Context) this.container).getReloadable() );
-            ((Context) this.container).addPropertyChangeListener(this);
+        if (this.context != null) {
+            setReloadable(this.context.getReloadable());
+            this.context.addPropertyChangeListener(this);
         }
-
     }
 
 
@@ -398,13 +387,13 @@ public class WebappLoader extends Lifecy
             try {
                 Thread.currentThread().setContextClassLoader
                     (WebappLoader.class.getClassLoader());
-                if (container instanceof Context) {
-                    ((Context) container).reload();
+                if (context != null) {
+                    context.reload();
                 }
             } finally {
-                if (container.getLoader() != null) {
+                if (context.getLoader() != null) {
                     Thread.currentThread().setContextClassLoader
-                        (container.getLoader().getClassLoader());
+                        (context.getLoader().getClassLoader());
                 }
             }
         } else {
@@ -508,8 +497,8 @@ public class WebappLoader extends Lifecy
     public String toString() {
 
         StringBuilder sb = new StringBuilder("WebappLoader[");
-        if (container != null)
-            sb.append(container.getName());
+        if (context != null)
+            sb.append(context.getName());
         sb.append("]");
         return (sb.toString());
 
@@ -529,8 +518,8 @@ public class WebappLoader extends Lifecy
         if (log.isDebugEnabled())
             log.debug(sm.getString("webappLoader.starting"));
 
-        if (container.getResources() == null) {
-            log.info("No resources for " + container);
+        if (context.getResources() == null) {
+            log.info("No resources for " + context);
             setState(LifecycleState.STARTING);
             return;
         }
@@ -557,7 +546,7 @@ public class WebappLoader extends Lifecy
         try {
 
             classLoader = createClassLoader();
-            classLoader.setResources(container.getResources());
+            classLoader.setResources(context.getResources());
             classLoader.setDelegate(this.delegate);
             classLoader.setSearchExternalFirst(searchExternalFirst);
             for (int i = 0; i < repositories.length; i++) {
@@ -574,15 +563,15 @@ public class WebappLoader extends Lifecy
 
             // Binding the Webapp class loader to the directory context
             DirContextURLStreamHandler.bind(classLoader,
-                    this.container.getResources());
+                    this.context.getResources());
 
-            String contextName = container.getName();
+            String contextName = context.getName();
             if (!contextName.startsWith("/")) {
                 contextName = "/" + contextName;
             }
-            ObjectName cloname = new ObjectName(container.getDomain() +
+            ObjectName cloname = new ObjectName(context.getDomain() +
                     ":type=WebappClassLoader,context=" + contextName +
-                    ",host=" + container.getParent().getName());
+                    ",host=" + context.getParent().getName());
             Registry.getRegistry(null, null)
                 .registerComponent(classLoader, cloname, null);
 
@@ -613,9 +602,8 @@ public class WebappLoader extends Lifecy
         setState(LifecycleState.STOPPING);
 
         // Remove context attributes as appropriate
-        if (container instanceof Context) {
-            ServletContext servletContext =
-                ((Context) container).getServletContext();
+        if (context != null) {
+            ServletContext servletContext = context.getServletContext();
             servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
         }
 
@@ -624,13 +612,13 @@ public class WebappLoader extends Lifecy
         DirContextURLStreamHandler.unbind(classLoader);
 
         try {
-            String contextName = container.getName();
+            String contextName = context.getName();
             if (!contextName.startsWith("/")) {
                 contextName = "/" + contextName;
             }
-            ObjectName cloname = new ObjectName(container.getDomain() +
+            ObjectName cloname = new ObjectName(context.getDomain() +
                     ":type=WebappClassLoader,context=" + contextName +
-                    ",host=" + container.getParent().getName());
+                    ",host=" + context.getParent().getName());
             Registry.getRegistry(null, null).unregisterComponent(cloname);
         } catch (Exception e) {
             log.error("LifecycleException ", e);
@@ -682,7 +670,7 @@ public class WebappLoader extends Lifecy
         WebappClassLoader classLoader = null;
 
         if (parentClassLoader == null) {
-            parentClassLoader = container.getParentClassLoader();
+            parentClassLoader = context.getParentClassLoader();
         }
         Class<?>[] argTypes = { ClassLoader.class };
         Object[] args = { parentClassLoader };
@@ -701,12 +689,11 @@ public class WebappLoader extends Lifecy
 
         if (!Globals.IS_SECURITY_ENABLED)
             return;
-        if (!(container instanceof Context))
+        if (context == null)
             return;
 
         // Tell the class loader the root of the context
-        ServletContext servletContext =
-            ((Context) container).getServletContext();
+        ServletContext servletContext = context.getServletContext();
 
         // Assigning permissions for the work directory
         File workDir =
@@ -796,10 +783,9 @@ public class WebappLoader extends Lifecy
      */
     private void setRepositories() throws IOException {
 
-        if (!(container instanceof Context))
+        if (context == null)
             return;
-        ServletContext servletContext =
-            ((Context) container).getServletContext();
+        ServletContext servletContext = context.getServletContext();
         if (servletContext == null)
             return;
 
@@ -816,7 +802,7 @@ public class WebappLoader extends Lifecy
 
         classLoader.setWorkDir(workDir);
 
-        DirContext resources = container.getResources();
+        DirContext resources = context.getResources();
 
         // Setting up the class repository (/WEB-INF/classes), if it exists
 
@@ -979,10 +965,9 @@ public class WebappLoader extends Lifecy
     private void setClassPath() {
 
         // Validate our current state information
-        if (!(container instanceof Context))
+        if (context == null)
             return;
-        ServletContext servletContext =
-            ((Context) container).getServletContext();
+        ServletContext servletContext = context.getServletContext();
         if (servletContext == null)
             return;
 
@@ -1140,7 +1125,7 @@ public class WebappLoader extends Lifecy
 
     @Override
     protected String getDomainInternal() {
-        return container.getDomain();
+        return context.getDomain();
     }
 
 
@@ -1149,25 +1134,17 @@ public class WebappLoader extends Lifecy
 
         StringBuilder name = new StringBuilder("type=Loader");
 
-        if (container instanceof Context) {
-            name.append(",context=");
-            Context context = (Context) container;
+        name.append(",context=");
 
-            String contextName = context.getName();
-            if (!contextName.startsWith("/")) {
-                name.append("/");
-            }
-            name.append(contextName);
-
-            name.append(",host=");
-            name.append(context.getParent().getName());
-        } else {
-            // Unlikely / impossible? Handle it to be safe
-            name.append(",container=");
-            name.append(container.getName());
+        String contextName = context.getName();
+        if (!contextName.startsWith("/")) {
+            name.append("/");
         }
+        name.append(contextName);
+
+        name.append(",host=");
+        name.append(context.getParent().getName());
 
         return name.toString();
     }
-
 }

Modified: tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java Wed Jul  4 
21:20:46 2012
@@ -715,8 +715,8 @@ public class MBeanFactory {
         // Add the new instance to its parent component
         ObjectName pname = new ObjectName(parent);
         Container container = getParentContainerFromParent(pname);
-        if (container != null) {
-            container.setLoader(loader);
+        if (container instanceof Context) {
+            ((Context) container).setLoader(loader);
         }
         // FIXME add Loader.getObjectName
         //ObjectName oname = loader.getObjectName();
@@ -852,8 +852,9 @@ public class MBeanFactory {
         ObjectName oname = new ObjectName(name);
         // Acquire a reference to the component to be removed
         Container container = getParentContainerFromChild(oname);
-        container.setLoader(null);
-
+        if (container instanceof Context) {
+            ((Context) container).setLoader(null);
+        }
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java Wed Jul  4 
21:20:46 2012
@@ -26,9 +26,7 @@ import javax.management.ObjectName;
 
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
-import org.apache.catalina.Engine;
 import org.apache.catalina.Group;
-import org.apache.catalina.Host;
 import org.apache.catalina.Loader;
 import org.apache.catalina.Role;
 import org.apache.catalina.Server;
@@ -463,28 +461,18 @@ public class MBeanUtils {
      *
      * @exception MalformedObjectNameException if a name cannot be created
      */
-    static ObjectName createObjectName(String domain,
-                                              Loader loader)
+    static ObjectName createObjectName(String domain, Loader loader)
         throws MalformedObjectNameException {
 
         ObjectName name = null;
-        Container container = loader.getContainer();
-
-        if (container instanceof Engine) {
-            name = new ObjectName(domain + ":type=Loader");
-        } else if (container instanceof Host) {
-            name = new ObjectName(domain + ":type=Loader,host=" +
-                              container.getName());
-        } else if (container instanceof Context) {
-            Context context = ((Context)container);
-            ContextName cn = new ContextName(context.getName());
-            Container host = context.getParent();
-            name = new ObjectName(domain + ":type=Loader,context=" +
-                    cn.getDisplayName() + ",host=" + host.getName());
-        }
+        Context context = loader.getContext();
 
-        return (name);
+        ContextName cn = new ContextName(context.getName());
+        Container host = context.getParent();
+        name = new ObjectName(domain + ":type=Loader,context=" +
+                cn.getDisplayName() + ",host=" + host.getName());
 
+        return name;
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/session/FileStore.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/FileStore.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/FileStore.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/FileStore.java Wed Jul  4 
21:20:46 2012
@@ -255,8 +255,8 @@ public final class FileStore extends Sto
             fis = new FileInputStream(file.getAbsolutePath());
             bis = new BufferedInputStream(fis);
             Container container = manager.getContainer();
-            if (container != null)
-                loader = container.getLoader();
+            if (container instanceof Context)
+                loader = ((Context) container).getLoader();
             if (loader != null)
                 classLoader = loader.getClassLoader();
             if (classLoader != null)

Modified: tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java Wed Jul  4 
21:20:46 2012
@@ -622,8 +622,8 @@ public class JDBCStore extends StoreBase
                     if (rst.next()) {
                         bis = new BufferedInputStream(rst.getBinaryStream(2));
 
-                        if (container != null) {
-                            loader = container.getLoader();
+                        if (container instanceof org.apache.catalina.Context) {
+                            loader = ((org.apache.catalina.Context) 
container).getLoader();
                         }
                         if (loader != null) {
                             classLoader = loader.getClassLoader();

Modified: tomcat/trunk/java/org/apache/catalina/session/StandardManager.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StandardManager.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/StandardManager.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/session/StandardManager.java Wed Jul  
4 21:20:46 2012
@@ -215,8 +215,8 @@ public class StandardManager extends Man
         try {
             fis = new FileInputStream(file.getAbsolutePath());
             bis = new BufferedInputStream(fis);
-            if (container != null)
-                loader = container.getLoader();
+            if (container instanceof Context)
+                loader = ((Context) container).getLoader();
             if (loader != null)
                 classLoader = loader.getClassLoader();
             if (classLoader != null) {

Modified: tomcat/trunk/java/org/apache/catalina/util/Introspection.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/Introspection.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/Introspection.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/Introspection.java Wed Jul  4 
21:20:46 2012
@@ -22,7 +22,7 @@ import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
-import org.apache.catalina.Container;
+import org.apache.catalina.Context;
 import org.apache.catalina.Globals;
 import org.apache.juli.logging.Log;
 import org.apache.tomcat.util.ExceptionUtils;
@@ -116,9 +116,9 @@ public class Introspection {
      * class cannot be loaded, a debug level log message will be written to the
      * Container's log and null will be returned.
      */
-    public static Class<?> loadClass(Container container, String className) {
-        ClassLoader cl = container.getLoader().getClassLoader();
-        Log log = container.getLogger();
+    public static Class<?> loadClass(Context context, String className) {
+        ClassLoader cl = context.getLoader().getClassLoader();
+        Log log = context.getLogger();
         Class<?> clazz = null;
         try {
             clazz = cl.loadClass(className);

Modified: 
tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java 
Wed Jul  4 21:20:46 2012
@@ -48,7 +48,7 @@ public class TestVirtualWebappLoader ext
 
         VirtualWebappLoader loader = new VirtualWebappLoader();
 
-        loader.setContainer(ctx);
+        loader.setContext(ctx);
         ctx.setLoader(loader);
         ctx.setResources(new FileDirContext());
         ctx.resourcesStart();

Modified: 
tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java?rev=1357412&r1=1357411&r2=1357412&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java 
Wed Jul  4 21:20:46 2012
@@ -36,7 +36,7 @@ import static org.junit.Assert.fail;
 
 import org.junit.Test;
 
-import org.apache.catalina.Container;
+import org.apache.catalina.Context;
 import org.apache.catalina.Loader;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.deploy.FilterDef;
@@ -328,9 +328,9 @@ public class TestContextConfigAnnotation
             return this.getClass().getClassLoader();
         }
         @Override
-        public Container getContainer() { return null; }
+        public Context getContext() { return null; }
         @Override
-        public void setContainer(Container container) {}
+        public void setContext(Context context) {}
         @Override
         public boolean getDelegate() { return false; }
         @Override



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to