[jboss-cvs] JBossAS SVN: r72891 - in projects/jboss-deployers/trunk: deployers-spi/src/main/org/jboss/deployers/spi/annotations and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 30 07:51:33 EDT 2008


Author: alesj
Date: 2008-04-30 07:51:33 -0400 (Wed, 30 Apr 2008)
New Revision: 72891

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ClassSignaturePair.java
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultElement.java
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/WeakClassLoaderHolder.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/Element.java
Modified:
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java
Log:
Better AnnotationEnv.
TODO on tests.

Added: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ClassSignaturePair.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ClassSignaturePair.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ClassSignaturePair.java	2008-04-30 11:51:33 UTC (rev 72891)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.deployers.plugins.annotations;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.util.JBossObject;
+
+/**
+ * Class name and signature pair.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ClassSignaturePair extends JBossObject
+{
+   private String className;
+   private Signature signature;
+
+   public ClassSignaturePair(String className, Signature signature)
+   {
+      if (className == null)
+         throw new IllegalArgumentException("Null class name");
+
+      this.className = className;
+      this.signature = signature;
+   }
+
+   public String getClassName()
+   {
+      return className;
+   }
+
+   public Signature getSignature()
+   {
+      return signature;
+   }
+
+   protected int getHashCode()
+   {
+      int hash = className.hashCode();
+      if (signature != null)
+         hash += 7 * signature.hashCode();
+      return hash;
+   }
+
+   public boolean equals(Object obj)
+   {
+      if (obj instanceof ClassSignaturePair == false)
+         return false;
+
+      ClassSignaturePair csPair = (ClassSignaturePair)obj;
+      if (className.equals(csPair.getClassName()))
+         return equals(signature, csPair.getSignature());
+      else
+         return false;
+   }
+}

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java	2008-04-30 11:46:40 UTC (rev 72890)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java	2008-04-30 11:51:33 UTC (rev 72891)
@@ -23,14 +23,19 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.annotation.ElementType;
-import java.lang.ref.WeakReference;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashMap;
-import java.util.Collections;
-import java.util.HashSet;
 
 import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.deployers.spi.annotations.Element;
+import org.jboss.metadata.spi.signature.Signature;
 import org.jboss.util.collection.CollectionsFactory;
 
 /**
@@ -38,18 +43,14 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class DefaultAnnotationEnvironment implements AnnotationEnvironment
+public class DefaultAnnotationEnvironment extends WeakClassLoaderHolder implements AnnotationEnvironment
 {
-   private WeakReference<ClassLoader> clRef;
-   private Map<Class<? extends Annotation>, Map<ElementType, Set<String>>> env;
+   private Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env;
 
    public DefaultAnnotationEnvironment(ClassLoader classLoader)
    {
-      if (classLoader == null)
-         throw new IllegalArgumentException("Null classloader");
-
-      this.clRef = new WeakReference<ClassLoader>(classLoader);
-      this.env = new HashMap<Class<? extends Annotation>, Map<ElementType, Set<String>>>();
+      super(classLoader);
+      this.env = new HashMap<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>();
    }
 
    /**
@@ -58,89 +59,120 @@
     * @param annClass the annotation class
     * @param type the annotation type
     * @param className the class name
+    * @param signature the signature
     */
-   void putAnnotation(Class<? extends Annotation> annClass, ElementType type, String className)
+   void putAnnotation(Class<? extends Annotation> annClass, ElementType type, String className, Signature signature)
    {
-      Map<ElementType, Set<String>> elements = env.get(annClass);
+      Map<ElementType, Set<ClassSignaturePair>> elements = env.get(annClass);
       if (elements == null)
       {
-         elements = new HashMap<ElementType, Set<String>>();
+         elements = new HashMap<ElementType, Set<ClassSignaturePair>>();
          env.put(annClass, elements);
       }
-      Set<String> classes = elements.get(type);
+      Set<ClassSignaturePair> classes = elements.get(type);
       if (classes == null)
       {
          classes = CollectionsFactory.createLazySet();
          elements.put(type, classes);
       }
-      classes.add(className);
+      classes.add(new ClassSignaturePair(className, signature));
    }
 
    /**
-    * Get matching class names.
+    * Get matching cs pairs.
     *
     * @param annClass the annotation class
     * @param type the annotation type
     * @return class names
     */
-   protected Set<String> getClassNames(Class<? extends Annotation> annClass, ElementType type)
+   protected Set<ClassSignaturePair> getCSPairs(Class<? extends Annotation> annClass, ElementType type)
    {
-      Set<String> classNames = null;
+      Set<ClassSignaturePair> pairs = null;
 
-      Map<ElementType, Set<String>> elements = env.get(annClass);
+      Map<ElementType, Set<ClassSignaturePair>> elements = env.get(annClass);
       if (elements != null)
-         classNames = elements.get(type);
+         pairs = elements.get(type);
 
-      return (classNames != null) ? classNames : Collections.<String>emptySet();
+      return (pairs != null) ? pairs : Collections.<ClassSignaturePair>emptySet();
    }
 
    /**
     * Transform class names into classes.
     *
-    * @param classNames the class names
+    * @param pairs the cs pairs
     * @return classes
     */
-   protected Set<Class<?>> transform(Set<String> classNames)
+   protected Set<Class<?>> transformToClasses(Set<ClassSignaturePair> pairs)
    {
-      ClassLoader classLoader = clRef.get();
-      if (classLoader == null)
-         throw new IllegalArgumentException("ClassLoader was already garbage collected.");
+      Set<Class<?>> classes = new HashSet<Class<?>>(pairs.size());
+      for (ClassSignaturePair pair : pairs)
+         classes.add(loadClass(pair.getClassName()));
+      return classes;
+   }
 
-      try
-      {
-         Set<Class<?>> classes = new HashSet<Class<?>>(classNames.size());
-         for (String className : classNames)
-            classes.add(classLoader.loadClass(className));
-         return classes;
-      }
-      catch (ClassNotFoundException e)
-      {
-         throw new RuntimeException(e);
-      }
+   /**
+    * Transform class names into classes.
+    *
+    * @param type the annotation type
+    * @param annClass the annotation class
+    * @param expectedAccessibleObjectClass the ao class
+    * @return classes
+    */
+   protected <A extends Annotation, M extends AccessibleObject> Set<Element<A, M>> transformToElements(
+         ElementType type,
+         Class<A> annClass,
+         Class<M> expectedAccessibleObjectClass
+   )
+   {
+      ClassLoader classLoader = getClassLoader();
+      Set<ClassSignaturePair> pairs = getCSPairs(annClass, type);
+      Set<Element<A, M>> elements = new HashSet<Element<A, M>>();
+      for (ClassSignaturePair pair : pairs)
+         elements.add(toElement(classLoader, pair, annClass, expectedAccessibleObjectClass));
+      return elements;
    }
 
+   /**
+    * Transform cs pair to element.
+    *
+    * @param classLoader the class loader
+    * @param pair the cs pair
+    * @param annClass the annotation class
+    * @param aoClass the ao class
+    * @return element
+    */
+   protected <A extends Annotation, M extends AccessibleObject> Element<A, M> toElement(
+         ClassLoader classLoader,
+         ClassSignaturePair pair,
+         Class<A> annClass,
+         Class<M> aoClass)
+   {
+      return null;
+   }
+
+
    public Set<Class<?>> classIsAnnotatedWith(Class<? extends Annotation> annotation)
    {
-      return transform(getClassNames(annotation, ElementType.TYPE));
+      return transformToClasses(getCSPairs(annotation, ElementType.TYPE));
    }
 
-   public Set<Class<?>> classHasConstructorAnnotatedWith(Class<? extends Annotation> annotation)
+   public <A extends Annotation> Set<Element<A, Constructor>> classHasConstructorAnnotatedWith(Class<A> annotation)
    {
-      return transform(getClassNames(annotation, ElementType.CONSTRUCTOR));
+      return transformToElements(ElementType.CONSTRUCTOR, annotation, Constructor.class);
    }
 
-   public Set<Class<?>> classHasFieldAnnotatedWith(Class<? extends Annotation> annotation)
+   public <A extends Annotation> Set<Element<A, Field>> classHasFieldAnnotatedWith(Class<A> annotation)
    {
-      return transform(getClassNames(annotation, ElementType.FIELD));
+      return transformToElements(ElementType.FIELD, annotation, Field.class);
    }
 
-   public Set<Class<?>> classHasMethodAnnotatedWith(Class<? extends Annotation> annotation)
+   public <A extends Annotation> Set<Element<A, Method>> classHasMethodAnnotatedWith(Class<A> annotation)
    {
-      return transform(getClassNames(annotation, ElementType.METHOD));
+      return transformToElements(ElementType.METHOD, annotation, Method.class);
    }
 
-   public Set<Class<?>> classHasParameterAnnotatedWith(Class<? extends Annotation> annotation)
+   public <A extends Annotation> Set<Element<A, AccessibleObject>> classHasParameterAnnotatedWith(Class<A> annotation)
    {
-      return transform(getClassNames(annotation, ElementType.PARAMETER)); 
+      return transformToElements(ElementType.CONSTRUCTOR, annotation, AccessibleObject.class);
    }
 }

Added: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultElement.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultElement.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultElement.java	2008-04-30 11:51:33 UTC (rev 72891)
@@ -0,0 +1,147 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.deployers.plugins.annotations;
+
+import java.lang.annotation.Annotation;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.AccessibleObject;
+
+import org.jboss.deployers.spi.annotations.Element;
+import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
+import org.jboss.metadata.spi.loader.MetaDataLoader;
+import org.jboss.metadata.spi.retrieval.AnnotationItem;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.reflect.plugins.introspection.ReflectionUtils;
+
+/**
+ * Default annoattions element.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultElement<A extends Annotation, M extends AccessibleObject> extends WeakClassLoaderHolder implements Element<A, M>
+{
+   private String className;
+   private Signature signature;
+   private Class<A> annClass;
+   private Class<M> aoClass;
+
+   private SoftReference<Class<?>> classRef;
+
+   public DefaultElement(ClassLoader classLoader, String className, Signature signature, Class<A> annClass, Class<M> aoClass)
+   {
+      super(classLoader);
+
+      if (className == null)
+         throw new IllegalArgumentException("Null className");
+      if (signature == null)
+         throw new IllegalArgumentException("Null signature");
+      if (annClass == null)
+         throw new IllegalArgumentException("Null annotation class");
+      if (aoClass == null)
+         throw new IllegalArgumentException("Null ao class");
+
+      this.className = className;
+      this.signature = signature;
+      this.annClass = annClass;
+      this.aoClass = aoClass;
+   }
+
+   public Class<?> getOwner()
+   {
+      if (classRef != null)
+      {
+         Class<?> clazz = classRef.get();
+         if (clazz != null)
+            return clazz;
+      }
+
+      Class<?> clazz = loadClass(className);
+      classRef = new SoftReference<Class<?>>(clazz);
+      return clazz;
+   }
+
+   /**
+    * Get meta data retireval for signature on owner.
+    *
+    * @return meta data retrieval
+    */
+   protected MetaDataRetrieval getMetaDataRetrieval()
+   {
+      MetaDataLoader loader = new AnnotatedElementMetaDataLoader(getOwner());
+      MetaDataRetrieval retrieval = loader.getComponentMetaDataRetrieval(signature);
+      if (retrieval == null)
+         throw new IllegalArgumentException("No such signature " + signature + " on loader: " + loader);
+
+      return retrieval;
+   }
+
+   public A getAnnotation()
+   {
+      AnnotationItem<A> item = getMetaDataRetrieval().retrieveAnnotation(annClass);
+      if (item == null)
+         throw new IllegalArgumentException("Expecting annotation: " + annClass);
+
+      return item.getAnnotation();
+   }
+
+   public M getAccessibleObject()
+   {
+      AccessibleObject result = null;
+
+      Class<?> clazz = getOwner();
+      if (signature instanceof ConstructorSignature)
+      {
+         try
+         {
+            result = clazz.getConstructor(signature.getParametersTypes(clazz));
+         }
+         catch (NoSuchMethodException ignored)
+         {
+         }
+      }
+      else if (signature instanceof MethodSignature)
+      {
+         try
+         {
+            result = clazz.getMethod(signature.getName(), signature.getParametersTypes(clazz));
+         }
+         catch (NoSuchMethodException ignored)
+         {
+         }
+      }
+      else if (signature instanceof FieldSignature)
+      {
+         result = ReflectionUtils.findField(clazz, signature.getName());
+      }
+
+      if (result == null)
+         throw new IllegalArgumentException("Expected accessible object " + className + "." + signature);
+      if (aoClass.isInstance(result) == false)
+         throw new IllegalArgumentException("Expected accessible object " + className + "." + signature + " of type " + aoClass);
+
+      return aoClass.cast(result);
+   }
+}

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java	2008-04-30 11:46:40 UTC (rev 72890)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java	2008-04-30 11:51:33 UTC (rev 72891)
@@ -25,16 +25,17 @@
 import java.lang.annotation.ElementType;
 
 import javassist.ClassPool;
+import javassist.CtBehavior;
 import javassist.CtClass;
 import javassist.CtMember;
 import javassist.NotFoundException;
-import javassist.CtBehavior;
 import org.jboss.classloading.spi.visitor.ClassFilter;
 import org.jboss.classloading.spi.visitor.ResourceContext;
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.classloading.spi.visitor.ResourceVisitor;
 import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
 import org.jboss.logging.Logger;
+import org.jboss.metadata.spi.signature.Signature;
 
 /**
  * Generic annotation scanner deployer.
@@ -115,7 +116,7 @@
    protected void handleCtClass(CtClass ctClass, ResourceContext resource) throws ClassNotFoundException, NotFoundException
    {
       Object[] annotations = forceAnnotations ? ctClass.getAnnotations() : ctClass.getAvailableAnnotations();
-      handleAnnotations(ElementType.TYPE, annotations, resource);
+      handleAnnotations(ElementType.TYPE, null, annotations, resource);
       handleCtMembers(ElementType.CONSTRUCTOR, ctClass.getDeclaredConstructors(), resource);
       handleCtMembers(ElementType.METHOD, ctClass.getDeclaredMethods(), resource);
       handleCtMembers(ElementType.FIELD, ctClass.getDeclaredFields(), resource);
@@ -149,13 +150,13 @@
          for (CtMember member : members)
          {
             Object[] annotations = forceAnnotations ? member.getAnnotations() : member.getAvailableAnnotations();
-            handleAnnotations(type, annotations, resource);
+            handleAnnotations(type, member, annotations, resource);
             if (member instanceof CtBehavior)
             {
                CtBehavior behavior = (CtBehavior)member;
                Object[][] paramAnnotations = forceAnnotations ? behavior.getParameterAnnotations() : behavior.getAvailableParameterAnnotations();
                for (Object[] paramAnn : paramAnnotations)
-                  handleAnnotations(ElementType.PARAMETER, paramAnn, resource);
+                  handleAnnotations(ElementType.PARAMETER, member, paramAnn, resource);
             }
          }
       }
@@ -165,17 +166,23 @@
     * Handle annotations.
     *
     * @param type where we found the annotations
+    * @param member the ct member
     * @param annotations the actual annotations
     * @param resource the resource we're visiting
     */
-   protected void handleAnnotations(ElementType type, Object[] annotations, ResourceContext resource)
+   protected void handleAnnotations(ElementType type, CtMember member, Object[] annotations, ResourceContext resource)
    {
       if (annotations != null && annotations.length > 0)
       {
          for (Object annObject : annotations)
          {
             Annotation annotation = Annotation.class.cast(annObject);
-            env.putAnnotation(annotation.annotationType(), type, resource.getClassName());
+            Signature signature = null;
+/*
+            if (member != null)
+               signature = JavassistSignatureFactory.getSignature(member);
+*/
+            env.putAnnotation(annotation.annotationType(), type, resource.getClassName(), signature);
          }
       }
    }

Added: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/WeakClassLoaderHolder.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/WeakClassLoaderHolder.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/WeakClassLoaderHolder.java	2008-04-30 11:51:33 UTC (rev 72891)
@@ -0,0 +1,74 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.deployers.plugins.annotations;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * ClassLoader holder helper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+abstract class WeakClassLoaderHolder
+{
+   private WeakReference<ClassLoader> clRef;
+
+   public WeakClassLoaderHolder(ClassLoader classLoader)
+   {
+      if (classLoader == null)
+         throw new IllegalArgumentException("Null classloader");
+
+      clRef = new WeakReference<ClassLoader>(classLoader);
+   }
+
+   /**
+    * Get the classloader from weak ref.
+    *
+    * @return the classloader
+    */
+   protected ClassLoader getClassLoader()
+   {
+      ClassLoader classLoader = clRef.get();
+      if (classLoader == null)
+         throw new IllegalArgumentException("ClassLoader was already garbage collected.");
+
+      return classLoader;
+   }
+
+   /**
+    * Load class from class name.
+    *
+    * @param className the class name
+    * @return loaded class
+    */
+   protected Class<?> loadClass(String className)
+   {
+      try
+      {
+         return getClassLoader().loadClass(className);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java	2008-04-30 11:46:40 UTC (rev 72890)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java	2008-04-30 11:51:33 UTC (rev 72891)
@@ -22,6 +22,10 @@
 package org.jboss.deployers.spi.annotations;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.Set;
 
 /**
@@ -45,7 +49,7 @@
     * @param annotation the annotation we're querying for
     * @return set of matching classes
     */
-   Set<Class<?>> classHasConstructorAnnotatedWith(Class<? extends Annotation> annotation);
+   <A extends Annotation> Set<Element<A, Constructor>> classHasConstructorAnnotatedWith(Class<A> annotation);
 
    /**
     * Get all classes who have some field annotated with annotation param.
@@ -53,7 +57,7 @@
     * @param annotation the annotation we're querying for
     * @return set of matching classes
     */
-   Set<Class<?>> classHasFieldAnnotatedWith(Class<? extends Annotation> annotation);
+   <A extends Annotation> Set<Element<A, Field>> classHasFieldAnnotatedWith(Class<A> annotation);
 
    /**
     * Get all classes who have some method annotated with annotation param.
@@ -61,7 +65,7 @@
     * @param annotation the annotation we're querying for
     * @return set of matching classes
     */
-   Set<Class<?>> classHasMethodAnnotatedWith(Class<? extends Annotation> annotation);      
+   <A extends Annotation> Set<Element<A, Method>> classHasMethodAnnotatedWith(Class<A> annotation);
 
    /**
     * Get all classes who have some method's/constructor's parameter annotated with annotation param.
@@ -69,5 +73,5 @@
     * @param annotation the annotation we're querying for
     * @return set of matching classes
     */
-   Set<Class<?>> classHasParameterAnnotatedWith(Class<? extends Annotation> annotation);
+   <A extends Annotation> Set<Element<A, AccessibleObject>> classHasParameterAnnotatedWith(Class<A> annotation);
 }

Copied: projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/Element.java (from rev 72864, projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/Element.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/Element.java	2008-04-30 11:51:33 UTC (rev 72891)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.deployers.spi.annotations;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+
+/**
+ * Annotation holder element.
+ *
+ * @param <A> exact annotation type
+ * @param <M> exact accessible object type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface Element<A extends Annotation, M extends AccessibleObject>
+{
+   /**
+    * Get the annotation owner class.
+    *
+    * @return the annotation owner class
+    */
+   Class<?> getOwner();
+
+   /**
+    * Get the annotation instance.
+    *
+    * @return the annotation instance
+    */
+   A getAnnotation();
+
+   /**
+    * Get the accessible object that holds the annotation.
+    *
+    * @return the accessible objetc instance
+    */
+   M getAccessibleObject();
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list