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

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Jul 3 18:23:57 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-07-03 18:23:57 -0400 (Thu, 03 Jul 2008)
New Revision: 43

Added:
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/JNDI.java
Modified:
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
   ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java
   ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentMetaModelTest.java
   ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java
   ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/util/Util.java
Log:
ComponentModel for JMS - needs a lot of refactoring

Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java	2008-07-03 21:29:26 UTC (rev 42)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -5,7 +5,9 @@
 
 import javax.webbeans.EnterpriseBeanLookup;
 
+import org.jboss.webbeans.util.JNDI;
 
+
 public class EjbManager
 {
    
@@ -24,12 +26,12 @@
    {
       if (ejb.getEjbLinkJndiName() != null)
       {
-         return (T) lookupInJndi(ejb.getEjbLinkJndiName());
+         return (T) JNDI.lookup(ejb.getEjbLinkJndiName());
       }
       try
       {
          // TODO How is a JNDI lookup failure shown to us?
-         return (T) lookupInJndi(ejb.getDefaultJndiName());
+         return (T) JNDI.lookup(ejb.getDefaultJndiName());
       }
       catch (Exception e) 
       {
@@ -54,11 +56,5 @@
       }
       
    }
-   
-   protected Object lookupInJndi(String name)
-   {
-      // TODO Write JNDI lookup
-      return null;
-   }
 
 }

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/JMSConstructor.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -0,0 +1,24 @@
+package org.jboss.webbeans.injectable;
+
+import javax.webbeans.Container;
+
+import org.jboss.webbeans.util.JNDI;
+
+public class JMSConstructor<T> implements ComponentConstructor<T>
+{
+
+   Class<? extends T> type;
+   
+   private String jndiName;
+   
+   public JMSConstructor(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+   
+   public T invoke(Container container)
+   {
+      return JNDI.lookup(jndiName, type);
+   }
+
+}


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

Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java	2008-07-03 21:29:26 UTC (rev 42)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -1,7 +1,6 @@
 package org.jboss.webbeans.model;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
@@ -13,7 +12,6 @@
 import javax.webbeans.Dependent;
 import javax.webbeans.DeploymentType;
 import javax.webbeans.Destroys;
-import javax.webbeans.Initializer;
 import javax.webbeans.Named;
 import javax.webbeans.ScopeType;
 
@@ -23,7 +21,6 @@
 import org.jboss.webbeans.bindings.ProductionBinding;
 import org.jboss.webbeans.ejb.EjbMetaData;
 import org.jboss.webbeans.injectable.ComponentConstructor;
-import org.jboss.webbeans.injectable.SimpleConstructor;
 import org.jboss.webbeans.injectable.InjectableMethod;
 import org.jboss.webbeans.util.AnnotatedItem;
 import org.jboss.webbeans.util.LoggerUtil;
@@ -85,6 +82,11 @@
       // TODO Interceptors
    }
    
+   public AbstractComponentModel()
+   {
+      // TODO Auto-generated constructor stub
+   }
+   
    @SuppressWarnings("unchecked")
    protected static Class<?> initType(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
    {

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -0,0 +1,103 @@
+package org.jboss.webbeans.model;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Set;
+
+import javax.webbeans.Current;
+import javax.webbeans.Dependent;
+import javax.webbeans.ScopeType;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.bindings.DependentBinding;
+import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.injectable.JMSConstructor;
+import org.jboss.webbeans.util.AnnotatedItem;
+import org.jboss.webbeans.util.MutableAnnotatedItem;
+import org.jboss.webbeans.util.Reflections;
+
+public class JmsComponentModel<T> extends AbstractComponentModel<T>
+{
+
+   // TODO Work out how to handle xml elements which don't correspond to annotations
+   
+   private Set<Annotation> bindingTypes;
+   private Class<? extends T> type;
+   private Annotation scopeType;
+   private String jndiName;
+   private ComponentConstructor<T> constructor;
+   
+   public JmsComponentModel(AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
+   {
+      AnnotatedItem annotatedItem = new MutableAnnotatedItem(null, new HashMap<Class<? extends Annotation>, Annotation>());
+      type = initType(xmlAnnotatedItem);
+      bindingTypes = initBindingTypes(annotatedItem, xmlAnnotatedItem);
+      scopeType = new DependentBinding();
+      checkBindingTypesAllowed(bindingTypes, type);
+      checkScopeAllowed(xmlAnnotatedItem, type);
+      // TODO Initialize queue. topic
+      this.constructor = new JMSConstructor<T>(jndiName);
+   }
+   
+   
+
+   @SuppressWarnings("unchecked")
+   protected static void checkBindingTypesAllowed(Set<Annotation> bindingTypes,
+         Class<?> type)
+   {
+      if (bindingTypes.size() == 0)
+      {
+         throw new RuntimeException("Must declare at least one binding type for JMS Component " + type);
+      }
+      if (Reflections.annotationSetMatches(bindingTypes, Current.class))
+      {
+         throw new RuntimeException("Cannot declared the binding type @Current for JMS Component " + type);
+      }
+      
+   }
+
+   protected static <T> Class<? extends T> initType(AnnotatedItem xmlAnnotatedItem)
+   {
+      // TODO return TopicPublisher if its a topic or QueueSession if its a queue
+      return null;
+   }
+   
+   protected static void checkScopeAllowed(AnnotatedItem xmlAnnotatedItem, Class<?> type)
+   {
+      Set<Annotation> scopeTypeAnnotations = xmlAnnotatedItem.getAnnotations(ScopeType.class);
+      if (scopeTypeAnnotations.size() > 0 && ! scopeTypeAnnotations.iterator().next().annotationType().equals(Dependent.class))
+      {
+         throw new RuntimeException("JMS component may only have scope @Dependent for " + type);
+      }
+   }
+   
+   @Override
+   public ComponentConstructor<T> getConstructor()
+   {
+      return constructor;
+   }
+   
+   @Override
+   public Set<Annotation> getBindingTypes()
+   {
+      return bindingTypes;
+   }
+   
+   @Override
+   protected Class<? extends T> getType()
+   {
+      return type;
+   }
+   
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+   
+   @Override
+   public Annotation getScopeType()
+   {
+      return scopeType;
+   }
+   
+}


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

Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/JNDI.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/JNDI.java	                        (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/JNDI.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.util;
+
+public class JNDI
+{
+
+   public static Object lookup(String name)
+   {
+      return lookup(name, Object.class);
+   }
+   
+   public static <T> T lookup(String name, Class<? extends T> expectedType)
+   {
+      return null;
+   }
+   
+}


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

Modified: 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	2008-07-03 21:29:26 UTC (rev 42)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -5,7 +5,9 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 
 
 public class Reflections
@@ -113,4 +115,40 @@
       }
       return constructors;
    }
+
+   public static boolean annotationTypeSetMatches(Set<Class<? extends Annotation>> annotations, Class<? extends Annotation>... annotationTypes)
+   {
+      List<Class<? extends Annotation>> annotationTypeList = new ArrayList<Class<? extends Annotation>>();
+      annotationTypeList.addAll(Arrays.asList(annotationTypes));
+      for (Class<? extends Annotation> annotation : annotations)
+      {
+         if (annotationTypeList.contains(annotation))
+         {
+            annotationTypeList.remove(annotation);
+         }
+         else
+         {
+            return false;
+         }
+      }
+      return annotationTypeList.size() == 0;
+   }
+
+   public static boolean annotationSetMatches(Set<Annotation> annotations, Class<? extends Annotation>... annotationTypes)
+   {
+      List<Class<? extends Annotation>> annotationTypeList = new ArrayList<Class<? extends Annotation>>();
+      annotationTypeList.addAll(Arrays.asList(annotationTypes));
+      for (Annotation annotation : annotations)
+      {
+         if (annotationTypeList.contains(annotation.annotationType()))
+         {
+            annotationTypeList.remove(annotation.annotationType());
+         }
+         else
+         {
+            return false;
+         }
+      }
+      return annotationTypeList.size() == 0;
+   }
 }

Modified: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentMetaModelTest.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentMetaModelTest.java	2008-07-03 21:29:26 UTC (rev 42)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentMetaModelTest.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -1,6 +1,5 @@
 package org.jboss.webbeans.test;
 
-import static org.jboss.webbeans.test.util.Util.annotationSetMatches;
 
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
@@ -63,6 +62,7 @@
 import org.jboss.webbeans.util.AnnotatedItem;
 import org.jboss.webbeans.util.ClassAnnotatedItem;
 import org.jboss.webbeans.util.MutableAnnotatedItem;
+import org.jboss.webbeans.util.Reflections;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -165,7 +165,7 @@
       
       SimpleComponentModel<Cat> cat = new SimpleComponentModel<Cat>(new ClassAnnotatedItem(Cat.class), annotatedItem, container);
       assert cat.getBindingTypes().size() == 1;
-      assert annotationSetMatches(cat.getBindingTypes(), Asynchronous.class);
+      assert Reflections.annotationSetMatches(cat.getBindingTypes(), Asynchronous.class);
    }
    
    @SuppressWarnings("unchecked")
@@ -174,7 +174,7 @@
    {
       SimpleComponentModel<Cat> cat = new SimpleComponentModel<Cat>(new ClassAnnotatedItem(Cat.class), emptyAnnotatedItem, container);
       assert cat.getBindingTypes().size() == 1;
-      assert annotationSetMatches(cat.getBindingTypes(), Synchronous.class);
+      assert Reflections.annotationSetMatches(cat.getBindingTypes(), Synchronous.class);
    }
    
    @SuppressWarnings("unchecked")
@@ -186,7 +186,7 @@
       AnnotatedItem annotatedItem = new MutableAnnotatedItem(Antelope.class, annotations);
       
       SimpleComponentModel<Antelope> antelope = new SimpleComponentModel<Antelope>(emptyAnnotatedItem, annotatedItem, container);
-      assert annotationSetMatches(antelope.getBindingTypes(), Asynchronous.class);
+      assert Reflections.annotationSetMatches(antelope.getBindingTypes(), Asynchronous.class);
    }
    
    @SuppressWarnings("unchecked")
@@ -417,7 +417,7 @@
       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);
+      assert Reflections.annotationSetMatches(order.getBindingTypes(), Current.class, Synchronous.class);
       assert order.getScopeType().annotationType().equals(Dependent.class);
    }
    

Modified: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java	2008-07-03 21:29:26 UTC (rev 42)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -1,7 +1,5 @@
 package org.jboss.webbeans.test;
 
-import static org.jboss.webbeans.test.util.Util.annotationSetMatches;
-
 import java.lang.annotation.Annotation;
 import java.util.HashMap;
 import java.util.Map;
@@ -26,6 +24,8 @@
 import org.jboss.webbeans.util.AnnotatedItem;
 import org.jboss.webbeans.util.ClassAnnotatedItem;
 import org.jboss.webbeans.util.MutableAnnotatedItem;
+import org.jboss.webbeans.util.Reflections;
+import static org.jboss.webbeans.util.Reflections.annotationSetMatches;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -49,7 +49,7 @@
    {
       EnterpriseComponentModel<Lion> lion = new EnterpriseComponentModel<Lion>(new ClassAnnotatedItem(Lion.class), emptyAnnotatedItem, container);
       assert lion.getScopeType().annotationType().equals(Dependent.class);
-      annotationSetMatches(lion.getBindingTypes(), Current.class);
+      Reflections.annotationSetMatches(lion.getBindingTypes(), Current.class);
       assert lion.getName().equals("lion");
    }
    
@@ -62,7 +62,7 @@
       
       EnterpriseComponentModel<Giraffe> giraffe = new EnterpriseComponentModel<Giraffe>(new ClassAnnotatedItem(Giraffe.class), annotatedItem, container);
       assert giraffe.getScopeType().annotationType().equals(Dependent.class);
-      annotationSetMatches(giraffe.getBindingTypes(), Current.class);
+      Reflections.annotationSetMatches(giraffe.getBindingTypes(), Current.class);
    }
    
    @Test
@@ -102,7 +102,7 @@
    {
 
       EnterpriseComponentModel<Tiger> tiger = new EnterpriseComponentModel<Tiger>(new ClassAnnotatedItem(Tiger.class), emptyAnnotatedItem, container);
-      annotationSetMatches(tiger.getBindingTypes(), Synchronous.class);
+      Reflections.annotationSetMatches(tiger.getBindingTypes(), Synchronous.class);
       assert tiger.getRemoveMethod().getMethod().getName().equals("remove");
       assert tiger.getName() == null;
    }
@@ -182,7 +182,7 @@
    public void testMessageDriven()
    {
       EnterpriseComponentModel<Leopard> leopard = new EnterpriseComponentModel<Leopard>(new ClassAnnotatedItem(Leopard.class), emptyAnnotatedItem, container);
-      annotationSetMatches(leopard.getBindingTypes(), Current.class);
+      Reflections.annotationSetMatches(leopard.getBindingTypes(), Current.class);
    }
 
 }

Modified: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/util/Util.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/util/Util.java	2008-07-03 21:29:26 UTC (rev 42)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/util/Util.java	2008-07-03 22:23:57 UTC (rev 43)
@@ -1,48 +1,7 @@
 package org.jboss.webbeans.test.util;
 
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
 
 public class Util
 {
-
-   public static boolean annotationSetMatches(Set<Annotation> annotations, Class<? extends Annotation>... annotationTypes)
-   {
-      List<Class<? extends Annotation>> annotationTypeList = new ArrayList<Class<? extends Annotation>>();
-      annotationTypeList.addAll(Arrays.asList(annotationTypes));
-      for (Annotation annotation : annotations)
-      {
-         if (annotationTypeList.contains(annotation.annotationType()))
-         {
-            annotationTypeList.remove(annotation.annotationType());
-         }
-         else
-         {
-            return false;
-         }
-      }
-      return annotationTypeList.size() == 0;
-   }
    
-   public static boolean annotationTypeSetMatches(Set<Class<? extends Annotation>> annotations, Class<? extends Annotation>... annotationTypes)
-   {
-      List<Class<? extends Annotation>> annotationTypeList = new ArrayList<Class<? extends Annotation>>();
-      annotationTypeList.addAll(Arrays.asList(annotationTypes));
-      for (Class<? extends Annotation> annotation : annotations)
-      {
-         if (annotationTypeList.contains(annotation))
-         {
-            annotationTypeList.remove(annotation);
-         }
-         else
-         {
-            return false;
-         }
-      }
-      return annotationTypeList.size() == 0;
-   }
-   
 }




More information about the weld-commits mailing list