[jboss-cvs] JBossAS SVN: r93939 - in trunk: server/src/main/org/jboss/web/deployers and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 22 20:08:29 EDT 2009


Author: remy.maucherat at jboss.com
Date: 2009-09-22 20:08:28 -0400 (Tue, 22 Sep 2009)
New Revision: 93939

Added:
   trunk/server/src/main/org/jboss/deployment/HandlesTypesClassFilter.java
   trunk/server/src/main/org/jboss/deployment/ServletContainerInitializerDeployer.java
Removed:
   trunk/server/src/main/org/jboss/web/deployers/HandlesTypesClassFilter.java
   trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java
Modified:
   trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
Log:
- Move the SCI deployer to the deployment package.
- Remove the call to the Catalina annotation scanning.

Modified: trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java	2009-09-22 23:49:43 UTC (rev 93938)
+++ trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java	2009-09-23 00:08:28 UTC (rev 93939)
@@ -287,12 +287,17 @@
          AnnotationFinder<AnnotatedElement> finder, Map<VirtualFile, Collection<Class<?>>> classes)
    {
       Web30MetaDataCreator creator = new Web30MetaDataCreator(finder);
+      boolean metaData = false;
       for (VirtualFile path : classes.keySet())
       {
          WebMetaData annotationMetaData = creator.create(classes.get(path));
          if (annotationMetaData != null)
+         {
             unit.addAttachment(WEB_ANNOTATED_ATTACHMENT_NAME + ":" + path.getName(), annotationMetaData, WebMetaData.class);
+            metaData = true;
+         }
       }
+      unit.addAttachment(WEB_ANNOTATED_ATTACHMENT_NAME, Boolean.TRUE);
    }
 
    /**

Copied: trunk/server/src/main/org/jboss/deployment/HandlesTypesClassFilter.java (from rev 93931, trunk/server/src/main/org/jboss/web/deployers/HandlesTypesClassFilter.java)
===================================================================
--- trunk/server/src/main/org/jboss/deployment/HandlesTypesClassFilter.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/deployment/HandlesTypesClassFilter.java	2009-09-23 00:08:28 UTC (rev 93939)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployment;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.ServletContainerInitializer;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * A VirtualFileVisitor that traverses unit root and determines the
+ * class files that extend, implement, or are annotated by HandlesTypes.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @author Remy Maucherat
+ * @version $Revision: 82920 $
+ */
+public class HandlesTypesClassFilter implements VirtualFileVisitor
+{
+   private static Logger log = Logger.getLogger(HandlesTypesClassFilter.class);
+   private ClassLoader loader;
+   private int rootLength;
+   private HashSet<String> childPaths = new HashSet<String>();
+   //private HashMap<VirtualFile, Class<?>> pathToClasses = new HashMap<VirtualFile, Class<?>>();
+   private Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes;
+   private Class<?>[] typesArray;
+   private Map<Class<?>, ServletContainerInitializer> typesMap;
+
+   public HandlesTypesClassFilter(VFSDeploymentUnit unit, ClassLoader loader,
+         VirtualFile classpathRoot, Class<?>[] typesArray, Map<Class<?>, ServletContainerInitializer> typesMap,
+         Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes)
+   {
+      this.loader = loader;
+      this.handlesTypes = handlesTypes;
+      this.typesArray = typesArray;
+      this.typesMap = typesMap;
+
+      // Work out the root length. If there is a root, we need to add one to jump across the next /
+      String rootName = classpathRoot.getPathName();
+      rootLength = rootName.length();
+      if (rootLength > 0)
+         rootLength += 1;
+      List<DeploymentUnit> children = unit.getChildren();
+      if(children != null)
+      {
+         for(DeploymentUnit cu : children)
+         {
+            String path = cu.getName();
+            childPaths.add(path);
+         }
+      }
+   }
+
+   public VisitorAttributes getAttributes()
+   {
+      VisitorAttributes attributes = new VisitorAttributes();
+      attributes.setIncludeRoot(true);
+      attributes.setRecurseFilter(new NoChildFilter());
+      return attributes;
+   }
+
+   public void visit(VirtualFile file)
+   {
+      try
+      {
+         if(file.isLeaf())
+         {
+            accepts(file);
+         }
+      }
+      catch (IOException e)
+      {
+         throw new Error("Error visiting " + file, e);
+      }
+   }
+
+   public boolean accepts(VirtualFile file)
+   {
+      boolean accepts = file.getPathName().endsWith(".class");
+      if(accepts)
+      {
+         accepts = false;
+         String className = null;
+         try
+         {
+            className = getClassName(file);
+            Class<?> c = loader.loadClass(className);
+            for (Class<?> clazz : typesArray)
+            {
+               if ((clazz.isAnnotation() && c.isAnnotationPresent((Class<? extends Annotation>) clazz))
+                     || clazz.isAssignableFrom(c))
+               {
+                  ServletContainerInitializer sci = typesMap.get(clazz);
+                  handlesTypes.get(sci).add(c);
+               }
+            }
+         }
+         catch(NoClassDefFoundError ignored)
+         {
+            log.debug("Incomplete class: "+className+", NCDFE: "+ignored);
+         }
+         catch(Exception ignored)
+         {
+            if(log.isTraceEnabled())
+               log.trace("Failed to load class: "+className, ignored);
+         }
+      }
+      return accepts;
+   }
+
+   protected String getFilePath(VirtualFile file)
+   {
+      String path = null;
+      try
+      {
+         path = file.toURI().toString();
+      }
+      catch(Exception e)
+      {
+      }
+      return path;
+   }
+
+   /**
+    * Search the classpaths for the root of this file.
+    *
+    * @param classFile the class file
+    * @return fqn class name
+    * @throws IOException for any error
+    */
+   protected String getClassName(VirtualFile classFile) throws IOException
+   {
+      String pathName = classFile.getPathName();
+      String name = pathName.substring(rootLength, pathName.length()-6);
+      name = name.replace('/', '.');
+      return name;
+   }
+
+   class NoChildFilter implements VirtualFileFilter
+   {
+      public boolean accepts(VirtualFile file)
+      {
+         String path = getFilePath(file);
+         boolean accepts = false;
+         try
+         {
+            accepts = file.isLeaf() == false && childPaths.contains(path) == false;
+         }
+         catch(Exception e)
+         {
+         }
+         return accepts;
+      }
+      
+   }
+}

Copied: trunk/server/src/main/org/jboss/deployment/ServletContainerInitializerDeployer.java (from rev 93931, trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java)
===================================================================
--- trunk/server/src/main/org/jboss/deployment/ServletContainerInitializerDeployer.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/deployment/ServletContainerInitializerDeployer.java	2009-09-23 00:08:28 UTC (rev 93939)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployment;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.Set;
+
+import javax.servlet.ServletContainerInitializer;
+import javax.servlet.annotation.HandlesTypes;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.metadata.web.spec.WebMetaData;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A deployer that processes ServletContainerInitializer.
+ * 
+ * @author Remy Maucherat
+ * @version $Revision: 93820 $
+ */
+public class ServletContainerInitializerDeployer extends AbstractDeployer
+{
+   public static final String SCI_ATTACHMENT_NAME = "sci."+WebMetaData.class.getName();
+   public static final String SCI_HANDLESTYPES_ATTACHMENT_NAME = "sci.hasndlestypes."+WebMetaData.class.getName();
+  
+   /**
+    * Create a new MergedJBossWebMetaDataDeployer.
+    */
+   public ServletContainerInitializerDeployer()
+   {
+      setStage(DeploymentStages.POST_CLASSLOADER);
+      addOutput(SCI_ATTACHMENT_NAME);
+      addOutput(SCI_HANDLESTYPES_ATTACHMENT_NAME);
+   }
+
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      // Load the ServletContainerInitializer services
+      ServiceLoader<ServletContainerInitializer> serviceLoader = 
+         ServiceLoader.load(ServletContainerInitializer.class, unit.getClassLoader());
+      Map<Class<?>, ServletContainerInitializer> typesMap = 
+         new HashMap<Class<?>, ServletContainerInitializer>();
+      Set<ServletContainerInitializer> scis = new HashSet<ServletContainerInitializer>();
+      Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = 
+         new HashMap<ServletContainerInitializer, Set<Class<?>>>();
+      for (ServletContainerInitializer service : serviceLoader)
+      {
+         scis.add(service);
+         if (service.getClass().isAnnotationPresent(HandlesTypes.class))
+         {
+            HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
+            Class<?>[] typesArray = handlesTypesAnnotation.value();
+            if (typesArray != null)
+            {
+               for (Class<?> type : typesArray)
+               {
+                  typesMap.put(type, service);
+                  handlesTypes.put(service, new HashSet<Class<?>>());
+               }
+            }
+         }
+      }
+      
+      Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
+      // Find classes which extend, implement, or are annotated by HandlesTypes
+      if (typesArray.length > 0 && unit instanceof VFSDeploymentUnit)
+      {
+         VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit) unit;
+         VirtualFile webInfLib = vfsUnit.getFile("WEB-INF/lib");
+         if (webInfLib != null)
+         {
+            try
+            {
+               List<VirtualFile> jars = webInfLib.getChildren();
+               for (VirtualFile jar : jars)
+               {
+                  HandlesTypesClassFilter classVisitor = new HandlesTypesClassFilter(vfsUnit, unit.getClassLoader(), 
+                        jar, typesArray, typesMap, handlesTypes);
+                  jar.visit(classVisitor);
+               }
+            }
+            catch (IOException e)
+            {
+            }
+         }
+      }
+      
+      unit.addAttachment(SCI_ATTACHMENT_NAME, scis);
+      unit.addAttachment(SCI_HANDLESTYPES_ATTACHMENT_NAME, handlesTypes);
+  }
+
+}

Deleted: trunk/server/src/main/org/jboss/web/deployers/HandlesTypesClassFilter.java
===================================================================
--- trunk/server/src/main/org/jboss/web/deployers/HandlesTypesClassFilter.java	2009-09-22 23:49:43 UTC (rev 93938)
+++ trunk/server/src/main/org/jboss/web/deployers/HandlesTypesClassFilter.java	2009-09-23 00:08:28 UTC (rev 93939)
@@ -1,187 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.web.deployers;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.servlet.ServletContainerInitializer;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileFilter;
-import org.jboss.virtual.VirtualFileVisitor;
-import org.jboss.virtual.VisitorAttributes;
-
-/**
- * A VirtualFileVisitor that traverses unit root and determines the
- * class files that extend, implement, or are annotated by HandlesTypes.
- * 
- * @author Scott.Stark at jboss.org
- * @author Remy Maucherat
- * @version $Revision: 82920 $
- */
-public class HandlesTypesClassFilter implements VirtualFileVisitor
-{
-   private static Logger log = Logger.getLogger(HandlesTypesClassFilter.class);
-   private ClassLoader loader;
-   private int rootLength;
-   private HashSet<String> childPaths = new HashSet<String>();
-   //private HashMap<VirtualFile, Class<?>> pathToClasses = new HashMap<VirtualFile, Class<?>>();
-   private Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes;
-   private Class<?>[] typesArray;
-   private Map<Class<?>, ServletContainerInitializer> typesMap;
-
-   public HandlesTypesClassFilter(VFSDeploymentUnit unit, ClassLoader loader,
-         VirtualFile classpathRoot, Class<?>[] typesArray, Map<Class<?>, ServletContainerInitializer> typesMap,
-         Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes)
-   {
-      this.loader = loader;
-      this.handlesTypes = handlesTypes;
-      this.typesArray = typesArray;
-      this.typesMap = typesMap;
-
-      // Work out the root length. If there is a root, we need to add one to jump across the next /
-      String rootName = classpathRoot.getPathName();
-      rootLength = rootName.length();
-      if (rootLength > 0)
-         rootLength += 1;
-      List<DeploymentUnit> children = unit.getChildren();
-      if(children != null)
-      {
-         for(DeploymentUnit cu : children)
-         {
-            String path = cu.getName();
-            childPaths.add(path);
-         }
-      }
-   }
-
-   public VisitorAttributes getAttributes()
-   {
-      VisitorAttributes attributes = new VisitorAttributes();
-      attributes.setIncludeRoot(true);
-      attributes.setRecurseFilter(new NoChildFilter());
-      return attributes;
-   }
-
-   public void visit(VirtualFile file)
-   {
-      try
-      {
-         if(file.isLeaf())
-         {
-            accepts(file);
-         }
-      }
-      catch (IOException e)
-      {
-         throw new Error("Error visiting " + file, e);
-      }
-   }
-
-   public boolean accepts(VirtualFile file)
-   {
-      boolean accepts = file.getPathName().endsWith(".class");
-      if(accepts)
-      {
-         accepts = false;
-         String className = null;
-         try
-         {
-            className = getClassName(file);
-            Class<?> c = loader.loadClass(className);
-            for (Class<?> clazz : typesArray)
-            {
-               if ((clazz.isAnnotation() && c.isAnnotationPresent((Class<? extends Annotation>) clazz))
-                     || clazz.isAssignableFrom(c))
-               {
-                  ServletContainerInitializer sci = typesMap.get(clazz);
-                  handlesTypes.get(sci).add(c);
-               }
-            }
-         }
-         catch(NoClassDefFoundError ignored)
-         {
-            log.debug("Incomplete class: "+className+", NCDFE: "+ignored);
-         }
-         catch(Exception ignored)
-         {
-            if(log.isTraceEnabled())
-               log.trace("Failed to load class: "+className, ignored);
-         }
-      }
-      return accepts;
-   }
-
-   protected String getFilePath(VirtualFile file)
-   {
-      String path = null;
-      try
-      {
-         path = file.toURI().toString();
-      }
-      catch(Exception e)
-      {
-      }
-      return path;
-   }
-
-   /**
-    * Search the classpaths for the root of this file.
-    *
-    * @param classFile the class file
-    * @return fqn class name
-    * @throws IOException for any error
-    */
-   protected String getClassName(VirtualFile classFile) throws IOException
-   {
-      String pathName = classFile.getPathName();
-      String name = pathName.substring(rootLength, pathName.length()-6);
-      name = name.replace('/', '.');
-      return name;
-   }
-
-   class NoChildFilter implements VirtualFileFilter
-   {
-      public boolean accepts(VirtualFile file)
-      {
-         String path = getFilePath(file);
-         boolean accepts = false;
-         try
-         {
-            accepts = file.isLeaf() == false && childPaths.contains(path) == false;
-         }
-         catch(Exception e)
-         {
-         }
-         return accepts;
-      }
-      
-   }
-}

Deleted: trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	2009-09-22 23:49:43 UTC (rev 93938)
+++ trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	2009-09-23 00:08:28 UTC (rev 93939)
@@ -1,136 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.web.deployers;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
-
-import javax.servlet.ServletContainerInitializer;
-import javax.servlet.annotation.HandlesTypes;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.deployment.AnnotatedClassFilter;
-import org.jboss.deployment.AnnotationMetaDataDeployer;
-import org.jboss.metadata.ear.jboss.JBossAppMetaData;
-import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
-import org.jboss.metadata.web.jboss.JBossWebMetaData;
-import org.jboss.metadata.web.spec.AbsoluteOrderingMetaData;
-import org.jboss.metadata.web.spec.AnnotationMergedView;
-import org.jboss.metadata.web.spec.OrderingElementMetaData;
-import org.jboss.metadata.web.spec.Web25MetaData;
-import org.jboss.metadata.web.spec.Web30MetaData;
-import org.jboss.metadata.web.spec.WebFragmentMetaData;
-import org.jboss.metadata.web.spec.WebCommonMetaData;
-import org.jboss.metadata.web.spec.WebMetaData;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * A deployer that processes ServletContainerInitializer.
- * 
- * @author Remy Maucherat
- * @version $Revision: 93820 $
- */
-public class ServletContainerInitializerDeployer extends AbstractDeployer
-{
-   public static final String SCI_ATTACHMENT_NAME = "sci."+WebMetaData.class.getName();
-   public static final String SCI_HANDLESTYPES_ATTACHMENT_NAME = "sci.hasndlestypes."+WebMetaData.class.getName();
-  
-   /**
-    * Create a new MergedJBossWebMetaDataDeployer.
-    */
-   public ServletContainerInitializerDeployer()
-   {
-      setStage(DeploymentStages.POST_CLASSLOADER);
-      addOutput(SCI_ATTACHMENT_NAME);
-      addOutput(SCI_HANDLESTYPES_ATTACHMENT_NAME);
-   }
-
-   public void deploy(DeploymentUnit unit) throws DeploymentException
-   {
-      // Load the ServletContainerInitializer services
-      ServiceLoader<ServletContainerInitializer> serviceLoader = 
-         ServiceLoader.load(ServletContainerInitializer.class, unit.getClassLoader());
-      Map<Class<?>, ServletContainerInitializer> typesMap = 
-         new HashMap<Class<?>, ServletContainerInitializer>();
-      Set<ServletContainerInitializer> scis = new HashSet<ServletContainerInitializer>();
-      Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = 
-         new HashMap<ServletContainerInitializer, Set<Class<?>>>();
-      for (ServletContainerInitializer service : serviceLoader)
-      {
-         scis.add(service);
-         if (service.getClass().isAnnotationPresent(HandlesTypes.class))
-         {
-            HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
-            Class<?>[] typesArray = handlesTypesAnnotation.value();
-            if (typesArray != null)
-            {
-               for (Class<?> type : typesArray)
-               {
-                  typesMap.put(type, service);
-                  handlesTypes.put(service, new HashSet<Class<?>>());
-               }
-            }
-         }
-      }
-      
-      Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
-      // Find classes which extend, implement, or are annotated by HandlesTypes
-      if (typesArray.length > 0 && unit instanceof VFSDeploymentUnit)
-      {
-         VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit) unit;
-         VirtualFile webInfLib = vfsUnit.getFile("WEB-INF/lib");
-         if (webInfLib != null)
-         {
-            try
-            {
-               List<VirtualFile> jars = webInfLib.getChildren();
-               for (VirtualFile jar : jars)
-               {
-                  HandlesTypesClassFilter classVisitor = new HandlesTypesClassFilter(vfsUnit, unit.getClassLoader(), 
-                        jar, typesArray, typesMap, handlesTypes);
-                  jar.visit(classVisitor);
-               }
-            }
-            catch (IOException e)
-            {
-            }
-         }
-      }
-      
-      unit.addAttachment(SCI_ATTACHMENT_NAME, scis);
-      unit.addAttachment(SCI_HANDLESTYPES_ATTACHMENT_NAME, handlesTypes);
-  }
-
-}

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	2009-09-22 23:49:43 UTC (rev 93938)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java	2009-09-23 00:08:28 UTC (rev 93939)
@@ -36,9 +36,12 @@
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletContext;
 import javax.xml.namespace.QName;
 
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
 import org.apache.catalina.core.ContextJarRepository;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.deploy.Multipart;
@@ -55,6 +58,7 @@
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployment.ServletContainerInitializerDeployer;
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
 import org.jboss.logging.Logger;
@@ -146,14 +150,38 @@
       runDestroy = deployerConfig.get().isDeleteWorkDirs();
    }
 
-   @Override
+   public void lifecycleEvent(LifecycleEvent event) {
+      if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) {
+         // Invoke ServletContainerInitializer
+         Set<ServletContainerInitializer> scis = (Set<ServletContainerInitializer>) 
+            deploymentUnitLocal.get().getAttachment(ServletContainerInitializerDeployer.SCI_ATTACHMENT_NAME);
+         Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = (Map<ServletContainerInitializer, Set<Class<?>>>) 
+            deploymentUnitLocal.get().getAttachment(ServletContainerInitializerDeployer.SCI_HANDLESTYPES_ATTACHMENT_NAME);
+         if (scis != null)
+         {
+            for (ServletContainerInitializer sci : scis)
+            {
+               try
+               {
+                  sci.onStartup(handlesTypes.get(sci), context.getServletContext());
+               }
+               catch (Throwable t)
+               {
+                  log.error("Error calling onStartup for servlet container initializer: " + sci.getClass().getName(), t);
+                  ok = false;
+               }
+            }
+         }
+      }
+      super.lifecycleEvent(event);
+   }
+   
    protected void applicationWebConfig()
    {
       processWebMetaData(metaDataLocal.get());
       processContextParameters();
    }
 
-   @Override
    protected void defaultWebConfig()
    {
       processWebMetaData(metaDataShared.get());
@@ -1002,12 +1030,12 @@
 
    public void applicationServletContainerInitializerConfig()
    {
-      // FIXME: Likely invoke the SCI with what was found in the deployers
+      // Do nothing here
    }
    
    protected void createFragmentsOrder()
    {
-      // FIXME: Propagate the order to StandardContext, will be needed for an attribute
+      // Do nothing here
    }
 
    protected void applicationExtraDescriptorsConfig()
@@ -1020,9 +1048,7 @@
       // Process Servlet API related annotations that were dependent on Servlet declarations
       if (ok && !context.getIgnoreAnnotations())
       {
-         // TODO: Process servlets which are annotations, or multipart config and constraints
-         // TODO: Don't call Catalina
-         WebAnnotationSet.loadApplicationAnnotations(context);
+         // TODO: Process servlets meta data which are marked as annotations for multipart config, run as and constraints
       }
       
       if (ok)




More information about the jboss-cvs-commits mailing list