[webbeans-commits] Webbeans SVN: r847 - in ri/trunk: webbeans-ri/src/test/java/org/jboss/webbeans/test/mock and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Jan 9 07:13:56 EST 2009


Author: pete.muir at jboss.org
Date: 2009-01-09 07:13:56 -0500 (Fri, 09 Jan 2009)
New Revision: 847

Modified:
   ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbResolver.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java
Log:
Actually commit @PersistenceContext work 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-01-09 11:57:21 UTC (rev 846)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-01-09 12:13:56 UTC (rev 847)
@@ -23,7 +23,10 @@
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
 import javax.webbeans.DefinitionException;
+import javax.webbeans.ExecutionException;
 import javax.webbeans.Initializer;
 import javax.webbeans.InjectionPoint;
 
@@ -251,17 +254,29 @@
 
       for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getPersistenceContextAnnotation()))
       {
+         if (field.getAnnotation(PersistenceContext.class).type().equals(PersistenceContextType.EXTENDED))
+         {
+            throw new ExecutionException("Cannot inject an extended persistence context into " + field);
+         }
          InjectionPoint injectionPoint = new InjectionPointImpl(field, this, beanInstance);
-         Object puInstance = manager.getEjbResolver().resolvePersistenceUnit(injectionPoint, manager.getNaming());
+         Object puInstance = manager.getEjbResolver().resolvePersistenceContext(injectionPoint, manager.getNaming());
          field.inject(beanInstance, puInstance);
       }
       
       for (AnnotatedMethod<?> method : annotatedItem.getAnnotatedMethods(manager.getEjbResolver().getPersistenceContextAnnotation()))
       {
          InjectionPoint injectionPoint = new InjectionPointImpl(method, this, beanInstance);
-         Object puInstance = manager.getEjbResolver().resolvePersistenceUnit(injectionPoint, manager.getNaming());
+         Object puInstance = manager.getEjbResolver().resolvePersistenceContext(injectionPoint, manager.getNaming());
          method.invoke(beanInstance, puInstance);
       }
+      
+      for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getResourceAnnotation()))
+      {
+         InjectionPoint injectionPoint = new InjectionPointImpl(field, this, beanInstance);
+         Object resourceInstance = manager.getEjbResolver().resolveResource(injectionPoint, manager.getNaming());
+         field.inject(beanInstance, resourceInstance);
+      }
+      
    }
 
    /**

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java	2009-01-09 11:57:21 UTC (rev 846)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java	2009-01-09 12:13:56 UTC (rev 847)
@@ -2,8 +2,8 @@
 
 import java.lang.annotation.Annotation;
 
+import javax.annotation.Resource;
 import javax.ejb.EJB;
-import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceContext;
 import javax.webbeans.InjectionPoint;
 
@@ -56,13 +56,24 @@
          return null;
       }
 
-      public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint, Naming naming)
+      public Object resolvePersistenceContext(InjectionPoint injectionPoint, Naming naming)
       {
          // TODO Implement PU resolution for Unit tests
          return null;
       }
 
+      public Class<? extends Annotation> getResourceAnnotation()
+      {
+         return Resource.class;
+      }
 
+      public Object resolveResource(InjectionPoint injectionPoint, Naming naming)
+      {
+         // TODO Auto-generated method stub
+         return null;
+      }
+
+
       
    };
    

Modified: ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbResolver.java
===================================================================
--- ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbResolver.java	2009-01-09 11:57:21 UTC (rev 846)
+++ ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbResolver.java	2009-01-09 12:13:56 UTC (rev 847)
@@ -2,14 +2,13 @@
 
 import java.lang.annotation.Annotation;
 
-import javax.webbeans.DefinitionException;
 import javax.webbeans.InjectionPoint;
 
 import org.jboss.webbeans.resources.spi.Naming;
 
 /**
  * A container should implement this interface to allow the Web Beans RI to
- * resolve EJBs and JPA persistence units
+ * resolve EJBs, Resources and JPA persistence units
  * 
  * @author Pete Muir
  * 
@@ -20,55 +19,69 @@
    public static final String PROPERTY_NAME = EjbResolver.class.getName();
    
    /**
-    * Resolve the value for the given
+    * Resolve the value for the given @EJB injection point
     * 
-    * @EJB injection point
-    * 
-    * @param injectionPoint
-    *           The injection point metadata
-    * @return the JNDI name
+    * @param injectionPoint the injection point metadata
+    * @return an instance of the EJB
     * @throws IllegalArgumentException
-    *            if the injection point is not annotated with @EJB
-    * @throws DefinitionException
-    *            if the injection point is not suitable for injection
+    *            if the injection point is not annotated with @EJB, or, if the 
+    *            injection point is a method that doesn't follow JavaBean
+    *            conventions
     * @throws IllegalStateException
     *            if no EJBs can be resolved for injection
     */
    public Object resolveEjb(InjectionPoint injectionPoint, Naming naming);
    
    /**
-    * Resolve the value for the given
+    * Resolve the value for the given @PersistenceContext injection point
     * 
-    * @PersistenceContext injection point
-    * 
-    * @param injectionPoint
-    *           The injection point metadata
-    * @return the JNDI name
+    * @param injectionPoint the injection point metadata
+    * @param naming the pluggable Web Beans JNDI lookup facility
+    * @return an instance of the persistence unit
     * @throws IllegalArgumentException
-    *            if the injection point is not annotated with @PersistenceContext
-    * @throws UnsupportedOperationException
-    *            if the injection point is annotated @PersistenceContext(EXTENTED)
+    *            if the injection point is not annotated with 
+    *            @PersistenceContext, or, if the injection point is a method 
+    *            that doesn't follow JavaBean conventions
     * @throws IllegalStateException
     *            if no suitable persistence units can be resolved for injection
     */
-   public Object resolvePersistenceUnit(InjectionPoint injectionPoint, Naming naming);
+   public Object resolvePersistenceContext(InjectionPoint injectionPoint, Naming naming);
    
    /**
-    * Get the annotation which defines an
+    * Resolve the value for the given @Resource injection point
     * 
-    * @EJB injection point
+    * @param injectionPoint the injection point metadata
+    * @param naming the pluggable Web Beans JNDI lookup facility
+    * @return an instance of the resource
+    * @throws IllegalArgumentException
+    *            if the injection point is not annotated with @Resource, or, if 
+    *            the injection point is a method that doesn't follow JavaBean 
+    *            conventions
+    * @throws IllegalStateException
+    *            if no resource can be resolved for injection
+    */
+   public Object resolveResource(InjectionPoint injectionPoint, Naming naming);
+   
+   /**
+    * Get the annotation which defines an @EJB injection point
     * 
     * @return the annotation which defines an @EJB injection point
     */
    public Class<? extends Annotation> getEJBAnnotation();
    
    /**
-    * Get the annoation which defines a
+    * Get the annotation which defines a @PersistenceContext injection point
     * 
-    * @PersistenceContext injection point
-    * 
-    * @return the annoation which defines a @PersistenceContext injection point
+    * @return the annotation which defines a @PersistenceContext injection point
     */
    public Class<? extends Annotation> getPersistenceContextAnnotation();
    
+   /**
+    * Get the annotation which defines a @Resource injection point
+    * 
+    * @return the annotation which defines a @Resource injection point
+    */
+   public Class<? extends Annotation> getResourceAnnotation();
+   
+   
 }




More information about the weld-commits mailing list