[jboss-cvs] JBossAS SVN: r68937 - projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 14 04:46:03 EST 2008


Author: wolfc
Date: 2008-01-14 04:46:03 -0500 (Mon, 14 Jan 2008)
New Revision: 68937

Modified:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ManagedObjectAdvisor.java
Log:
Allow for different annotation repository

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java	2008-01-14 09:44:50 UTC (rev 68936)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java	2008-01-14 09:46:03 UTC (rev 68937)
@@ -26,11 +26,11 @@
 
 import org.jboss.aop.Advisor;
 import org.jboss.aop.AspectManager;
-import org.jboss.aop.ClassAdvisor;
 import org.jboss.aop.Domain;
 import org.jboss.aop.DomainDefinition;
 import org.jboss.aop.MethodInfo;
 import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.annotation.AnnotationRepository;
 import org.jboss.aop.joinpoint.ConstructionInvocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.aop.util.MethodHashing;
@@ -114,6 +114,11 @@
     */
    protected void initializeAdvisor(String name, Domain domain, Class<? extends T> beanClass)
    {
+      initializeAdvisor(name, domain, beanClass, null);
+   }
+   
+   protected void initializeAdvisor(String name, Domain domain, Class<? extends T> beanClass, AnnotationRepository annotations)
+   {
       if(this.advisor != null) throw new IllegalStateException("advisor already set to " + advisor);
       
       assert name != null : "name is null";
@@ -122,12 +127,12 @@
       
       // Decouple setting the advisor and initializing it, so interceptors
       // can get it.
-      this.advisor = new ManagedObjectAdvisor<T, C>((C) this, name, domain);
+      this.advisor = new ManagedObjectAdvisor<T, C>((C) this, name, domain, annotations);
       advisor.getAnnotations().addClassAnnotation(InterceptorFactoryRef.class, new InterceptorFactoryRefImpl(ContainerInterceptorFactory.class));
       advisor.initialize(beanClass);
    }
    
-   protected final ClassAdvisor getAdvisor()
+   protected final ManagedObjectAdvisor<T, C> getAdvisor()
    {
       if(advisor == null) throw new IllegalStateException("advisor has not been initialized");
       return advisor;
@@ -148,7 +153,7 @@
    /*
     * TODO: this should not be here, it's an AspectManager helper function.
     */
-   private static final Domain getDomain(String domainName)
+   protected static final Domain getDomain(String domainName)
    {
       DomainDefinition domainDefinition = AspectManager.instance().getContainer(domainName);
       if(domainDefinition == null)

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ManagedObjectAdvisor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ManagedObjectAdvisor.java	2008-01-14 09:44:50 UTC (rev 68936)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ManagedObjectAdvisor.java	2008-01-14 09:46:03 UTC (rev 68937)
@@ -21,6 +21,9 @@
  */
 package org.jboss.ejb3.interceptors.container;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Member;
 import java.util.List;
 
 import org.jboss.aop.AspectManager;
@@ -30,10 +33,13 @@
 import org.jboss.aop.InstanceAdvisorDelegate;
 import org.jboss.aop.advice.AspectDefinition;
 import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.annotation.AnnotationRepository;
 import org.jboss.aop.introduction.AnnotationIntroduction;
 import org.jboss.aop.joinpoint.Joinpoint;
 import org.jboss.aop.metadata.SimpleMetaData;
 import org.jboss.ejb3.interceptors.ManagedObject;
+import org.jboss.ejb3.interceptors.aop.ExtendedAdvisor;
+import org.jboss.ejb3.metadata.annotation.ExtendedAnnotationRepository;
 import org.jboss.logging.Logger;
 
 /**
@@ -42,7 +48,7 @@
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
-public class ManagedObjectAdvisor<T, C extends AbstractContainer<T, C>> extends ClassAdvisor implements InstanceAdvisor
+public class ManagedObjectAdvisor<T, C extends AbstractContainer<T, C>> extends ClassAdvisor implements ExtendedAdvisor, InstanceAdvisor
 {
    private static final Logger log = Logger.getLogger(ManagedObjectAdvisor.class);
    
@@ -51,15 +57,38 @@
    
    protected ManagedObjectAdvisor(C container, String name, AspectManager manager)
    {
+      this(container, name, manager, null);
+   }
+
+   /**
+    * 
+    * @param container
+    * @param name
+    * @param manager
+    * @param pAnnotations   an alternate annotation repository or null for the default
+    */
+   protected ManagedObjectAdvisor(C container, String name, AspectManager manager, AnnotationRepository pAnnotations)
+   {
       super(name, manager);
+      
       assert container != null : "container is null";
       
       this.container = container;
       
+      if(pAnnotations != null)
+         this.annotations = pAnnotations;
+      
       // For convenience we add the ManagedObject annotation
-      annotations.addClassAnnotation(ManagedObject.class, new Object());
+      ManagedObject annotation = new ManagedObject()
+      {
+         public Class<? extends Annotation> annotationType()
+         {
+            return ManagedObject.class;
+         }
+      };
+      annotations.addClassAnnotation(ManagedObject.class, annotation);
    }
-
+   
    private void deployAnnotationIntroduction(AnnotationIntroduction introduction)
    {
       log.debug("deploy annotation introduction " + introduction);
@@ -190,4 +219,59 @@
    {
       throw new RuntimeException("NYI");
    }
+   
+   /* ExtendedAdvisor */
+
+   public boolean isAnnotationPresent(Class<?> cls, Class<? extends Annotation> annotationType)
+   {
+      if(annotations instanceof ExtendedAnnotationRepository)
+      {
+         // TODO: disabled?
+         if(((ExtendedAnnotationRepository) annotations).hasAnnotation(cls, annotationType))
+            return true;
+      }
+      return cls.isAnnotationPresent(annotationType);
+   }
+
+   public boolean isAnnotationPresent(Class<?> cls, Member member, Class<? extends Annotation> annotationType)
+   {
+      if(annotations instanceof ExtendedAnnotationRepository)
+      {
+         // TODO: disabled?
+         if(((ExtendedAnnotationRepository) annotations).hasAnnotation(cls, member, annotationType))
+            return true;
+      }
+      if(member instanceof AnnotatedElement)
+      {
+         if(((AnnotatedElement) member).isAnnotationPresent(annotationType))
+            return true;
+      }
+      return false;
+   }
+
+   public <A extends Annotation> A resolveAnnotation(Class<?> cls, Class<A> annotationType)
+   {
+      A annotation = null;
+      if(annotations instanceof ExtendedAnnotationRepository)
+      {
+         // TODO: disabled?
+         annotation = ((ExtendedAnnotationRepository) annotations).resolveAnnotation(cls, annotationType);
+      }
+      if(annotation == null)
+         annotation = cls.getAnnotation(annotationType);
+      return annotation;
+   }
+
+   public <A extends Annotation> A resolveAnnotation(Class<?> cls, Member member, Class<A> annotationType)
+   {
+      A annotation = null;
+      if(annotations instanceof ExtendedAnnotationRepository)
+      {
+         // TODO: disabled?
+         annotation = ((ExtendedAnnotationRepository) annotations).resolveAnnotation(cls, member, annotationType);
+      }
+      if(annotation == null && member instanceof AnnotatedElement)
+         annotation = ((AnnotatedElement) member).getAnnotation(annotationType);
+      return annotation;
+   }
 }




More information about the jboss-cvs-commits mailing list