[jboss-cvs] JBossAS SVN: r83708 - in branches/tdiesler/Branch_5_0: server/src/main/org/jboss/web/deployers and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 30 16:12:16 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-01-30 16:12:16 -0500 (Fri, 30 Jan 2009)
New Revision: 83708

Modified:
   branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/WebApplication.java
   branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java
   branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java
   branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/WebModule.java
   branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
   branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
   branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java
   branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
   branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
   branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DeploymentAspectHttpServer.java
   branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DynamicEndpointDeploymentAspect.java
Log:
[JBAS-6436] Fix in memory webapp deployment

Modified: branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/WebApplication.java
===================================================================
--- branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/WebApplication.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/WebApplication.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -25,7 +25,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
 
 /** A WebApplication represents the information for a war deployment.
@@ -39,7 +39,7 @@
 public class WebApplication
 {
    /** */
-   private VFSDeploymentUnit unit;
+   private DeploymentUnit unit;
    /** Class loader of this application */
    protected ClassLoader classLoader = null;
    /** name of this application */
@@ -102,11 +102,11 @@
       this.classLoader = classLoader;
    }
 
-   public VFSDeploymentUnit getDeploymentUnit()
+   public DeploymentUnit getDeploymentUnit()
    {
       return unit;
    }
-   public void setDeploymentUnit(VFSDeploymentUnit unit)
+   public void setDeploymentUnit(DeploymentUnit unit)
    {
       this.unit = unit;
    }
@@ -168,8 +168,6 @@
     */
    public void setURL(URL url)
    {
-      if (url == null)
-         throw new IllegalArgumentException("Null URL");
       this.url = url;
    }
 

Modified: branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java
===================================================================
--- branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -30,16 +30,17 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.jboss.beans.metadata.api.annotations.Inject;
 import org.jboss.bootstrap.spi.ServerConfig;
 import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.spi.deployer.helpers.AttachmentLocator;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
-import org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
 import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
@@ -84,657 +85,670 @@
  * @author  adrian at jboss.org
  * @version $Revision: 55985 $
  */
-public abstract class AbstractWarDeployer extends AbstractSimpleVFSRealDeployer<JBossWebMetaData>
+public abstract class AbstractWarDeployer extends AbstractSimpleRealDeployer<JBossWebMetaData>
 {
-   public static final String DEPLOYER = "org.jboss.web.AbstractWebContainer.deployer";
-   public static final String WEB_APP = "org.jboss.web.AbstractWebContainer.webApp";
-   public static final String WEB_MODULE = "org.jboss.web.AbstractWebContainer.webModule";
-   public static final String ERROR = "org.jboss.web.AbstractWebContainer.error";
+  public static final String DEPLOYER = "org.jboss.web.AbstractWebContainer.deployer";
+  public static final String WEB_APP = "org.jboss.web.AbstractWebContainer.webApp";
+  public static final String WEB_MODULE = "org.jboss.web.AbstractWebContainer.webModule";
+  public static final String ERROR = "org.jboss.web.AbstractWebContainer.error";
 
-   /** A mapping of deployed warUrl strings to the WebApplication object */
-   protected HashMap deploymentMap = new HashMap();
-   /** The parent class loader first model flag */
-   protected boolean java2ClassLoadingCompliance = false;
-   /** A flag indicating if war archives should be unpacked */
-   protected boolean unpackWars = true;
-   /** A flag indicating if local dirs with WEB-INF/web.xml should be treated as wars
-    */
-   protected boolean acceptNonWarDirs = false;
+  /** A mapping of deployed warUrl strings to the WebApplication object */
+  protected HashMap deploymentMap = new HashMap();
+  /** The parent class loader first model flag */
+  protected boolean java2ClassLoadingCompliance = false;
+  /** A flag indicating if war archives should be unpacked */
+  protected boolean unpackWars = true;
+  /** A flag indicating if local dirs with WEB-INF/web.xml should be treated as wars
+   */
+  protected boolean acceptNonWarDirs = false;
 
-   /** If true, ejb-links that don't resolve don't cause an error (fallback to jndi-name) */
-   protected boolean lenientEjbLink = false;
+  /** If true, ejb-links that don't resolve don't cause an error (fallback to jndi-name) */
+  protected boolean lenientEjbLink = false;
 
-   /** The default security-domain name to use */
-   protected String defaultSecurityDomain = "java:/jaas/other";
-   /** The request attribute name under which the JAAS Subject is store */
-   private String subjectAttributeName = null;
-   /** Legacy support for MBeanServer */
-   private MBeanServer server;
-   private MainDeployerStructure mainDeployer;
-   
-   private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
+  /** The default security-domain name to use */
+  protected String defaultSecurityDomain = "java:/jaas/other";
+  /** The request attribute name under which the JAAS Subject is store */
+  private String subjectAttributeName = null;
+  /** Legacy support for MBeanServer */
+  private MBeanServer server;
+  private MainDeployerStructure mainDeployer;
 
-   /**
-    * Create a new AbstractWarDeployer.
-    */
-   public AbstractWarDeployer()
-   {
-      super(JBossWebMetaData.class); 
-      setOutput(ServiceMetaData.class);
-      setOutput(WarDeployment.class);
-   }
+  private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
 
-   /** Get the flag indicating if the normal Java2 parent first class loading
-    * model should be used over the servlet 2.3 web container first model.
-    * @return true for parent first, false for the servlet 2.3 model
-    * @jmx:managed-attribute
-    */
-   public boolean getJava2ClassLoadingCompliance()
-   {
-      return java2ClassLoadingCompliance;
-   }
+  /**
+   * Create a new AbstractWarDeployer.
+   */
+  public AbstractWarDeployer()
+  {
+    super(JBossWebMetaData.class);
+    setOutput(ServiceMetaData.class);
+    setOutput(WarDeployment.class);
+  }
 
-   /** Set the flag indicating if the normal Java2 parent first class loading
-    * model should be used over the servlet 2.3 web container first model.
-    * @param flag true for parent first, false for the servlet 2.3 model
-    * @jmx:managed-attribute
-    */
-   public void setJava2ClassLoadingCompliance(boolean flag)
-   {
-      java2ClassLoadingCompliance = flag;
-   }
+  /** Get the flag indicating if the normal Java2 parent first class loading
+   * model should be used over the servlet 2.3 web container first model.
+   * @return true for parent first, false for the servlet 2.3 model
+   * @jmx:managed-attribute
+   */
+  public boolean getJava2ClassLoadingCompliance()
+  {
+    return java2ClassLoadingCompliance;
+  }
 
-   /** Set the flag indicating if war archives should be unpacked. This may
-    * need to be set to false as long extraction paths under deploy can
-    * show up as deployment failures on some platforms.
-    * 
-    * @jmx:managed-attribute
-    * @return true is war archives should be unpacked
-    */
-   public boolean getUnpackWars()
-   {
-      return unpackWars;
-   }
+  /** Set the flag indicating if the normal Java2 parent first class loading
+   * model should be used over the servlet 2.3 web container first model.
+   * @param flag true for parent first, false for the servlet 2.3 model
+   * @jmx:managed-attribute
+   */
+  public void setJava2ClassLoadingCompliance(boolean flag)
+  {
+    java2ClassLoadingCompliance = flag;
+  }
 
-   /** Get the flag indicating if war archives should be unpacked. This may
-    * need to be set to false as long extraction paths under deploy can
-    * show up as deployment failures on some platforms.
-    * 
-    * @jmx:managed-attribute
-    * @param flag , true is war archives should be unpacked
-    */
-   public void setUnpackWars(boolean flag)
-   {
-      this.unpackWars = flag;
-   }
+  /** Set the flag indicating if war archives should be unpacked. This may
+   * need to be set to false as long extraction paths under deploy can
+   * show up as deployment failures on some platforms.
+   * 
+   * @jmx:managed-attribute
+   * @return true is war archives should be unpacked
+   */
+  public boolean getUnpackWars()
+  {
+    return unpackWars;
+  }
 
-   /**
-    * Get the flag indicating if local dirs with WEB-INF/web.xml should be
-    * treated as wars
-    * @return true if local dirs with WEB-INF/web.xml should be treated as wars
-    * @jmx.managed-attribute
-    */
-   public boolean getAcceptNonWarDirs()
-   {
-      return acceptNonWarDirs;
-   }
+  /** Get the flag indicating if war archives should be unpacked. This may
+   * need to be set to false as long extraction paths under deploy can
+   * show up as deployment failures on some platforms.
+   * 
+   * @jmx:managed-attribute
+   * @param flag , true is war archives should be unpacked
+   */
+  public void setUnpackWars(boolean flag)
+  {
+    this.unpackWars = flag;
+  }
 
-   /**
-    * Set the flag indicating if local dirs with WEB-INF/web.xml should be
-    * treated as wars
-    * @param flag - true if local dirs with WEB-INF/web.xml should be treated as wars
-    * @jmx.managed-attribute
-    */
-   public void setAcceptNonWarDirs(boolean flag)
-   {
-      this.acceptNonWarDirs = flag;
-   }
+  /**
+   * Get the flag indicating if local dirs with WEB-INF/web.xml should be
+   * treated as wars
+   * @return true if local dirs with WEB-INF/web.xml should be treated as wars
+   * @jmx.managed-attribute
+   */
+  public boolean getAcceptNonWarDirs()
+  {
+    return acceptNonWarDirs;
+  }
 
-   /**
-    * Get the flag indicating if ejb-link errors should be ignored
-    * in favour of trying the jndi-name in jboss-web.xml
-    * @return the LenientEjbLink flag 
-    *    
-    * @jmx:managed-attribute
-    */
-   public boolean getLenientEjbLink()
-   {
-      return lenientEjbLink;
-   }
+  /**
+   * Set the flag indicating if local dirs with WEB-INF/web.xml should be
+   * treated as wars
+   * @param flag - true if local dirs with WEB-INF/web.xml should be treated as wars
+   * @jmx.managed-attribute
+   */
+  public void setAcceptNonWarDirs(boolean flag)
+  {
+    this.acceptNonWarDirs = flag;
+  }
 
-   /**
-    * Set the flag indicating if ejb-link errors should be ignored
-    * in favour of trying the jndi-name in jboss-web.xml
-    *    
-    * @jmx:managed-attribute
-    */
-   public void setLenientEjbLink(boolean flag)
-   {
-      lenientEjbLink = flag;
-   }
+  /**
+   * Get the flag indicating if ejb-link errors should be ignored
+   * in favour of trying the jndi-name in jboss-web.xml
+   * @return the LenientEjbLink flag 
+   *    
+   * @jmx:managed-attribute
+   */
+  public boolean getLenientEjbLink()
+  {
+    return lenientEjbLink;
+  }
 
-   /** Get the default security domain implementation to use if a war
-    * does not declare a security-domain.
-    *
-    * @return jndi name of the security domain binding to use.
-    * @jmx:managed-attribute
-    */
-   public String getDefaultSecurityDomain()
-   {
-      return defaultSecurityDomain;
-   }
+  /**
+   * Set the flag indicating if ejb-link errors should be ignored
+   * in favour of trying the jndi-name in jboss-web.xml
+   *    
+   * @jmx:managed-attribute
+   */
+  public void setLenientEjbLink(boolean flag)
+  {
+    lenientEjbLink = flag;
+  }
 
-   /** Set the default security domain implementation to use if a war
-    * does not declare a security-domain.
-    *
-    * @param defaultSecurityDomain - jndi name of the security domain binding
-    * to use.
-    * @jmx:managed-attribute
-    */
-   public void setDefaultSecurityDomain(String defaultSecurityDomain)
-   {
-      this.defaultSecurityDomain = defaultSecurityDomain;
-   }
+  /** Get the default security domain implementation to use if a war
+   * does not declare a security-domain.
+   *
+   * @return jndi name of the security domain binding to use.
+   * @jmx:managed-attribute
+   */
+  public String getDefaultSecurityDomain()
+  {
+    return defaultSecurityDomain;
+  }
 
-   @Inject
-   public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
-   {
-      this.persistenceUnitDependencyResolver = resolver;
-   }
-   
-   /** Get the session attribute number under which the caller Subject is stored
-    * @jmx:managed-attribute
-    */
-   public String getSubjectAttributeName()
-   {
-      return subjectAttributeName;
-   }
+  /** Set the default security domain implementation to use if a war
+   * does not declare a security-domain.
+   *
+   * @param defaultSecurityDomain - jndi name of the security domain binding
+   * to use.
+   * @jmx:managed-attribute
+   */
+  public void setDefaultSecurityDomain(String defaultSecurityDomain)
+  {
+    this.defaultSecurityDomain = defaultSecurityDomain;
+  }
 
-   /** Set the session attribute number under which the caller Subject is stored
-    * @jmx:managed-attribute
-    */
-   public void setSubjectAttributeName(String subjectAttributeName)
-   {
-      this.subjectAttributeName = subjectAttributeName;
-   }
+  @Inject
+  public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
+  {
+    this.persistenceUnitDependencyResolver = resolver;
+  }
 
-   public void start() throws Exception
-   {
-      // TODO: remove dependency on jmx
-      this.server = MBeanServerLocator.locateJBoss();
-   }
+  /** Get the session attribute number under which the caller Subject is stored
+   * @jmx:managed-attribute
+   */
+  public String getSubjectAttributeName()
+  {
+    return subjectAttributeName;
+  }
 
-   public void stop() throws Exception
-   {
+  /** Set the session attribute number under which the caller Subject is stored
+   * @jmx:managed-attribute
+   */
+  public void setSubjectAttributeName(String subjectAttributeName)
+  {
+    this.subjectAttributeName = subjectAttributeName;
+  }
 
-   }
+  public void start() throws Exception
+  {
+    // TODO: remove dependency on jmx
+    this.server = MBeanServerLocator.locateJBoss();
+  }
 
-   /**
-    * Get the AbstractWarDeployment bean for the deployment metadata. Subclasses
-    * override this method to provide a AbstractWarDeployment bean whose
-    * start/stop will control the deployment/undeployment of the web
-    * application.
-    * 
-    * @param unit - the deployment unit
-    * @param metaData - the input web application metadata
-    * @return the AbstractWarDeployment for the input WebMetaData
-    * @throws Exception - thrown on any failure
-    */
-   public abstract AbstractWarDeployment getDeployment(VFSDeploymentUnit unit, JBossWebMetaData metaData) throws Exception;
+  public void stop() throws Exception
+  {
 
-   /**
-    * Deploy a web app based on the WebMetaData. This calls
-    * {@link #getDeployment(VFSDeploymentUnit, WebMetaData)} to obtain an
-    * AbstractWarDeployment bean that is wrapped in a ServiceMetaData by
-    * deployWebModule.
-    * 
-    * This will set the WebMetaData.contextRoot if it has not been set based
-    * on the war deployment name.
-    * 
-    * @see #deployWebModule(VFSDeploymentUnit, WebMetaData, AbstractWarDeployment)
-    * @see #buildWebContext(VFSDeploymentUnit, String, String, WebMetaData)
-    * 
-    * @param unit - the war for the deployment
-    * @param metaData - the metadata for the deployment
-    */
-   @Override
-   public void deploy(VFSDeploymentUnit unit, JBossWebMetaData metaData) throws DeploymentException
-   {
-      log.debug("Begin deploy, " + metaData);
+  }
 
-      // Merge any settings from the ear level
-      JBossAppMetaData earMetaData = AttachmentLocator.search(unit, JBossAppMetaData.class);
-      if (earMetaData != null)
+  /**
+   * Get the AbstractWarDeployment bean for the deployment metadata. Subclasses
+   * override this method to provide a AbstractWarDeployment bean whose
+   * start/stop will control the deployment/undeployment of the web
+   * application.
+   * 
+   * @param unit - the deployment unit
+   * @param metaData - the input web application metadata
+   * @return the AbstractWarDeployment for the input WebMetaData
+   * @throws Exception - thrown on any failure
+   */
+  public abstract AbstractWarDeployment getDeployment(DeploymentUnit unit, JBossWebMetaData metaData) throws Exception;
+
+  /**
+   * Deploy a web app based on the WebMetaData. This calls
+   * {@link #getDeployment(DeploymentUnit, WebMetaData)} to obtain an
+   * AbstractWarDeployment bean that is wrapped in a ServiceMetaData by
+   * deployWebModule.
+   * 
+   * This will set the WebMetaData.contextRoot if it has not been set based
+   * on the war deployment name.
+   * 
+   * @see #deployWebModule(DeploymentUnit, WebMetaData, AbstractWarDeployment)
+   * @see #buildWebContext(WebMetaData, DeploymentUnit, String, String)
+   * 
+   * @param unit - the war for the deployment
+   * @param metaData - the metadata for the deployment
+   */
+  @Override
+  public void deploy(DeploymentUnit unit, JBossWebMetaData metaData) throws DeploymentException
+  {
+    log.debug("Begin deploy, " + metaData);
+
+    // Merge any settings from the ear level
+    JBossAppMetaData earMetaData = AttachmentLocator.search(unit, JBossAppMetaData.class);
+    if (earMetaData != null)
+    {
+      String path = unit.getRelativePath();
+      ModuleMetaData webModule = earMetaData.getModule(path);
+      if (webModule != null)
       {
-         String path = unit.getRelativePath();
-         ModuleMetaData webModule = earMetaData.getModule(path);
-         if (webModule != null)
-         {
-            // Check for a context-root setting
-            String contextRoot = metaData.getContextRoot();
-            if (contextRoot == null)
-            {
-               WebModuleMetaData wmodule = (WebModuleMetaData)webModule.getValue();
-               contextRoot = wmodule.getContextRoot();
-               metaData.setContextRoot(contextRoot);
-            }
+        // Check for a context-root setting
+        String contextRoot = metaData.getContextRoot();
+        if (contextRoot == null)
+        {
+          WebModuleMetaData wmodule = (WebModuleMetaData)webModule.getValue();
+          contextRoot = wmodule.getContextRoot();
+          metaData.setContextRoot(contextRoot);
+        }
 
-            // Add any alt-dd setting
-            metaData.setAlternativeDD(webModule.getAlternativeDD());
-         }
-
-         // Merge security domain/roles
-         if (metaData.getSecurityDomain() == null && earMetaData.getSecurityDomain() != null)
-            metaData.setSecurityDomain(earMetaData.getSecurityDomain());
-         // TODO
-         metaData.mergeSecurityRoles(earMetaData.getSecurityRoles());
+        // Add any alt-dd setting
+        metaData.setAlternativeDD(webModule.getAlternativeDD());
       }
 
-      try
+      // Merge security domain/roles
+      if (metaData.getSecurityDomain() == null && earMetaData.getSecurityDomain() != null)
+        metaData.setSecurityDomain(earMetaData.getSecurityDomain());
+      // TODO
+      metaData.mergeSecurityRoles(earMetaData.getSecurityRoles());
+    }
+
+    try
+    {
+      /* Unpack wars to the tmp directory for now until tomcat can use the vfs directly. Since
+       * the vfs deals with the distinction between a true directory, the only way we can tell from
+       * this level of the api is to look for a url that ends in '/'. Here we assume that the name is
+       * the root url.
+       */
+      String warName = unit.getName();
+
+      /**
+       * Ignore the jacc policy service bean 
+       */
+      if (warName.startsWith("jboss:") && warName.contains("id="))
+        return;
+
+      if (unit instanceof VFSDeploymentUnit)
       {
-         /* Unpack wars to the tmp directory for now until tomcat can use the vfs directly. Since
-          * the vfs deals with the distinction between a true directory, the only way we can tell from
-          * this level of the api is to look for a url that ends in '/'. Here we assume that the name is
-          * the root url.
-          */
-         String warName = unit.getName();
+        VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)unit;
+        VirtualFile vfsRoot = vfsUnit.getRoot();
 
-         /**
-          * Ignore the jacc policy service bean 
-          */
-         if (warName.startsWith("jboss:") && warName.contains("id="))
-            return;
+        URL expWarUrl = vfsRoot.toURL();
 
-         URL expWarUrl = unit.getRoot().toURL();
-         if (warName.endsWith("/") == false
-               || warName.endsWith("!/") == true) // Hack for jar urls being exposed
-         {
-            if (warName.startsWith("jar:"))
-            {
-               if (warName.endsWith("!/"))
-                  warName = warName.substring(4, warName.length() - 2);
-               else
-                  warName = warName.substring(4, warName.length());
-            }
-            URL warURL = new URL(warName);
-            ServerConfig config = ServerConfigLocator.locate();
-            String prefix = warURL.getFile();
-            int lastSlash = prefix.lastIndexOf('/');
-            if (lastSlash > 0)
-               prefix = prefix.substring(lastSlash + 1);
-            int dotWar = prefix.lastIndexOf(".war");
-            if (dotWar > 0)
-               prefix = prefix.substring(0, dotWar);
+        // Hack for jar urls being exposed
+        if (warName.endsWith("/") == false || warName.endsWith("!/") == true)
+        {
+          if (warName.startsWith("jar:"))
+          {
+            if (warName.endsWith("!/"))
+              warName = warName.substring(4, warName.length() - 2);
+            else
+              warName = warName.substring(4, warName.length());
+          }
+          URL warURL = new URL(warName);
+          ServerConfig config = ServerConfigLocator.locate();
+          String prefix = warURL.getFile();
+          int lastSlash = prefix.lastIndexOf('/');
+          if (lastSlash > 0)
+            prefix = prefix.substring(lastSlash + 1);
+          int dotWar = prefix.lastIndexOf(".war");
+          if (dotWar > 0)
+            prefix = prefix.substring(0, dotWar);
 
-            File expWarFile = File.createTempFile(prefix, "-exp.war", config.getServerTempDeployDir());
-            expWarFile.delete();
-            if (expWarFile.mkdir() == false)
-               throw new DeploymentException("Was unable to mkdir: " + expWarFile);
-            log.debug("Unpacking war to: " + expWarFile);
-            VirtualFile root = unit.getRoot();
-            InputStream is = root.openStream();
-            try
-            {
-               JarUtils.unjar(is, expWarFile);
-            }
-            finally
-            {
-               is.close();
-            }
-            expWarUrl = expWarFile.toURL();
+          File expWarFile = File.createTempFile(prefix, "-exp.war", config.getServerTempDeployDir());
+          expWarFile.delete();
+          if (expWarFile.mkdir() == false)
+            throw new DeploymentException("Was unable to mkdir: " + expWarFile);
+          
+          log.debug("Unpacking war to: " + expWarFile);
+          VirtualFile root = vfsRoot;
+          InputStream is = root.openStream();
+          try
+          {
+            JarUtils.unjar(is, expWarFile);
+          }
+          finally
+          {
+            is.close();
+          }
+          expWarUrl = expWarFile.toURL();
 
-            // Map
-            VirtualFile warVF = unit.getRoot();
-            String warPathName = warVF.getPathName();
-            if (warPathName.endsWith("/") == false)
-               warPathName += "/";
-            List<VirtualFile> classpathVFs = unit.getClassPath();
-            if (classpathVFs != null)
+          // Map
+          String warPathName = vfsRoot.getPathName();
+          if (warPathName.endsWith("/") == false)
+            warPathName += "/";
+          
+          List<VirtualFile> classpathVFs = vfsUnit.getClassPath();
+          if (classpathVFs != null)
+          {
+            ArrayList<URL> classpath = new ArrayList<URL>();
+            for (VirtualFile vf : classpathVFs)
             {
-               ArrayList<URL> classpath = new ArrayList<URL>();
-               for (VirtualFile vf : classpathVFs)
-               {
-                  try
-                  {
-                     String path = vf.getPathName();
-                     if (path.startsWith(warPathName))
-                     {
-                        path = path.substring(warPathName.length());
-                        URL pathURL = new URL(expWarUrl, path);
-                        classpath.add(pathURL);
-                     }
-                     else
-                     {
-                        log.debug("Ignoring path element: " + vf);
-                     }
-                  }
-                  catch (Exception e)
-                  {
-                     log.debug("Ignoring path element: " + vf, e);
-                  }
-               }
-               unit.addAttachment("org.jboss.web.expandedWarClasspath", classpath);
+              try
+              {
+                String path = vf.getPathName();
+                if (path.startsWith(warPathName))
+                {
+                  path = path.substring(warPathName.length());
+                  URL pathURL = new URL(expWarUrl, path);
+                  classpath.add(pathURL);
+                }
+                else
+                {
+                  log.debug("Ignoring path element: " + vf);
+                }
+              }
+              catch (Exception e)
+              {
+                log.debug("Ignoring path element: " + vf, e);
+              }
             }
+            unit.addAttachment("org.jboss.web.expandedWarClasspath", classpath);
+          }
 
-            // Indicate that an expanded URL exists
-            unit.addAttachment("org.jboss.web.expandedWarURL", expWarUrl, URL.class);
-         }
+          // Indicate that an expanded URL exists
+          unit.addAttachment("org.jboss.web.expandedWarURL", expWarUrl, URL.class);
+        }
 
-         // Resolve any ear relative alt-dd path to an expWarUrl/WEB-INF/alt-dd.xml file
-         String altDDPath = metaData.getAlternativeDD();
-         if (altDDPath != null)
-         {
-            // First see if this is already a war local dd
-            VirtualFile altDD = unit.getMetaDataFile(altDDPath);
-            if (altDD == null)
+        // Resolve any ear relative alt-dd path to an expWarUrl/WEB-INF/alt-dd.xml file
+        String altDDPath = metaData.getAlternativeDD();
+        if (altDDPath != null)
+        {
+          // First see if this is already a war local dd
+          VirtualFile altDD = vfsUnit.getMetaDataFile(altDDPath);
+          if (altDD == null)
+          {
+            // Pass absolute paths through
+            File file = new File(altDDPath);
+            if (!file.exists() || !file.isAbsolute())
             {
-               // Pass absolute paths through
-               File file = new File(altDDPath);
-               if (!file.exists() || !file.isAbsolute())
-               {
-                  // Should be an relative to the top deployment
-                  VFSDeploymentUnit topUnit = unit.getTopLevel();
-                  if (topUnit == unit)
-                     throw new DeploymentException("Unable to resolve " + altDDPath + " as WEB-INF path");
-                  altDD = topUnit.getFile(altDDPath);
-                  if (altDD == null)
-                     throw new DeploymentException("Unable to resolve " + altDDPath + " as a deployment path");
-                  File webInf = new File(expWarUrl.toURI());
-                  File altDDFile = new File(webInf, "WEB-INF/" + altDD.getName());
-                  log.debug("Copying the altDD to: " + altDDFile);
-                  Files.copy(altDD.toURL(), altDDFile);
-                  metaData.setAlternativeDD(altDDFile.getAbsolutePath());
-               }
+              // Should be an relative to the top deployment
+              VFSDeploymentUnit topUnit = vfsUnit.getTopLevel();
+              if (topUnit == unit)
+                throw new DeploymentException("Unable to resolve " + altDDPath + " as WEB-INF path");
+              
+              altDD = topUnit.getFile(altDDPath);
+              if (altDD == null)
+                throw new DeploymentException("Unable to resolve " + altDDPath + " as a deployment path");
+              
+              File webInf = new File(expWarUrl.toURI());
+              File altDDFile = new File(webInf, "WEB-INF/" + altDD.getName());
+              log.debug("Copying the altDD to: " + altDDFile);
+              Files.copy(altDD.toURL(), altDDFile);
+              metaData.setAlternativeDD(altDDFile.getAbsolutePath());
             }
-         }
+          }
+        }
+      }
 
-         ClassLoadingMetaData classLoading = metaData.getClassLoading();
-         if (classLoading == null)
-            classLoading = new ClassLoadingMetaData();
-         // pass in the java2ClassLoadingCompliance if it was not set at the war level
-         if (classLoading.wasJava2ClassLoadingComplianceSet() == false)
-            classLoading.setJava2ClassLoadingCompliance(this.java2ClassLoadingCompliance);
-         metaData.setClassLoading(classLoading);
+      ClassLoadingMetaData classLoading = metaData.getClassLoading();
+      if (classLoading == null)
+        classLoading = new ClassLoadingMetaData();
+      
+      // Pass in the java2ClassLoadingCompliance if it was not set at the war level
+      if (classLoading.wasJava2ClassLoadingComplianceSet() == false)
+        classLoading.setJava2ClassLoadingCompliance(this.java2ClassLoadingCompliance);
+      
+      metaData.setClassLoading(classLoading);
 
-         // Build the context root if its not been set or is specified at the ear
-         String webContext = metaData.getContextRoot();
-         webContext = buildWebContext(webContext, warName, metaData, unit);
-         metaData.setContextRoot(webContext);
+      // Build the context root if its not been set or is specified at the ear
+      String webContext = metaData.getContextRoot();
+      webContext = buildWebContext(unit, webContext, warName, metaData);
+      metaData.setContextRoot(webContext);
 
-         AbstractWarDeployment deployment = getDeployment(unit, metaData);
-         deployment.setMainDeployer(mainDeployer);
-         // TODO: until deployment is a MC bean
-         deployment.setPersistenceUnitDependencyResolver(persistenceUnitDependencyResolver);
-         deployWebModule(unit, metaData, deployment);
-      }
-      catch (Exception e)
-      {
-         throw new DeploymentException("Failed to create web module", e);
-      }
-   }
+      AbstractWarDeployment deployment = getDeployment(unit, metaData);
+      deployment.setMainDeployer(mainDeployer);
+      
+      // TODO: until deployment is a MC bean
+      deployment.setPersistenceUnitDependencyResolver(persistenceUnitDependencyResolver);
+      deployWebModule(unit, metaData, deployment);
+    }
+    catch (Exception e)
+    {
+      throw new DeploymentException("Failed to create web module", e);
+    }
+  }
 
-   /**
-    * Cleanup war deployer specifics.
-    */
-   @Override
-   public void undeploy(VFSDeploymentUnit unit, JBossWebMetaData metaData)
-   {
-      try
+  /**
+   * Cleanup war deployer specifics.
+   */
+  @Override
+  public void undeploy(DeploymentUnit unit, JBossWebMetaData metaData)
+  {
+    try
+    {
+      // Delete any expanded war
+      URL warURL = unit.getAttachment("org.jboss.web.expandedWarURL", URL.class);
+      if (warURL != null)
       {
-         // Delete any expanded war
-         URL warURL = unit.getAttachment("org.jboss.web.expandedWarURL", URL.class);
-         if (warURL != null)
-         {
-            File war = new File(warURL.toURI());
-            Files.delete(war);
-         }
+        File war = new File(warURL.toURI());
+        Files.delete(war);
       }
-      catch (Exception e)
-      {
-         log.debug("Failed to remove expanded war", e);
-      }
-      /* Clear class loader refs
-       metaData.setContextLoader(null);
-       metaData.setResourceClassLoader(null);
-       metaData.setENCLoader(null);
-       */
-   }
+    }
+    catch (Exception e)
+    {
+      log.debug("Failed to remove expanded war", e);
+    }
+  }
 
-   public void addDeployedApp(String warURL, WebApplication webApp)
-   {
-      deploymentMap.put(warURL, webApp);
-   }
+  public void addDeployedApp(String warURL, WebApplication webApp)
+  {
+    deploymentMap.put(warURL, webApp);
+  }
 
-   /** Get the WebApplication object for a deployed war.
-    @param warUrl the war url string as originally passed to deploy().
-    @return The WebApplication created during the deploy step if the
-    warUrl is valid, null if no such deployment exists.
-    */
-   public WebApplication getDeployedApp(String warUrl)
-   {
-      WebApplication appInfo = (WebApplication)deploymentMap.get(warUrl);
-      return appInfo;
-   }
+  /** Get the WebApplication object for a deployed war.
+   @param warUrl the war url string as originally passed to deploy().
+   @return The WebApplication created during the deploy step if the
+   warUrl is valid, null if no such deployment exists.
+   */
+  public WebApplication getDeployedApp(String warUrl)
+  {
+    WebApplication appInfo = (WebApplication)deploymentMap.get(warUrl);
+    return appInfo;
+  }
 
-   public WebApplication removeDeployedApp(String warURL)
-   {
-      WebApplication appInfo = (WebApplication)deploymentMap.remove(warURL);
-      return appInfo;
-   }
+  public WebApplication removeDeployedApp(String warURL)
+  {
+    WebApplication appInfo = (WebApplication)deploymentMap.remove(warURL);
+    return appInfo;
+  }
 
-   /** Returns the applications deployed by the web container subclasses.
-    @jmx:managed-attribute
-    @return An Iterator of WebApplication objects for the deployed wars.
-    */
-   public Iterator getDeployedApplications()
-   {
-      return deploymentMap.values().iterator();
-   }
+  /** Returns the applications deployed by the web container subclasses.
+   @jmx:managed-attribute
+   @return An Iterator of WebApplication objects for the deployed wars.
+   */
+  public Iterator getDeployedApplications()
+  {
+    return deploymentMap.values().iterator();
+  }
 
-   /** A utility method that uses reflection to access a URL[] getURLs method
-    * so that non-URLClassLoader class loaders that support this method can
-    * provide info.
-    */
-   public static URL[] getClassLoaderURLs(ClassLoader cl)
-   {
-      URL[] urls = {};
-      try
+  /** A utility method that uses reflection to access a URL[] getURLs method
+   * so that non-URLClassLoader class loaders that support this method can
+   * provide info.
+   */
+  public static URL[] getClassLoaderURLs(ClassLoader cl)
+  {
+    URL[] urls = {};
+    try
+    {
+      Class returnType = urls.getClass();
+      Class[] parameterTypes = {};
+      Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
+      if (returnType.isAssignableFrom(getURLs.getReturnType()))
       {
-         Class returnType = urls.getClass();
-         Class[] parameterTypes = {};
-         Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
-         if (returnType.isAssignableFrom(getURLs.getReturnType()))
-         {
-            Object[] args = {};
-            urls = (URL[])getURLs.invoke(cl, args);
-         }
-         if (urls == null || urls.length == 0)
-         {
-            getURLs = cl.getClass().getMethod("getAllURLs", parameterTypes);
-            if (returnType.isAssignableFrom(getURLs.getReturnType()))
-            {
-               Object[] args = {};
-               urls = (URL[])getURLs.invoke(cl, args);
-            }
-         }
+        Object[] args = {};
+        urls = (URL[])getURLs.invoke(cl, args);
       }
-      catch (Exception ignore)
+      if (urls == null || urls.length == 0)
       {
+        getURLs = cl.getClass().getMethod("getAllURLs", parameterTypes);
+        if (returnType.isAssignableFrom(getURLs.getReturnType()))
+        {
+          Object[] args = {};
+          urls = (URL[])getURLs.invoke(cl, args);
+        }
       }
-      return urls;
-   }
+    }
+    catch (Exception ignore)
+    {
+    }
+    return urls;
+  }
 
-   /** This method creates a context-root string from either the
-    WEB-INF/jboss-web.xml context-root element is one exists, or the
-    filename portion of the warURL. It is called if the deployment
-    webContext value is null which indicates a standalone war deployment.
-    A war name of ROOT.war is handled as a special case of a war that
-    should be installed as the default web context.
-    @param ctxPath - war level context-root
-    @param warName - 
-    */
-   protected String buildWebContext(String ctxPath, String warName, JBossWebMetaData metaData, VFSDeploymentUnit unit)
-   {
-      // Build a war root context from the war name if one was not specified
-      String webContext = ctxPath;
+  /** This method creates a context-root string from either the
+   WEB-INF/jboss-web.xml context-root element is one exists, or the
+   filename portion of the warURL. It is called if the deployment
+   webContext value is null which indicates a standalone war deployment.
+   A war name of ROOT.war is handled as a special case of a war that
+   should be installed as the default web context.
+  * @param ctxPath - war level context-root
+  * @param warName - 
+   */
+  protected String buildWebContext(DeploymentUnit unit, String ctxPath, String warName, JBossWebMetaData metaData)
+  {
+    // Build a war root context from the war name if one was not specified
+    String webContext = ctxPath;
 
-      // Build the context from the deployment name
-      if (webContext == null)
+    // Build the context from the deployment name
+    if (webContext == null)
+    {
+      // Build the context from the war name, strip the .war suffix
+      webContext = warName;
+      webContext = webContext.replace('\\', '/');
+      if (webContext.endsWith("/"))
+        webContext = webContext.substring(0, webContext.length() - 1);
+      int prefix = webContext.lastIndexOf('/');
+      if (prefix > 0)
+        webContext = webContext.substring(prefix + 1);
+      int suffix = webContext.lastIndexOf(".war");
+      if (suffix > 0)
+        webContext = webContext.substring(0, suffix);
+      // Strip any '<int-value>.' prefix
+      int index = 0;
+      for (; index < webContext.length(); index++)
       {
-         // Build the context from the war name, strip the .war suffix
-         webContext = warName;
-         webContext = webContext.replace('\\', '/');
-         if (webContext.endsWith("/"))
-            webContext = webContext.substring(0, webContext.length() - 1);
-         int prefix = webContext.lastIndexOf('/');
-         if (prefix > 0)
-            webContext = webContext.substring(prefix + 1);
-         int suffix = webContext.lastIndexOf(".war");
-         if (suffix > 0)
-            webContext = webContext.substring(0, suffix);
-         // Strip any '<int-value>.' prefix
-         int index = 0;
-         for (; index < webContext.length(); index++)
-         {
-            char c = webContext.charAt(index);
-            if (Character.isDigit(c) == false && c != '.')
-               break;
-         }
-         webContext = webContext.substring(index);
+        char c = webContext.charAt(index);
+        if (Character.isDigit(c) == false && c != '.')
+          break;
       }
+      webContext = webContext.substring(index);
+    }
 
-      // Servlet containers are anal about the web context starting with '/'
-      if (webContext.length() > 0 && webContext.charAt(0) != '/')
-         webContext = "/" + webContext;
-      // And also the default root context must be an empty string, not '/'
-      else if (webContext.equals("/"))
-         webContext = "";
-      return webContext;
-   }
+    // Servlet containers are anal about the web context starting with '/'
+    if (webContext.length() > 0 && webContext.charAt(0) != '/')
+      webContext = "/" + webContext;
+    
+    // And also the default root context must be an empty string, not '/'
+    else if (webContext.equals("/"))
+      webContext = "";
+    
+    return webContext;
+  }
 
-   /**
-    * TODO: The use of an MBeanServer needs to be removed
-    * @return
-    */
-   @Deprecated
-   protected MBeanServer getServer()
-   {
-      return server;
-   }
+  /**
+   * TODO: The use of an MBeanServer needs to be removed
+   * @return
+   */
+  @Deprecated
+  protected MBeanServer getServer()
+  {
+    return server;
+  }
 
-   public MainDeployerStructure getMainDeployer()
-   {
-      return mainDeployer;
-   }
+  public MainDeployerStructure getMainDeployer()
+  {
+    return mainDeployer;
+  }
 
-   public void setMainDeployer(MainDeployerStructure mainDeployer)
-   {
-      this.mainDeployer = mainDeployer;
-   }
+  public void setMainDeployer(MainDeployerStructure mainDeployer)
+  {
+    this.mainDeployer = mainDeployer;
+  }
 
-   /**
-    * Get the object name of the ServiceMetaData instance associated with
-    * the WebMetaData. This uses the pattern:
-    * "jboss.web.deployment:war="+metaData.getContextRoot()
-    * if there are no virtual hosts, otherwise
-    * "jboss.web.deployment:war="+metaData.getVirtualHosts()[0]+metaData.getContextRoot()
-    * @param metaData - the web app metaData
-    * @return the war object name
-    */
-   protected String getObjectName(JBossWebMetaData metaData)
-   {
-      // Obtain the war virtual host and context root to define a unique war name
-      String virtualHost = "";
-      List<String> hosts = metaData.getVirtualHosts();
-      if(hosts != null && hosts.size() > 0)
-      {
-         virtualHost = hosts.get(0);
-      }
-      String ctxPath = metaData.getContextRoot();
-      // The ctx path value cannot be empty in the object name
-      if (ctxPath == null || ctxPath.length() == 0)
-         ctxPath = "/";
-      String objectName = "jboss.web.deployment:war=" + virtualHost + ctxPath;
-      return objectName;
-   }
+  /**
+   * Get the object name of the ServiceMetaData instance associated with
+   * the WebMetaData. This uses the pattern:
+   * "jboss.web.deployment:war="+metaData.getContextRoot()
+   * if there are no virtual hosts, otherwise
+   * "jboss.web.deployment:war="+metaData.getVirtualHosts()[0]+metaData.getContextRoot()
+   * @param metaData - the web app metaData
+   * @return the war object name
+   */
+  protected String getObjectName(JBossWebMetaData metaData)
+  {
+    // Obtain the war virtual host and context root to define a unique war name
+    String virtualHost = "";
+    List<String> hosts = metaData.getVirtualHosts();
+    if (hosts != null && hosts.size() > 0)
+    {
+      virtualHost = hosts.get(0);
+    }
+    String ctxPath = metaData.getContextRoot();
+    
+    // The ctx path value cannot be empty in the object name
+    if (ctxPath == null || ctxPath.length() == 0)
+      ctxPath = "/";
+    
+    String objectName = "jboss.web.deployment:war=" + virtualHost + ctxPath;
+    return objectName;
+  }
 
-   /**
-    * Called by deploy first to create a ServiceMetaData instance that wraps the
-    * AbstractWarDeployment bean and then attach it to the deployment unit. The
-    * presence of the ServiceMetaData attachment makes the deployment unit
-    * "relevant" to the deployers that handle mbean services.
-    * 
-    * @param unit - the deployment unit
-    * @param metaData - the web app metadata passed to deploy
-    * @param deployment - the web app deployment bean created by getDeployment
-    * @throws Exception
-    */
-   protected void deployWebModule(VFSDeploymentUnit unit, JBossWebMetaData metaData, AbstractWarDeployment deployment) throws Exception
-   {
-      log.debug("deployWebModule: " + unit.getName());
-      try
-      {
-         ServiceMetaData webModule = new ServiceMetaData();
-         String name = getObjectName(metaData);
-         ObjectName objectName = new ObjectName(name);
-         webModule.setObjectName(objectName);
-         webModule.setCode(WebModule.class.getName());
-         // WebModule(DeploymentUnit, AbstractWarDeployer, AbstractWarDeployment)
-         ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
-         constructor.setSignature(new String[] { VFSDeploymentUnit.class.getName(), AbstractWarDeployer.class.getName(), AbstractWarDeployment.class.getName() });
-         constructor.setParameters(new Object[] { unit, this, deployment });
-         webModule.setConstructor(constructor);
+  /**
+   * Called by deploy first to create a ServiceMetaData instance that wraps the
+   * AbstractWarDeployment bean and then attach it to the deployment unit. The
+   * presence of the ServiceMetaData attachment makes the deployment unit
+   * "relevant" to the deployers that handle mbean services.
+   * 
+   * @param unit - the deployment unit
+   * @param metaData - the web app metadata passed to deploy
+   * @param deployment - the web app deployment bean created by getDeployment
+   * @throws Exception
+   */
+  protected void deployWebModule(DeploymentUnit unit, JBossWebMetaData metaData, AbstractWarDeployment deployment) throws Exception
+  {
+    log.debug("deployWebModule: " + unit.getName());
+    try
+    {
+      ServiceMetaData webModule = new ServiceMetaData();
+      String name = getObjectName(metaData);
+      ObjectName objectName = new ObjectName(name);
+      webModule.setObjectName(objectName);
+      webModule.setCode(WebModule.class.getName());
+      
+      // WebModule(DeploymentUnit, AbstractWarDeployer, AbstractWarDeployment)
+      ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
+      constructor.setSignature(new String[] { DeploymentUnit.class.getName(), AbstractWarDeployer.class.getName(), AbstractWarDeployment.class.getName() });
+      constructor.setParameters(new Object[] { unit, this, deployment });
+      webModule.setConstructor(constructor);
 
-         List<ServiceAttributeMetaData> attrs = new ArrayList<ServiceAttributeMetaData>();
+      List<ServiceAttributeMetaData> attrs = new ArrayList<ServiceAttributeMetaData>();
 
-         ServiceAttributeMetaData attr = new ServiceAttributeMetaData();
-         attr.setName("SecurityManagement");
-         ServiceInjectionValueMetaData injectionValue = new ServiceInjectionValueMetaData(deployment.getSecurityManagementName());
-         attr.setValue(injectionValue);
-         attrs.add(attr);
-         
-         ServiceAttributeMetaData attrPR = new ServiceAttributeMetaData();
-         attrPR.setName("PolicyRegistration");
-         ServiceInjectionValueMetaData injectionValuePR = new ServiceInjectionValueMetaData(deployment.getPolicyRegistrationName());
-         attrPR.setValue(injectionValuePR);
-         attrs.add(attrPR);
-         
-         ServiceAttributeMetaData attrKernel = new ServiceAttributeMetaData();
-         attrKernel.setName("Kernel");
-         ServiceInjectionValueMetaData injectionValueKernel = new ServiceInjectionValueMetaData(KernelConstants.KERNEL_NAME);
-         attrKernel.setValue(injectionValueKernel);
-         attrs.add(attrKernel);
+      ServiceAttributeMetaData attr = new ServiceAttributeMetaData();
+      attr.setName("SecurityManagement");
+      ServiceInjectionValueMetaData injectionValue = new ServiceInjectionValueMetaData(deployment.getSecurityManagementName());
+      attr.setValue(injectionValue);
+      attrs.add(attr);
 
-         webModule.setAttributes(attrs);
+      ServiceAttributeMetaData attrPR = new ServiceAttributeMetaData();
+      attrPR.setName("PolicyRegistration");
+      ServiceInjectionValueMetaData injectionValuePR = new ServiceInjectionValueMetaData(deployment.getPolicyRegistrationName());
+      attrPR.setValue(injectionValuePR);
+      attrs.add(attrPR);
 
-         // Dependencies...Still have old jmx names here
-         Collection<String> depends = metaData.getDepends();
-         List<ServiceDependencyMetaData> dependencies = new ArrayList<ServiceDependencyMetaData>();
-         if (depends != null && depends.isEmpty() == false)
-         {
-            if (log.isTraceEnabled())
-               log.trace(name + " has dependencies: " + depends);
+      ServiceAttributeMetaData attrKernel = new ServiceAttributeMetaData();
+      attrKernel.setName("Kernel");
+      ServiceInjectionValueMetaData injectionValueKernel = new ServiceInjectionValueMetaData(KernelConstants.KERNEL_NAME);
+      attrKernel.setValue(injectionValueKernel);
+      attrs.add(attrKernel);
 
-            for (String iDependOn : depends)
-            {
-               ServiceDependencyMetaData sdmd = new ServiceDependencyMetaData();
-               sdmd.setIDependOn(iDependOn);
-               dependencies.add(sdmd);
-            }
-         }
-         webModule.setDependencies(dependencies);
+      webModule.setAttributes(attrs);
 
-         // Here's where a bit of magic happens. By attaching the ServiceMetaData
-         // to the deployment, we now make the deployment "relevant" to
-         // deployers that use ServiceMetaData as an input (e.g. the
-         // org.jboss.system.deployers.ServiceDeployer).  Those deployers
-         // can now take over deploying the web module.
+      // Dependencies...Still have old jmx names here
+      Collection<String> depends = metaData.getDepends();
+      List<ServiceDependencyMetaData> dependencies = new ArrayList<ServiceDependencyMetaData>();
+      if (depends != null && depends.isEmpty() == false)
+      {
+        if (log.isTraceEnabled())
+          log.trace(name + " has dependencies: " + depends);
 
-         unit.addAttachment("WarServiceMetaData", webModule, ServiceMetaData.class);
+        for (String iDependOn : depends)
+        {
+          ServiceDependencyMetaData sdmd = new ServiceDependencyMetaData();
+          sdmd.setIDependOn(iDependOn);
+          dependencies.add(sdmd);
+        }
       }
-      catch (Exception e)
-      {
-         throw DeploymentException.rethrowAsDeploymentException("Error creating rar deployment " + unit.getName(), e);
-      }
-   }
+      webModule.setDependencies(dependencies);
+
+      // Here's where a bit of magic happens. By attaching the ServiceMetaData
+      // to the deployment, we now make the deployment "relevant" to
+      // deployers that use ServiceMetaData as an input (e.g. the
+      // org.jboss.system.deployers.ServiceDeployer). Those deployers
+      // can now take over deploying the web module.
+
+      unit.addAttachment("WarServiceMetaData", webModule, ServiceMetaData.class);
+    }
+    catch (Exception e)
+    {
+      throw DeploymentException.rethrowAsDeploymentException("Error creating rar deployment " + unit.getName(), e);
+    }
+  }
 }

Modified: branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java
===================================================================
--- branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -36,6 +36,7 @@
 import javax.naming.NamingException;
 
 import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.bootstrap.spi.ServerConfig;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
@@ -126,22 +127,22 @@
    /**
     * The default security-domain name to use
     */
-   protected String defaultSecurityDomain; 
-   
+   protected String defaultSecurityDomain;
+
    /** The Security PolicyRegistration Name **/
    protected String policyRegistrationName;
-   
+
    /** The Security PolicyRegistration **/
    protected PolicyRegistration policyRegistration;
 
    /** The security management name */
    protected String securityManagementName;
-   
+
    /** The security management */
    protected ISecurityManagement securityManagement;
-   
+
    private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
-   
+
    public AbstractWarDeployment()
    {
       log = Logger.getLogger(getClass());
@@ -166,16 +167,16 @@
     */
    public static String shortWarUrlFromServerHome(String warUrl)
    {
-       String serverHomeUrl =  System.getProperty(org.jboss.bootstrap.spi.ServerConfig.SERVER_HOME_URL);
+      String serverHomeUrl = System.getProperty(ServerConfig.SERVER_HOME_URL);
 
-       if (warUrl == null || serverHomeUrl == null)
-           return warUrl;
+      if (warUrl == null || serverHomeUrl == null)
+         return warUrl;
 
-       if (warUrl.startsWith(serverHomeUrl))
+      if (warUrl.startsWith(serverHomeUrl))
          return ".../" + warUrl.substring(serverHomeUrl.length());
-       else
+      else
          return warUrl;
-   } 
+   }
 
    /**
     * Initialize the deployment using an instance specific configuration object.
@@ -279,8 +280,8 @@
     */
    public String getDefaultSecurityDomain()
    {
-	  if(defaultSecurityDomain == null)
-		  throw new IllegalStateException("Default Security Domain is null");
+      if (defaultSecurityDomain == null)
+         throw new IllegalStateException("Default Security Domain is null");
       return defaultSecurityDomain;
    }
 
@@ -294,19 +295,19 @@
    public void setDefaultSecurityDomain(String defaultSecurityDomain)
    {
       this.defaultSecurityDomain = defaultSecurityDomain;
-   } 
+   }
 
    protected PersistenceUnitDependencyResolver getPersistenceUnitDependencyResolver()
    {
       return persistenceUnitDependencyResolver;
    }
-   
+
    @Inject
    public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
    {
       this.persistenceUnitDependencyResolver = resolver;
    }
-   
+
    /**
     * Get the Policy Registration Name
     * @return
@@ -361,7 +362,7 @@
    public void setSecurityManagementName(String securityManagement)
    {
       this.securityManagementName = securityManagement;
-   } 
+   }
 
    /**
     * Get the securityManagement.
@@ -415,8 +416,7 @@
     * be null if war was is not being deployed as part of an enterprise
     * application. It also contains the URL of the web application war.
     */
-   public synchronized WebApplication start(VFSDeploymentUnit unit, JBossWebMetaData metaData)
-      throws Exception
+   public synchronized WebApplication start(DeploymentUnit unit, JBossWebMetaData metaData) throws Exception
    {
       Thread thread = Thread.currentThread();
       ClassLoader appClassLoader = thread.getContextClassLoader();
@@ -425,39 +425,39 @@
       {
          // Create a classloader for the war to ensure a unique ENC
          // TODO: this should be handled by the WarClassLoaderDeployer
-         /*
-         VirtualFile root = unit.getRoot();
-         URL[] empty = {root.toURL()};
-         URLClassLoader warLoader = URLClassLoader.newInstance(empty, unit.getClassLoader());
-         */
          ClassLoader warLoader = unit.getClassLoader();
          thread.setContextClassLoader(warLoader);
          String webContext = metaData.getContextRoot();
-   
+
          // Get the war URL
-         // FIXME: JBAS-3812 - TomcatDeployment should use modified WebMetaData
          URL warURL = unit.getAttachment("org.jboss.web.expandedWarURL", URL.class);
+         if (warURL == null && unit instanceof VFSDeploymentUnit)
+            warURL = ((VFSDeploymentUnit)unit).getRoot().toURL();
+
+         // For in-memory WebMetaData deployments we use the deployment name as the warURL
+         // The WS Endpoint API uses this approach
          if (warURL == null)
-            warURL = unit.getRoot().toURL();
+            warURL = new URL(unit.getName());
 
          // Strip any jar: url syntax. This should be be handled by the vfs
-         String warURLString = warURL.toString();
-         if( warURLString.startsWith("jar:") )
-            warURLString = warURLString.substring(4, warURLString.length()-2);
-         
+         String warURLStr = warURL.toString();
+         if (warURLStr.startsWith("jar:"))
+            warURLStr = warURLStr.substring(4, warURLStr.length() - 2);
+
          log.debug("webContext: " + webContext);
-         log.debug("warURL: " + warURLString);
-   
+         log.debug("warURL: " + warURLStr);
+
          // Register the permissions with the JACC layer
          String contextID = metaData.getJaccContextID();
-         if( contextID == null )
+         if (contextID == null)
             contextID = unit.getSimpleName();
-         metaData.setJaccContextID(contextID);  
-   
+
+         metaData.setJaccContextID(contextID);
+
          webApp = new WebApplication(metaData);
          webApp.setClassLoader(warLoader);
          webApp.setDeploymentUnit(unit);
-         performDeploy(webApp, warURLString);
+         performDeploy(webApp, warURLStr);
       }
       finally
       {
@@ -472,12 +472,11 @@
     * performUndeploy()} method to perform the container specific undeployment
     * steps and unregisters the the warUrl from the deployment map.
     */
-   public synchronized void stop(DeploymentUnit di, WebApplication webApp)
-      throws Exception
+   public synchronized void stop(DeploymentUnit di, WebApplication webApp) throws Exception
    {
       URL warURL = webApp.getURL();
       String warUrl = warURL.toString();
-      performUndeploy(webApp, warUrl); 
+      performUndeploy(webApp, warUrl);
    }
 
    /**
@@ -490,6 +489,7 @@
     * @param warUrl The string for the URL of the web application war.
     */
    protected abstract void performDeploy(WebApplication webApp, String warUrl) throws Exception;
+
    /**
     * Called as part of the stop() method template to ask the subclass for
     * perform the web container specific undeployment steps.
@@ -498,8 +498,7 @@
     * application/module/web application.xml descriptor and virtual-host.
     * @param warUrl The string for the URL of the web application war.
     */
-   protected abstract void performUndeploy(WebApplication webApp, String warUrl)
-      throws Exception;
+   protected abstract void performUndeploy(WebApplication webApp, String warUrl) throws Exception;
 
    /**
     * This method is invoked from within subclass performDeploy() method
@@ -508,11 +507,10 @@
     * @param metaData the WebMetaData from the WebApplication object passed to
     * the performDeploy method.
     */
-   protected void processEnc(ClassLoader loader, WebApplication webApp)
-      throws Exception
+   protected void processEnc(ClassLoader loader, WebApplication webApp) throws Exception
    {
-	  if(loader == null)
-		  throw new IllegalArgumentException("Classloader passed to process ENC refs is null");
+      if (loader == null)
+         throw new IllegalArgumentException("Classloader passed to process ENC refs is null");
       log.debug("AbstractWebContainer.parseWebAppDescriptors, Begin");
       InitialContext iniCtx = new InitialContext();
       Context envCtx = null;
@@ -531,15 +529,15 @@
          }
          // TODO: The enc should be an input?
          currentThread.setContextClassLoader(loader);
-         //webApp.setENCLoader(loader);
-         envCtx = (Context) iniCtx.lookup("java:comp");
+         // webApp.setENCLoader(loader);
+         envCtx = (Context)iniCtx.lookup("java:comp");
 
          // TODO: inject the ORB
          ORB orb = null;
          try
          {
             ObjectName ORB_NAME = new ObjectName("jboss:service=CorbaORB");
-            orb = (ORB) server.getAttribute(ORB_NAME, "ORB");
+            orb = (ORB)server.getAttribute(ORB_NAME, "ORB");
             // Bind the orb
             if (orb != null)
             {
@@ -569,10 +567,9 @@
       log.debug("AbstractWebContainer.parseWebAppDescriptors, End");
    }
 
-   protected void processEncReferences(WebApplication webApp, Context envCtx)
-           throws ClassNotFoundException, NamingException
+   protected void processEncReferences(WebApplication webApp, Context envCtx) throws ClassNotFoundException, NamingException
    {
-      VFSDeploymentUnit unit = webApp.getDeploymentUnit();
+      DeploymentUnit unit = webApp.getDeploymentUnit();
       JBossWebMetaData metaData = webApp.getMetaData();
       EnvironmentEntriesMetaData envEntries = metaData.getEnvironmentEntries();
       log.debug("addEnvEntries");
@@ -597,32 +594,33 @@
       linkServiceRefs(unit, serviceRefs, envCtx);
    }
 
-   private void linkServiceRefs(VFSDeploymentUnit unit, ServiceReferencesMetaData serviceRefs, Context envCtx) throws NamingException
+   private void linkServiceRefs(DeploymentUnit unit, ServiceReferencesMetaData serviceRefs, Context envCtx) throws NamingException
    {
       ClassLoader loader = unit.getClassLoader();
-      UnifiedVirtualFile vfsRoot = new VirtualFileAdaptor(unit.getRoot());
-      for(ServiceReferenceMetaData sref : serviceRefs)
+      if (unit instanceof VFSDeploymentUnit)
       {
-         String refName = sref.getServiceRefName();
-         new ServiceReferenceHandler().bindServiceRef(envCtx, refName, vfsRoot, loader, sref);
+         VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)unit;
+         UnifiedVirtualFile vfsRoot = new VirtualFileAdaptor(vfsUnit.getRoot());
+         for (ServiceReferenceMetaData sref : serviceRefs)
+         {
+            String refName = sref.getServiceRefName();
+            new ServiceReferenceHandler().bindServiceRef(envCtx, refName, vfsRoot, loader, sref);
+         }
       }
    }
 
-   protected void addEnvEntries(EnvironmentEntriesMetaData envEntries, Context envCtx)
-      throws ClassNotFoundException, NamingException
+   protected void addEnvEntries(EnvironmentEntriesMetaData envEntries, Context envCtx) throws ClassNotFoundException, NamingException
    {
       for (EnvironmentEntryMetaData entry : envEntries)
       {
-         log.debug("Binding env-entry: " + entry.getName() + " of type: " +
-            entry.getType() + " to value:" + entry.getValue());
+         log.debug("Binding env-entry: " + entry.getName() + " of type: " + entry.getType() + " to value:" + entry.getValue());
          bindEnvEntry(envCtx, entry);
       }
    }
 
-   protected void linkResourceEnvRefs(ResourceEnvironmentReferencesMetaData resourceEnvRefs, Context envCtx)
-      throws NamingException
+   protected void linkResourceEnvRefs(ResourceEnvironmentReferencesMetaData resourceEnvRefs, Context envCtx) throws NamingException
    {
-      for(ResourceEnvironmentReferenceMetaData ref : resourceEnvRefs)
+      for (ResourceEnvironmentReferenceMetaData ref : resourceEnvRefs)
       {
          String resourceName = ref.getJndiName();
          String refName = ref.getResourceEnvRefName();
@@ -646,16 +644,14 @@
          }
          else
          {
-            throw new NamingException("resource-env-ref: " + refName
-               + " has no valid JNDI binding. Check the jboss-web/resource-env-ref.");
+            throw new NamingException("resource-env-ref: " + refName + " has no valid JNDI binding. Check the jboss-web/resource-env-ref.");
          }
       }
    }
 
-   protected void linkResourceRefs(ResourceReferencesMetaData resourceRefs, Context envCtx)
-      throws NamingException
+   protected void linkResourceRefs(ResourceReferencesMetaData resourceRefs, Context envCtx) throws NamingException
    {
-      for(ResourceReferenceMetaData ref : resourceRefs)
+      for (ResourceReferenceMetaData ref : resourceRefs)
       {
          String jndiName = ref.getJndiName();
          String refName = ref.getResourceName();
@@ -689,16 +685,14 @@
          }
          else
          {
-            throw new NamingException("resource-ref: " + refName
-               + " has no valid JNDI binding. Check the jboss-web/resource-ref.");
+            throw new NamingException("resource-ref: " + refName + " has no valid JNDI binding. Check the jboss-web/resource-ref.");
          }
       }
    }
 
-   protected void linkMessageDestinationRefs(DeploymentUnit unit, MessageDestinationReferencesMetaData msgRefs, Context envCtx)
-      throws NamingException
+   protected void linkMessageDestinationRefs(DeploymentUnit unit, MessageDestinationReferencesMetaData msgRefs, Context envCtx) throws NamingException
    {
-      for(MessageDestinationReferenceMetaData ref : msgRefs)
+      for (MessageDestinationReferenceMetaData ref : msgRefs)
       {
          String refName = ref.getName();
          String jndiName = ref.getJndiName();
@@ -709,8 +703,8 @@
             {
                MessageDestinationMetaData messageDestination = EjbUtil50.findMessageDestination(mainDeployer, unit, link);
                if (messageDestination == null)
-                  throw new NamingException("message-destination-ref '" + refName +
-                     "' message-destination-link '" + link + "' not found and no jndi-name in jboss-web.xml");
+                  throw new NamingException("message-destination-ref '" + refName + "' message-destination-link '" + link
+                        + "' not found and no jndi-name in jboss-web.xml");
                else
                {
                   String linkJNDIName = messageDestination.getJndiName();
@@ -721,37 +715,33 @@
                }
             }
             else
-               log.warn("message-destination-ref '" + refName +
-                  "' ignoring message-destination-link '" + link + "' because it has a jndi-name in jboss-web.xml");
+               log.warn("message-destination-ref '" + refName + "' ignoring message-destination-link '" + link + "' because it has a jndi-name in jboss-web.xml");
          }
          else if (jndiName == null)
-            throw new NamingException("message-destination-ref '" + refName +
-               "' has no message-destination-link in web.xml and no jndi-name in jboss-web.xml");
+            throw new NamingException("message-destination-ref '" + refName + "' has no message-destination-link in web.xml and no jndi-name in jboss-web.xml");
          Util.bind(envCtx, refName, new LinkRef(jndiName));
       }
    }
 
-   protected void linkEjbRefs(DeploymentUnit unit, EJBReferencesMetaData ejbRefs, Context envCtx)
-      throws NamingException
+   protected void linkEjbRefs(DeploymentUnit unit, EJBReferencesMetaData ejbRefs, Context envCtx) throws NamingException
    {
-      for(EJBReferenceMetaData ejb : ejbRefs)
+      for (EJBReferenceMetaData ejb : ejbRefs)
       {
          String name = ejb.getName();
          String linkName = ejb.getLink();
          String jndiName = null;
-         
-         //use ejb-link if it is specified
+
+         // use ejb-link if it is specified
          if (linkName != null)
          {
             jndiName = EjbUtil50.findEjbLink(mainDeployer, unit, linkName);
-             
-            //if flag does not allow misconfigured ejb-links, it is an error
+
+            // if flag does not allow misconfigured ejb-links, it is an error
             if ((jndiName == null) && !(getLenientEjbLink()))
                throw new NamingException("ejb-ref: " + name + ", no ejb-link match");
          }
 
-         
-         //fall through to the jndiName
+         // fall through to the jndiName
          if (jndiName == null)
          {
             jndiName = ejb.getJndiName();
@@ -764,26 +754,24 @@
       }
    }
 
-   protected void linkEjbLocalRefs(DeploymentUnit unit, EJBLocalReferencesMetaData ejbLocalRefs, Context envCtx)
-      throws NamingException
+   protected void linkEjbLocalRefs(DeploymentUnit unit, EJBLocalReferencesMetaData ejbLocalRefs, Context envCtx) throws NamingException
    {
-      for(EJBLocalReferenceMetaData ejb : ejbLocalRefs)
+      for (EJBLocalReferenceMetaData ejb : ejbLocalRefs)
       {
          String name = ejb.getName();
          String linkName = ejb.getLink();
          String jndiName = null;
 
-         //use the ejb-link field if it is specified
+         // use the ejb-link field if it is specified
          if (linkName != null)
          {
             jndiName = EjbUtil50.findLocalEjbLink(mainDeployer, unit, linkName);
-             
-            //if flag does not allow misconfigured ejb-links, it is an error    
+
+            // if flag does not allow misconfigured ejb-links, it is an error
             if ((jndiName == null) && !(getLenientEjbLink()))
                throw new NamingException("ejb-ref: " + name + ", no ejb-link match");
          }
 
-
          if (jndiName == null)
          {
             jndiName = ejb.getJndiName();
@@ -792,13 +780,11 @@
                String msg = null;
                if (linkName == null)
                {
-                  msg = "ejb-local-ref: '" + name + "', no ejb-link in web.xml and "
-                     + "no local-jndi-name in jboss-web.xml";
+                  msg = "ejb-local-ref: '" + name + "', no ejb-link in web.xml and " + "no local-jndi-name in jboss-web.xml";
                }
                else
                {
-                  msg = "ejb-local-ref: '" + name + "', with web.xml ejb-link: '"
-                     + linkName + "' failed to resolve to an ejb with a LocalHome";
+                  msg = "ejb-local-ref: '" + name + "', with web.xml ejb-link: '" + linkName + "' failed to resolve to an ejb with a LocalHome";
                }
                throw new NamingException(msg);
             }
@@ -818,23 +804,22 @@
     * element. If there was no security-domain element then the bindings are to
     * NullSecurityManager instance which simply allows all access.
     */
-   protected void linkSecurityDomain(String securityDomain, Context envCtx)
-      throws NamingException
+   protected void linkSecurityDomain(String securityDomain, Context envCtx) throws NamingException
    {
       if (securityDomain == null)
       {
          securityDomain = getDefaultSecurityDomain();
          log.debug("No security-domain given, using default: " + securityDomain);
       }
-      
-      //JBAS-6060: Tolerate a Security Domain configuration without the java:/jaas prefix
-      if(securityDomain.startsWith(SecurityConstants.JAAS_CONTEXT_ROOT) == false)
+
+      // JBAS-6060: Tolerate a Security Domain configuration without the java:/jaas prefix
+      if (securityDomain.startsWith(SecurityConstants.JAAS_CONTEXT_ROOT) == false)
          securityDomain = SecurityConstants.JAAS_CONTEXT_ROOT + "/" + securityDomain;
-      
+
       log.debug("Linking security/securityMgr to JNDI name: " + securityDomain);
       Util.bind(envCtx, "security/securityMgr", new LinkRef(securityDomain));
-      Util.bind(envCtx, "security/realmMapping", new LinkRef(securityDomain+"/realmMapping"));
-      Util.bind(envCtx, "security/authorizationMgr", new LinkRef(securityDomain+"/authorizationMgr"));
+      Util.bind(envCtx, "security/realmMapping", new LinkRef(securityDomain + "/realmMapping"));
+      Util.bind(envCtx, "security/authorizationMgr", new LinkRef(securityDomain + "/authorizationMgr"));
       Util.bind(envCtx, "security/security-domain", new LinkRef(securityDomain));
       Util.bind(envCtx, "security/subject", new LinkRef(securityDomain + "/subject"));
    }
@@ -848,11 +833,7 @@
     */
    public String[] getStandardCompileClasspath(ClassLoader loader)
    {
-      String[] jspResources = {
-         "javax/servlet/resources/web-app_2_3.dtd",
-         "org/apache/jasper/resources/jsp12.dtd",
-         "javax/ejb/EJBHome.class"
-      };
+      String[] jspResources = { "javax/servlet/resources/web-app_2_3.dtd", "org/apache/jasper/resources/jsp12.dtd", "javax/ejb/EJBHome.class" };
       ArrayList tmp = new ArrayList();
       for (int j = 0; j < jspResources.length; j++)
       {
@@ -897,8 +878,7 @@
       }
       try
       {
-         URL[] globalUrls = (URL[]) server.getAttribute(LoaderRepositoryFactory.DEFAULT_LOADER_REPOSITORY,
-            "URLs");
+         URL[] globalUrls = (URL[])server.getAttribute(LoaderRepositoryFactory.DEFAULT_LOADER_REPOSITORY, "URLs");
          addURLs(tmp, globalUrls);
       }
       catch (Exception e)
@@ -918,10 +898,9 @@
          URL url = urls[u];
          urlSet.add(url.toExternalForm());
       }
-   } 
+   }
 
-   public static void bindEnvEntry(Context ctx, EnvironmentEntryMetaData entry)
-      throws ClassNotFoundException, NamingException
+   public static void bindEnvEntry(Context ctx, EnvironmentEntryMetaData entry) throws ClassNotFoundException, NamingException
    {
       ClassLoader loader = EnvironmentEntryMetaData.class.getClassLoader();
       Class type = loader.loadClass(entry.getType());
@@ -955,7 +934,7 @@
          String input = entry.getValue();
          if (input == null || input.length() == 0)
          {
-            value = new Character((char) 0);
+            value = new Character((char)0);
          }
          else
          {
@@ -978,4 +957,3 @@
       }
    }
 }
-

Modified: branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/WebModule.java
===================================================================
--- branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/WebModule.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/server/src/main/org/jboss/web/deployers/WebModule.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -21,6 +21,7 @@
  */
 package org.jboss.web.deployers;
 
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.deployment.DeploymentException;
 import org.jboss.kernel.Kernel;
@@ -49,18 +50,18 @@
 {
    private static Logger log = Logger.getLogger(WebModule.class);
 
-   private VFSDeploymentUnit di;
+   private DeploymentUnit unit;
    private AbstractWarDeployer container;
    private AbstractWarDeployment deployment; 
 
    private ISecurityManagement securityManagement;
    
-   public WebModule(VFSDeploymentUnit di, AbstractWarDeployer container, AbstractWarDeployment deployment)
+   public WebModule(DeploymentUnit unit, AbstractWarDeployer container, AbstractWarDeployment deployment)
    {
-      this.di = di;
+      this.unit = unit;
       this.container = container;
       this.deployment = deployment;
-      this.deployment.setDeploymentUnit(di);
+      this.deployment.setDeploymentUnit(unit);
    }
 
    public void setKernel(Kernel kernel)
@@ -103,7 +104,7 @@
 
    public void destroy()
    {
-      this.di = null;
+      this.unit = null;
       this.container = null;
       this.deployment = null;      
    }
@@ -114,10 +115,10 @@
       throws Exception
    {
       // Get the war URL
-      JBossWebMetaData metaData = di.getAttachment(JBossWebMetaData.class); 
-      WebApplication webApp = deployment.start(di, metaData);
-      String warURL = di.getName();
-      container.addDeployedApp(warURL, webApp);
+      JBossWebMetaData metaData = unit.getAttachment(JBossWebMetaData.class); 
+      WebApplication webApp = deployment.start(unit, metaData);
+      String depName = unit.getName();
+      container.addDeployedApp(depName, webApp);
    }
 
    /** Invokes the deployer stop
@@ -125,17 +126,17 @@
    public synchronized void stopModule()
       throws DeploymentException
    {
-      String warURL = di.getName();
+      String depName = unit.getName();
       try
       {
-         WebApplication webApp = container.removeDeployedApp(warURL);
+         WebApplication webApp = container.removeDeployedApp(depName);
          if( deployment != null && webApp != null )
          {
-            deployment.stop(di, webApp);
+            deployment.stop(unit, webApp);
          }
          else
          {
-            log.debug("Failed to find deployer/deployment for war: "+warURL);
+            log.debug("Failed to find deployer/deployment for war: "+depName);
          }
       }
       catch (Exception e)

Modified: branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
===================================================================
--- branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -45,6 +45,7 @@
 import javax.servlet.Servlet;
 
 import org.apache.InstanceManager;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.deployment.MappedReferenceMetaDataResolverDeployer;
 import org.jboss.deployment.dependency.ContainerDependencyMetaData;
@@ -127,7 +128,7 @@
 
    protected DependencyPolicy dependencyPolicy = new JBoss5DependencyPolicy(this);
    protected Collection<InjectionHandler<Environment>> handlers;
-   protected VFSDeploymentUnit unit;
+   protected DeploymentUnit unit;
    protected ClassLoader webLoader;
    protected WebApplication appInfo;
    protected JBossWebMetaData webDD;
@@ -183,7 +184,7 @@
        dynamicClassLoaders.add("org.apache.jasper.servlet.JasperLoader");
    }
    
-   public TomcatInjectionContainer(WebApplication appInfo, VFSDeploymentUnit unit, org.apache.catalina.Context catalinaContext, PersistenceUnitDependencyResolver resolver)
+   public TomcatInjectionContainer(WebApplication appInfo, DeploymentUnit unit, org.apache.catalina.Context catalinaContext, PersistenceUnitDependencyResolver resolver)
    {
       super(new SimpleJavaEEModule(appInfo.getName()));
       
@@ -567,7 +568,10 @@
 
    public VirtualFile getRootFile()
    {
-      return unit.getRoot();
+      if (unit instanceof VFSDeploymentUnit)
+         return ((VFSDeploymentUnit)unit).getRoot();
+      else
+         return null;
    }
 
    public String getIdentifier()

Modified: branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
===================================================================
--- branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -99,7 +99,7 @@
    private static Logger log = Logger.getLogger(JBossContextConfig.class);
 
    private boolean runDestroy = false;
-   
+
    /**
     * <p>
     * Creates a new instance of {@code JBossContextConfig}.
@@ -145,7 +145,7 @@
    {
       if (context instanceof StandardContext)
       {
-         ((StandardContext) context).setReplaceWelcomeFiles(true);
+         ((StandardContext)context).setReplaceWelcomeFiles(true);
       }
 
       // Metadata complete
@@ -161,7 +161,7 @@
       else
          context.setPublicId(org.apache.catalina.startup.Constants.WebDtdPublicId_22);
 
-      // processContextParameters() provides a merged view of the context params 
+      // processContextParameters() provides a merged view of the context params
 
       // Display name
       DescriptionGroupMetaData dg = metaData.getDescriptionGroup();
@@ -459,8 +459,8 @@
          Iterator iter = keys != null ? keys.iterator() : null;
          while (iter != null && iter.hasNext())
          {
-            String key = (String) iter.next();
-            String authenticatorStr = (String) authProps.get(key);
+            String key = (String)iter.next();
+            String authenticatorStr = (String)authProps.get(key);
             Class authClass = tcl.loadClass(authenticatorStr);
             authenticators.put(key, authClass.newInstance());
          }
@@ -480,9 +480,9 @@
     */
    private Properties getAuthenticatorsFromJndi() throws NamingException
    {
-      return (Properties) new InitialContext().lookup("TomcatAuthenticators");
+      return (Properties)new InitialContext().lookup("TomcatAuthenticators");
    }
-   
+
    /**
     * Process the context parameters. Let a user application
     * override the sharedMetaData values.
@@ -491,9 +491,9 @@
    {
       JBossWebMetaData local = metaDataLocal.get();
       JBossWebMetaData shared = metaDataShared.get();
-      
+
       Map<String, String> overrideParams = new HashMap<String, String>();
-      
+
       List<ParamValueMetaData> params = local.getContextParams();
       if (params != null)
       {
@@ -507,57 +507,54 @@
       {
          for (ParamValueMetaData param : params)
          {
-            if(overrideParams.get(param.getParamName()) == null)
+            if (overrideParams.get(param.getParamName()) == null)
             {
                overrideParams.put(param.getParamName(), param.getParamValue());
             }
          }
-      }      
-      
-      for(String key : overrideParams.keySet())
+      }
+
+      for (String key : overrideParams.keySet())
       {
          context.addParameter(key, overrideParams.get(key));
       }
-      
+
    }
 
    /**
     * Process a "init" event for this Context.
     */
-   protected void init() {
-      
-      if (TomcatService.OLD_CODE) {
-         super.init();
-         return;
-      }
-      
+   protected void init()
+   {
       context.setConfigured(false);
       ok = true;
-      
-      if (!context.getOverride()) {
-          processContextConfig("context.xml", false);
-          processContextConfig(getHostConfigPath(org.apache.catalina.startup.Constants.HostContextXml), false);
+
+      if (!context.getOverride())
+      {
+         processContextConfig("context.xml", false);
+         processContextConfig(getHostConfigPath(org.apache.catalina.startup.Constants.HostContextXml), false);
       }
       // This should come from the deployment unit
       processContextConfig(context.getConfigFile(), true);
-      
+
    }
-   
-   
+
    protected void processContextConfig(String resourceName, boolean local)
    {
       ContextMetaData contextMetaData = null;
-      try {
+      try
+      {
          SchemaBinding schema = JBossXBBuilder.build(ContextMetaData.class);
          Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
          u.setSchemaValidation(false);
          u.setValidation(false);
          u.setEntityResolver(new JBossEntityResolver());
          InputStream is = null;
-         try {
-            if (local)
+         try
+         {
+            if (local && deploymentUnitLocal instanceof VFSDeploymentUnit)
             {
-               VirtualFile vf = ((VFSDeploymentUnit) deploymentUnitLocal.get()).getFile(resourceName);
+               VirtualFile vf = ((VFSDeploymentUnit)deploymentUnitLocal.get()).getFile(resourceName);
                if (vf != null)
                   is = vf.openStream();
             }
@@ -565,34 +562,46 @@
             {
                is = getClass().getClassLoader().getResourceAsStream(resourceName);
             }
-            if (is == null) {
+            if (is == null)
+            {
                return;
             }
             contextMetaData = ContextMetaData.class.cast(u.unmarshal(is, schema));
-         } finally {
-            if (is != null) {
-               try {
+         }
+         finally
+         {
+            if (is != null)
+            {
+               try
+               {
                   is.close();
-               } catch (IOException e) {
+               }
+               catch (IOException e)
+               {
                   // Ignore
                }
             }
          }
-      } catch (Exception e) {
+      }
+      catch (Exception e)
+      {
          log.error("XML error parsing: " + resourceName, e);
          ok = false;
          return;
       }
-      
-      try {
+
+      try
+      {
          if (contextMetaData != null)
          {
-            
-            if (contextMetaData.getAttributes() != null) {
+
+            if (contextMetaData.getAttributes() != null)
+            {
                Iterator<QName> names = contextMetaData.getAttributes().keySet().iterator();
-               while (names.hasNext()) {
+               while (names.hasNext())
+               {
                   QName name = names.next();
-                  String value = (String) contextMetaData.getAttributes().get(name);
+                  String value = (String)contextMetaData.getAttributes().get(name);
                   // FIXME: This should be done by XB
                   value = StringPropertyReplacer.replaceProperties(value);
                   IntrospectionUtils.setProperty(context, name.getLocalPart(), value);
@@ -602,53 +611,59 @@
             TomcatService.addLifecycleListeners(context, contextMetaData.getListeners());
 
             // Context/Realm
-            if (contextMetaData.getRealm() != null) {
-               context.setRealm((org.apache.catalina.Realm) TomcatService.getInstance(contextMetaData.getRealm(), null));
+            if (contextMetaData.getRealm() != null)
+            {
+               context.setRealm((org.apache.catalina.Realm)TomcatService.getInstance(contextMetaData.getRealm(), null));
             }
-            
+
             // Context/Valve
             TomcatService.addValves(context, contextMetaData.getValves());
-            
+
             // Context/InstanceListener
-            if (contextMetaData.getInstanceListeners() != null) {
+            if (contextMetaData.getInstanceListeners() != null)
+            {
                Iterator<String> listeners = contextMetaData.getInstanceListeners().iterator();
                while (listeners.hasNext())
                {
                   context.addInstanceListener(listeners.next());
                }
             }
-            
+
             // Context/Loader
-            if (contextMetaData.getLoader() != null) {
+            if (contextMetaData.getLoader() != null)
+            {
                // This probably won't work very well in JBoss
-               context.setLoader((org.apache.catalina.Loader) TomcatService.getInstance(contextMetaData.getLoader(), 
-                     "org.apache.catalina.loader.WebappLoader"));
+               context.setLoader((org.apache.catalina.Loader)TomcatService.getInstance(contextMetaData.getLoader(), "org.apache.catalina.loader.WebappLoader"));
             }
-            
+
             // Context/Manager
-            if (contextMetaData.getManager() != null) {
-               context.setManager((org.apache.catalina.Manager) TomcatService.getInstance(contextMetaData.getManager(), 
+            if (contextMetaData.getManager() != null)
+            {
+               context.setManager((org.apache.catalina.Manager)TomcatService.getInstance(contextMetaData.getManager(),
                      "org.apache.catalina.session.StandardManager"));
             }
-            
+
             // Context/Parameter
-            if (contextMetaData.getParameters() != null) {
+            if (contextMetaData.getParameters() != null)
+            {
                Iterator<ParameterMetaData> parameterMetaDatas = contextMetaData.getParameters().iterator();
                while (parameterMetaDatas.hasNext())
                {
                   ParameterMetaData parameterMetaData = parameterMetaDatas.next();
-                  context.addApplicationParameter((org.apache.catalina.deploy.ApplicationParameter) TomcatService.getInstance(parameterMetaData, null));
+                  context.addApplicationParameter((org.apache.catalina.deploy.ApplicationParameter)TomcatService.getInstance(parameterMetaData, null));
                }
             }
 
             // Context/Resources
-            if (contextMetaData.getResources() != null) {
-               context.setResources((javax.naming.directory.DirContext) TomcatService.getInstance(contextMetaData.getResources(), 
+            if (contextMetaData.getResources() != null)
+            {
+               context.setResources((javax.naming.directory.DirContext)TomcatService.getInstance(contextMetaData.getResources(),
                      "org.apache.naming.resources.FileDirContext"));
             }
-            
+
             // Context/SessionCookie
-            if (contextMetaData.getSessionCookie() != null) {
+            if (contextMetaData.getSessionCookie() != null)
+            {
                SessionCookie sessionCookie = new SessionCookie();
                sessionCookie.setComment(contextMetaData.getSessionCookie().getComment());
                sessionCookie.setDomain(contextMetaData.getSessionCookie().getDomain());
@@ -657,7 +672,7 @@
                sessionCookie.setSecure(contextMetaData.getSessionCookie().getSecure());
                context.setSessionCookie(sessionCookie);
             }
-            
+
          }
       }
       catch (Exception e)
@@ -665,13 +680,15 @@
          log.error("Error processing: " + resourceName, e);
          ok = false;
       }
-      
+
    }
-   
-   protected void destroy() {
-	   if (runDestroy) {
-		   super.destroy();
-	   }
+
+   protected void destroy()
+   {
+      if (runDestroy)
+      {
+         super.destroy();
+      }
    }
-   
+
 }

Modified: branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java
===================================================================
--- branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployer.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -28,6 +28,7 @@
 
 import javax.management.ObjectName;
 
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.metadata.web.jboss.JBoss50WebMetaData;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
@@ -401,30 +402,6 @@
    }
 
    /**
-    * A trival extension of URLClassLoader that uses an empty URL[] as its classpath so that all work is delegated to
-    * its parent.
-    */
-   /*
-    * static class ENCLoader extends URLClassLoader { private boolean parentFirst;
-    * 
-    * ENCLoader(URL[] urls, ClassLoader parent, boolean parentFirst) { super(urls, parent); this.parentFirst =
-    * parentFirst; }
-    * 
-    * protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if
-    * (parentFirst) return super.loadClass(name, resolve); try { Class clazz = findClass(name); if (resolve) {
-    * resolveClass(clazz); } return clazz; } catch (ClassNotFoundException e) { return getParent().loadClass(name); } } }
-    * 
-    * public static ClassLoader getTmpLoader(URL warURL, ClassLoader parent, boolean parentFirst) throws Exception {
-    * 
-    * String path = warURL.getFile(); ArrayList<URL> list = new ArrayList<URL>(); File classesDir = new File(path,
-    * "WEB-INF/classes"); if (classesDir.exists()) { list.add(classesDir.toURL()); } File libDir = new File(path,
-    * "WEB-INF/lib"); if (libDir.exists()) { File[] jars = libDir.listFiles(); int length = jars != null ? jars.length :
-    * 0; for (int j = 0; j < length; j++) { File jar = jars[j]; if(jar.getAbsolutePath().endsWith(".jar")) {
-    * list.add(jar.toURL()); } } } ENCLoader loader = new ENCLoader(list.toArray(new URL[list.size()]), parent,
-    * parentFirst); return loader; }
-    */
-
-   /**
     * Create a tomcat war deployment bean for the deployment unit/metaData.
     * 
     * @param unit - the current web app deployment unit
@@ -432,7 +409,7 @@
     * @return TomcatDeployment instnace
     */
    @Override
-   public AbstractWarDeployment getDeployment(VFSDeploymentUnit unit, JBossWebMetaData metaData) throws Exception
+   public AbstractWarDeployment getDeployment(DeploymentUnit unit, JBossWebMetaData metaData) throws Exception
    {
       String className = (deploymentClass == null)
             ? "org.jboss.web.tomcat.service.deployers.TomcatDeployment"

Modified: branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -22,9 +22,7 @@
 package org.jboss.web.tomcat.service.deployers;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLDecoder;
@@ -40,6 +38,7 @@
 
 import javax.management.Attribute;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -51,6 +50,7 @@
 import org.apache.catalina.core.StandardContext;
 import org.apache.tomcat.util.modeler.Registry;
 import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
@@ -89,7 +89,7 @@
 
    private DeployerConfig config;
 
-   private final String[] javaVMs = {" jboss.management.local:J2EEServer=Local,j2eeType=JVM,name=localhost"};
+   private final String[] javaVMs = { " jboss.management.local:J2EEServer=Local,j2eeType=JVM,name=localhost" };
 
    private final String serverName = "jboss";
 
@@ -112,7 +112,7 @@
    @Override
    public void init(Object containerConfig) throws Exception
    {
-      this.config = (DeployerConfig) containerConfig;
+      this.config = (DeployerConfig)containerConfig;
       super.setJava2ClassLoadingCompliance(config.isJava2ClassLoadingCompliance());
       super.setUnpackWars(config.isUnpackWars());
       super.setLenientEjbLink(config.isLenientEjbLink());
@@ -120,10 +120,11 @@
    }
 
    @Override
-   protected void performDeploy(WebApplication webApp, String warUrl) throws Exception
+   protected void performDeploy(WebApplication webApp, String warUrlStr) throws Exception
    {
       // Decode the URL as tomcat can't deal with paths with escape chars
-      warUrl = URLDecoder.decode(warUrl, "UTF-8");
+      warUrlStr = URLDecoder.decode(warUrlStr, "UTF-8");
+
       webApp.setDomain(config.getCatalinaDomain());
       JBossWebMetaData metaData = webApp.getMetaData();
       String hostName = null;
@@ -143,18 +144,20 @@
             hostName = hostNames.next().toString();
          }
       }
-      performDeployInternal(hostName, webApp, warUrl);
+
+      performDeployInternal(webApp, hostName, warUrlStr);
       while (hostNames.hasNext())
       {
          String additionalHostName = hostNames.next().toString();
-         performDeployInternal(additionalHostName, webApp, warUrl);
+         performDeployInternal(webApp, additionalHostName, warUrlStr);
       }
    }
 
-   protected void performDeployInternal(String hostName, WebApplication webApp, String warUrl) throws Exception
+   protected void performDeployInternal(WebApplication webApp, String hostName, String warUrlStr) throws Exception
    {
-
       JBossWebMetaData metaData = webApp.getMetaData();
+      DeploymentUnit unit = webApp.getDeploymentUnit();
+      
       String ctxPath = metaData.getContextRoot();
       if (ctxPath.equals("/") || ctxPath.equals("/ROOT") || ctxPath.equals(""))
       {
@@ -163,105 +166,49 @@
          metaData.setContextRoot(ctxPath);
       }
 
-      log.info("deploy, ctxPath=" + ctxPath + ", vfsUrl=" + webApp.getDeploymentUnit().getFile("").getPathName());
+      log.info("deploy, ctxPath=" + ctxPath);
 
-      URL url = new URL(warUrl);
-
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
       metaData.setContextLoader(loader);
 
-      StandardContext context = (StandardContext) Class.forName(config.getContextClassName()).newInstance();
+      StandardContext context = (StandardContext)Class.forName(config.getContextClassName()).newInstance();
+      injectionContainer = new TomcatInjectionContainer(webApp, unit, context, getPersistenceUnitDependencyResolver());
 
-      injectionContainer = new TomcatInjectionContainer(webApp, webApp.getDeploymentUnit(), context,
-            getPersistenceUnitDependencyResolver());
-
-      Loader webLoader = webApp.getDeploymentUnit().getAttachment(Loader.class);
+      Loader webLoader = unit.getAttachment(Loader.class);
       if (webLoader == null)
-         webLoader = getWebLoader(webApp.getDeploymentUnit(), metaData, loader, url);
+         webLoader = getWebLoader(unit, metaData, loader);
 
-      webApp.setName(url.getPath());
+      URL warUrl = new URL(warUrlStr);
+
+      webApp.setName(ctxPath);
       webApp.setClassLoader(loader);
-      webApp.setURL(url);
+      webApp.setURL(warUrl);
 
-      String objectNameS = config.getCatalinaDomain() + ":j2eeType=WebModule,name=//"
-            + ((hostName == null) ? "localhost" : hostName) + ctxPath + ",J2EEApplication=none,J2EEServer=none";
-
-      ObjectName objectName = new ObjectName(objectNameS);
-
+      ObjectName objectName = getObjectName(hostName, ctxPath);
       if (Registry.getRegistry(null, null).getMBeanServer().isRegistered(objectName))
-         throw new DeploymentException("Web mapping already exists for deployment URL " + warUrl);
+         throw new DeploymentException("Web mapping already exists for: " + objectName);
 
       Registry.getRegistry(null, null).registerComponent(context, objectName, config.getContextClassName());
 
-      if (TomcatService.OLD_CODE)
-      {
-         String ctxConfig = null;
-         File warFile = new File(url.getFile());
-         if (warFile.isDirectory() == false)
-         {
-            // Using VFS access
-            VFSDirContext resources = new VFSDirContext();
-            resources.setVirtualFile(webApp.getDeploymentUnit().getFile(""));
-            context.setResources(resources);
-            // Find META-INF/context.xml
-            VirtualFile file = webApp.getDeploymentUnit().getFile(CONTEXT_CONFIG_FILE);
-            if (file != null)
-            {
-               // Copy the META-INF/context.xml from the VFS to the temp folder
-               InputStream is = file.openStream();
-               FileOutputStream fos = null;
-               try
-               {
-                  byte[] buffer = new byte[512];
-                  int bytes;
-                  // FIXME: use JBoss'temp folder instead
-                  File tempFile = File.createTempFile("context-", ".xml");
-                  tempFile.deleteOnExit();
-                  fos = new FileOutputStream(tempFile);
-                  while ((bytes = is.read(buffer)) > 0)
-                  {
-                     fos.write(buffer, 0, bytes);
-                  }
-                  ctxConfig = tempFile.getAbsolutePath();
-               }
-               finally
-               {
-                  is.close();
-                  if (fos != null)
-                  {
-                     fos.close();
-                  }
-               }
-            }
-         }
-         else
-         {
-            // Using direct filesystem access: no operation needed
-            // Find META-INF/context.xml
-            File webDD = new File(warFile, CONTEXT_CONFIG_FILE);
-            if (webDD.exists() == true)
-            {
-               ctxConfig = webDD.getAbsolutePath();
-            }
-         }
-
-         context.setConfigFile(ctxConfig);
-      }
-      else
-      {
-         context.setConfigFile(CONTEXT_CONFIG_FILE);
-      }
+      context.setConfigFile(CONTEXT_CONFIG_FILE);
       context.setInstanceManager(injectionContainer);
-      context.setDocBase(url.getFile());
       context.setDefaultContextXml("context.xml");
       context.setDefaultWebXml("conf/web.xml");
       context.setPublicId(metaData.getPublicID());
+
+      String docbase = unit.getAttachment("org.jboss.web.explicitDocBase", String.class);
+      if (docbase == null)
+         docbase = warUrl.getFile();
+      
+      context.setDocBase(docbase);
+
       // If there is an alt-dd set it
       if (metaData.getAlternativeDD() != null)
       {
          log.debug("Setting altDDName to: " + metaData.getAlternativeDD());
          context.setAltDDName(metaData.getAlternativeDD());
       }
+
       context.setJavaVMs(javaVMs);
       context.setServer(serverName);
       context.setSaveConfig(false);
@@ -321,31 +268,30 @@
       // Set the session cookies flag according to metadata
       switch (metaData.getSessionCookies())
       {
-         case JBossWebMetaData.SESSION_COOKIES_ENABLED :
+         case JBossWebMetaData.SESSION_COOKIES_ENABLED:
             context.setCookies(true);
             log.debug("Enabling session cookies");
             break;
-         case JBossWebMetaData.SESSION_COOKIES_DISABLED :
+         case JBossWebMetaData.SESSION_COOKIES_DISABLED:
             context.setCookies(false);
             log.debug("Disabling session cookies");
             break;
-         default :
+         default:
             log.debug("Using session cookies default setting");
       }
 
       String metaDataSecurityDomain = metaData.getSecurityDomain();
       if (metaDataSecurityDomain != null)
          metaDataSecurityDomain = metaDataSecurityDomain.trim();
-      
+
       // Add a valve to establish security context
-      SecurityContextEstablishmentValve scevalve = new SecurityContextEstablishmentValve(metaDataSecurityDomain,
-            SecurityUtil.unprefixSecurityDomain(config.getDefaultSecurityDomain()), 
-            SecurityActions.loadClass(config.getSecurityContextClassName()), getSecurityManagement());
+      SecurityContextEstablishmentValve scevalve = new SecurityContextEstablishmentValve(metaDataSecurityDomain, SecurityUtil.unprefixSecurityDomain(config
+            .getDefaultSecurityDomain()), SecurityActions.loadClass(config.getSecurityContextClassName()), getSecurityManagement());
       context.addValve(scevalve);
 
       // Add a valve to estalish the JACC context before authorization valves
       Certificate[] certs = null;
-      CodeSource cs = new CodeSource(url, certs);
+      CodeSource cs = new CodeSource(warUrl, certs);
       JaccContextValve jaccValve = new JaccContextValve(metaData, cs);
       context.addValve(jaccValve);
 
@@ -370,7 +316,7 @@
       catch (Exception e)
       {
          context.destroy();
-         DeploymentException.rethrowAsDeploymentException("URL " + warUrl + " deployment failed", e);
+         DeploymentException.rethrowAsDeploymentException("URL " + warUrlStr + " deployment failed", e);
       }
       finally
       {
@@ -385,7 +331,7 @@
       if (context.getState() != 1)
       {
          context.destroy();
-         throw new DeploymentException("URL " + warUrl + " deployment failed");
+         throw new DeploymentException("URL " + warUrlStr + " deployment failed");
       }
 
       // Clustering
@@ -398,7 +344,7 @@
             AbstractJBossManager manager = null;
             String managerClassName = config.getManagerClass();
             Class managerClass = Thread.currentThread().getContextClassLoader().loadClass(managerClassName);
-            manager = (AbstractJBossManager) managerClass.newInstance();
+            manager = (AbstractJBossManager)managerClass.newInstance();
             String name = "//" + ((hostName == null) ? "localhost" : hostName) + ctxPath;
             manager.init(name, metaData);
 
@@ -409,8 +355,7 @@
          catch (ClusteringNotSupportedException e)
          {
             // JBAS-3513 Just log a WARN, not an ERROR
-            log.warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: "
-                  + e.getMessage());
+            log.warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: " + e.getMessage());
          }
          catch (NoClassDefFoundError ncdf)
          {
@@ -431,7 +376,7 @@
        */
       SecurityAssociationValve valve = new SecurityAssociationValve(metaData, config.getSecurityManagerService());
       valve.setSubjectAttributeName(config.getSubjectAttributeName());
-      server.invoke(objectName, "addValve", new Object[]{valve}, new String[]{"org.apache.catalina.Valve"});
+      server.invoke(objectName, "addValve", new Object[] { valve }, new String[] { "org.apache.catalina.Valve" });
 
       /*
        * TODO: Retrieve the state, and throw an exception in case of a failure Integer state = (Integer)
@@ -461,7 +406,7 @@
 
       protected JBossWebMetaData metaData;
 
-      protected VFSDeploymentUnit unit;
+      protected DeploymentUnit unit;
 
       public EncListener(ClassLoader loader, Loader webLoader, WebApplication webApp)
       {
@@ -498,13 +443,13 @@
                currentThread.setContextClassLoader(webLoader.getClassLoader());
                metaData.setENCLoader(webLoader.getClassLoader());
                InitialContext iniCtx = new InitialContext();
-               Context envCtx = (Context) iniCtx.lookup("java:comp");
+               Context envCtx = (Context)iniCtx.lookup("java:comp");
                // Add ORB/UserTransaction
                ORB orb = null;
                try
                {
                   ObjectName ORB_NAME = new ObjectName("jboss:service=CorbaORB");
-                  orb = (ORB) server.getAttribute(ORB_NAME, "ORB");
+                  orb = (ORB)server.getAttribute(ORB_NAME, "ORB");
                   // Bind the orb
                   if (orb != null)
                   {
@@ -518,10 +463,8 @@
                }
 
                // JTA links
-               envCtx
-                     .bind("TransactionSynchronizationRegistry", new LinkRef("java:TransactionSynchronizationRegistry"));
-               log
-                     .debug("Linked java:comp/TransactionSynchronizationRegistry to JNDI name: java:TransactionSynchronizationRegistry");
+               envCtx.bind("TransactionSynchronizationRegistry", new LinkRef("java:TransactionSynchronizationRegistry"));
+               log.debug("Linked java:comp/TransactionSynchronizationRegistry to JNDI name: java:TransactionSynchronizationRegistry");
                envCtx.bind("UserTransaction", new LinkRef("UserTransaction"));
                log.debug("Linked java:comp/UserTransaction to JNDI name: UserTransaction");
                envCtx = envCtx.createSubcontext("env");
@@ -554,8 +497,7 @@
 
    }
 
-   public Loader getWebLoader(VFSDeploymentUnit unit, JBossWebMetaData metaData, ClassLoader loader, URL url)
-         throws MalformedURLException
+   public Loader getWebLoader(DeploymentUnit unit, JBossWebMetaData metaData, ClassLoader loader) throws MalformedURLException
    {
       Loader webLoader = null;
 
@@ -564,12 +506,12 @@
        * else scoped class loading does not see the war level overrides. The call to setWarURL adds these paths to the
        * deployment UCL.
        */
-      ArrayList<URL> classpath = (ArrayList<URL>) unit.getAttachment("org.jboss.web.expandedWarClasspath");
-      if (classpath == null)
+      ArrayList<URL> classpath = (ArrayList<URL>)unit.getAttachment("org.jboss.web.expandedWarClasspath");
+      if (classpath == null && unit instanceof VFSDeploymentUnit)
       {
          try
          {
-            VirtualFile classes = unit.getFile("WEB-INF/classes");
+            VirtualFile classes = ((VFSDeploymentUnit)unit).getFile("WEB-INF/classes");
             // Tomcat can't handle the vfs urls yet
             URL vfsURL = classes.toURL();
             String vfsurl = vfsURL.toString();
@@ -587,14 +529,8 @@
       WebCtxLoader jbossLoader = new WebCtxLoader(loader, injectionContainer);
       if (classpath != null)
          jbossLoader.setClasspath(classpath);
+
       webLoader = jbossLoader;
-      /*
-       * if (classLoading != null && classLoading.isJava2ClassLoadingCompliance()) { WebCtxLoader jbossLoader = new
-       * WebCtxLoader(loader, injectionContainer); if (classpath != null) jbossLoader.setClasspath(classpath); webLoader =
-       * jbossLoader; } else { String[] pkgs = config.getFilteredPackages(); WebAppLoader jbossLoader = new
-       * WebAppLoader(loader, pkgs, injectionContainer); jbossLoader.setDelegate(getJava2ClassLoadingCompliance()); if
-       * (classpath != null) jbossLoader.setClasspath(classpath); webLoader = jbossLoader; }
-       */
       return webLoader;
    }
 
@@ -608,18 +544,17 @@
     * undeployment steps.
     */
    @Override
-   protected void performUndeploy(WebApplication warInfo, String warUrl) throws Exception
+   protected void performUndeploy(WebApplication webApp, String warUrl) throws Exception
    {
-      if (warInfo == null)
+      if (webApp == null)
       {
          log.debug("performUndeploy, no WebApplication found for URL " + warUrl);
          return;
       }
 
-      log.info("undeploy, ctxPath=" + warInfo.getMetaData().getContextRoot() + ", vfsUrl="
-            + warInfo.getDeploymentUnit().getFile("").getPathName());
+      log.info("undeploy, ctxPath=" + webApp.getMetaData().getContextRoot());
 
-      JBossWebMetaData metaData = warInfo.getMetaData();
+      JBossWebMetaData metaData = webApp.getMetaData();
       String hostName = null;
       // Get any jboss-web/virtual-hosts
       List<String> vhostNames = metaData.getVirtualHosts();
@@ -637,37 +572,41 @@
             hostName = hostNames.next().toString();
          }
       }
-      performUndeployInternal(hostName, warUrl, warInfo);
+      performUndeployInternal(webApp, hostName, warUrl);
       while (hostNames.hasNext())
       {
          String additionalHostName = hostNames.next().toString();
-         performUndeployInternal(additionalHostName, warUrl, warInfo);
+         performUndeployInternal(webApp, additionalHostName, warUrl);
       }
 
    }
 
-   protected void performUndeployInternal(String hostName, String warUrl, WebApplication warInfo) throws Exception
+   protected void performUndeployInternal(WebApplication webApp, String hostName, String warUrl) throws Exception
    {
-
-      JBossWebMetaData metaData = warInfo.getMetaData();
+      JBossWebMetaData metaData = webApp.getMetaData();
       String ctxPath = metaData.getContextRoot();
 
+      ObjectName objectName = getObjectName(hostName, ctxPath);
+
       // TODO: Need to remove the dependency on MBeanServer
       MBeanServer server = MBeanServerLocator.locateJBoss();
-      // If the server is gone, all apps were stopped already
-      if (server == null)
-         return;
 
-      ObjectName objectName = new ObjectName(config.getCatalinaDomain() + ":j2eeType=WebModule,name=//"
-            + ((hostName == null) ? "localhost" : hostName) + ctxPath + ",J2EEApplication=none,J2EEServer=none");
-
-      if (server.isRegistered(objectName))
+      // If the server is gone, all apps were stopped already
+      if (server != null)
       {
          // Contexts should be stopped by the host already
-         server.invoke(objectName, "destroy", new Object[]{}, new String[]{});
+         if (server.isRegistered(objectName))
+            server.invoke(objectName, "destroy", new Object[] {}, new String[] {});
       }
    }
 
+   private ObjectName getObjectName(String hostName, String ctxPath) throws MalformedObjectNameException
+   {
+      hostName = (hostName == null ? "localhost" : hostName);
+      String onamestr = config.getCatalinaDomain() + ":j2eeType=WebModule,name=//" + hostName + ctxPath + ",J2EEApplication=none,J2EEServer=none";
+      return new ObjectName(onamestr);
+   }
+
    /**
     * Resolve the input virtual host names to the names of the configured Hosts
     * 
@@ -686,12 +625,12 @@
          Iterator iter = hosts.iterator();
          while (iter.hasNext())
          {
-            ObjectName host = (ObjectName) iter.next();
+            ObjectName host = (ObjectName)iter.next();
             String name = host.getKeyProperty("host");
             if (name != null)
             {
                vhostToHostNames.put(name, name);
-               String[] aliases = (String[]) server.invoke(host, "findAliases", null, null);
+               String[] aliases = (String[])server.invoke(host, "findAliases", null, null);
                int count = aliases != null ? aliases.length : 0;
                for (int n = 0; n < count; n++)
                {
@@ -707,7 +646,7 @@
       {
          for (String vhost : vhostNames)
          {
-            String host = (String) vhostToHostNames.get(vhost);
+            String host = (String)vhostToHostNames.get(vhost);
             if (host == null)
             {
                log.warn("Failed to map vhost: " + vhost);
@@ -734,9 +673,9 @@
       Iterator iter = engines.iterator();
       while (iter.hasNext())
       {
-         ObjectName engine = (ObjectName) iter.next();
+         ObjectName engine = (ObjectName)iter.next();
 
-         String defaultHost = (String) server.getAttribute(engine, "defaultHost");
+         String defaultHost = (String)server.getAttribute(engine, "defaultHost");
          if (defaultHost != null)
          {
             defaultHosts.add(defaultHost);

Modified: branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
===================================================================
--- branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -29,7 +29,6 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.management.Attribute;
 import javax.management.MBeanServer;
 import javax.management.Notification;
 import javax.management.NotificationListener;
@@ -85,10 +84,10 @@
  */
 public class TomcatService extends ServiceMBeanSupport implements NotificationListener, TomcatServiceMBean
 {
-   
+
    /** The associated Tomcat deployer * */
    private TomcatDeployer tomcatDeployer;
-   
+
    // Use a flag because isInShutdown doesn't appear to be correct
    private boolean connectorsRunning = false;
 
@@ -104,8 +103,6 @@
       this.tomcatDeployer = tomcatDeployer;
    }
 
-   public static boolean OLD_CODE = false;
-   
    // In our lifecycle, we invoke the webserver lifecycle-related operations
    // in the TomcatDeployer
 
@@ -122,194 +119,184 @@
 
       log.debug("Starting tomcat deployer");
       MBeanServer server = super.getServer();
-      SecurityActions.setSystemProperty("catalina.ext.dirs", 
-            (SecurityActions.getSystemProperty("jboss.server.home.dir", null) + File.separator + "lib"));
+      SecurityActions.setSystemProperty("catalina.ext.dirs", (SecurityActions.getSystemProperty("jboss.server.home.dir", null) + File.separator + "lib"));
 
       String objectNameS = tomcatDeployer.getDomain() + ":type=server";
       ObjectName objectName = new ObjectName(objectNameS);
 
-      if (OLD_CODE) {
+      // Parse main server.xml
+      // FIXME: this could be done somewhere else
+      SchemaBinding schema = JBossXBBuilder.build(ServerMetaData.class);
+      Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+      u.setSchemaValidation(false);
+      u.setValidation(false);
+      u.setEntityResolver(new JBossEntityResolver());
+      InputStream is = null;
+      ServerMetaData serverMetaData = null;
+      try
+      {
+         File configFile = new File(tomcatDeployer.getConfigFile());
+         if (configFile.exists())
+         {
+            is = new FileInputStream(configFile);
+         }
+         else
+         {
+            is = getClass().getClassLoader().getResourceAsStream(tomcatDeployer.getConfigFile());
+         }
+         if (is == null)
+         {
+            log.error("Could not read configured server.xml (will try default): " + tomcatDeployer.getConfigFile());
+            is = getClass().getClassLoader().getResourceAsStream("server.xml");
+         }
+         serverMetaData = ServerMetaData.class.cast(u.unmarshal(is, schema));
+      }
+      finally
+      {
+         if (is != null)
+         {
+            try
+            {
+               is.close();
+            }
+            catch (IOException e)
+            {
+               // Ignore
+            }
+         }
+      }
 
-         // Set the modeler Registry MBeanServer to the that of the tomcat service
-         Registry.getRegistry().setMBeanServer(server);
+      // FIXME: could try to do stuff with EngineConfig and HostConfig, although neither
+      // should be useful in JBoss
 
-         Registry.getRegistry().registerComponent(Class.forName("org.apache.catalina.startup.Catalina").newInstance(),
-               objectName, "org.apache.catalina.startup.Catalina");
+      // Create the Catalina instance
+      Catalina catalina = new Catalina();
+      catalina.setCatalinaHome(System.getProperty("jboss.server.home.dir"));
+      catalina.setUseNaming(false);
+      catalina.setUseShutdownHook(false);
+      catalina.setAwait(false);
+      catalina.setRedirectStreams(false);
 
-         server.setAttribute(objectName, new Attribute("catalinaHome", System.getProperty("jboss.server.home.dir")));
-         server.setAttribute(objectName, new Attribute("configFile", tomcatDeployer.getConfigFile()));
-         server.setAttribute(objectName, new Attribute("useNaming", new Boolean(false)));
-         server.setAttribute(objectName, new Attribute("useShutdownHook", new Boolean(false)));
-         server.setAttribute(objectName, new Attribute("await", new Boolean(false)));
-         server.setAttribute(objectName, new Attribute("redirectStreams", new Boolean(false)));
+      // Set the modeler Registry MBeanServer to the that of the tomcat service
+      Registry.getRegistry(null, null).setMBeanServer(server);
+      // Register the Catalina instance
+      Registry.getRegistry(null, null).registerComponent(catalina, objectName, "org.apache.catalina.startup.Catalina");
 
-      } else {
-      
-         // Parse main server.xml
-         // FIXME: this could be done somewhere else
-         SchemaBinding schema = JBossXBBuilder.build(ServerMetaData.class);
-         Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
-         u.setSchemaValidation(false);
-         u.setValidation(false);
-         u.setEntityResolver(new JBossEntityResolver());
-         InputStream is = null;
-         ServerMetaData serverMetaData = null;
-         try {
-            File configFile = new File(tomcatDeployer.getConfigFile());
-            if (configFile.exists())
+      // Use the server.xml metadata to create a Server instance and assign it to the Catalina instance
+
+      // Server
+      org.apache.catalina.Server catalinaServer = (org.apache.catalina.Server)getInstance(serverMetaData, "org.apache.catalina.core.StandardServer");
+      addLifecycleListeners(catalinaServer, serverMetaData.getListeners());
+
+      // Server/Service
+      if (serverMetaData.getServices() == null)
+      {
+         throw new IllegalArgumentException("No services");
+      }
+      Iterator<ServiceMetaData> serviceMetaDatas = serverMetaData.getServices().iterator();
+      while (serviceMetaDatas.hasNext())
+      {
+         ServiceMetaData serviceMetaData = serviceMetaDatas.next();
+         org.apache.catalina.Service service = (org.apache.catalina.Service)getInstance(serviceMetaData, "org.apache.catalina.core.StandardService");
+         addLifecycleListeners(service, serviceMetaData.getListeners());
+         service.setName(serviceMetaData.getName());
+         service.setServer(catalinaServer);
+         catalinaServer.addService(service);
+
+         // Server/Service/Executor
+         // FIXME
+
+         // Server/Service/Connector
+         if (serviceMetaData.getConnectors() != null)
+         {
+            Iterator<ConnectorMetaData> connectorMetaDatas = serviceMetaData.getConnectors().iterator();
+            while (connectorMetaDatas.hasNext())
             {
-               is = new FileInputStream(configFile);
-            }
-            else
-            {
-               is = getClass().getClassLoader().getResourceAsStream(tomcatDeployer.getConfigFile());
-            }
-            if (is == null) {
-               log.error("Could not read configured server.xml (will try default): " + tomcatDeployer.getConfigFile());
-               is = getClass().getClassLoader().getResourceAsStream("server.xml");
-            }
-            serverMetaData = ServerMetaData.class.cast(u.unmarshal(is, schema));
-         } finally {
-            if (is != null) {
-               try {
-                  is.close();
-               } catch (IOException e) {
-                  // Ignore
+               ConnectorMetaData connectorMetaData = connectorMetaDatas.next();
+               Connector connector = new Connector(connectorMetaData.getProtocol());
+               if (connectorMetaData.getAttributes() != null)
+               {
+                  Iterator<QName> names = connectorMetaData.getAttributes().keySet().iterator();
+                  while (names.hasNext())
+                  {
+                     QName name = names.next();
+                     String value = (String)connectorMetaData.getAttributes().get(name);
+                     // FIXME: This should be done by XB
+                     value = StringPropertyReplacer.replaceProperties(value);
+                     IntrospectionUtils.setProperty(connector, name.getLocalPart(), value);
+                  }
                }
+               service.addConnector(connector);
             }
          }
-         
-         // FIXME: could try to do stuff with EngineConfig and HostConfig, although neither
-         //        should be useful in JBoss
-         
-         // Create the Catalina instance
-         Catalina catalina = new Catalina();
-         catalina.setCatalinaHome(System.getProperty("jboss.server.home.dir"));
-         catalina.setUseNaming(false);
-         catalina.setUseShutdownHook(false);
-         catalina.setAwait(false);
-         catalina.setRedirectStreams(false);
-         
-         // Set the modeler Registry MBeanServer to the that of the tomcat service
-         Registry.getRegistry(null, null).setMBeanServer(server);
-         // Register the Catalina instance
-         Registry.getRegistry(null, null).registerComponent(catalina, objectName, "org.apache.catalina.startup.Catalina");
-         
-         // Use the server.xml metadata to create a Server instance and assign it to the Catalina instance
-         
-         // Server
-         org.apache.catalina.Server catalinaServer = 
-            (org.apache.catalina.Server) getInstance(serverMetaData, "org.apache.catalina.core.StandardServer");
-         addLifecycleListeners(catalinaServer, serverMetaData.getListeners());
-         
-         // Server/Service
-         if (serverMetaData.getServices() == null)
+
+         // Server/Service/Engine
+         EngineMetaData engineMetaData = serviceMetaData.getEngine();
+         org.apache.catalina.Engine engine = (org.apache.catalina.Engine)getInstance(engineMetaData, "org.apache.catalina.core.StandardEngine");
+         addLifecycleListeners(engine, engineMetaData.getListeners());
+         engine.setName(engineMetaData.getName());
+         // FIXME: This should be done by XB
+         if (engineMetaData.getJvmRoute() != null)
          {
-            throw new IllegalArgumentException("No services");
+            engine.setJvmRoute(StringPropertyReplacer.replaceProperties(engineMetaData.getJvmRoute()));
          }
-         Iterator<ServiceMetaData> serviceMetaDatas = serverMetaData.getServices().iterator();
-         while (serviceMetaDatas.hasNext())
+         // engine.setJvmRoute(engineMetaData.getJvmRoute());
+         engine.setDefaultHost(engineMetaData.getDefaultHost());
+         service.setContainer(engine);
+
+         // Server/Service/Engine/Realm
+         if (engineMetaData.getRealm() != null)
          {
-            ServiceMetaData serviceMetaData = serviceMetaDatas.next();
-            org.apache.catalina.Service service = 
-               (org.apache.catalina.Service) getInstance(serviceMetaData, "org.apache.catalina.core.StandardService");
-            addLifecycleListeners(service, serviceMetaData.getListeners());
-            service.setName(serviceMetaData.getName());
-            service.setServer(catalinaServer);
-            catalinaServer.addService(service);
-            
-            // Server/Service/Executor
-            // FIXME
-            
-            // Server/Service/Connector
-            if (serviceMetaData.getConnectors() != null)
+            engine.setRealm((org.apache.catalina.Realm)getInstance(engineMetaData.getRealm(), null));
+         }
+
+         // Server/Service/Engine/Valve
+         addValves(engine, engineMetaData.getValves());
+
+         // Server/Service/Engine/Host
+         if (engineMetaData.getHosts() != null)
+         {
+            Iterator<HostMetaData> hostMetaDatas = engineMetaData.getHosts().iterator();
+            while (hostMetaDatas.hasNext())
             {
-               Iterator<ConnectorMetaData> connectorMetaDatas = serviceMetaData.getConnectors().iterator();
-               while (connectorMetaDatas.hasNext())
+               HostMetaData hostMetaData = hostMetaDatas.next();
+               org.apache.catalina.Host host = (org.apache.catalina.Host)getInstance(hostMetaData, "org.apache.catalina.core.StandardHost");
+               addLifecycleListeners(host, hostMetaData.getListeners());
+               host.setName(hostMetaData.getName());
+               // FIXME: not really needed, and could hurt extensibility; probably needed until JBW GA with a fix
+               host.setConfigClass("org.jboss.web.tomcat.service.deployers.JBossContextConfig");
+               engine.addChild(host);
+
+               // Server/Service/Engine/Host/Realm
+               if (hostMetaData.getRealm() != null)
                {
-                  ConnectorMetaData connectorMetaData = connectorMetaDatas.next();
-                  Connector connector = new Connector(connectorMetaData.getProtocol());
-                  if (connectorMetaData.getAttributes() != null)
-                  {
-                     Iterator<QName> names = connectorMetaData.getAttributes().keySet().iterator();
-                     while (names.hasNext())
-                     {
-                        QName name = names.next();
-                        String value = (String) connectorMetaData.getAttributes().get(name);
-                        // FIXME: This should be done by XB
-                        value = StringPropertyReplacer.replaceProperties(value);
-                        IntrospectionUtils.setProperty(connector, name.getLocalPart(), value);
-                     }
-                  }
-                  service.addConnector(connector);
+                  host.setRealm((org.apache.catalina.Realm)getInstance(hostMetaData.getRealm(), null));
                }
-            }
-            
-            // Server/Service/Engine
-            EngineMetaData engineMetaData = serviceMetaData.getEngine();
-            org.apache.catalina.Engine engine = 
-               (org.apache.catalina.Engine) getInstance(engineMetaData, "org.apache.catalina.core.StandardEngine");
-            addLifecycleListeners(engine, engineMetaData.getListeners());
-            engine.setName(engineMetaData.getName());
-            // FIXME: This should be done by XB
-            if (engineMetaData.getJvmRoute() != null) {
-               engine.setJvmRoute(StringPropertyReplacer.replaceProperties(engineMetaData.getJvmRoute()));
-            }
-            //engine.setJvmRoute(engineMetaData.getJvmRoute());
-            engine.setDefaultHost(engineMetaData.getDefaultHost());
-            service.setContainer(engine);
-            
-            // Server/Service/Engine/Realm
-            if (engineMetaData.getRealm() != null) {
-               engine.setRealm((org.apache.catalina.Realm) getInstance(engineMetaData.getRealm(), null));
-            }
-            
-            // Server/Service/Engine/Valve
-            addValves(engine, engineMetaData.getValves());
-            
-            // Server/Service/Engine/Host
-            if (engineMetaData.getHosts() != null)
-            {
-               Iterator<HostMetaData> hostMetaDatas = engineMetaData.getHosts().iterator();
-               while (hostMetaDatas.hasNext())
+
+               // Server/Service/Engine/Host/Valve
+               addValves(host, hostMetaData.getValves());
+
+               // Server/Service/Engine/Host/Alias
+               if (hostMetaData.getAliases() != null)
                {
-                  HostMetaData hostMetaData = hostMetaDatas.next();
-                  org.apache.catalina.Host host =
-                     (org.apache.catalina.Host) getInstance(hostMetaData, "org.apache.catalina.core.StandardHost");
-                  addLifecycleListeners(host, hostMetaData.getListeners());
-                  host.setName(hostMetaData.getName());
-                  // FIXME: not really needed, and could hurt extensibility; probably needed until JBW GA with a fix
-                  host.setConfigClass("org.jboss.web.tomcat.service.deployers.JBossContextConfig");
-                  engine.addChild(host);
-                  
-                  // Server/Service/Engine/Host/Realm
-                  if (hostMetaData.getRealm() != null) {
-                     host.setRealm((org.apache.catalina.Realm) getInstance(hostMetaData.getRealm(), null));
+                  Iterator<String> aliases = hostMetaData.getAliases().iterator();
+                  while (aliases.hasNext())
+                  {
+                     host.addAlias(aliases.next());
                   }
-                  
-                  // Server/Service/Engine/Host/Valve
-                  addValves(host, hostMetaData.getValves());
-                  
-                  // Server/Service/Engine/Host/Alias
-                  if (hostMetaData.getAliases() != null) {
-                     Iterator<String> aliases = hostMetaData.getAliases().iterator();
-                     while (aliases.hasNext()) {
-                        host.addAlias(aliases.next());
-                     }
-                  }
-                  
                }
+
             }
-            
          }
-         
-         // Set the resulting Server to the Catalina instance
-         catalina.setServer(catalinaServer);
+
       }
-      
+
+      // Set the resulting Server to the Catalina instance
+      catalina.setServer(catalinaServer);
+
       // Start Tomcat
-      server.invoke(objectName, "create", new Object[]{}, new String[]{});
-      server.invoke(objectName, "start", new Object[]{}, new String[]{});
+      server.invoke(objectName, "create", new Object[] {}, new String[] {});
+      server.invoke(objectName, "start", new Object[] {}, new String[] {});
 
       // Set up the authenticators in JNDI such that they can be configured for web apps
       InitialContext ic = new InitialContext();
@@ -341,7 +328,7 @@
       // we'll never receive Server.START_NOTIFICATION_TYPE, so check
       // with the Server and start the connectors immediately, if this is the case.
       // Otherwise register to receive the server start-up notification.
-      Boolean started = (Boolean) server.getAttribute(ServerImplMBean.OBJECT_NAME, "Started");
+      Boolean started = (Boolean)server.getAttribute(ServerImplMBean.OBJECT_NAME, "Started");
       if (started.booleanValue() == true)
       {
          log.debug("Server '" + ServerImplMBean.OBJECT_NAME + "' already started, starting connectors now");
@@ -364,18 +351,22 @@
    protected static Object getInstance(AnyXmlMetaData metaData, String defaultClassName) throws Exception
    {
       String className = metaData.getClassName();
-      if (className == null) {
+      if (className == null)
+      {
          className = defaultClassName;
       }
-      if (className == null) {
+      if (className == null)
+      {
          throw new IllegalArgumentException("No className specified for element");
       }
       Object instance = TomcatService.class.getClassLoader().loadClass(className).newInstance();
-      if (metaData.getAttributes() != null) {
+      if (metaData.getAttributes() != null)
+      {
          Iterator<QName> names = metaData.getAttributes().keySet().iterator();
-         while (names.hasNext()) {
+         while (names.hasNext())
+         {
             QName name = names.next();
-            String value = (String) metaData.getAttributes().get(name);
+            String value = (String)metaData.getAttributes().get(name);
             // FIXME: This should be done by XB
             value = StringPropertyReplacer.replaceProperties(value);
             IntrospectionUtils.setProperty(instance, name.getLocalPart(), value);
@@ -383,13 +374,14 @@
       }
       return instance;
    }
-   
+
    /**
     * Associate lifecycle listeners with the instance, if it implements Lifecycle.
     */
    protected static void addLifecycleListeners(Object instance, List<ListenerMetaData> list) throws Exception
    {
-      if (list == null) {
+      if (list == null)
+      {
          return;
       }
       org.apache.catalina.Lifecycle lifecycle = null;
@@ -399,24 +391,24 @@
       }
       else
       {
-         lifecycle = (org.apache.catalina.Lifecycle) instance;
+         lifecycle = (org.apache.catalina.Lifecycle)instance;
       }
       Iterator<ListenerMetaData> listenerMetaDatas = list.iterator();
       while (listenerMetaDatas.hasNext())
       {
          ListenerMetaData listenerMetaData = listenerMetaDatas.next();
-         lifecycle.addLifecycleListener((org.apache.catalina.LifecycleListener) getInstance(listenerMetaData, null));
+         lifecycle.addLifecycleListener((org.apache.catalina.LifecycleListener)getInstance(listenerMetaData, null));
       }
 
    }
-   
-   
+
    /**
     * Associate valves with the instance, if it implements Lifecycle.
     */
    protected static void addValves(Object instance, List<ValveMetaData> list) throws Exception
    {
-      if (list == null) {
+      if (list == null)
+      {
          return;
       }
       org.apache.catalina.Pipeline pipeline = null;
@@ -426,18 +418,17 @@
       }
       else
       {
-         pipeline = (org.apache.catalina.Pipeline) instance;
+         pipeline = (org.apache.catalina.Pipeline)instance;
       }
       Iterator<ValveMetaData> valveMetaDatas = list.iterator();
       while (valveMetaDatas.hasNext())
       {
          ValveMetaData valveMetaData = valveMetaDatas.next();
-         pipeline.addValve((org.apache.catalina.Valve) getInstance(valveMetaData, null));
+         pipeline.addValve((org.apache.catalina.Valve)getInstance(valveMetaData, null));
       }
 
    }
-   
-   
+
    @Override
    protected void stopService() throws Exception
    {
@@ -446,7 +437,7 @@
          throw new IllegalStateException("Must set TomcatDeployer before stopping");
 
       // Hot undeploy
-      Boolean inShutdown = (Boolean) server.getAttribute(ServerImplMBean.OBJECT_NAME, "InShutdown");
+      Boolean inShutdown = (Boolean)server.getAttribute(ServerImplMBean.OBJECT_NAME, "InShutdown");
       if (inShutdown.booleanValue() == false)
       {
          log.debug("Server '" + ServerImplMBean.OBJECT_NAME + "' already started, stopping connectors now");
@@ -458,9 +449,9 @@
       String objectNameS = tomcatDeployer.getDomain() + ":type=server";
       ObjectName objectName = new ObjectName(objectNameS);
 
-      server.invoke(objectName, "stop", new Object[]{}, new String[]{});
+      server.invoke(objectName, "stop", new Object[] {}, new String[] {});
 
-      server.invoke(objectName, "destroy", new Object[]{}, new String[]{});
+      server.invoke(objectName, "destroy", new Object[] {}, new String[] {});
 
       server.unregisterMBean(objectName);
 
@@ -471,7 +462,7 @@
       Iterator iterator = server2.queryMBeans(queryObjectName, null).iterator();
       while (iterator.hasNext())
       {
-         ObjectInstance oi = (ObjectInstance) iterator.next();
+         ObjectInstance oi = (ObjectInstance)iterator.next();
          ObjectName toRemove = oi.getObjectName();
          // Exception: Don't unregister the service right now
          if (!"WebServer".equals(toRemove.getKeyProperty("service")))
@@ -486,7 +477,7 @@
       iterator = server2.queryMBeans(queryObjectName, null).iterator();
       while (iterator.hasNext())
       {
-         ObjectInstance oi = (ObjectInstance) iterator.next();
+         ObjectInstance oi = (ObjectInstance)iterator.next();
          ObjectName name = oi.getObjectName();
          server2.unregisterMBean(name);
       }
@@ -622,7 +613,7 @@
       ObjectName service = new ObjectName(tomcatDeployer.getDomain() + ":type=Service,serviceName=jboss.web");
       Object[] args = {};
       String[] sig = {};
-      Connector[] connectors = (Connector[]) server.invoke(service, "findConnectors", args, sig);
+      Connector[] connectors = (Connector[])server.invoke(service, "findConnectors", args, sig);
       for (int n = 0; n < connectors.length; n++)
       {
          Lifecycle lc = connectors[n];
@@ -646,7 +637,7 @@
       ObjectName service = new ObjectName(tomcatDeployer.getDomain() + ":type=Service,serviceName=jboss.web");
       Object[] args = {};
       String[] sig = {};
-      Connector[] connectors = (Connector[]) server.invoke(service, "findConnectors", args, sig);
+      Connector[] connectors = (Connector[])server.invoke(service, "findConnectors", args, sig);
       for (int n = 0; n < connectors.length; n++)
       {
          connectors[n].pause();
@@ -773,7 +764,7 @@
       if (this.tomcatDeployer != null)
          this.tomcatDeployer.setSessionCookieForSSOAuth(sessionCookieForSSOAuth);
    }
-   
+
    /**
     * {@inheritDoc}
     * 
@@ -787,7 +778,7 @@
       KernelController kernelController = controllerContext == null ? null : controllerContext.getKernel().getController();
       JBossWebMicrocontainerBeanLocator.setKernelController(kernelController);
    }
-   
+
    /**
     * {@inheritDoc}
     * 

Modified: branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DeploymentAspectHttpServer.java
===================================================================
--- branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DeploymentAspectHttpServer.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DeploymentAspectHttpServer.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -21,6 +21,9 @@
  */
 package org.jboss.wsf.container.jboss50.transport;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.xml.ws.Endpoint;
 import javax.xml.ws.WebServiceException;
 
@@ -44,6 +47,8 @@
  */
 public class DeploymentAspectHttpServer extends AbstractExtensible implements HttpServer
 {
+   private Map<String,Deployment> deployments = new HashMap<String,Deployment>();
+   
    /** Start an instance of this HTTP server */
    public void start()
    {
@@ -61,6 +66,7 @@
    /** Publish an JAXWS endpoint to the HTTP server */
    public void publish(HttpContext context, Endpoint endpoint)
    {
+      String contextRoot = context.getContextRoot();
       Class implClass = getImplementorClass(endpoint);
 
       try
@@ -70,21 +76,20 @@
          DeploymentModelFactory depModelFactory = spiProvider.getSPI(DeploymentModelFactory.class);
 
          // Create/Setup the deployment
-         Deployment dep = depModelFactory.newDeployment("endpoint-deployment", implClass.getClassLoader());
-         dep.setRuntimeClassLoader(dep.getInitialClassLoader());
+         Deployment deployment = depModelFactory.newDeployment("endpoint-deployment", implClass.getClassLoader());
+         deployment.setRuntimeClassLoader(deployment.getInitialClassLoader());
 
          // Create/Setup the service
-         Service service = dep.getService();
-         service.setContextRoot(context.getContextRoot());
+         Service service = deployment.getService();
+         service.setContextRoot(contextRoot);
 
          // Create/Setup the endpoint
          org.jboss.wsf.spi.deployment.Endpoint ep = depModelFactory.newEndpoint(implClass.getName());
          service.addEndpoint(ep);
 
          // Deploy using deployment aspects
-         DeploymentAspectManagerFactory depManagerFactory = spiProvider.getSPI(DeploymentAspectManagerFactory.class);
-         DeploymentAspectManager depManager = depManagerFactory.getDeploymentAspectManager("WSDeploymentAspectManagerEndpointAPI");
-         depManager.deploy(dep);
+         getDeploymentAspectManager().deploy(deployment);
+         deployments.put(contextRoot, deployment);
       }
       catch (RuntimeException rte)
       {
@@ -99,8 +104,13 @@
    /** Destroys an JAXWS endpoint on the HTTP server */
    public void destroy(HttpContext context, Endpoint endpoint)
    {
+      String contextRoot = context.getContextRoot();
+      
       try
       {
+         Deployment deployment = deployments.remove(contextRoot);
+         if (deployment != null)
+            getDeploymentAspectManager().undeploy(deployment);
       }
       catch (RuntimeException rte)
       {
@@ -112,6 +122,14 @@
       }
    }
 
+   private DeploymentAspectManager getDeploymentAspectManager()
+   {
+      SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+      DeploymentAspectManagerFactory depManagerFactory = spiProvider.getSPI(DeploymentAspectManagerFactory.class);
+      DeploymentAspectManager depManager = depManagerFactory.getDeploymentAspectManager("WSDeploymentAspectManagerEndpointAPI");
+      return depManager;
+   }
+
    private Class getImplementorClass(Endpoint endpoint)
    {
       Object implementor = endpoint.getImplementor();

Modified: branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DynamicEndpointDeploymentAspect.java
===================================================================
--- branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DynamicEndpointDeploymentAspect.java	2009-01-30 20:44:38 UTC (rev 83707)
+++ branches/tdiesler/Branch_5_0/webservices/src/main/org/jboss/wsf/container/jboss50/transport/DynamicEndpointDeploymentAspect.java	2009-01-30 21:12:16 UTC (rev 83708)
@@ -21,6 +21,9 @@
  */
 package org.jboss.wsf.container.jboss50.transport;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.xml.ws.WebServiceException;
 
 import org.jboss.deployers.client.plugins.deployment.AbstractDeployment;
@@ -31,10 +34,10 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.wsf.container.jboss50.deployment.tomcat.WebMetaDataModifier;
 import org.jboss.wsf.spi.deployment.Deployment;
 import org.jboss.wsf.spi.deployment.DeploymentAspect;
 import org.jboss.wsf.spi.deployment.WSFDeploymentException;
-import org.jboss.wsf.container.jboss50.deployment.tomcat.WebMetaDataModifier;
 
 /**
  * Deploy the generated webapp to JBoss
@@ -50,6 +53,8 @@
    private DeploymentFactory factory = new DeploymentFactory();
    private WebMetaDataModifier webMetaDataModifier;
    private DeployerClient mainDeployer;
+   
+   private Map<String,AbstractDeployment> deployments = new HashMap<String,AbstractDeployment>();
 
    public void setWebMetaDataModifier(WebMetaDataModifier webMetaDataModifier)
    {
@@ -67,16 +72,22 @@
       if (jbwmd == null)
          throw new WebServiceException("Cannot find web meta data");
 
+      ClassLoader epLoader = dep.getRuntimeClassLoader();
+      
       try
       {
          webMetaDataModifier.modifyMetaData(dep);
 
-         AbstractDeployment deployment = createSimpleDeployment(dep.getService().getContextRoot());
+         String contextRoot = dep.getService().getContextRoot();
+         AbstractDeployment deployment = createSimpleDeployment("http://jaxws-endpoint-api" + contextRoot);
          MutableAttachments mutableAttachments = (MutableAttachments)deployment.getPredeterminedManagedObjects();
          mutableAttachments.addAttachment(WebMetaDataModifier.PROPERTY_GENERATED_WEBAPP, Boolean.TRUE);
-         mutableAttachments.addAttachment(ClassLoaderFactory.class, new ContextClassLoaderFactory());
+         mutableAttachments.addAttachment("org.jboss.web.explicitDocBase", "/", String.class);
+         mutableAttachments.addAttachment(ClassLoaderFactory.class, new ContextClassLoaderFactory(epLoader));
          mutableAttachments.addAttachment(JBossWebMetaData.class, jbwmd);
          mainDeployer.deploy(deployment);
+         
+         deployments.put(contextRoot, deployment);
       }
       catch (Exception ex)
       {
@@ -88,8 +99,10 @@
    {
       try
       {
-         AbstractDeployment deployment = createSimpleDeployment(dep.getService().getContextRoot());
-         mainDeployer.undeploy(deployment);
+         String contextRoot = dep.getService().getContextRoot();
+         AbstractDeployment deployment = deployments.remove(contextRoot);
+         if (deployment != null)
+            mainDeployer.undeploy(deployment);
       }
       catch (Exception ex)
       {
@@ -100,20 +113,27 @@
    private AbstractDeployment createSimpleDeployment(String name)
    {
       AbstractDeployment unit = new AbstractDeployment(name);
-      // There is one top level deployment
       factory.addContext(unit, "");
       return unit;
    }
 
    private static class ContextClassLoaderFactory implements ClassLoaderFactory
    {
+      private ClassLoader classloader;
+      
+      public ContextClassLoaderFactory(ClassLoader classloader)
+      {
+         this.classloader = classloader;
+      }
+
       public ClassLoader createClassLoader(DeploymentUnit unit) throws Exception
       {
-         return Thread.currentThread().getContextClassLoader();
+         return classloader;
       }
 
       public void removeClassLoader(DeploymentUnit unit) throws Exception
       {
+         classloader = null;
       }
    }
 }




More information about the jboss-cvs-commits mailing list