[jboss-cvs] jboss-cvs-commits Digest, Vol 39, Issue 290

Ales Justin ales.justin at gmail.com
Tue Sep 22 15:07:52 EDT 2009


This looks too broad, handling any deployment.
Shouldn't it handle only web deployments?

> Added: trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java
> ===================================================================
> --- trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	                        (rev 0)
> +++ trunk/server/src/main/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	2009-09-22 17:20:06 UTC (rev 93931)
> @@ -0,0 +1,136 @@
> +/*
> + * 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);
> +  }
> +
> +}



More information about the jboss-cvs-commits mailing list