protected void processEncReferences(WebApplication webApp, Context envCtx)
     throws ClassNotFoundException, NamingException {
   DeploymentUnit unit = webApp.getDeploymentUnit();
   JBossWebMetaData metaData = webApp.getMetaData();
   EnvironmentEntriesMetaData envEntries = metaData.getEnvironmentEntries();
   log.debug("addEnvEntries");
   addEnvEntries(envEntries, envCtx);
   ResourceEnvironmentReferencesMetaData resourceEnvRefs =
       metaData.getResourceEnvironmentReferences();
   log.debug("linkResourceEnvRefs");
   linkResourceEnvRefs(resourceEnvRefs, envCtx);
   ResourceReferencesMetaData resourceRefs = metaData.getResourceReferences();
   log.debug("linkResourceRefs");
   linkResourceRefs(resourceRefs, envCtx);
   log.debug("linkMessageDestinationRefs");
   MessageDestinationReferencesMetaData msgRefs = metaData.getMessageDestinationReferences();
   linkMessageDestinationRefs(unit, msgRefs, envCtx);
   EJBReferencesMetaData ejbRefs = metaData.getEjbReferences();
   log.debug("linkEjbRefs");
   linkEjbRefs(unit, ejbRefs, envCtx);
   EJBLocalReferencesMetaData ejbLocalRefs = metaData.getEjbLocalReferences();
   log.debug("linkEjbLocalRefs");
   linkEjbLocalRefs(unit, ejbLocalRefs, envCtx);
   log.debug("linkServiceRefs");
   ServiceReferencesMetaData serviceRefs = metaData.getServiceReferences();
   linkServiceRefs(unit, serviceRefs, envCtx);
 }
 /*
     protected void setUpDistributableSessionManager(ClassLoader loader)
     {
         try
         {
             Manager sm=(Manager)getDistributableSessionManager();
             Store store=sm.getStore();
             if(store instanceof AbstractReplicatedStore)
                 ((AbstractReplicatedStore)store).setLoader(loader);
             if(_timeOutPresent)
                 sm.setMaxInactiveInterval(_timeOutMinutes*60);
             getSessionHandler().setSessionManager(sm);
         }
         catch(Exception e)
         {
             __log.error("could not set up Distributable HttpSession Manager - using local one",e);
         }
     }
 */
 protected void setUpENC(ClassLoader loader) throws Exception {
   _webApp.setClassLoader(loader);
   _webApp.setName(getDisplayName());
   _webApp.setAppData(this);
   __log.debug("setting up ENC...");
   _descriptorParser.parseWebAppDescriptors(loader, _webApp.getMetaData());
   __log.debug("setting up ENC succeeded");
 }
  /**
   * A template pattern implementation of the deploy() method. This method calls the {@link
   * #performDeploy(WebApplication, String, WebDescriptorParser) performDeploy()} method to perform
   * the container specific deployment steps and registers the returned WebApplication in the
   * deployment map. The steps performed are:
   *
   * <p>ClassLoader appClassLoader = thread.getContextClassLoader(); URLClassLoader warLoader =
   * URLClassLoader.newInstance(empty, appClassLoader); thread.setContextClassLoader(warLoader);
   * WebDescriptorParser webAppParser = ...; WebMetaData metaData = di.metaData; // Create JACC
   * permissions, contextID, etc. ... WebApplication warInfo = new WebApplication(metaData);
   * performDeploy(warInfo, warUrl, webAppParser); deploymentMap.put(warUrl, warInfo);
   * thread.setContextClassLoader(appClassLoader);
   *
   * <p>The subclass performDeploy() implementation needs to invoke processEnc(loader, warInfo) to
   * have the JNDI java:comp/env namespace setup before any web app component can access this
   * namespace.
   *
   * <p>Also, an MBean for each servlet deployed should be created and its JMX ObjectName placed
   * into the DeploymentInfo.mbeans list so that the JSR77 layer can create the approriate model
   * view. The servlet MBean needs to provide access to the min, max and total time in milliseconds.
   * Expose this information via MinServiceTime, MaxServiceTime and TotalServiceTime attributes to
   * integrate seemlessly with the JSR77 factory layer.
   *
   * @param unit The deployment info that contains the context-root element value from the J2EE
   *     application/module/web application.xml descriptor. This may 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(DeploymentUnit unit, JBossWebMetaData metaData)
      throws Exception {
    Thread thread = Thread.currentThread();
    ClassLoader appClassLoader = thread.getContextClassLoader();
    WebApplication webApp = null;
    try {
      // Create a classloader for the war to ensure a unique ENC
      ClassLoader warLoader = unit.getClassLoader();
      thread.setContextClassLoader(warLoader);
      String webContext = metaData.getContextRoot();

      // Get the war URL
      URL warUrl = unit.getAttachment("org.jboss.web.expandedWarURL", URL.class);
      if (warUrl == null && unit instanceof VFSDeploymentUnit) {
        VFSDeploymentUnit vdu = VFSDeploymentUnit.class.cast(unit);
        warUrl = VFSUtils.getRealURL(vdu.getRoot());
      }

      // Dynamic WebMetaData deployments might not provide an URL
      // We use the DEploymentUnit name as identifier instead.
      // The JAXWS Endpoint API for example does this.
      String warURLString = (warUrl != null ? warUrl.toExternalForm() : unit.getName());

      // Strip any jar: url syntax. This should be be handled by the vfs
      if (warURLString.startsWith("jar:"))
        warURLString = warURLString.substring(4, warURLString.length() - 2);

      log.debug("webContext: " + webContext);
      log.debug("warURL: " + warURLString);

      // Register the permissions with the JACC layer
      String contextID = metaData.getJaccContextID();
      if (contextID == null) contextID = unit.getSimpleName();
      metaData.setJaccContextID(contextID);

      webApp = new WebApplication(metaData);
      webApp.setClassLoader(warLoader);
      webApp.setDeploymentUnit(unit);
      performDeploy(webApp, warURLString);
    } finally {
      thread.setContextClassLoader(appClassLoader);
    }
    return webApp;
  }
  /**
   * This method is invoked from within subclass performDeploy() method implementations when they
   * invoke WebDescriptorParser.parseWebAppDescriptors().
   *
   * @param loader the ClassLoader for the web application. May not be null.
   * @param metaData the WebMetaData from the WebApplication object passed to the performDeploy
   *     method.
   */
  protected void processEnc(ClassLoader loader, WebApplication webApp) throws Exception {
    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;
    Thread currentThread = Thread.currentThread();
    ClassLoader currentLoader = currentThread.getContextClassLoader();
    JBossWebMetaData metaData = webApp.getMetaData();
    try {
      // Create a java:comp/env environment unique for the web application
      log.debug("Creating ENC using ClassLoader: " + loader);
      ClassLoader parent = loader.getParent();
      while (parent != null) {
        log.debug(".." + parent);
        parent = parent.getParent();
      }
      // TODO: The enc should be an input?
      currentThread.setContextClassLoader(loader);
      // 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");
        // Bind the orb
        if (orb != null) {
          NonSerializableFactory.rebind(envCtx, "ORB", orb);
          log.debug("Bound java:comp/ORB");
        }
      } catch (Throwable t) {
        log.debug("Unable to retrieve orb" + t.toString());
      }

      // TODO: injection, Add a link to the global transaction manager
      envCtx.bind("UserTransaction", new LinkRef("UserTransaction"));
      log.debug("Linked java:comp/UserTransaction to JNDI name: UserTransaction");
      envCtx = envCtx.createSubcontext("env");
      processEncReferences(webApp, envCtx);
    } finally {
      currentThread.setContextClassLoader(currentLoader);
    }

    String securityDomain = metaData.getSecurityDomain();
    log.debug("linkSecurityDomain");
    linkSecurityDomain(securityDomain, envCtx);
    log.debug("AbstractWebContainer.parseWebAppDescriptors, End");
  }
 /**
  * A template pattern implementation of the undeploy() method. This method calls the {@link
  * #performUndeploy(String, WebApplication) 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 {
   URL warURL = webApp.getURL();
   String warUrl = warURL.toString();
   performUndeploy(webApp, warUrl);
 }