[webbeans-commits] Webbeans SVN: r28 - in ri/trunk/webbeans-impl: src/main/java/org/jboss/webbeans and 3 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Jul 1 08:14:57 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-07-01 08:14:57 -0400 (Tue, 01 Jul 2008)
New Revision: 28

Added:
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
Modified:
   ri/trunk/webbeans-impl/pom.xml
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java
   ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java
Log:
Start on chapter 3.1, alter emma setup

Modified: ri/trunk/webbeans-impl/pom.xml
===================================================================
--- ri/trunk/webbeans-impl/pom.xml	2008-07-01 12:14:37 UTC (rev 27)
+++ ri/trunk/webbeans-impl/pom.xml	2008-07-01 12:14:57 UTC (rev 28)
@@ -31,34 +31,18 @@
          <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>emma-maven-plugin</artifactId>
-            <version>1.0-SNAPSHOT</version>
             <inherited>true</inherited>
-            <executions>
-               <execution>
-                  <goals>
-                     <goal>instrument</goal>
-                  </goals>
-               </execution>
-            </executions>
          </plugin>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
                <forkMode>always</forkMode>
+               <reportFormat>xml</reportFormat>
             </configuration>
          </plugin>
       </plugins>
    </build>
 
-   <reporting>
-      <plugins>
-         <plugin>
-            <groupId>org.codehaus.mojo</groupId>
-            <artifactId>emma-maven-plugin</artifactId>
-            <version>1.0-SNAPSHOT</version>
-            <inherited>true</inherited>
-         </plugin>
-      </plugins>
-   </reporting>
+   
 </project>
\ No newline at end of file

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,33 @@
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+
+public abstract class AbstractInjectedThingMetaModel
+{
+   
+   private Annotation[] bindingTypes;
+   
+   public AbstractInjectedThingMetaModel(Annotation[] bindingTypes)
+   {
+      this.bindingTypes = bindingTypes;
+   }
+   
+   public AbstractInjectedThingMetaModel()
+   {
+      this.bindingTypes = new Annotation[0];
+   }
+
+   public Annotation[] getBindingTypes()
+   {
+      return bindingTypes;
+   }
+   
+   public abstract Class<?> getType();
+   
+   @Override
+   public String toString()
+   {
+      return getType() + " with binding types " + getBindingTypes();
+   }
+
+}


Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java	2008-07-01 12:14:37 UTC (rev 27)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -1,6 +1,7 @@
 package org.jboss.webbeans;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -9,6 +10,7 @@
 import javax.webbeans.BindingType;
 import javax.webbeans.ComponentInstance;
 import javax.webbeans.Container;
+import javax.webbeans.Dependent;
 import javax.webbeans.DeploymentType;
 import javax.webbeans.Named;
 import javax.webbeans.ScopeType;
@@ -16,8 +18,11 @@
 import org.jboss.webbeans.bindings.CurrentBinding;
 import org.jboss.webbeans.bindings.DependentBinding;
 import org.jboss.webbeans.bindings.ProductionBinding;
+import org.jboss.webbeans.ejb.EJB;
 import org.jboss.webbeans.util.AnnotatedItem;
 import org.jboss.webbeans.util.LoggerUtil;
+import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
 
 /**
  * Web Beans Component meta model
@@ -28,24 +33,31 @@
 public class ComponentInstanceImpl<T> extends ComponentInstance<T>
 {
    
+   public enum ComponentType
+   {
+      SIMPLE,
+      EJB_SESSION
+      ;
+   }
    
-   
    public static final String LOGGER_NAME = "componentInstance";
    
    private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
    
-   private Class<?> type;
+   private Class<? extends T> type;
    private Set<Annotation> bindingTypes;
-   private Annotation componentType;
+   private Annotation deploymentType;
    private String name;
    private Annotation scopeType;
-   
+   private ComponentType componentType;
+   private ConstructorMetaModel<T> constructor;
    /**
     * 
     * @param annotatedItem Annotations read from java classes
     * @param xmlAnnotatedItem Annotations read from XML
     * @param container
     */
+   @SuppressWarnings("unchecked")
    public ComponentInstanceImpl(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
    {
       if (annotatedItem == null)
@@ -58,15 +70,18 @@
          throw new NullPointerException("xmlAnnotatedItem must not be null. If the component is declared just in Java, pass in an empty xmlAnnotatedItem");
       }
       
-      this.type = getType(annotatedItem, xmlAnnotatedItem);
+      this.type = (Class<? extends T>) initType(annotatedItem, xmlAnnotatedItem);
       log.fine("Building Web Bean component metadata for " +  type);
+      this.componentType = initComponentType(type);
+      checkComponentImplementation(componentType, type);
+      this.constructor = new ConstructorMetaModel<T>(type);
       MergedComponentStereotypes stereotypes = new MergedComponentStereotypes(annotatedItem, xmlAnnotatedItem, container);
       this.bindingTypes = initBindingTypes(annotatedItem, xmlAnnotatedItem);
-      this.componentType = initComponentType(stereotypes, annotatedItem, xmlAnnotatedItem, container);
+      this.deploymentType = initDeploymentType(stereotypes, annotatedItem, xmlAnnotatedItem, container);
       this.scopeType = initScopeType(stereotypes, annotatedItem, xmlAnnotatedItem);
-      this.name = initName(stereotypes, annotatedItem, xmlAnnotatedItem);
+      this.name = initName(stereotypes, annotatedItem, xmlAnnotatedItem, componentType, type);
       checkRequiredTypesImplemented(stereotypes, type);
-      checkScopeAllowed(stereotypes, scopeType);
+      checkScopeAllowed(stereotypes, scopeType, type);
       // TODO Interceptors
    }
    
@@ -74,8 +89,55 @@
     * A series of static methods which implement the algorithms defined in the Web Beans spec for component meta data
     */
    
-   protected static Class<?> getType(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
+   protected static ComponentType initComponentType(Class<?> type)
    {
+      if (EJB.isStatefulEjbComponent(type) || EJB.isStatelessEjbComponent(type))
+      {
+         return ComponentType.EJB_SESSION;
+      }
+      else
+      {
+         return ComponentType.SIMPLE;
+      }
+   }
+   
+   protected static void checkComponentImplementation(ComponentType componentType, Class<?> type)
+   {
+      switch (componentType)
+      {
+      case SIMPLE:
+         checkSimpleComponentImplementation(type);
+         break;
+      }
+   }
+   
+   protected static void checkSimpleComponentImplementation(Class<?> type)
+   {
+      if (Reflections.isAbstract(type))
+      {
+         throw new RuntimeException("Web Bean implementation class " + type + " cannot be declared abstract");
+      }
+   }
+   
+   protected static boolean isDeclaredFinal(Class<?> type)
+   {
+      if (Reflections.isFinal(type))
+      {
+         return true;
+      }
+      for (Method method : type.getDeclaredMethods())
+      {
+         if (Reflections.isFinal(method))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
+
+   @SuppressWarnings("unchecked")
+   protected static Class<?> initType(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
+   {
       if (annotatedItem.getAnnotatedClass() != null && xmlAnnotatedItem.getAnnotatedClass() != null && !annotatedItem.getAnnotatedClass().equals(xmlAnnotatedItem.getAnnotatedClass()))
       {
          throw new IllegalArgumentException("Cannot build a component which specifies different classes in XML and Java");
@@ -97,18 +159,23 @@
    }
    
    /**
-    * Check that the scope type is allowed by the stereotypes on the component
+    * Check that the scope type is allowed by the stereotypes on the component and the component type
+    * @param type 
     */
-   protected static void checkScopeAllowed(MergedComponentStereotypes stereotypes, Annotation scopeType)
+   protected static void checkScopeAllowed(MergedComponentStereotypes stereotypes, Annotation scopeType, Class<?> type)
    {
+      log.finest("Checking if " + scopeType + " is allowed");
       if (stereotypes.getSupportedScopes().size() > 0)
       {
-         log.finest("Checking if " + scopeType + " is allowed");
          if (!stereotypes.getSupportedScopes().contains(scopeType.annotationType()))
          {
             throw new RuntimeException("Scope " + scopeType + " is not an allowed by the component's stereotype");
          }
       }
+      if (isDeclaredFinal(type) && !scopeType.annotationType().equals(Dependent.class))
+      {
+         throw new RuntimeException("Scope " + scopeType + " is not allowed as the component is declared final or has methods declared final");
+      }
    }
    
    /**
@@ -172,7 +239,7 @@
       return new DependentBinding();
    }
 
-   protected static Annotation initComponentType(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
+   protected static Annotation initDeploymentType(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
    {
       Set<Annotation> xmlDeploymentTypes = xmlAnnotatedItem.getAnnotations(DeploymentType.class);
       
@@ -244,7 +311,7 @@
       return bindingTypes;
    }
 
-   protected static String initName(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
+   protected static String initName(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ComponentType componentType, Class<?> type)
    {
       boolean componentNameDefaulted = false;
       String name = null;
@@ -276,7 +343,10 @@
       }
       if ("".equals(name) && (componentNameDefaulted || stereotypes.isComponentNameDefaulted()))
       {
-         // TODO Write default name alogorithm
+         if (ComponentType.SIMPLE.equals(componentType))
+         {
+            name = Strings.decapitalize(type.getName());
+         }
          log.finest("Default name is TODO" );
       }
       return name;
@@ -297,7 +367,6 @@
    @Override
    public T create(Container container)
    {
-      // TODO Auto-generated method stub
       return null;
    }
 
@@ -315,9 +384,9 @@
    }
 
    @Override
-   public Annotation getComponentType()
+   public Annotation getDeploymentType()
    {
-      return componentType;
+      return deploymentType;
    }
 
    @Override

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,122 @@
+package org.jboss.webbeans;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.webbeans.BindingType;
+import javax.webbeans.Container;
+import javax.webbeans.Initializer;
+
+import org.jboss.webbeans.util.LoggerUtil;
+import org.jboss.webbeans.util.Reflections;
+
+public class ConstructorMetaModel<T>
+{
+   
+public static final String LOGGER_NAME = "componentConstructor";
+   
+   private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
+
+   private Constructor<T> constructor;
+   
+   private List<AbstractInjectedThingMetaModel> injectedParameters;
+
+   @SuppressWarnings("unchecked")
+   public ConstructorMetaModel(Class<? extends T> type)
+   {
+      this.injectedParameters = new ArrayList<AbstractInjectedThingMetaModel>();
+      if (type.getConstructors().length == 1)
+      {
+         this.constructor = type.getConstructors()[0];
+         log.finest("Exactly one constructor (" + constructor +") defined, using it as the component constructor for " + type);
+      }
+      else if (type.getConstructors().length > 1)
+      {
+         
+         List<Constructor<T>> initializerAnnotatedConstructors = Reflections.getConstructors(type, Initializer.class);
+         List<Constructor<T>> bindingTypeAnnotatedConstructors = Reflections.getConstructorsForMetaAnnotatedParameter(type, BindingType.class);
+         if ((initializerAnnotatedConstructors.size() + bindingTypeAnnotatedConstructors.size()) > 1)
+         {
+            if (initializerAnnotatedConstructors.size() > 1)
+            {
+               throw new RuntimeException("Cannot have more than one constructor annotated with @Initializer for " + type);
+            }
+            
+            else if (bindingTypeAnnotatedConstructors.size() > 1)
+            {
+               throw new RuntimeException("Cannot have more than one constructor with binding types specified on constructor parameters for " + type);
+            }
+            
+            else
+            {
+               throw new RuntimeException("Specify a constructor either annotated with @Initializer or with parameters annotated with binding types for " + type);
+            }
+         }
+         else if (initializerAnnotatedConstructors.size() == 1)
+         {
+            this.constructor = initializerAnnotatedConstructors.get(0);
+            log.finest("Exactly one constructor (" + constructor +") annotated with @Initializer defined, using it as the component constructor for " + type);
+         }
+         else if (bindingTypeAnnotatedConstructors.size() == 1)
+         {
+            this.constructor = bindingTypeAnnotatedConstructors.get(0);
+            log.finest("Exactly one constructor (" + constructor +") with parameters annotated with binding types defined, using it as the component constructor for " + type);
+         }
+      }
+      else if (type.getConstructors().length == 0)
+      {      
+         this.constructor = (Constructor<T>) Reflections.getConstructor(type);
+         log.finest("No constructor defined, using implicit no arguement constructor");
+      }
+      
+      for (int i = 0; i < constructor.getParameterTypes().length; i++)
+      {
+         if (constructor.getParameterAnnotations()[i].length > 0)
+         {
+            InjectedParameterMetaModel parameter = new InjectedParameterMetaModel(constructor.getParameterAnnotations()[i], constructor.getParameterTypes()[i]);
+            injectedParameters.add(i, parameter);
+         }
+         else
+         {
+            InjectedParameterMetaModel parameter = new InjectedParameterMetaModel(constructor.getParameterTypes()[i]);
+            injectedParameters.add(i, parameter);
+         }
+      }
+      log.finest("Initialized metadata for " + constructor + " with injectable parameters " + injectedParameters);
+      if (this.constructor == null)
+      {
+         throw new RuntimeException("Cannot determine constructor to use");
+      }
+   }
+   
+   public Constructor<T> getConstructor()
+   {
+      return constructor;
+   }
+   
+   public List<AbstractInjectedThingMetaModel> getInjectedAttributes()
+   {
+      return injectedParameters;
+   }
+   
+   public T newInstance(Container container)
+   {
+      Object[] parameters = new Object[injectedParameters.size()];
+      log.finest("Creating new instance of " + constructor.getDeclaringClass() + " with injected parameters " + injectedParameters);
+      for (int i = 0; i < injectedParameters.size(); i++)
+      {
+         parameters[i] = container.getInstanceByType(injectedParameters.get(i).getType(), injectedParameters.get(0).getBindingTypes());
+      }
+      try
+      {
+         return constructor.newInstance(parameters);
+      }
+      catch (Exception e) 
+      {
+         throw new RuntimeException("Error instantiating " + constructor.getDeclaringClass(), e);
+      }
+   }
+   
+}


Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,27 @@
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+
+public class InjectedParameterMetaModel extends AbstractInjectedThingMetaModel
+{
+   
+   private Class<?> type;
+   
+   public InjectedParameterMetaModel(Annotation[] bindingTypes, Class<?> type)
+   {
+      super(bindingTypes);
+      this.type = type;
+   }
+
+   public InjectedParameterMetaModel(Class<?> type)
+   {
+      super();
+      this.type = type;
+   }
+
+   public Class<?> getType()
+   {
+      return type;
+   }
+   
+}


Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,72 @@
+package org.jboss.webbeans.ejb;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.webbeans.util.Reflections;
+
+
+ at SuppressWarnings("unchecked")
+public class EJB
+{
+   
+   public @interface Dummy {}
+   
+   public static final Class<Annotation> STATELESS;
+   public static final Class<Annotation> STATEFUL;
+   public static final Class<Annotation> MESSAGE_DRIVEN;
+   
+   static 
+   {
+      STATELESS = classForName("javax.ejb.Stateless");
+      STATEFUL = classForName("javax.ejb.Stateful");
+      MESSAGE_DRIVEN = classForName("javax.ejb.MessageDriven");
+   }
+   
+   private static Class classForName(String name)
+   {
+      try
+      {
+         return Reflections.classForName(name);
+      }
+      catch (ClassNotFoundException cnfe)
+      {
+         return Dummy.class;
+      }
+   }
+   
+   public static boolean isStatelessEjbComponent(Class<?> clazz)
+   {
+      EjbMetaData ejbMetaData = getEjbMetaData(clazz);
+      if (ejbMetaData != null)
+      {
+         return ejbMetaData.isStateless();
+      }
+      return false;
+   }
+
+   public static boolean isStatefulEjbComponent(Class<?> clazz)
+   {
+      EjbMetaData ejbMetaData = getEjbMetaData(clazz);
+      if (ejbMetaData != null)
+      {
+         return ejbMetaData.isStateful();
+      }
+      return false;
+   }
+   
+   public static boolean isMessageDrivenEjbComponent(Class<?> clazz)
+   {
+      EjbMetaData ejbMetaData = getEjbMetaData(clazz);
+      if (ejbMetaData != null)
+      {
+         return ejbMetaData.isMessageDriven();
+      }
+      return false;
+   }
+   
+   public static EjbMetaData getEjbMetaData(Class<?> clazz)
+   {
+      return null;
+   }
+   
+}


Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,24 @@
+package org.jboss.webbeans.ejb;
+
+public class EjbMetaData
+{
+
+   public boolean isStateless()
+   {
+      // TODO Auto-generated method stub
+      return false;
+   }
+
+   public boolean isStateful()
+   {
+      // TODO Auto-generated method stub
+      return false;
+   }
+
+   public boolean isMessageDriven()
+   {
+      // TODO Auto-generated method stub
+      return false;
+   }
+
+}


Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,116 @@
+package org.jboss.webbeans.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class Reflections
+{
+   
+   public static Class<?> classForName(String name) throws ClassNotFoundException
+   {
+      try 
+      {
+         return Thread.currentThread().getContextClassLoader().loadClass(name);
+      }
+      catch (Exception e)
+      {
+         return Class.forName(name);
+      }
+   }
+
+   public static boolean isFinal(Class<?> clazz)
+   {
+      return Modifier.isFinal(clazz.getModifiers());
+   }
+   
+   public static boolean isFinal(Method method)
+   {
+      return Modifier.isFinal(method.getModifiers());
+   }
+   
+   public static boolean isAbstract(Class<?> clazz)
+   {
+      return Modifier.isAbstract(clazz.getModifiers());
+   }
+   
+   public static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... parameterTypes)
+   {
+      try
+      {
+         return clazz.getConstructor(parameterTypes);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error accessing constructor (with parameters " + parameterTypes + ") of " + clazz, e);
+      }
+   }
+   
+   public static List<Method> getMethods(Class<?> clazz, Class<? extends Annotation> annotationType) 
+   {
+      List<Method> methods = new ArrayList<Method>();
+      for (Method method : clazz.getMethods())
+      {
+         if (method.isAnnotationPresent(annotationType))
+         {
+            methods.add(method);
+         }
+      }
+      return methods;
+   }
+   
+   public static <T> List<Constructor<T>> getConstructors(Class<? extends T> clazz, Class<? extends Annotation> annotationType) 
+   {
+      List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
+      for (Constructor<T> constructor : constructors)
+      {
+         if (constructor.isAnnotationPresent(annotationType))
+         {
+            constructors.add(constructor);
+         }
+      }
+      return constructors;
+   }
+   
+   public static <T> List<Constructor<T>> getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> parameterAnnotationType) 
+   {
+      List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
+      for (Constructor<T> constructor : constructors)
+      {
+         for (Annotation[] annotations : constructor.getParameterAnnotations())
+         {
+            for (Annotation annotation : annotations)
+            {
+               if (annotation.annotationType().equals(parameterAnnotationType))
+               {
+                  constructors.add(constructor);
+               }
+            }
+         }
+      }
+      return constructors;
+   }
+   
+   public static <T> List<Constructor<T>> getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> metaAnnotationType) 
+   {
+      List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
+      for (Constructor<T> constructor : constructors)
+      {
+         for (Annotation[] annotations : constructor.getParameterAnnotations())
+         {
+            for (Annotation annotation : annotations)
+            {
+               if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
+               {
+                  constructors.add(constructor);
+               }
+            }
+         }
+      }
+      return constructors;
+   }
+}


Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.util;
+
+import java.beans.Introspector;
+
+public class Strings
+{
+
+   public static String decapitalize(String camelCase)
+   {
+      return Introspector.decapitalize(camelCase);
+   }
+   
+}


Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java	2008-07-01 12:14:37 UTC (rev 27)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java	2008-07-01 12:14:57 UTC (rev 28)
@@ -119,7 +119,7 @@
       AnnotatedItem xmlDefinedDeploymentTypeAnnotatedItem = new MutableAnnotatedItem(ComponentWithTooManyDeploymentTypes.class, xmlDefinedDeploymentTypeAnnotations);
       
       ComponentInstance<ComponentWithTooManyDeploymentTypes> component = new ComponentInstanceImpl<ComponentWithTooManyDeploymentTypes>(new ClassAnnotatedItem(ComponentWithTooManyDeploymentTypes.class), xmlDefinedDeploymentTypeAnnotatedItem, container);
-      assert component.getComponentType().annotationType().equals(AnotherDeploymentType.class);
+      assert component.getDeploymentType().annotationType().equals(AnotherDeploymentType.class);
    }
    
    @Test
@@ -127,7 +127,7 @@
    {
       AnnotatedItem antelopeAnnotatedItem = new MutableAnnotatedItem(Antelope.class, new HashMap<Class<? extends Annotation>, Annotation>());
       ComponentInstance<Antelope> antelope = new ComponentInstanceImpl<Antelope>(emptyAnnotatedItem, antelopeAnnotatedItem, container);
-      assert antelope.getComponentType().annotationType().equals(Production.class);
+      assert antelope.getDeploymentType().annotationType().equals(Production.class);
    }
    
    @Test
@@ -135,7 +135,7 @@
    {
       AnnotatedItem annotatedItem = new MutableAnnotatedItem(Tuna.class, new HashMap<Class<? extends Annotation>, Annotation>());
       ComponentInstance<Tuna> tuna = new ComponentInstanceImpl<Tuna>(new ClassAnnotatedItem(Tuna.class), annotatedItem, container);
-      assert tuna.getComponentType().annotationType().equals(Production.class);
+      assert tuna.getDeploymentType().annotationType().equals(Production.class);
    }
    
    @Test
@@ -146,7 +146,7 @@
       AnnotatedItem annotatedItem = new MutableAnnotatedItem(Moose.class, annotations);
       
       ComponentInstance<Moose> moose = new ComponentInstanceImpl<Moose>(new ClassAnnotatedItem(Moose.class), annotatedItem, container);
-      assert moose.getComponentType().annotationType().equals(HornedAnimalDeploymentType.class);
+      assert moose.getDeploymentType().annotationType().equals(HornedAnimalDeploymentType.class);
       
    }
    
@@ -411,7 +411,7 @@
       AnnotatedItem currentSynchronousOrderAnnotatedItem = new MutableAnnotatedItem(Order.class, orderXmlAnnotations);
       
       ComponentInstance<Order> order = new ComponentInstanceImpl<Order>(new ClassAnnotatedItem(Order.class), currentSynchronousOrderAnnotatedItem, container);
-      assert Production.class.equals(order.getComponentType().annotationType());
+      assert Production.class.equals(order.getDeploymentType().annotationType());
       assert "currentSynchronousOrder".equals(order.getName());
       assert order.getBindingTypes().size() == 2;
       assert annotationSetMatches(order.getBindingTypes(), Current.class, Synchronous.class);
@@ -423,7 +423,7 @@
    {
       ComponentInstance<Gorilla> gorilla = new ComponentInstanceImpl<Gorilla>(new ClassAnnotatedItem(Gorilla.class), emptyAnnotatedItem, container);
       assert gorilla.getName() == null;
-      assert gorilla.getComponentType().annotationType().equals(Production.class);
+      assert gorilla.getDeploymentType().annotationType().equals(Production.class);
       assert gorilla.getBindingTypes().iterator().next().annotationType().equals(Current.class);
       assert gorilla.getScopeType().annotationType().equals(RequestScoped.class);
    }




More information about the weld-commits mailing list