openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r909952 - in /openwebbeans/trunk/webbeans-openejb: ./ src/main/java/org/apache/webbeans/ejb/ src/main/java/org/apache/webbeans/ejb/resource/ src/main/resources/META-INF/services/ src/test/java/org/apache/webbeans/ejb/
Date Sun, 14 Feb 2010 02:05:47 GMT
Author: gerdogdu
Date: Sun Feb 14 02:05:46 2010
New Revision: 909952

URL: http://svn.apache.org/viewvc?rev=909952&view=rev
Log:
[OWB-281] update resource plugin handling

Added:
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourcePlugin.java
      - copied, changed from r908638, openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceServiceImpl.java
Removed:
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceServiceImpl.java
Modified:
    openwebbeans/trunk/webbeans-openejb/pom.xml
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceFactory.java
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java
    openwebbeans/trunk/webbeans-openejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
    openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/OpenEJBIntegrationTest.java

Modified: openwebbeans/trunk/webbeans-openejb/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/pom.xml?rev=909952&r1=909951&r2=909952&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/pom.xml (original)
+++ openwebbeans/trunk/webbeans-openejb/pom.xml Sun Feb 14 02:05:46 2010
@@ -36,7 +36,7 @@
 		
 		<dependency>
 		    <groupId>org.apache.geronimo.specs</groupId>
-		    <artifactId>geronimo-el_1.0_spec</artifactId>
+		    <artifactId>geronimo-el_2.2_spec</artifactId>
 		    <scope>test</scope>
 		</dependency>
 		
@@ -57,8 +57,6 @@
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
-			<version>4.5</version>
-			<scope>test</scope>
 		</dependency>
 		
 	</dependencies>

Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java?rev=909952&r1=909951&r2=909952&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
Sun Feb 14 02:05:46 2010
@@ -13,19 +13,13 @@
  */
 package org.apache.webbeans.ejb;
 
-import java.lang.annotation.Annotation;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import javax.ejb.EJB;
-import javax.ejb.Stateful;
-import javax.ejb.Stateless;
-import javax.ejb.Singleton;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.SessionBeanType;
 
-import org.apache.commons.lang.Validate;
 import org.apache.openejb.Container;
 import org.apache.openejb.DeploymentInfo;
 import org.apache.openejb.core.singleton.SingletonContainer;
@@ -37,10 +31,8 @@
 import org.apache.webbeans.ejb.util.EjbDefinitionUtility;
 import org.apache.webbeans.ejb.util.EjbUtility;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.exception.WebBeansPassivationException;
-import org.apache.webbeans.plugins.AbstractOpenWebBeansPlugin;
+import org.apache.webbeans.plugins.AbstractOwbPlugin;
 import org.apache.webbeans.plugins.OpenWebBeansEjbPlugin;
-import org.apache.webbeans.util.AnnotationUtil;
 
 /**
  * EJB related stuff.
@@ -50,7 +42,7 @@
  * @version $Rev$ $Date$
  *
  */
-public class EjbPlugin extends AbstractOpenWebBeansPlugin implements OpenWebBeansEjbPlugin
+public class EjbPlugin extends AbstractOwbPlugin implements OpenWebBeansEjbPlugin
 {
     private ContainerSystem containerSystem = null;
     
@@ -64,32 +56,7 @@
     {
         
     }
-    
-    /** @{inheritDoc} */
-    @Override
-    public boolean isPassivationCapable(Bean<?> component) throws WebBeansPassivationException
-    {
-        Validate.notNull(component);
         
-        if (AnnotationUtil.hasAnnotation(component.getBeanClass().getAnnotations(), Stateful.class
))
-        {
-            // stateful session beans are passivation capable by default
-            //X TODO we might check the non-transient childs of the session bean?
-            return true;
-        }
-
-        if (AnnotationUtil.hasAnnotation(component.getBeanClass().getAnnotations(), Stateless.class
) ||
-            AnnotationUtil.hasAnnotation(component.getBeanClass().getAnnotations(), Singleton.class
)   )
-        {
-            throw new WebBeansPassivationException("WebBeans component: " + component.getName()
+ 
-                          " is not passivation capable and thus must not be used in a passivation
scope!");
-        }        
-        
-        // means this component is not handled by this EjbPlugin
-        return false;
-    }
-
-    
     @Override
     public <T> Bean<T> defineSessionBean(Class<T> clazz)
     {
@@ -208,16 +175,5 @@
     {
         return EjbDefinitionUtility.defineEjbBeanProxy((EjbBean<?>)bean,iface, creationalContext);
     }
-
-    @Override
-    public boolean isResourceAnnotation(Class<? extends Annotation> annotationClass)
-    {
-        if(annotationClass.equals(EJB.class))
-        {
-            return true;
-        }
-        
-        return false;
-    }
        
 }

Copied: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourcePlugin.java
(from r908638, openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceServiceImpl.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourcePlugin.java?p2=openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourcePlugin.java&p1=openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceServiceImpl.java&r1=908638&r2=909952&rev=909952&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceServiceImpl.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourcePlugin.java
Sun Feb 14 02:05:46 2010
@@ -13,18 +13,56 @@
  */
 package org.apache.webbeans.ejb.resource;
 
-import java.lang.reflect.Field;
+import java.lang.annotation.Annotation;
 
-import org.apache.webbeans.spi.ResourceService;
+import javax.ejb.EJB;
 
-public class OpenEjbResourceServiceImpl implements ResourceService
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.plugins.AbstractOwbPlugin;
+import org.apache.webbeans.plugins.OpenWebBeansResourcePlugin;
+
+public class OpenEjbResourcePlugin extends AbstractOwbPlugin implements OpenWebBeansResourcePlugin
 {
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(OpenEjbResourcePlugin.class);
+
+    @Override
+    public void clear()
+    {
+        ResourceFactory.getInstance().close();
+    }
+
+    @Override
+    public boolean isResourceAnnotation(Class<? extends Annotation> annotationClass)
+    {
+        if(annotationClass.equals(EJB.class))
+        {
+            return true;
+        }
+        
+        return false;
+    }
+
 
     @Override
-    public Object getResource(Field field)
+    public <T> T getResource(Class<?> owner, String name, Class<T> resourceType,
Annotation[] resoAnnotations)
     {
-        return ResourceFactory.getInstance().getResourceObject(field);
+        try
+        {
+            return ResourceFactory.getInstance().getResource(resourceType, resoAnnotations);
+            
+        }catch(Exception e)
+        {
+            logger.error("Unable to get resource with class " + resourceType + " in " + owner
+ " with name " + name,e);
+            throw new WebBeansConfigurationException("Unable to get resource with class "
+ resourceType + " in " + owner + " with name " + name,e);
+        }
     }
-    
 
+
+    @Override
+    public <T> void validateResource(Class<?> owner, String name, Class<T>
resourceType, Annotation[] resoAnnotations)
+    {
+        getResource(owner, name, resourceType, resoAnnotations);
+    }
+     
 }

Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceFactory.java?rev=909952&r1=909951&r2=909952&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceFactory.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceFactory.java
Sun Feb 14 02:05:46 2010
@@ -13,15 +13,19 @@
  */
 package org.apache.webbeans.ejb.resource;
 
-import java.lang.reflect.Field;
+import java.lang.annotation.Annotation;
 
 import javax.naming.Context;
+import javax.naming.NamingException;
 
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ContainerSystem;
+import org.apache.webbeans.logger.WebBeansLogger;
 
 public class ResourceFactory
 {
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(ResourceFactory.class);
+    
     private static ResourceFactory factory = null;
     
     private ResourceInjectionProcessor processor = null;
@@ -52,15 +56,29 @@
         return factory;
     }
     
-    public Object getResourceObject(Field field) throws RuntimeException
+    public <T> T getResource(Class<T> resourceType,Annotation[] resoAnnotations)
throws Exception
     {
         try
         {
-            return this.processor.getResourceObject(field);   
+            return this.processor.getResourceObject(resourceType, resoAnnotations);   
             
         } catch(Exception e)
         {
-            throw new RuntimeException(e);
+           throw e;
+        }
+    }
+    
+    public void close()
+    {
+        try
+        {
+            context.close();
+            factory = null;
+            processor = null;
+        }
+        catch (NamingException e)
+        {
+            logger.warn("Unable to clear ResourceFactory",e);
         }
     }
 

Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java?rev=909952&r1=909951&r2=909952&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ResourceInjectionProcessor.java
Sun Feb 14 02:05:46 2010
@@ -13,7 +13,7 @@
  */
 package org.apache.webbeans.ejb.resource;
 
-import java.lang.reflect.Field;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationTargetException;
 
 import javax.annotation.Resource;
@@ -32,6 +32,7 @@
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.persistence.JtaEntityManager;
 import org.apache.openejb.persistence.JtaEntityManagerRegistry;
+import org.apache.webbeans.util.AnnotationUtil;
 
 
 class ResourceInjectionProcessor
@@ -43,52 +44,49 @@
         this.context = context;
     }
 
-    public Object getResourceObject(Field field) throws IllegalAccessException, InvocationTargetException,
NamingException
+    public <T> T getResourceObject(Class<T> resourceType, Annotation[] resourceAnns)
throws IllegalAccessException, InvocationTargetException, NamingException
     {
+        Object resource = null;
+        
         if (context == null)
         {
             // No resource injection
             return null;
         }
 
-        if (field.isAnnotationPresent(Resource.class))
+        if (AnnotationUtil.hasAnnotation(resourceAnns, Resource.class))
         {
-            Resource annotation = field.getAnnotation(Resource.class);
-            
-            return lookupFieldResource(context, "openejb/Resource/"+annotation.name());
+            Resource annotation = AnnotationUtil.getAnnotation(resourceAnns, Resource.class);
           
+            resource= lookupFieldResource(context, "openejb/Resource/"+annotation.name());
             
         }
         
-        if (field.isAnnotationPresent(EJB.class))
+        if (AnnotationUtil.hasAnnotation(resourceAnns, EJB.class))
         {
-            EJB annotation = field.getAnnotation(EJB.class);
-            
-            return lookupFieldResource(context, annotation.name());
+            EJB annotation = AnnotationUtil.getAnnotation(resourceAnns, EJB.class);     
      
+            resource = lookupFieldResource(context, annotation.name());
         }
         
-        if (field.isAnnotationPresent(WebServiceRef.class))
+        if (AnnotationUtil.hasAnnotation(resourceAnns, WebServiceRef.class))
         {
-            WebServiceRef annotation = field.getAnnotation(WebServiceRef.class);
-            
-            return lookupFieldResource(context, annotation.name());
+            WebServiceRef annotation = AnnotationUtil.getAnnotation(resourceAnns, WebServiceRef.class);
           
+            resource = lookupFieldResource(context, annotation.name());
         }
         
-        if (field.isAnnotationPresent(PersistenceContext.class))
+        if (AnnotationUtil.hasAnnotation(resourceAnns, PersistenceContext.class))
         {
-            PersistenceContext annotation = field.getAnnotation(PersistenceContext.class);
-            
-            return this.getPersistenceContext(context, annotation.unitName());
+            PersistenceContext annotation = AnnotationUtil.getAnnotation(resourceAnns, PersistenceContext.class);
           
+            resource = this.getPersistenceContext(context, annotation.unitName());
             
         }
         
-        if (field.isAnnotationPresent(PersistenceUnit.class))
+        if (AnnotationUtil.hasAnnotation(resourceAnns, PersistenceUnit.class))
         {
-            PersistenceUnit annotation = field.getAnnotation(PersistenceUnit.class);
-            
-            return this.getPersistenceUnit(context, annotation.unitName());
+            PersistenceUnit annotation = AnnotationUtil.getAnnotation(resourceAnns, PersistenceUnit.class);
           
+            resource = this.getPersistenceUnit(context, annotation.unitName());
         }
         
-        return null;
+        return resourceType.cast(resource);
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-openejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin?rev=909952&r1=909951&r2=909952&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
Sun Feb 14 02:05:46 2010
@@ -18,4 +18,5 @@
 # this file contains the service implementation for the 
 # JMS integration into OpenWebBeans
 # this file contains information for java.util.ServiceLoader
-org.apache.webbeans.ejb.EjbPlugin
\ No newline at end of file
+org.apache.webbeans.ejb.EjbPlugin
+org.apache.webbeans.ejb.resource.OpenEjbResourcePlugin
\ No newline at end of file

Modified: openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/OpenEJBIntegrationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/OpenEJBIntegrationTest.java?rev=909952&r1=909951&r2=909952&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/OpenEJBIntegrationTest.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/test/java/org/apache/webbeans/ejb/OpenEJBIntegrationTest.java
Sun Feb 14 02:05:46 2010
@@ -13,6 +13,7 @@
  */
 package org.apache.webbeans.ejb;
 
+import java.lang.reflect.Field;
 import java.util.Properties;
 
 import javax.naming.Context;
@@ -46,15 +47,17 @@
         p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
         p.put("movieDatabaseUnmanaged.JtaManaged", "false");
         
-        Context context = new InitialContext(p);
+        new InitialContext(p);
 
         ResourceFactory rf = ResourceFactory.getInstance();
         
         Class<TestBean> c = TestBean.class;
-        EntityManagerFactory emf = (EntityManagerFactory) rf.getResourceObject(c.getField("emf"));
+        Field field = c.getField("emf");
+        EntityManagerFactory emf = (EntityManagerFactory) rf.getResource(field.getType(),
field.getDeclaredAnnotations());
         Assert.assertNotNull( emf );
         
-        EntityManager em = (EntityManager) rf.getResourceObject(c.getField("em"));
+        field = c.getField("em");
+        EntityManager em = (EntityManager) rf.getResource(field.getType(), field.getDeclaredAnnotations());
         Assert.assertNotNull( em );
     }
 



Mime
View raw message