[jboss-cvs] jboss-seam/src/main/org/jboss/seam/deployment ...

Gavin King gavin.king at jboss.com
Tue Nov 21 14:42:32 EST 2006


  User: gavin   
  Date: 06/11/21 14:42:31

  Modified:    src/main/org/jboss/seam/deployment   Scanner.java
                        ComponentScanner.java
  Log:
  fix JBSEAM-519
  
  Revision  Changes    Path
  1.20      +24 -1     jboss-seam/src/main/org/jboss/seam/deployment/Scanner.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Scanner.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/deployment/Scanner.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- Scanner.java	20 Nov 2006 23:44:02 -0000	1.19
  +++ Scanner.java	21 Nov 2006 19:42:31 -0000	1.20
  @@ -1,4 +1,4 @@
  -//$Id: Scanner.java,v 1.19 2006/11/20 23:44:02 gavin Exp $
  +//$Id: Scanner.java,v 1.20 2006/11/21 19:42:31 gavin Exp $
   package org.jboss.seam.deployment;
   
   import java.io.DataInputStream;
  @@ -15,6 +15,7 @@
   
   import javassist.bytecode.AnnotationsAttribute;
   import javassist.bytecode.ClassFile;
  +import javassist.bytecode.annotation.MemberValue;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -159,6 +160,28 @@
         return false; 
      }
   
  +   protected String getAnnotationValue(ClassFile cf, Class<? extends Annotation> annotationType, String memberName)
  +   { 
  +      AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute( AnnotationsAttribute.visibleTag ); 
  +      if ( visible != null ) 
  +      {
  +         javassist.bytecode.annotation.Annotation annotation = visible.getAnnotation( annotationType.getName() );
  +         if (annotation==null)
  +         {
  +            return null;
  +         }
  +         else
  +         {
  +            MemberValue memberValue = annotation.getMemberValue(memberName);
  +            return memberValue==null ? null : memberValue.toString(); //TODO: toString() here is probably Bad ;-)
  +         }
  +      }
  +      else
  +      {
  +         return null;
  +      }
  +   }
  +
      public static String componentFilename(String name)
      {
         return name.substring( 0, name.lastIndexOf(".class") ) + ".component.xml";
  
  
  
  1.4       +62 -49    jboss-seam/src/main/org/jboss/seam/deployment/ComponentScanner.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ComponentScanner.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/deployment/ComponentScanner.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ComponentScanner.java	18 Nov 2006 00:38:22 -0000	1.3
  +++ ComponentScanner.java	21 Nov 2006 19:42:31 -0000	1.4
  @@ -1,5 +1,6 @@
   package org.jboss.seam.deployment;
   
  +import org.jboss.seam.annotations.Install;
   import org.jboss.seam.annotations.Name;
   
   import java.io.IOException;
  @@ -11,8 +12,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -public class ComponentScanner
  -    extends Scanner 
  +public class ComponentScanner extends Scanner
   {
       private static final Log log = LogFactory.getLog(ComponentScanner.class);
   
  @@ -25,15 +25,18 @@
       
       public ComponentScanner(String resourceName, ClassLoader classLoader)
       {
  -        super(resourceName,classLoader);
  +      super(resourceName, classLoader);
       }
       
       /**
  -     * Returns only Seam components (ie: classes annotated with @Name)
  +    * Returns only Seam components (ie: classes annotated with
  +    * 
  +    * @Name)
        */
       public Set<Class<Object>> getClasses()
       {
  -        if (classes == null) {
  +      if (classes == null)
  +      {
               classes = new HashSet<Class<Object>>();
               scan();
           } 
  @@ -43,24 +46,34 @@
       @Override
       protected void handleItem(String name)
       {
  -        if (name.endsWith(".class")) {
  +      if ( name.endsWith(".class") )
  +      {
               String classname = filenameToClassname(name);
               String filename = Scanner.componentFilename(name);
  -            try {
  +         try
  +         {
                   ClassFile classFile = getClassFile(name);
  -                if (hasAnnotation(classFile, Name.class) || 
  -                    classLoader.getResources(filename).hasMoreElements() ) 
  +            boolean installable = ( hasAnnotation(classFile, Name.class) || classLoader.getResources(filename).hasMoreElements() )
  +                     && !"false".equals( getAnnotationValue(classFile, Install.class, "value") );
  +            if (installable)
                   {
  -                    classes.add( (Class<Object>) classLoader.loadClass(classname) );
  +               if ( log.isDebugEnabled() ) log.debug("found component class: " + name);
  +               classes.add((Class<Object>) classLoader.loadClass(classname));
                   }
  -            } catch (ClassNotFoundException cnfe) {
  -                log.debug( "could not load class: " + classname, cnfe );
  +         }
  +         catch (ClassNotFoundException cnfe)
  +         {
  +            log.debug("could not load class: " + classname, cnfe);
   
  -            } catch (NoClassDefFoundError ncdfe) {
  -                log.debug( "could not load class (missing dependency): " + classname, ncdfe );
  +         }
  +         catch (NoClassDefFoundError ncdfe)
  +         {
  +            log.debug("could not load class (missing dependency): " + classname, ncdfe);
   
  -            } catch (IOException ioe) {
  -                log.debug( "could not load classfile: " + classname, ioe );
  +         }
  +         catch (IOException ioe)
  +         {
  +            log.debug("could not load classfile: " + classname, ioe);
               }
           }
       }
  
  
  



More information about the jboss-cvs-commits mailing list