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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 10 00:10:42 EST 2009


Author: remy.maucherat at jboss.com
Date: 2009-11-10 00:10:38 -0500 (Tue, 10 Nov 2009)
New Revision: 96210

Added:
   trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java
   trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java
Removed:
   trunk/server/src/main/java/org/jboss/deployment/HandlesTypesClassFilter.java
   trunk/server/src/main/java/org/jboss/deployment/ServletContainerInitializerDeployer.java
Modified:
   trunk/server/src/main/java/org/jboss/web/deployers/MergedJBossWebMetaDataDeployer.java
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
   trunk/tomcat/src/resources/war-deployers-jboss-beans.xml
Log:
- Fix ServletContainerInitializer implementation.

Deleted: trunk/server/src/main/java/org/jboss/deployment/HandlesTypesClassFilter.java
===================================================================
--- trunk/server/src/main/java/org/jboss/deployment/HandlesTypesClassFilter.java	2009-11-10 05:09:36 UTC (rev 96209)
+++ trunk/server/src/main/java/org/jboss/deployment/HandlesTypesClassFilter.java	2009-11-10 05:10:38 UTC (rev 96210)
@@ -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.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 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);
-      }
-   }
-
-   @SuppressWarnings("unchecked")
-   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/java/org/jboss/deployment/ServletContainerInitializerDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/deployment/ServletContainerInitializerDeployer.java	2009-11-10 05:09:36 UTC (rev 96209)
+++ trunk/server/src/main/java/org/jboss/deployment/ServletContainerInitializerDeployer.java	2009-11-10 05:10:38 UTC (rev 96210)
@@ -1,124 +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.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
-   {
-      if (!unit.getSimpleName().endsWith(".war"))
-      {
-         return;
-      }
-      // 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);
-  }
-
-}

Copied: trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java (from rev 94420, trunk/server/src/main/java/org/jboss/deployment/HandlesTypesClassFilter.java)
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java	                        (rev 0)
+++ trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java	2009-11-10 05:10:38 UTC (rev 96210)
@@ -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.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 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);
+      }
+   }
+
+   @SuppressWarnings("unchecked")
+   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;
+      }
+      
+   }
+}

Modified: trunk/server/src/main/java/org/jboss/web/deployers/MergedJBossWebMetaDataDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/MergedJBossWebMetaDataDeployer.java	2009-11-10 05:09:36 UTC (rev 96209)
+++ trunk/server/src/main/java/org/jboss/web/deployers/MergedJBossWebMetaDataDeployer.java	2009-11-10 05:10:38 UTC (rev 96210)
@@ -29,6 +29,7 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.jboss.deployers.spi.DeploymentException;
@@ -63,6 +64,7 @@
    public static final String WEB_MERGED_ATTACHMENT_NAME = "merged."+JBossWebMetaData.class.getName();
    public static final String WEB_ORDER_ATTACHMENT_NAME = "order."+WebMetaData.class.getName();
    public static final String WEB_OVERLAYS_ATTACHMENT_NAME = "overlays."+WebMetaData.class.getName();
+   public static final String WEB_SCIS_ATTACHMENT_NAME = "localscis."+WebMetaData.class.getName();
 
    private boolean metaDataCompleteIsDefault = false;
 
@@ -126,6 +128,7 @@
       List<WebOrdering> orderings = new ArrayList<WebOrdering>();
       HashSet<String> jarsSet = new HashSet<String>();
       Set<VirtualFile> overlays = new HashSet<VirtualFile>();
+      Map<String, VirtualFile> scis = new HashMap<String, VirtualFile>();
       VirtualFile webInfLib = null;
       boolean fragmentFound = false;
       HashMap<String, WebFragmentMetaData> webFragments = new HashMap<String, WebFragmentMetaData>();
@@ -147,6 +150,12 @@
                   {
                      overlays.add(overlay);
                   }
+                  // Find ServletContainerInitializer services
+                  VirtualFile sci = jar.getChild("META-INF/services/javax.servlet.ServletContainerInitializer");
+                  if (sci != null)
+                  {
+                     scis.put(jar.getName(), sci);
+                  }
                }
             }
             catch (IOException e)
@@ -333,6 +342,7 @@
       
       unit.addAttachment(WEB_ORDER_ATTACHMENT_NAME, order);
       unit.addAttachment(WEB_OVERLAYS_ATTACHMENT_NAME, overlays);
+      unit.addAttachment(WEB_SCIS_ATTACHMENT_NAME, scis);
       
       // The fragments and corresponding annotations will need to be merged in order
       // For each JAR in the order: 

Copied: trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java (from rev 94215, trunk/server/src/main/java/org/jboss/deployment/ServletContainerInitializerDeployer.java)
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	                        (rev 0)
+++ trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	2009-11-10 05:10:38 UTC (rev 96210)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+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.handlestypes."+WebMetaData.class.getName();
+  
+   protected boolean init = false;
+   
+   /**
+    * Create a new MergedJBossWebMetaDataDeployer.
+    */
+   public ServletContainerInitializerDeployer()
+   {
+      setStage(DeploymentStages.POST_CLASSLOADER);
+      addInput(MergedJBossWebMetaDataDeployer.WEB_ORDER_ATTACHMENT_NAME);
+      addInput(MergedJBossWebMetaDataDeployer.WEB_SCIS_ATTACHMENT_NAME);
+      addOutput(SCI_ATTACHMENT_NAME);
+      addOutput(SCI_HANDLESTYPES_ATTACHMENT_NAME);
+   }
+
+   @SuppressWarnings("unchecked")
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      if (!unit.getSimpleName().endsWith(".war"))
+      {
+         return;
+      }
+      Set<ServletContainerInitializer> scis = new HashSet<ServletContainerInitializer>();
+      // Load the shared ServletContainerInitializer services
+      ServiceLoader<ServletContainerInitializer> serviceLoader = 
+         ServiceLoader.load(ServletContainerInitializer.class, this.getClass().getClassLoader()/*unit.getClassLoader()*/);
+      for (ServletContainerInitializer service : serviceLoader)
+      {
+         scis.add(service);
+      }
+      // Find local ServletContainerInitializer services
+      List<String> order = 
+         (List<String>) unit.getAttachment(MergedJBossWebMetaDataDeployer.WEB_ORDER_ATTACHMENT_NAME);
+      Map<String, VirtualFile> localScis = (Map<String, VirtualFile>) 
+         unit.getAttachment(MergedJBossWebMetaDataDeployer.WEB_SCIS_ATTACHMENT_NAME);
+      for (String jar : order)
+      {
+         VirtualFile sci = localScis.get(jar);
+         if (sci != null)
+         {
+            InputStream is = null;
+            try
+            {
+               // Get the ServletContainerInitializer class name
+               is = sci.openStream();
+               BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+               String servletContainerInitializerClassName = reader.readLine();
+               int pos = servletContainerInitializerClassName.indexOf('#');
+               if (pos > 0) {
+                   servletContainerInitializerClassName = servletContainerInitializerClassName.substring(0, pos);
+               }
+               servletContainerInitializerClassName = servletContainerInitializerClassName.trim();
+               // Instantiate the ServletContainerInitializer
+               ServletContainerInitializer service = 
+                  (ServletContainerInitializer) unit.getClassLoader()
+                     .loadClass(servletContainerInitializerClassName).newInstance();
+               scis.add(service);
+            }
+            catch (Exception e)
+            {
+               DeploymentException.rethrowAsDeploymentException("Deployment error processing SCI for JAR: " + jar, e);
+            }
+            finally
+            {
+               try
+               {
+                  if (is != null)
+                     is.close();
+               }
+               catch (IOException e)
+               {
+                  ;
+               }
+            }
+         }
+      }
+      // Process HandlesTypes for ServletContainerInitializer
+      Map<Class<?>, ServletContainerInitializer> typesMap = 
+         new HashMap<Class<?>, ServletContainerInitializer>();
+      Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = 
+         new HashMap<ServletContainerInitializer, Set<Class<?>>>();
+      for (ServletContainerInitializer service : scis)
+      {
+         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;
+         List<VirtualFile> classpath = vfsUnit.getClassPath();
+         try
+         {
+            for (VirtualFile classpathItem : classpath)
+            {
+               HandlesTypesClassFilter classVisitor = new HandlesTypesClassFilter(vfsUnit, unit.getClassLoader(), 
+                     classpathItem, typesArray, typesMap, handlesTypes);
+               classpathItem.visit(classVisitor);
+            }
+         }
+         catch (Exception e)
+         {
+            DeploymentException.rethrowAsDeploymentException("Deployment error scanning HandlesTypes", e);
+         }
+      }
+      
+      unit.addAttachment(SCI_ATTACHMENT_NAME, scis);
+      unit.addAttachment(SCI_HANDLESTYPES_ATTACHMENT_NAME, handlesTypes);
+  }
+
+}

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java	2009-11-10 05:09:36 UTC (rev 96209)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java	2009-11-10 05:10:38 UTC (rev 96210)
@@ -67,7 +67,6 @@
 import org.jboss.annotation.javaee.Icon;
 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;
@@ -118,6 +117,7 @@
 import org.jboss.util.xml.JBossEntityResolver;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.web.deployers.MergedJBossWebMetaDataDeployer;
+import org.jboss.web.deployers.ServletContainerInitializerDeployer;
 import org.jboss.web.tomcat.metadata.ContextMetaData;
 import org.jboss.web.tomcat.metadata.ParameterMetaData;
 import org.jboss.xb.binding.Unmarshaller;

Modified: trunk/tomcat/src/resources/war-deployers-jboss-beans.xml
===================================================================
--- trunk/tomcat/src/resources/war-deployers-jboss-beans.xml	2009-11-10 05:09:36 UTC (rev 96209)
+++ trunk/tomcat/src/resources/war-deployers-jboss-beans.xml	2009-11-10 05:10:38 UTC (rev 96210)
@@ -30,8 +30,7 @@
    <bean name="JBossWebAppParsingDeployer" class="org.jboss.deployment.JBossWebAppParsingDeployer">
       <property name="relativeOrder">2003</property>
    </bean>
-   <bean name="ServletContainerInitializerDeployer" class="org.jboss.deployment.ServletContainerInitializerDeployer">
-      <property name="relativeOrder">2004</property>
+   <bean name="ServletContainerInitializerDeployer" class="org.jboss.web.deployers.ServletContainerInitializerDeployer">
    </bean>
    <!-- Servlet 3.0 annotation support (performance drop) -->
    <bean name="WebAnnotationMetaDataDeployer" class="org.jboss.web.deployers.WarAnnotationMetaDataDeployer">




More information about the jboss-cvs-commits mailing list