[jboss-cvs] JBossAS SVN: r70916 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/ejb3dependencies and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 17 14:23:25 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-03-17 14:23:24 -0400 (Mon, 17 Mar 2008)
New Revision: 70916

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationRepository.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/ejb3dependencies/TestAnnotationRepository.java
Log:
Revert AnnotationRepository to version 70740, since the modified method signatures break an overriding class in EJB3

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationRepository.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationRepository.java	2008-03-17 17:20:12 UTC (rev 70915)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationRepository.java	2008-03-17 18:23:24 UTC (rev 70916)
@@ -21,12 +21,14 @@
   */
 package org.jboss.aop.annotation;
 
-import java.lang.annotation.Annotation;
 import java.lang.reflect.Member;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.jboss.annotation.factory.AnnotationCreator;
@@ -36,28 +38,30 @@
 
 /**
  * Repository for annotations that is used by the ClassAdvisor to override annotations.
+ * Generics have not been added to this class since that causes problems with EJB3 who have a class overriding this one
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
 public class AnnotationRepository
 {
-//   private static final String CLASS_ANNOTATION = "CLASS";
+   private static final String CLASS_ANNOTATION = "CLASS";
    
    /** Read/Write lock to be used when lazy creating the collections */
    protected Object lazyCollectionLock = new Object();
 
-   volatile Map<Object, Map<String, Object>> annotations = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
-   volatile Map<String, Object> classAnnotations = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP; 
-   volatile Map<Member, List<String>> disabledAnnotations = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
-   volatile List<String> disabledClassAnnotations = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+   @SuppressWarnings("unchecked") volatile Map annotations = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
+   @SuppressWarnings("unchecked") volatile Map classAnnotations = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
+   @SuppressWarnings("unchecked") volatile Map disabledAnnotations = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
    
-   public Map<Object, Map<String, Object>> getAnnotations()
+   @SuppressWarnings("unchecked") 
+   public Map getAnnotations()
    {
 	   return annotations;
    }
    
-   public Map<String, Object> getClassAnnotations()
+   @SuppressWarnings("unchecked") 
+   public Map getClassAnnotations()
    {
 	   return classAnnotations;
    }
@@ -68,50 +72,41 @@
       classAnnotations.put(annotation, value);
    }
 
-   public void addClassAnnotation(Class<?> annotation, Object value)
+   @SuppressWarnings("unchecked")
+   public void addClassAnnotation(Class annotation, Object value)
    {
       initClassAnnotationsMap();
       classAnnotations.put(annotation.getName(), value);
    }
 
-   public Object resolveClassAnnotation(Class<? extends Annotation> annotation)
+   @SuppressWarnings("unchecked")
+   public Object resolveClassAnnotation(Class annotation)
    {
-      return resolveTypedClassAnnotation(annotation);
-   }
-   
-   public <T extends Annotation> T resolveTypedClassAnnotation(Class<T> annotation)
-   {
       Object value = classAnnotations.get(annotation.getName());
       boolean reinsert = value instanceof String;
-      T ann = extractAnnotation(value, annotation);
+      value = extractAnnotation(value, annotation);
       if (reinsert)
       {
-         classAnnotations.put(annotation.getName(), ann);
+         classAnnotations.put(annotation.getName(), value);
       }
-      return ann;
+      return value;
    }
 
-   /**
-    * Overridden by EJB3
-    */
-   public Object resolveAnnotation(Member m, Class<? extends Annotation> annotation)
+   @SuppressWarnings("unchecked")
+   public Object resolveAnnotation(Member m, Class annotation)
    {
-      return resolveTypedAnnotation(m, annotation);
-   }
-   
-   public <T extends Annotation> T resolveTypedAnnotation(Member m, Class<T> annotation)
-   {
       Object value = resolveAnnotation(m, annotation.getName());
       boolean reinsert = value instanceof String;
-      T ann = extractAnnotation(value, annotation);
+      value = extractAnnotation(value, annotation);
       if (reinsert)
       {
          addAnnotation(m, annotation, value);
       }
-      return ann;
+      return value;
    }
 
-   protected <T extends Annotation> T  extractAnnotation(Object value, Class<T> annotation)
+   @SuppressWarnings("unchecked")
+   protected Object extractAnnotation(Object value, Class annotation)
    {
       if (value == null) return null;
       if (value instanceof String)
@@ -119,19 +114,20 @@
          String expr = (String) value;
          try
          {
-            return (T)AnnotationCreator.createAnnotation(expr, annotation);
+            return AnnotationCreator.createAnnotation(expr, annotation);
          }
          catch (Exception e)
          {
             throw new RuntimeException("Bad annotation expression " + expr, e);
          }
       }
-      return (T)value;
+      return value;
    }
 
+   @SuppressWarnings("unchecked")
    protected Object resolveAnnotation(Member m, String annotation)
    {
-      Map<String, Object> map = annotations.get(m);
+      Map map = (Map) annotations.get(m);
       if (map != null)
       {
          return map.get(annotation);
@@ -139,27 +135,41 @@
       return null;
    }
    
+   @SuppressWarnings("unchecked")
    public void disableAnnotation(Member m, String annotation)
    {
-      List<String> annotationList = disabledAnnotations.get(m);
+      List annotationList = (List)disabledAnnotations.get(m);
       if (annotationList == null)
       {
-         annotationList = new ArrayList<String>();
+         annotationList = new ArrayList();
          initDisabledAnnotationsMap();
          disabledAnnotations.put(m,annotationList);
       }
       annotationList.add(annotation);
    }
    
+   @SuppressWarnings("unchecked")
    public void disableAnnotation(String annotation)
    {
-      initDisabledClassAnnotationsList();
-      disabledClassAnnotations.add(annotation);
+      List annotationList = (List)disabledAnnotations.get(CLASS_ANNOTATION);
+      if (annotationList == null)
+      {
+         annotationList = new ArrayList();
+         initDisabledAnnotationsMap();
+         disabledAnnotations.put(CLASS_ANNOTATION,annotationList);
+      }
+      annotationList.add(annotation);
    }
    
+   @SuppressWarnings("unchecked")
    public void enableAnnotation(String annotation)
    {
-      disabledClassAnnotations.remove(annotation);
+      List annotationList = (List)disabledAnnotations.get(CLASS_ANNOTATION);
+      if (annotationList != null)
+      {
+         annotationList.remove(annotation);
+      }
+      
    }
    
    @SuppressWarnings("unchecked")
@@ -167,75 +177,67 @@
    {
       return isDisabled(m,annotation.getName());
    }
-      
-   public boolean isTypedDisabled(Member m, Class<? extends Annotation> annotation)
-   {
-      return isDisabled(m,annotation.getName());
-   }
    
+   @SuppressWarnings("unchecked")
    public boolean isDisabled(Member m, String annotation)
    {
-      List<String> overrideList = disabledAnnotations.get(m);
-      if (overrideList != null && overrideList.size() > 0)
+      List overrideList = (List)disabledAnnotations.get(m);
+      if (overrideList != null)
       {
-         for (String override : overrideList)
+         Iterator overrides = overrideList.iterator();
+         while (overrides.hasNext())
          {
+            String override = (String)overrides.next();
             if (override.equals(annotation))
-            {
                return true;
-            }
          }
       }
       return false;
    }
    
-   /**
-    * Required by EJB3
-    */
    @SuppressWarnings("unchecked")
    public boolean isDisabled(Class annotation)
    {
-      return isTypedDisabled(annotation);
-   }
-   
-   public boolean isTypedDisabled(Class<? extends Annotation> annotation)
-   {
       return isDisabled(annotation.getName());
    }
    
+   @SuppressWarnings("unchecked")
    public boolean isDisabled(String annotation)
    {
-      if (disabledClassAnnotations.size() > 0)
+      List overrideList = (List)disabledAnnotations.get(CLASS_ANNOTATION);
+      if (overrideList != null)
       {
-         for (String ann : disabledClassAnnotations)
+         Iterator overrides = overrideList.iterator();
+         while (overrides.hasNext())
          {
-            if (ann.equals(annotation))
-            {
+            String override = (String)overrides.next();
+            if (override.equals(annotation))
                return true;
-            }
          }
       }
       return false;
    }
 
-   public void addAnnotation(Member m, Class<? extends Annotation> annotation, Object value)
+   @SuppressWarnings("unchecked")
+   public void addAnnotation(Member m, Class annotation, Object value)
    {
-      Map<String, Object> map = annotations.get(m);
+      Map map = (Map) annotations.get(m);
       if (map == null)
       {
-         map = new HashMap<String, Object>();
+         map = new HashMap();
          initAnnotationsMap();
          annotations.put(m, map);
       }
       map.put(annotation.getName(), value);
    }
 
+   @SuppressWarnings("unchecked")
    public void addAnnotation(Member m, String annotation, Object value)
    {
-      Map<String, Object> map = annotations.get(m);
+      Map map = (Map) annotations.get(m);
       if (map == null)
       {
-         map = new HashMap<String, Object>();
+         map = new HashMap();
          initAnnotationsMap();
          annotations.put(m, map);
       }
@@ -247,12 +249,14 @@
       return classAnnotations.containsKey(annotation);
    }
 
-   public boolean hasClassAnnotation(Class<? extends Annotation> annotation)
+   @SuppressWarnings("unchecked")
+   public boolean hasClassAnnotation(Class annotation)
    {
       return classAnnotations.containsKey(annotation.getName());
    }
 
-   public boolean hasAnnotation(Member m, Class<? extends Annotation> annotation)
+   @SuppressWarnings("unchecked")
+   public boolean hasAnnotation(Member m, Class annotation)
    {
       return resolveAnnotation(m, annotation.getName()) != null;
    }
@@ -262,25 +266,28 @@
       return resolveAnnotation(m, annotation) != null;
    }
 
+   @SuppressWarnings("unchecked")
    public boolean hasAnnotation(CtMember m, String annotation)
    {
-      Map<String, Object> map = annotations.get(m);
-      if (map != null) return map.containsKey(annotation);
+      Set set = (Set) annotations.get(m);
+      if (set != null) return set.contains(annotation);
       return false;
    }
 
+   @SuppressWarnings("unchecked")
    public void addAnnotation(CtMember m, String annotation)
    {
-      Map<String, Object> map = annotations.get(m);
-      if (map == null)
+      Set set = (Set) annotations.get(m);
+      if (set == null)
       {
-         map = new HashMap<String, Object>();
+         set = new HashSet();
          initAnnotationsMap();
-         annotations.put(m, map);
+         annotations.put(m, set);
       }
-      map.put(annotation, annotation);
+      set.add(annotation);
    }
 
+   @SuppressWarnings("unchecked")
    protected void initAnnotationsMap()
    {
       if (annotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
@@ -289,12 +296,13 @@
          {
             if (annotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
             {
-               annotations = new ConcurrentHashMap<Object, Map<String, Object>>();;
+               annotations = new ConcurrentHashMap();;
             }
          }
       }
    }
 
+   @SuppressWarnings("unchecked")
    protected void initClassAnnotationsMap()
    {
       if (classAnnotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
@@ -303,12 +311,13 @@
          {
             if (classAnnotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
             {
-               classAnnotations = new ConcurrentHashMap<String, Object>();;
+               classAnnotations = new ConcurrentHashMap();;
             }
          }
       }
    }
 
+   @SuppressWarnings("unchecked")
    protected void initDisabledAnnotationsMap()
    {
       if (disabledAnnotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
@@ -317,23 +326,9 @@
          {
             if (disabledAnnotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
             {
-               disabledAnnotations = new ConcurrentHashMap<Member, List<String>>();;
+               disabledAnnotations = new ConcurrentHashMap();;
             }
          }
       }
    }
-
-   protected void initDisabledClassAnnotationsList()
-   {
-      if (disabledClassAnnotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
-      {
-         synchronized(lazyCollectionLock)
-         {
-            if (disabledClassAnnotations == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
-            {
-               disabledClassAnnotations = new ArrayList<String>();;
-            }
-         }
-      }
-   }
 }

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/ejb3dependencies/TestAnnotationRepository.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/ejb3dependencies/TestAnnotationRepository.java	2008-03-17 17:20:12 UTC (rev 70915)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/ejb3dependencies/TestAnnotationRepository.java	2008-03-17 18:23:24 UTC (rev 70916)
@@ -21,7 +21,6 @@
 */ 
 package org.jboss.test.aop.ejb3dependencies;
 
-import java.lang.annotation.Annotation;
 import java.lang.reflect.Member;
 
 import org.jboss.aop.annotation.AnnotationRepository;
@@ -33,8 +32,7 @@
 public class TestAnnotationRepository extends AnnotationRepository
 {
 
-   @Override
-   public Object resolveClassAnnotation(Class<? extends Annotation> annotation)
+   public Object resolveClassAnnotation(Class annotation)
    {
       return new AnnImpl("Clazz");
    }




More information about the jboss-cvs-commits mailing list