[webbeans-commits] Webbeans SVN: r243 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: model/bean and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Nov 5 07:27:31 EST 2008


Author: pete.muir at jboss.org
Date: 2008-11-05 07:27:30 -0500 (Wed, 05 Nov 2008)
New Revision: 243

Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractClassBeanModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
Log:
Start to check init methods

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java	2008-11-04 19:00:48 UTC (rev 242)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java	2008-11-05 12:27:30 UTC (rev 243)
@@ -33,7 +33,7 @@
     * If no annotations are present which are annotated with the given
     * annotation an empty set is returned
     */
-   public Set<AnnotatedField<Object>> getAnnotatedField(Class<? extends Annotation> annotationType);
+   public Set<AnnotatedField<Object>> getAnnotatedFields(Class<? extends Annotation> annotationType);
    
    /**
     * Get all fields which are annotated with the given meta annotation 
@@ -45,4 +45,14 @@
    public Set<AnnotatedField<Object>> getMetaAnnotatedFields(
          Class<? extends Annotation> metaAnnotationType);
    
+   /**
+    * Get all fields which are annotated with the given meta annotation 
+    * type
+    * 
+    * If no annotations are present which are annotated with the given meta
+    * annotation an empty set is returned
+    */
+   public Set<AnnotatedMethod<Object>> getAnnotatedMethods(
+         Class<? extends Annotation> annotationType);
+   
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java	2008-11-04 19:00:48 UTC (rev 242)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java	2008-11-05 12:27:30 UTC (rev 243)
@@ -2,6 +2,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.HashMap;
@@ -25,6 +26,9 @@
    private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> annotatedFields;
    private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> metaAnnotatedFields;
    
+   private Set<AnnotatedMethod<Object>> methods;
+   private Map<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>> annotatedMethods;
+   
    public SimpleAnnotatedType(Class<T> annotatedClass, Map<Class<? extends Annotation>, Annotation> annotationMap)
    {
       super(annotationMap);
@@ -108,7 +112,7 @@
       return metaAnnotatedFields;
    }
 
-   public Set<AnnotatedField<Object>> getAnnotatedField(
+   public Set<AnnotatedField<Object>> getAnnotatedFields(
          Class<? extends Annotation> annotationType)
    {
       if (annotatedFields == null)
@@ -147,5 +151,51 @@
    {
       return actualTypeArguments;
    }
+   
+   private void initMethods()
+   {
+      this.methods = new HashSet<AnnotatedMethod<Object>>();
+      for (Method member : clazz.getDeclaredMethods())
+      {
+         methods.add(new SimpleAnnotatedMethod<Object>(member));
+      }
+   }
+   
+   public Set<AnnotatedMethod<Object>> getAnnotatedMethods(Class<? extends Annotation> annotationType)
+   {
+      if (annotatedMethods == null)
+      {
+         initAnnotatedMethods();
+      }
+       
+      if (!annotatedMethods.containsKey(annotationType))
+      {
+         return new HashSet<AnnotatedMethod<Object>>();
+      }
+      else
+      {
+         return annotatedMethods.get(annotationType);
+      }
+   }
 
+   private void initAnnotatedMethods()
+   {
+      if (methods == null)
+      {
+         initMethods();
+      }
+      annotatedMethods = new HashMap<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>>();
+      for (AnnotatedMethod<Object> member : methods)
+      {
+         for (Annotation annotation : member.getAnnotations())
+         {
+            if (!annotatedMethods.containsKey(annotation))
+            {
+               annotatedMethods.put(annotation.annotationType(), new HashSet<AnnotatedMethod<Object>>());
+            }
+            annotatedMethods.get(annotation.annotationType()).add(member);
+         }
+      }
+   }
+
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java	2008-11-04 19:00:48 UTC (rev 242)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java	2008-11-05 12:27:30 UTC (rev 243)
@@ -278,7 +278,7 @@
       
       if (deploymentTypes.size() > 1)
       {
-         throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().getDelegate());
+         throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
       }
       if (deploymentTypes.size() == 1)
       {

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractClassBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractClassBeanModel.java	2008-11-04 19:00:48 UTC (rev 242)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractClassBeanModel.java	2008-11-05 12:27:30 UTC (rev 243)
@@ -6,10 +6,15 @@
 
 import javax.webbeans.BindingType;
 import javax.webbeans.DefinitionException;
+import javax.webbeans.Destructor;
+import javax.webbeans.Initializer;
+import javax.webbeans.Produces;
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.injectable.InjectableField;
+import org.jboss.webbeans.injectable.InjectableMethod;
 import org.jboss.webbeans.introspector.AnnotatedField;
+import org.jboss.webbeans.introspector.AnnotatedMethod;
 import org.jboss.webbeans.introspector.AnnotatedType;
 import org.jboss.webbeans.util.LoggerUtil;
 import org.jboss.webbeans.util.Reflections;
@@ -31,6 +36,7 @@
    private AnnotatedType<T> annotatedItem;
    private AnnotatedType<T> xmlAnnotatedItem;
    private Set<InjectableField<?>> injectableFields;
+   private Set<InjectableMethod<Object>> initializerMethods;
    
    /**
     * 
@@ -62,6 +68,7 @@
       // TODO This is too high
       checkBeanImplementation();
       // TODO Interceptors
+      initInitializerMethods();
    }
    
    @Override
@@ -119,6 +126,27 @@
       }
    }
    
+   protected void initInitializerMethods()
+   {
+      // TODO Support XML
+      initializerMethods = new HashSet<InjectableMethod<Object>>();
+      for (AnnotatedMethod<Object> annotatedMethod : annotatedItem.getAnnotatedMethods(Initializer.class))
+      {
+         if (Reflections.isStatic(annotatedMethod.getDelegate()))
+         {
+            throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be static");
+         }
+         if (annotatedMethod.getAnnotation(Produces.class) != null)
+         {
+            throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Produces");
+         }
+         if (annotatedMethod.getAnnotation(Destructor.class) != null)
+         {
+            throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Destructor");
+         }
+      }
+   }
+   
    @Override
    protected String getDefaultName()
    {
@@ -170,5 +198,10 @@
    {
       return injectableFields;
    }
+   
+   public Set<InjectableMethod<Object>> getInitializerMethods()
+   {
+      return initializerMethods;
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java	2008-11-04 19:00:48 UTC (rev 242)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java	2008-11-05 12:27:30 UTC (rev 243)
@@ -96,6 +96,11 @@
       return Modifier.isStatic(field.getModifiers());
    }
    
+   public static boolean isStatic(Method method)
+   {
+      return Modifier.isStatic(method.getModifiers());
+   }
+   
    public static boolean isAbstract(Class<?> clazz)
    {
       return Modifier.isAbstract(clazz.getModifiers());




More information about the weld-commits mailing list