jboynes     2004/02/20 08:57:11

  Modified:    modules/jetty/src/java/org/apache/geronimo/jetty/deployment
                        WARConfigBuilder.java
  Log:
  Define webapp GBean from plan and include module content in config
  
  Revision  Changes    Path
  1.3       +72 -1     
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WARConfigBuilder.java
  
  Index: WARConfigBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WARConfigBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WARConfigBuilder.java     20 Feb 2004 15:49:56 -0000      1.2
  +++ WARConfigBuilder.java     20 Feb 2004 16:57:11 -0000      1.3
  @@ -64,9 +64,12 @@
   import java.net.URI;
   import java.net.URISyntaxException;
   import java.net.URL;
  +import java.util.Collections;
  +import java.util.Properties;
   import java.util.jar.JarInputStream;
   import java.util.jar.JarOutputStream;
   import javax.management.MalformedObjectNameException;
  +import javax.management.ObjectName;
   
   import org.apache.geronimo.deployment.ConfigurationBuilder;
   import org.apache.geronimo.deployment.DeploymentContext;
  @@ -77,6 +80,8 @@
   import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.GConstructorInfo;
   import org.apache.geronimo.gbean.GReferenceInfo;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
  +import org.apache.geronimo.jetty.JettyWebApplicationContext;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.kernel.repository.Repository;
   import org.apache.geronimo.xbeans.geronimo.jetty.JettyAttributeType;
  @@ -175,15 +180,81 @@
               } catch (MalformedObjectNameException e) {
                   throw new DeploymentException(e);
               }
  +
  +            // todo do we need to support include and dependency or can we 
rely on the parent?
  +            // add low-level GBean definitions to the config
   //            addIncludes(context, configType);
   //            addDependencies(context, configType.getDependencyArray());
               ClassLoader cl = context.getClassLoader(repository);
               addGBeans(context, jettyWebApp.getGbeanArray(), cl);
  +
  +            // add the warfile's content to the configuration
  +            URI warRoot = URI.create("war/");
  +            context.addArchive(warRoot, module);
  +            context.addToClassPath(warRoot);
  +
  +            // add the GBean for the web application
  +            addWebAppGBean(context, jettyWebApp, warRoot);
  +
  +            // todo do we need to add GBeans to make the servlets JSR77 
ManagedObjects?
  +
               context.close();
               os.flush();
           } finally {
               fos.close();
           }
  +    }
  +
  +    private void addWebAppGBean(DeploymentContext context, JettyWebAppType 
webApp, URI warRoot) throws DeploymentException {
  +        String contextRoot = webApp.getContextRoot().trim();
  +        if (contextRoot.length() == 0) {
  +            throw new DeploymentException("Missing value for context-root");
  +        }
  +        URI configID = context.getConfigID();
  +
  +        Properties nameProps = new Properties();
  +        nameProps.put("J2EEServer", "null");
  +        nameProps.put("J2EEApplication", "null");
  +        nameProps.put("J2EEType", "WebModule");
  +        nameProps.put("ContextRoot", contextRoot);
  +        nameProps.put("Config", configID.toString());
  +        ObjectName name;
  +        try {
  +            name = new ObjectName("geronimo.jetty", nameProps);
  +        } catch (MalformedObjectNameException e) {
  +            throw new DeploymentException("Unable to construct ObjectName", 
e);
  +        }
  +
  +        GBeanMBean gbean = new 
GBeanMBean(JettyWebApplicationContext.GBEAN_INFO);
  +        try {
  +            gbean.setAttribute("URI", warRoot);
  +            gbean.setAttribute("ContextPath", contextRoot);
  +            gbean.setAttribute("ContextPriorityClassLoader", 
Boolean.valueOf(webApp.getContextPriorityClassloader()));
  +            gbean.setAttribute("PolicyContextID", null);
  +            //jndi
  +/*
  +            if (proxyFactory != null) {
  +                UserTransaction userTransaction = null;
  +                Context componentContext = new 
ComponentContextBuilder(proxyFactory, cl).buildContext(
  +                        webApp.getEjbRefArray(), 
jettyWebApp.getEjbRefArray(),
  +                        webApp.getEjbLocalRefArray(), 
jettyWebApp.getEjbLocalRefArray(),
  +                        webApp.getEnvEntryArray(),
  +                        webApp.getMessageDestinationRefArray(), 
jettyWebApp.getMessageDestinationRefArray(),
  +                        webApp.getResourceEnvRefArray(), 
jettyWebApp.getResourceEnvRefArray(),
  +                        webApp.getResourceRefArray(), 
jettyWebApp.getResourceRefArray(),
  +                        userTransaction);
  +                gbean.setAttribute("ComponentContext", componentContext);
  +            }
  +*/
  +
  +            gbean.setReferencePatterns("Configuration", 
Collections.singleton(Kernel.getConfigObjectName(configID)));
  +            gbean.setReferencePatterns("JettyContainer", 
Collections.singleton(new 
ObjectName("geronimo.web:type=WebContainer,container=Jetty"))); // @todo 
configurable
  +            gbean.setReferencePatterns("TransactionManager", 
Collections.EMPTY_SET);
  +            gbean.setReferencePatterns("TrackedConnectionAssociator", 
Collections.EMPTY_SET);
  +        } catch (Exception e) {
  +            throw new DeploymentException("Unable to initialize webapp 
GBean", e);
  +        }
  +        context.addGBean(name, gbean);
       }
   
       /**
  
  
  

Reply via email to