[jboss-cvs] JBossAS SVN: r106058 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/annotations/spi and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 15 12:28:25 EDT 2010


Author: alesj
Date: 2010-06-15 12:28:24 -0400 (Tue, 15 Jun 2010)
New Revision: 106058

Added:
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/InterfacesAnnotationVisitor.java
Modified:
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java
Log:
Refactor things a bit, separate concerns.


Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java	2010-06-15 16:05:43 UTC (rev 106057)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java	2010-06-15 16:28:24 UTC (rev 106058)
@@ -22,6 +22,7 @@
 
 package org.jboss.scanning.annotations.plugins;
 
+import org.jboss.classloading.spi.visitor.ClassFilter;
 import org.jboss.classloading.spi.visitor.ResourceContext;
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.scanning.annotations.spi.AnnotationIndex;
@@ -41,8 +42,10 @@
 {
    /** The repository */
    private final DefaultAnnotationRepository repository;
-   /** The visitor */
-   private final GenericAnnotationVisitor visitor;
+   /** The annotations visitor */
+   private final GenericAnnotationVisitor annotations;
+   /** The interfaces visitor */
+   private final InterfacesAnnotationVisitor interfaces;
 
    public AnnotationsScanningPlugin(ClassLoader cl)
    {
@@ -52,9 +55,12 @@
    public AnnotationsScanningPlugin(ReflectProvider provider, ResourceOwnerFinder finder, ClassLoader cl, ErrorHandler handler)
    {
       repository = new DefaultAnnotationRepository(cl);
-      // setup visitor
-      visitor = new GenericAnnotationVisitor(provider, finder, repository);
-      visitor.setErrorHandler(handler);
+      // setup annotations visitor
+      annotations = new GenericAnnotationVisitor(provider, finder, repository);
+      annotations.setErrorHandler(handler);
+      // setup interfaces visitor
+      interfaces = new InterfacesAnnotationVisitor(provider, repository);
+      interfaces.setErrorHandler(handler);
    }
 
    protected DefaultAnnotationRepository doCreateHandle()
@@ -81,11 +87,12 @@
 
    public ResourceFilter getFilter()
    {
-      return visitor.getFilter();
+      return ClassFilter.INSTANCE;
    }
 
    public void visit(ResourceContext resource)
    {
-      visitor.visit(resource);
+      annotations.visit(resource);
+      interfaces.visit(resource);
    }
 }

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java	2010-06-15 16:05:43 UTC (rev 106057)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java	2010-06-15 16:28:24 UTC (rev 106058)
@@ -22,11 +22,6 @@
 
 package org.jboss.scanning.annotations.plugins;
 
-import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.scanning.annotations.spi.Element;
-import org.jboss.scanning.spi.ScanningHandle;
-import org.jboss.util.collection.CollectionsFactory;
-
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
@@ -38,41 +33,31 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.scanning.annotations.spi.Element;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.util.collection.CollectionsFactory;
+
 /**
  * DefaultAnnotationEnvironment.
  *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
 public class DefaultAnnotationRepository extends MutableAnnotationRepository implements Externalizable, ScanningHandle<DefaultAnnotationRepository>
 {
-   /**
-    * The serial version UID
-    */
+   /** The serial version UID */
    private static final long serialVersionUID = 1L;
-   /**
-    * The info map
-    */
+   /** The info map */
    private Map<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>> env;
-   /**
-    * The checked class names
-    */
+   /** The checked class names */
    private transient Set<String> checkedClassNames = new HashSet<String>();
-   /**
-    * Should we keep the annotation
-    */
+   /** Should we keep the annotation */
    private boolean keepAnnotations;
-   /**
-    * annotation index of implemented interfaces
-    */
+   /** Annotation index of implemented interfaces */
    private Map<String, Set<String>> classesImplementingInterfaceAnnotatedWith;
 
-
    /**
     * Should only be used for de-serialization.
     */
@@ -123,33 +108,19 @@
    void cleanup()
    {
       env.clear();
+      classesImplementingInterfaceAnnotatedWith.clear();
       checkedClassNames.clear();
    }
 
-   /**
-    * Index of classes that implement an interface that are annotated directly with an annotation:
-    * <p/>
-    * i.e.
-    * <p/>
-    * <pre>&#64;Path("/foo")
-    * public interface MyIntf {}
-    * <p/>
-    * public class MyResource implements MyIntf {}
-    * </pre>
-    * <p/>
-    * In this case MyResource is related to @Path through MyIntf
-    *
-    * @param annotation
-    * @return
-    */
    public Set<String> classesImplementingInterfacesAnnotatedWith(String annotation)
    {
       Set<String> classes = classesImplementingInterfaceAnnotatedWith.get(annotation);
-      if (classes == null) classes = Collections.emptySet();
+      if (classes == null)
+         return Collections.emptySet();
+      
       return classes;
    }
 
-   @Override
    public void addClassImplementingInterfaceAnnotatedWith(String annotationName, String className)
    {
       Set<String> classes = classesImplementingInterfaceAnnotatedWith.get(annotationName);
@@ -161,7 +132,6 @@
       classes.add(className);
    }
 
-
    /**
     * Get env map.
     *

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java	2010-06-15 16:05:43 UTC (rev 106057)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java	2010-06-15 16:28:24 UTC (rev 106058)
@@ -22,27 +22,24 @@
 
 package org.jboss.scanning.annotations.plugins;
 
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.net.URL;
+
 import org.jboss.classloading.spi.visitor.ClassFilter;
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.reflect.spi.AnnotationValue;
 import org.jboss.reflect.spi.ClassInfo;
 import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
 import org.jboss.scanning.plugins.visitor.ClassHierarchyResourceVisitor;
 import org.jboss.scanning.plugins.visitor.ReflectProvider;
 
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.net.URL;
-
 /**
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
 public class GenericAnnotationVisitor extends ClassHierarchyResourceVisitor
 {
-   /**
-    * The mutable repository
-    */
+   /** The mutable repository */
    private MutableAnnotationRepository repository;
 
    public GenericAnnotationVisitor(ReflectProvider provider, ResourceOwnerFinder finder, MutableAnnotationRepository repository)
@@ -64,23 +61,6 @@
    }
 
    @Override
-   protected void handleInterfaces(ClassInfo classInfo)
-   {
-      ClassInfo[] interfaces = classInfo.getInterfaces();
-      if (interfaces != null && interfaces.length > 0)
-      {
-         for (ClassInfo intf : interfaces)
-         {
-            for (AnnotationValue val : intf.getAnnotations())
-            {
-               repository.addClassImplementingInterfaceAnnotatedWith(val.getAnnotationType().getName(), classInfo.getName());
-            }
-         }
-      }
-
-   }
-
-   @Override
    protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className, URL ownerURL)
    {
       if (annotations != null && annotations.length > 0)

Copied: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/InterfacesAnnotationVisitor.java (from rev 106056, projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java)
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/InterfacesAnnotationVisitor.java	                        (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/InterfacesAnnotationVisitor.java	2010-06-15 16:28:24 UTC (rev 106058)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.scanning.annotations.plugins;
+
+import org.jboss.classloading.spi.visitor.ClassFilter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.reflect.spi.AnnotationValue;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.scanning.plugins.visitor.ReflectProvider;
+import org.jboss.scanning.plugins.visitor.ReflectResourceVisitor;
+
+/**
+ * Index classes implementing interfaces with certain annotations.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class InterfacesAnnotationVisitor extends ReflectResourceVisitor
+{
+   /** The mutable repository */
+   private MutableAnnotationRepository repository;
+
+   public InterfacesAnnotationVisitor(ReflectProvider provider, MutableAnnotationRepository repository)
+   {
+      super(provider);
+      if (repository == null)
+         throw new IllegalArgumentException("Null repository");
+      this.repository = repository;
+   }
+
+   public ResourceFilter getFilter()
+   {
+      return ClassFilter.INSTANCE;
+   }
+
+   @Override
+   protected void handleClass(ResourceContext resource, ClassInfo classInfo) throws Exception
+   {
+      ClassInfo[] interfaces = classInfo.getInterfaces();
+      if (interfaces != null && interfaces.length > 0)
+      {
+         String className = classInfo.getName();
+         for (ClassInfo intf : interfaces)
+         {
+            for (AnnotationValue val : intf.getAnnotations())
+            {
+               String annotation = val.getAnnotationType().getName();
+               repository.addClassImplementingInterfaceAnnotatedWith(annotation, className);
+            }
+         }
+      }
+   }
+}
\ No newline at end of file

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java	2010-06-15 16:05:43 UTC (rev 106057)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java	2010-06-15 16:28:24 UTC (rev 106058)
@@ -22,14 +22,14 @@
 
 package org.jboss.scanning.annotations.plugins;
 
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.net.URL;
+
 import org.jboss.metadata.spi.signature.Signature;
 import org.jboss.scanning.annotations.spi.AnnotationIndex;
 import org.jboss.scanning.plugins.helpers.WeakClassLoaderHolder;
 
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.net.URL;
-
 /**
  * Mutable annotation repository.
  *
@@ -71,5 +71,11 @@
     */
    abstract boolean isAlreadyChecked(String className);
 
-   public abstract void addClassImplementingInterfaceAnnotatedWith(String annotationName, String className);
+   /**
+    * Add class implementing interface annotated with annotation.
+    *
+    * @param annotation the annotation name
+    * @param className the class name
+    */
+   abstract void addClassImplementingInterfaceAnnotatedWith(String annotation, String className);
 }
\ No newline at end of file

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java	2010-06-15 16:05:43 UTC (rev 106057)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java	2010-06-15 16:28:24 UTC (rev 106058)
@@ -32,6 +32,7 @@
  * New index/repository -- per classpath entry.
  *
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  */
 public interface AnnotationIndex extends AnnotationRepository
 {

Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java	2010-06-15 16:05:43 UTC (rev 106057)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java	2010-06-15 16:28:24 UTC (rev 106058)
@@ -22,22 +22,17 @@
 
 package org.jboss.scanning.plugins.visitor;
 
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.net.URL;
+
 import org.jboss.classloading.spi.visitor.ResourceContext;
 import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
 import org.jboss.metadata.spi.signature.MethodParametersSignature;
 import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.reflect.spi.AnnotatedInfo;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.ConstructorInfo;
-import org.jboss.reflect.spi.MemberInfo;
-import org.jboss.reflect.spi.MethodInfo;
-import org.jboss.reflect.spi.ParameterInfo;
+import org.jboss.reflect.spi.*;
 import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
 
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.net.URL;
-
 /**
  * Class hierarchy resource visitor.
  *
@@ -65,11 +60,6 @@
     */
    protected abstract boolean isRelevant(ClassInfo classInfo);
 
-   protected void handleInterfaces(ClassInfo classInfo)
-   {
-
-   }
-
    protected void handleClass(ResourceContext resource, ClassInfo classInfo) throws Exception
    {
       if (classInfo == null || isRelevant(classInfo) == false)
@@ -81,8 +71,6 @@
 
       URL ownerURL = finder.findOwnerURL(resource);
 
-      handleInterfaces(classInfo);
-
       Annotation[] annotations = classInfo.getUnderlyingAnnotations();
       handleAnnotations(ElementType.TYPE, (Signature) null, annotations, className, ownerURL);
 



More information about the jboss-cvs-commits mailing list