[jboss-cvs] JBossAS SVN: r67468 - in projects/aop/trunk/aop/src: resources/test/annotationoverride and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 26 19:23:00 EST 2007


Author: kabir.khan at jboss.com
Date: 2007-11-26 19:23:00 -0500 (Mon, 26 Nov 2007)
New Revision: 67468

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherAnnotation.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMD.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMDImpl.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeAnnotation.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMD.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMDImpl.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/SecurityActions.java
   projects/aop/trunk/aop/src/resources/test/annotationoverride/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/AnnotationOverrideTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/Woven.java
Log:
[JBAOP-490] Advisor.resolveAnnotation() and hasAnnotation() should check the MetaData in all cases

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2007-11-27 00:14:15 UTC (rev 67467)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -74,6 +74,8 @@
 import org.jboss.aop.pointcut.PointcutMethodMatch;
 import org.jboss.aop.util.UnmodifiableEmptyCollections;
 import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
 import org.jboss.metadata.spi.signature.MethodSignature;
 import org.jboss.util.NestedRuntimeException;
 import org.jboss.util.NotImplementedException;
@@ -343,8 +345,6 @@
       if (metadata != null)
       {
          Object value = metadata.getAnnotation(annotation);
-         // FIXME The metadata should already include the class annotations
-         //       so we should just return this result
          if (value != null) return value;
       }
 
@@ -353,7 +353,10 @@
 
       Object value = annotations.resolveClassAnnotation(annotation);
       if (clazz == null) return null;
-      if (value == null) value = AnnotationElement.getVisibleAnnotation(clazz, annotation);
+      if (value == null && metadata == null)
+      {
+         value = AnnotationElement.getVisibleAnnotation(clazz, annotation);
+      }
       return value;
    }
 
@@ -385,12 +388,14 @@
          {
             if (annotationClass == null)
             {
-               // FIXME ClassLoader - this should use "tgt.getClassLoader()"
-               annotationClass = SecurityActions.getContextClassLoader().loadClass(annotation);
+               ClassLoader cl = SecurityActions.getClassLoader(tgt);
+               if (cl == null)
+               {
+                  cl = SecurityActions.getContextClassLoader();
+               }
+               annotationClass = cl.loadClass(annotation);
             }
-            // FIXME The metadata should already include the class annotations
-            //       so we should just return this result
-            if (metadata.isAnnotationPresent(annotationClass)) return true;
+            if (annotationClass != null && metadata.isAnnotationPresent(annotationClass)) return true;
          }
       }
       catch (ClassNotFoundException e)
@@ -407,12 +412,16 @@
       if (tgt == null) return false;
       try
       {
-         return AnnotationElement.isAnyAnnotationPresent(tgt, annotation);
+         if (metadata == null)
+         {
+            return AnnotationElement.isAnyAnnotationPresent(tgt, annotation);
+         }
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
       }
+      return false;
    }
 
    public Object resolveAnnotation(Method m, Class annotation)
@@ -428,8 +437,6 @@
          MetaData methodMD = metadata.getComponentMetaData(signature);
          if (methodMD != null)
          {
-            // FIXME The metadata should already include the class annotations
-            //       so we should just return this result
             Object val = methodMD.getAnnotation(annotation);
             if (val != null) return val;
          }
@@ -439,36 +446,64 @@
          return null;
 
       Object value = annotations.resolveAnnotation(m, annotation);
-      if (value == null) value = AnnotationElement.getVisibleAnnotation(m, annotation);
+      if (value == null && metadata == null) 
+      {
+         value = AnnotationElement.getVisibleAnnotation(m, annotation);
+      }
       return value;
    }
 
    public Object resolveAnnotation(Method m, Class[] annotationChoices)
    {
-      Object value = null;
-      int i = 0;
-      while (value == null && i < annotationChoices.length){
-         value = annotations.resolveAnnotation(m, annotationChoices[i++]);
+      for (Class ann : annotationChoices)
+      {
+         Object val = resolveAnnotation(m, annotationChoices);
+         if (val != null) return val;
       }
-
-      i = 0;
-      while (value == null && i < annotationChoices.length){
-         value = AnnotationElement.getVisibleAnnotation(m, annotationChoices[i++]);
-      }
-      return value;
+      return null;
    }
 
    public Object resolveAnnotation(Field f, Class annotation)
    {
-      Object value = annotations.resolveAnnotation(f, annotation);
-      if (value == null) value = AnnotationElement.getVisibleAnnotation(f, annotation);
+      Object value = null;
+      if (metadata != null)
+      {
+         FieldSignature signature = new FieldSignature(f);
+         MetaData fieldMD = metadata.getComponentMetaData(signature);
+         if (fieldMD != null)
+         {
+            value = fieldMD.getAnnotation(annotation);
+            if (value != null) return value;
+         }
+      }
+      
+      value = annotations.resolveAnnotation(f, annotation);
+      if (value == null && metadata == null)
+      {
+         value = AnnotationElement.getVisibleAnnotation(f, annotation);
+      }
       return value;
    }
 
    public Object resolveAnnotation(Constructor c, Class annotation)
    {
-      Object value = annotations.resolveAnnotation(c, annotation);
-      if (value == null) value = AnnotationElement.getVisibleAnnotation(c, annotation);
+      Object value = null;
+      if (metadata != null)
+      {
+         ConstructorSignature signature = new ConstructorSignature(c);
+         MetaData conMD = metadata.getComponentMetaData(signature);
+         if (conMD != null)
+         {
+            value = conMD.getAnnotation(annotation);
+            if (value != null) return value;
+         }
+      }
+      
+      value = annotations.resolveAnnotation(c, annotation);
+      if (value == null && metadata == null)
+      {
+         value = AnnotationElement.getVisibleAnnotation(c, annotation);
+      }
       return value;
    }
 
@@ -489,77 +524,118 @@
          throw new RuntimeException("annotation or annotationClass must be passed in");
       }
 
-      try
+      if (annotation == null)
       {
-         if (metadata != null)
+         annotation = annotationClass.getName();
+      }
+      if (metadata != null)
+      {
+         if (hasJoinPointAnnotationFromStringName(m.getDeclaringClass(), new MethodSignature(m), annotation))
          {
-            if (annotationClass == null)
-            {
-               // FIXME ClassLoader - this should use "m.getClass().getClassLoader()"
-               annotationClass = SecurityActions.getContextClassLoader().loadClass(annotation);
-            }
-            // FIXME The metadata should already include the class annotations
-            //       so we should just return this result
-            MethodSignature signature = new MethodSignature(m.getName(), m.getParameterTypes());
-            MetaData methodMD = metadata.getComponentMetaData(signature);
-            if (methodMD != null)
-            {
-               if (methodMD.isAnnotationPresent(annotationClass))
-                  return true;
-            }
+            return true;
          }
       }
-      catch (ClassNotFoundException e)
+
+      if (annotations.hasAnnotation(m, annotation)) return true;
+      try
       {
-         //The "annotation" is probably aop metadata for which there will be no corresponding class
+         if (metadata == null)
+         {
+            return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         }
       }
-      catch(Exception e)
+      catch (Exception e)
       {
-         throw new RuntimeException(e);
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
       }
+      return false;
+   }
 
-      if (annotation == null)
+   public boolean hasAnnotation(Field m, String annotation)
+   {
+      if (metadata != null)
       {
-         annotation = annotationClass.getName();
+         if (hasJoinPointAnnotationFromStringName(m.getDeclaringClass(), new FieldSignature(m), annotation))
+         {
+            return true;
+         }
       }
-
       if (annotations.hasAnnotation(m, annotation)) return true;
       try
       {
-         return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         if (metadata == null)
+         {
+            return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         }
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
       }
+      return false;
    }
 
-   public boolean hasAnnotation(Field m, String annotation)
+   public boolean hasAnnotation(Constructor<?> m, String annotation)
    {
+      if (metadata != null)
+      {
+         if (hasJoinPointAnnotationFromStringName(m.getDeclaringClass(), new ConstructorSignature(m), annotation))
+         {
+            return true;
+         }
+      }
       if (annotations.hasAnnotation(m, annotation)) return true;
       try
       {
-         return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         if (metadata == null)
+         {
+            return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         }
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
       }
+      return false;
    }
 
-   public boolean hasAnnotation(Constructor m, String annotation)
+   private boolean hasJoinPointAnnotationFromStringName(Class declaringClass, org.jboss.metadata.spi.signature.Signature sig, String annotationName)
    {
-      if (annotations.hasAnnotation(m, annotation)) return true;
       try
       {
-         return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         if (metadata != null)
+         {
+            ClassLoader cl = SecurityActions.getClassLoader(declaringClass);
+            if (cl == null)
+            {
+               cl = SecurityActions.getContextClassLoader();
+            }
+            if (cl != null)
+            {
+               Class annotationClass = cl.loadClass(annotationName);
+               if (annotationClass != null)
+               {
+                  MetaData md = metadata.getComponentMetaData(sig);
+                  if (md != null)
+                  {
+                     if (md.isAnnotationPresent(annotationClass))
+                        return true;
+                  }
+               }
+            }
+         }
       }
-      catch (Exception e)
+      catch (ClassNotFoundException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         //The "annotation" is probably aop metadata for which there will be no corresponding class
       }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+      return false;
    }
-
+   
    public boolean hasAnnotation(CtClass clazz, String annotation)
    {
       if (annotations.hasClassAnnotation(annotation)) return true;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/SecurityActions.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/SecurityActions.java	2007-11-27 00:14:15 UTC (rev 67467)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/SecurityActions.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -184,4 +184,41 @@
          return GetDeclaredConstructorsAction.PRIVILEGED.getDeclaredConstructors(clazz);
       }
    }
+
+   
+   interface GetClassLoaderAction 
+   {
+      ClassLoader getClassLoader(Class clazz);
+      
+      GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(Class clazz)
+         {
+            return clazz.getClassLoader();
+         }};
+
+     GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(final Class clazz)
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+               public ClassLoader run()
+               {
+                  return clazz.getClassLoader();
+               }});
+         }};
+   }
+   
+   static ClassLoader getClassLoader(Class clazz)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+      }
+      else
+      {
+         return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+      }
+   }
 }

Modified: projects/aop/trunk/aop/src/resources/test/annotationoverride/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/annotationoverride/jboss-aop.xml	2007-11-27 00:14:15 UTC (rev 67467)
+++ projects/aop/trunk/aop/src/resources/test/annotationoverride/jboss-aop.xml	2007-11-27 00:23:00 UTC (rev 67468)
@@ -14,6 +14,7 @@
 		@org.jboss.test.aop.annotationoverride.Other(value="field")
 	</annotation>
 
+
 	<annotation expr="class(org.jboss.test.aop.annotationoverride.Proxied)">
 		@org.jboss.test.aop.annotationoverride.Some
 	</annotation>

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/AnnotationOverrideTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/AnnotationOverrideTestCase.java	2007-11-27 00:14:15 UTC (rev 67467)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/AnnotationOverrideTestCase.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -21,6 +21,7 @@
 */ 
 package org.jboss.test.aop.annotationoverride;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -32,6 +33,17 @@
 import org.jboss.aop.Advisor;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.ClassContainer;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeKey;
+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.test.aop.AOPTestWithSetup;
 
 /**
@@ -54,57 +66,231 @@
       return suite;
    }
 
-   public void testWovenClass() throws Exception
+   public void testWovenClassNoMetaData() throws Exception
    {
+      runTests(false);
+   }
+   
+   public void testWovenClassWithMetaData() throws Exception
+   {
+      runTests(true);
+   }
+   
+   public void testClassContainerProxiedClass() throws Exception
+   {
+      ClassContainer container = new ClassContainer("test", AspectManager.instance());
+      container.setClass(Proxied.class);
+      container.initializeClassContainer();
+      
+      Some some = (Some)container.resolveAnnotation(Some.class);
+      assertNotNull(some);
+      Other other = (Other)container.resolveAnnotation(Other.class);
+      assertNull(other);
+      
+      Method m = Proxied.class.getDeclaredMethod("method");
+      some = (Some)container.resolveAnnotation(m, Some.class);
+      assertNull(some);
+      other = (Other)container.resolveAnnotation(m, Other.class);
+      assertNotNull(other);
+      assertEquals("method", other.value());
+   }
+
+   private void runTests(boolean useMetaData) throws Exception
+   {
       Woven woven = new Woven();
       Advisor advisor = ((Advised)woven)._getAdvisor();
+
+      Method m = Woven.class.getDeclaredMethod("method"); 
+      Field f = Woven.class.getDeclaredField("field");
+      Constructor<Woven> c = Woven.class.getDeclaredConstructor();
+
+      if (useMetaData)
+      {
+         Annotation[] classAnnotations = new Annotation[] {new SomeMDImpl()};
+         Annotation[] ctorAnnotations = new Annotation[] {new OtherMDImpl("ctor")}; 
+         Annotation[] methodAnnotations = new Annotation[] {new OtherMDImpl("method")};
+         Annotation[] fieldAnnotations = new Annotation[] {new OtherMDImpl("field")};
+         setupMetaData(advisor, c, m, f, classAnnotations, ctorAnnotations, methodAnnotations, fieldAnnotations);
+      }
       
       Some some = (Some)advisor.resolveAnnotation(Some.class);
       assertNotNull(some);
       Other other = (Other)advisor.resolveAnnotation(Other.class);
       assertNull(other);
       
-      Method m = Woven.class.getDeclaredMethod("method");
+      SomeAnnotation someAnn = (SomeAnnotation)advisor.resolveAnnotation(SomeAnnotation.class);
+      assertNotNull(someAnn);
+      OtherAnnotation otherAnn = (OtherAnnotation)advisor.resolveAnnotation(OtherAnnotation.class);
+      assertNull(otherAnn);
+      
+      if (useMetaData)
+      {
+         SomeMD someMD = (SomeMD)advisor.resolveAnnotation(SomeMD.class);
+         assertNotNull(someMD);
+         OtherMD otherMD = (OtherMD)advisor.resolveAnnotation(OtherMD.class);
+         assertNull(otherMD);
+      }
+      
       some = (Some)advisor.resolveAnnotation(m, Some.class);
       assertNull(some);
       other = (Other)advisor.resolveAnnotation(m, Other.class);
       assertNotNull(other);
       assertEquals("method", other.value());
       
-      Field f = Woven.class.getDeclaredField("field");
+      someAnn = (SomeAnnotation)advisor.resolveAnnotation(m, SomeAnnotation.class);
+      assertNull(some);
+      otherAnn = (OtherAnnotation)advisor.resolveAnnotation(m, OtherAnnotation.class);
+      assertNotNull(otherAnn);
+      assertEquals("method", otherAnn.value());
+      
+      if (useMetaData)
+      {
+         SomeMD someMD = (SomeMD)advisor.resolveAnnotation(m, SomeMD.class);
+         assertNull(someMD);
+         OtherMD otherMD = (OtherMD)advisor.resolveAnnotation(m, OtherMD.class);
+         assertNotNull(otherMD);
+         assertEquals("method", otherMD.value());
+      }
+      
       some = (Some)advisor.resolveAnnotation(f, Some.class);
       assertNull(some);
       other = (Other)advisor.resolveAnnotation(f, Other.class);
       assertNotNull(other);
       assertEquals("field", other.value());
       
-      Constructor<Woven> c = Woven.class.getDeclaredConstructor();
+      someAnn = (SomeAnnotation)advisor.resolveAnnotation(f, SomeAnnotation.class);
+      assertNull(some);
+      otherAnn = (OtherAnnotation)advisor.resolveAnnotation(f, OtherAnnotation.class);
+      assertNotNull(other);
+      assertEquals("field", other.value());
+      
+      if (useMetaData)
+      {
+         SomeMD someMD = (SomeMD)advisor.resolveAnnotation(f, SomeMD.class);
+         assertNull(someMD);
+         OtherMD otherMD = (OtherMD)advisor.resolveAnnotation(f, OtherMD.class);
+         assertNotNull(otherMD);
+         assertEquals("field", otherMD.value());
+      }
+      
       some = (Some)advisor.resolveAnnotation(c, Some.class);
       assertNull(some);
       other = (Other)advisor.resolveAnnotation(c, Other.class);
       assertNotNull(other);
       assertEquals("ctor", other.value());
+
+      someAnn = (SomeAnnotation)advisor.resolveAnnotation(c, SomeAnnotation.class);
+      assertNull(some);
+      otherAnn = (OtherAnnotation)advisor.resolveAnnotation(c, OtherAnnotation.class);
+      assertNotNull(other);
+      assertEquals("ctor", other.value());
+      
+      if (useMetaData)
+      {
+         SomeMD someMD = (SomeMD)advisor.resolveAnnotation(c, SomeMD.class);
+         assertNull(someMD);
+         OtherMD otherMD = (OtherMD)advisor.resolveAnnotation(c, OtherMD.class);
+         assertNotNull(otherMD);
+         assertEquals("ctor", otherMD.value());
+      }
+      
+      assertTrue(advisor.hasAnnotation(SomeAnnotation.class.getName()));
+      assertTrue(advisor.hasAnnotation(Woven.class, SomeAnnotation.class.getName()));
+      assertTrue(advisor.hasAnnotation(Woven.class, SomeAnnotation.class));
+      
+      assertTrue(advisor.hasAnnotation(Some.class.getName()));
+      assertTrue(advisor.hasAnnotation(Woven.class, Some.class.getName()));
+      assertTrue(advisor.hasAnnotation(Woven.class, Some.class));
+      
+      assertFalse(advisor.hasAnnotation(Other.class.getName()));
+      assertFalse(advisor.hasAnnotation(Woven.class, Other.class.getName()));
+      assertFalse(advisor.hasAnnotation(Woven.class, Other.class));
+      
+      assertTrue(advisor.hasAnnotation(c, Other.class.getName()));
+      assertFalse(advisor.hasAnnotation(c, Some.class.getName()));
+      assertFalse(advisor.hasAnnotation(c, SomeAnnotation.class.getName()));
+      
+      assertTrue(advisor.hasAnnotation(f, Other.class.getName()));
+      assertFalse(advisor.hasAnnotation(f, Some.class.getName()));
+      assertFalse(advisor.hasAnnotation(f, SomeAnnotation.class.getName()));
+      
+      assertTrue(advisor.hasAnnotation(m, Other.class.getName()));
+      assertTrue(advisor.hasAnnotation(m, Other.class));
+      assertFalse(advisor.hasAnnotation(m, Some.class.getName()));
+      assertFalse(advisor.hasAnnotation(m, Some.class));
+      assertFalse(advisor.hasAnnotation(m, SomeAnnotation.class.getName()));
+      assertFalse(advisor.hasAnnotation(m, SomeAnnotation.class));
    }
    
-   public void testClassContainerProxiedClass() throws Exception
+   private void setupMetaData(Advisor advisor, 
+         Constructor<?> c, 
+         Method m, 
+         Field f, 
+         Annotation[] classAnnotations,
+         Annotation[] ctorAnnotations, 
+         Annotation[] methodAnnotations, 
+         Annotation[] fieldAnnotations)
    {
-      ClassContainer container = new ClassContainer("test", AspectManager.instance());
-      container.setClass(Proxied.class);
-      container.initializeClassContainer();
+      MutableMetaDataRepository repository = new BasicMetaDataRepository();
       
-      Some some = (Some)container.resolveAnnotation(Some.class);
-      assertNotNull(some);
-      Other other = (Other)container.resolveAnnotation(Other.class);
-      assertNull(other);
+      ScopeKey scopeKey = ScopeKey.DEFAULT_SCOPE.clone();
+      scopeKey.addScope(CommonLevels.INSTANCE, "Test");
+      scopeKey.addScope(CommonLevels.CLASS, advisor.getClazz().getName());
+      scopeKey.addScope(CommonLevels.WORK, String.valueOf(hashCode()));
+      ScopeKey key = scopeKey;
+      ScopeKey mutableScope = new ScopeKey(CommonLevels.INSTANCE, "Test".toString());
+      MemoryMetaDataLoader mutable = new MemoryMetaDataLoader(mutableScope);
+      repository.addMetaDataRetrieval(mutable);
+      addClassAnnotations(advisor.getClazz(), mutable, classAnnotations);
+      addMethodAnnotations(m, mutable, methodAnnotations);
+      addFieldAnnotations(f, mutable, fieldAnnotations);
+      addConstructorAnnotations(c, mutable, ctorAnnotations);
       
-      Method m = Proxied.class.getDeclaredMethod("method");
-      some = (Some)container.resolveAnnotation(m, Some.class);
-      assertNull(some);
-      other = (Other)container.resolveAnnotation(m, Other.class);
-      assertNotNull(other);
-      assertEquals("method", other.value());
+      MetaData metadata = new MetaDataRetrievalToMetaDataBridge(mutable); 
       
-      
+      advisor.setMetadata(metadata);
    }
-
+   
+   private void addClassAnnotations(Class<?> clazz, MemoryMetaDataLoader mutable, Annotation[] extraAnnotations)
+   {
+      Annotation[] anns = clazz.getAnnotations();
+      for (Annotation ann : anns)
+      {
+         mutable.addAnnotation(ann);
+      }
+      for (Annotation ann : extraAnnotations)
+      {
+         mutable.addAnnotation(ann);
+      }
+   }
+   
+   private void addMethodAnnotations(Method m, MemoryMetaDataLoader mutable, Annotation[] extraAnnotations)
+   {
+      addJoinpointAnnotations(mutable, new MethodSignature(m), m.getName(), m.getAnnotations(), extraAnnotations);
+   }
+   
+   private void addFieldAnnotations(Field f, MemoryMetaDataLoader mutable, Annotation[] extraAnnotations)
+   {
+      addJoinpointAnnotations(mutable, new FieldSignature(f), f.getName(), f.getAnnotations(), extraAnnotations);
+   }
+   
+   private void addConstructorAnnotations(Constructor<?> c, MemoryMetaDataLoader mutable, Annotation[] extraAnnotations)
+   {
+      addJoinpointAnnotations(mutable, new ConstructorSignature(c), c.getName(), c.getAnnotations(), extraAnnotations);
+   }
+   
+   private void addJoinpointAnnotations(MemoryMetaDataLoader mutable, Signature sig, String name, Annotation[] annotations, Annotation[] extraAnnotations)
+   {
+      ScopeKey scope = new ScopeKey(CommonLevels.JOINPOINT_OVERRIDE, name);
+      MemoryMetaDataLoader loader = new MemoryMetaDataLoader(scope);
+      for (Annotation ann : annotations)
+      {
+         loader.addAnnotation(ann);
+      }
+      for (Annotation ann : extraAnnotations)
+      {
+         loader.addAnnotation(ann);
+      }
+      mutable.addComponentMetaDataRetrieval(sig, loader);
+   }
 }

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherAnnotation.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherAnnotation.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherAnnotation.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.aop.annotationoverride;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME) @Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD})
+public @interface OtherAnnotation
+{
+   String value();
+}
+ 
\ No newline at end of file

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMD.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMD.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMD.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.aop.annotationoverride;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public @interface OtherMD 
+{
+   String value();
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMDImpl.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMDImpl.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/OtherMDImpl.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.aop.annotationoverride;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class OtherMDImpl implements OtherMD
+{
+   String value;
+   
+   public OtherMDImpl(String value)
+   {
+      this.value = value;
+   }
+   
+   public String value()
+   {
+      return value;
+   }
+
+   public Class<? extends Annotation> annotationType()
+   {
+      return OtherMD.class;
+   }
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeAnnotation.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeAnnotation.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeAnnotation.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.aop.annotationoverride;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE)
+public @interface SomeAnnotation 
+{
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMD.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMD.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMD.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -0,0 +1,31 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.aop.annotationoverride;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public @interface SomeMD {
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMDImpl.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMDImpl.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/SomeMDImpl.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.aop.annotationoverride;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SomeMDImpl implements SomeMD
+{
+   public Class<? extends Annotation> annotationType()
+   {
+      return SomeMD.class;
+   }
+
+}

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/Woven.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/Woven.java	2007-11-27 00:14:15 UTC (rev 67467)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationoverride/Woven.java	2007-11-27 00:23:00 UTC (rev 67468)
@@ -26,8 +26,15 @@
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public class Woven
+ at SomeAnnotation
+public class Woven 
 {  
+   @OtherAnnotation("ctor")
+   Woven(){}
+   
+   @OtherAnnotation("field")
    int field;
+   
+   @OtherAnnotation("method") 
    void method() {}
 }




More information about the jboss-cvs-commits mailing list