FileDocCategorySizeDatePackage
AppClientScanningDeployer.javaAPI DocJBoss 4.2.14436Fri Jul 13 20:53:48 BST 2007org.jboss.ejb3.deployers

AppClientScanningDeployer

public class AppClientScanningDeployer extends org.jboss.deployers.plugins.deployers.helpers.AbstractTypedDeployer
Scan the main & super classes for annotations.
author
Carlo de Wolf
version
$Revision: $

Fields Summary
Constructors Summary
public AppClientScanningDeployer()

      super(ApplicationClientDD.class);
      
      setRelativeOrder(POSTPROCESS_CLASSLOADING_DEPLOYER);
   
Methods Summary
public voiddeploy(org.jboss.deployers.spi.deployer.DeploymentUnit unit)

      ApplicationClientDD dd = unit.getAttachment(getDeploymentType());
      // FIXME: implement metadata complete
//      if(dd != null && dd.getMetaDataComplete())
//         return;
      // for now the EJB3 client deployer handles all
      if(dd != null)
         return;
      
      try
      {
         String mainClassName = getMainClassName(unit);
         if(mainClassName == null)
            return;
         
         Class<?> mainClass = unit.getClassLoader().loadClass(mainClassName);
         
         log.info("mainClass = " + mainClass);
         
         if(hasAnnotations(mainClass))
         {
            // add a dummy application client dd to fire up the ejb3 client deployer
            dd = new ApplicationClientDD();
            unit.addAttachment(ApplicationClientDD.class, dd);
         }
      }
      catch(ClassNotFoundException e)
      {
         throw new DeploymentException(e);
      }
      catch(IOException e)
      {
         throw new DeploymentException(e);
      }
   
private java.lang.StringgetMainClassName(org.jboss.deployers.spi.deployer.DeploymentUnit unit)

      VirtualFile file = unit.getMetaDataFile("MANIFEST.MF");
      log.trace("parsing " + file);

      if(file == null)
      {
         return null;
      }

      try
      {
         // TODO - use VFSUtils.readManifest
         InputStream is = file.openStream();
         Manifest mf;
         try
         {
            mf = new Manifest(is);
         }
         finally
         {
            is.close();
         }
         Attributes attrs = mf.getMainAttributes();
         String className = attrs.getValue(Attributes.Name.MAIN_CLASS);
         return className;
      }
      finally
      {
         file.close();
      }
   
private booleanhasAnnotations(java.lang.Class cls)

      if(cls == null)
         return false;
      
      // Note: this also returns true if super class has annotations
      if(cls.getAnnotations().length > 0)
         return true;
      
      for(Field f : cls.getDeclaredFields())
      {
         if(f.getAnnotations().length > 0)
            return true;
      }
      
      return hasAnnotations(cls.getSuperclass());