[jboss-cvs] JBossAS SVN: r79543 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 15 11:28:50 EDT 2008


Author: remy.maucherat at jboss.com
Date: 2008-10-15 11:28:49 -0400 (Wed, 15 Oct 2008)
New Revision: 79543

Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
Log:
- Add new code for parsing server.xml and context.xml files.
- Use TomcatService.OLD_CODE flag to enable (and recompile the 3 files).

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java	2008-10-15 15:12:41 UTC (rev 79542)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java	2008-10-15 15:28:49 UTC (rev 79543)
@@ -21,19 +21,25 @@
  */
 package org.jboss.web.tomcat.service.deployers;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.servlet.ServletContext;
 
 import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.deploy.SessionCookie;
 import org.apache.catalina.startup.ContextConfig;
+import org.apache.tomcat.util.IntrospectionUtils;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
 import org.jboss.logging.Logger;
@@ -67,6 +73,13 @@
 import org.jboss.metadata.web.spec.WebResourceCollectionMetaData;
 import org.jboss.metadata.web.spec.WebResourceCollectionsMetaData;
 import org.jboss.metadata.web.spec.WelcomeFileListMetaData;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.web.tomcat.metadata.ContextMetaData;
+import org.jboss.web.tomcat.metadata.ContextXMLObjectModelFactory;
+import org.jboss.web.tomcat.metadata.ParameterMetaData;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
 
 @SuppressWarnings("unchecked")
 public class JBossContextConfig extends ContextConfig
@@ -505,6 +518,150 @@
       
    }
 
+   /**
+    * Process a "init" event for this Context.
+    */
+   protected void init() {
+      
+      if (TomcatService.OLD_CODE) {
+         super.init();
+         return;
+      }
+      
+      context.setConfigured(false);
+      ok = true;
+      
+      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 {
+         ObjectModelFactory factory = new ContextXMLObjectModelFactory();
+         Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+         u.setSchemaValidation(false);
+         u.setValidation(false);
+         InputStream is = null;
+         try {
+            if (local)
+            {
+               VirtualFile vf = ((VFSDeploymentUnit) deploymentUnitLocal.get()).getFile(resourceName);
+               if (vf != null)
+                  is = vf.openStream();
+            }
+            else
+            {
+               is = getClass().getClassLoader().getResourceAsStream(resourceName);
+            }
+            if (is == null) {
+               return;
+            }
+            contextMetaData = ContextMetaData.class.cast(u.unmarshal(is, factory, null));
+         } finally {
+            if (is != null) {
+               try {
+                  is.close();
+               } catch (IOException e) {
+                  // Ignore
+               }
+            }
+         }
+      } catch (Exception e) {
+         log.error("XML error parsing: " + resourceName, e);
+         ok = false;
+         return;
+      }
+      
+      try {
+         if (contextMetaData != null)
+         {
+            
+            if (contextMetaData.getAttributes() != null) {
+               Iterator<String> names = contextMetaData.getAttributes().keySet().iterator();
+               while (names.hasNext()) {
+                  String name = names.next();
+                  String value = (String) contextMetaData.getAttributes().get(name);
+                  IntrospectionUtils.setProperty(context, name, value);
+               }
+            }
+
+            TomcatService.addLifecycleListeners(context, contextMetaData.getListeners());
+
+            // Context/Realm
+            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) {
+               Iterator<String> listeners = contextMetaData.getInstanceListeners().iterator();
+               while (listeners.hasNext())
+               {
+                  context.addInstanceListener(listeners.next());
+               }
+            }
+            
+            // Context/Loader
+            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/Manager
+            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) {
+               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/Resources
+            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) {
+               SessionCookie sessionCookie = new SessionCookie();
+               sessionCookie.setComment(contextMetaData.getSessionCookie().getComment());
+               sessionCookie.setDomain(contextMetaData.getSessionCookie().getDomain());
+               sessionCookie.setHttpOnly(contextMetaData.getSessionCookie().getHttpOnly());
+               sessionCookie.setPath(contextMetaData.getSessionCookie().getPath());
+               sessionCookie.setSecure(contextMetaData.getSessionCookie().getSecure());
+               context.setSessionCookie(sessionCookie);
+            }
+            
+         }
+      }
+      catch (Exception e)
+      {
+         log.error("Error processing: " + resourceName, e);
+         ok = false;
+      }
+      
+   }
+   
    protected void destroy() {
 	   if (runDestroy) {
 		   super.destroy();

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2008-10-15 15:12:41 UTC (rev 79542)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2008-10-15 15:28:49 UTC (rev 79543)
@@ -186,59 +186,63 @@
       }
       Registry.getRegistry().registerComponent(context, objectName, config.getContextClassName());
 
-      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)
+      if (TomcatService.OLD_CODE) {
+         String ctxConfig = null;
+         File warFile = new File(url.getFile());
+         if (warFile.isDirectory() == false)
          {
-            // Copy the META-INF/context.xml from the VFS to the temp folder
-            InputStream is = file.openStream();
-            FileOutputStream fos = null; 
-            try
+            // 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)
             {
-               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)
+               // Copy the META-INF/context.xml from the VFS to the temp folder
+               InputStream is = file.openStream();
+               FileOutputStream fos = null; 
+               try
                {
-                  fos.write(buffer, 0, bytes);
+                  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();
                }
-               ctxConfig = tempFile.getAbsolutePath();
-            }
-            finally
-            {
-               is.close();
-               if (fos != null)
+               finally
                {
-                  fos.close();
+                  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)
+         else
          {
-            ctxConfig = webDD.getAbsolutePath();
+            // 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.setInstanceManager(injectionContainer);
       context.setDocBase(url.getFile());
-      context.setConfigFile(ctxConfig);
       context.setDefaultContextXml("context.xml");
       context.setDefaultWebXml("conf/web.xml");
       context.setPublicId(metaData.getPublicID());

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java	2008-10-15 15:12:41 UTC (rev 79542)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java	2008-10-15 15:28:49 UTC (rev 79543)
@@ -23,7 +23,11 @@
 package org.jboss.web.tomcat.service.deployers;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Iterator;
+import java.util.List;
 
 import javax.management.Attribute;
 import javax.management.MBeanServer;
@@ -37,7 +41,9 @@
 
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.connector.Connector;
+import org.apache.catalina.startup.Catalina;
 import org.apache.catalina.startup.CatalinaProperties;
+import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.modeler.Registry;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
@@ -45,7 +51,19 @@
 import org.jboss.system.ServiceMBeanSupport;
 import org.jboss.system.server.Server;
 import org.jboss.system.server.ServerImplMBean;
+import org.jboss.web.tomcat.metadata.AnyXmlMetaData;
+import org.jboss.web.tomcat.metadata.ConnectorMetaData;
+import org.jboss.web.tomcat.metadata.EngineMetaData;
+import org.jboss.web.tomcat.metadata.HostMetaData;
+import org.jboss.web.tomcat.metadata.ListenerMetaData;
+import org.jboss.web.tomcat.metadata.ServerMetaData;
+import org.jboss.web.tomcat.metadata.ServerXMLObjectModelFactory;
+import org.jboss.web.tomcat.metadata.ServiceMetaData;
+import org.jboss.web.tomcat.metadata.ValveMetaData;
 import org.jboss.web.tomcat.security.HttpServletRequestPolicyContextHandler;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
 
 /**
  * Temporary workaround to support controlling the lifecycle of the webserver runtime portion of TomcatDeployer via a
@@ -80,6 +98,8 @@
       this.tomcatDeployer = tomcatDeployer;
    }
 
+   public static boolean OLD_CODE = true;
+   
    // In our lifecycle, we invoke the webserver lifecycle-related operations
    // in the TomcatDeployer
 
@@ -101,21 +121,179 @@
       String objectNameS = tomcatDeployer.getDomain() + ":type=server";
       ObjectName objectName = new ObjectName(objectNameS);
 
-      // Set the modeler Registry MBeanServer to the that of the tomcat service
-      Registry.getRegistry().setMBeanServer(server);
+      if (OLD_CODE) {
 
-      Registry.getRegistry().registerComponent(Class.forName("org.apache.catalina.startup.Catalina").newInstance(),
-            objectName, "org.apache.catalina.startup.Catalina");
+         // Set the modeler Registry MBeanServer to the that of the tomcat service
+         Registry.getRegistry().setMBeanServer(server);
 
-      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)));
+         Registry.getRegistry().registerComponent(Class.forName("org.apache.catalina.startup.Catalina").newInstance(),
+               objectName, "org.apache.catalina.startup.Catalina");
 
+         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)));
+
+      } else {
+      
+         // Parse main server.xml
+         // FIXME: this could be done somewhere else
+         ObjectModelFactory factory = new ServerXMLObjectModelFactory();
+         Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+         u.setSchemaValidation(false);
+         u.setValidation(false);
+         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, factory, null));
+         } finally {
+            if (is != null) {
+               try {
+                  is.close();
+               } catch (IOException e) {
+                  // Ignore
+               }
+            }
+         }
+         
+         // 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)
+         {
+            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.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())
+               {
+                  ConnectorMetaData connectorMetaData = connectorMetaDatas.next();
+                  Connector connector = new Connector(connectorMetaData.getProtocol());
+                  if (connectorMetaData.getAttributes() != null)
+                  {
+                     Iterator<String> names = connectorMetaData.getAttributes().keySet().iterator();
+                     while (names.hasNext())
+                     {
+                        String name = names.next();
+                        String value = (String) connectorMetaData.getAttributes().get(name);
+                        IntrospectionUtils.setProperty(connector, name, value);
+                     }
+                  }
+                  service.addConnector(connector);
+               }
+            }
+            
+            // 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());
+            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())
+               {
+                  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));
+                  }
+                  
+                  // 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);
+      }
+      
+      // Start Tomcat
       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
@@ -165,6 +343,84 @@
 
    }
 
+   /**
+    * Create a JavaBean corresponding to the given metadata, similar to what the digester is doing.
+    */
+   protected static Object getInstance(AnyXmlMetaData metaData, String defaultClassName) throws Exception
+   {
+      String className = metaData.getClassName();
+      if (className == null) {
+         className = defaultClassName;
+      }
+      if (className == null) {
+         throw new IllegalArgumentException("No className specified for element");
+      }
+      Object instance = TomcatService.class.getClassLoader().loadClass(className).newInstance();
+      if (metaData.getAttributes() != null) {
+         Iterator<String> names = metaData.getAttributes().keySet().iterator();
+         while (names.hasNext()) {
+            String name = names.next();
+            String value = (String) metaData.getAttributes().get(name);
+            IntrospectionUtils.setProperty(instance, name, value);
+         }
+      }
+      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) {
+         return;
+      }
+      org.apache.catalina.Lifecycle lifecycle = null;
+      if (!(instance instanceof org.apache.catalina.Lifecycle))
+      {
+         return;
+      }
+      else
+      {
+         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));
+      }
+
+   }
+   
+   
+   /**
+    * Associate valves with the instance, if it implements Lifecycle.
+    */
+   protected static void addValves(Object instance, List<ValveMetaData> list) throws Exception
+   {
+      if (list == null) {
+         return;
+      }
+      org.apache.catalina.Pipeline pipeline = null;
+      if (!(instance instanceof org.apache.catalina.Pipeline))
+      {
+         return;
+      }
+      else
+      {
+         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));
+      }
+
+   }
+   
+   
    @Override
    protected void stopService() throws Exception
    {




More information about the jboss-cvs-commits mailing list