/**
   * 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;
  }
 protected VirtualFile modify(VirtualFile file) throws Exception {
   return VFSUtils.explode(file);
 }