You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/07/25 23:09:32 UTC

svn commit: r797837 - in /incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb: component/EjbBean.java component/creation/EjbBeanCreatorImpl.java proxy/EjbBeanProxyHandler.java util/EjbValidator.java

Author: gerdogdu
Date: Sat Jul 25 21:09:32 2009
New Revision: 797837

URL: http://svn.apache.org/viewvc?rev=797837&view=rev
Log:
Update some EJB checks.

Modified:
    incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/EjbBean.java
    incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/creation/EjbBeanCreatorImpl.java
    incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java   (contents, props changed)
    incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/util/EjbValidator.java

Modified: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/EjbBean.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/EjbBean.java?rev=797837&r1=797836&r2=797837&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/EjbBean.java (original)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/EjbBean.java Sat Jul 25 21:09:32 2009
@@ -31,51 +31,97 @@
 import org.apache.webbeans.component.WebBeansType;
 
 /**
+ * Defines bean contract for the session beans.
+ * 
  * @version $Rev$ $Date$
  */
 public class EjbBean<T> extends AbstractInjectionTargetBean<T> implements EnterpriseBeanMarker
 {
+    /**Session bean type*/
     private SessionBeanType ejbType;
     
+    /**OpenEJB deployment info*/
     private DeploymentInfo deploymentInfo;    
     
+    /**Current bean instance*/
     private T instance = null;
     
+    /**Injected reference local interface type*/
     private Class<?> iface = null;
     
+    /**Remove stateful bean instance*/
+    private boolean removeStatefulInstance = false;
+    
+    /**
+     * Creates a new instance of the session bean.
+     * @param ejbClassType ebj class type
+     */
     public EjbBean(Class<T> ejbClassType)
     {
         super(WebBeansType.ENTERPRISE,ejbClassType);
     }
 
+    /**
+     * Sets local interface type.
+     * @param iface local interface type
+     */
     public void setIface(Class<?> iface)
     {
         this.iface = iface;
     }
     
+    /**
+     * Sets remove flag.
+     * @param remove flag
+     */
+    public void setRemoveStatefulInstance(boolean remove)
+    {
+        this.removeStatefulInstance = remove;
+    }
+    
+    /**
+     * Sets session bean's deployment info.
+     * @param deploymentInfo deployment info
+     */
     public void setDeploymentInfo(DeploymentInfo deploymentInfo)
     {
         this.deploymentInfo = deploymentInfo;
     }
         
+    /**
+     * Returns bean's deployment info.
+     * @return bean's deployment info
+     */
     public DeploymentInfo getDeploymentInfo()
     {
         return this.deploymentInfo;
     }
     
         
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void injectFields(T instance, CreationalContext<T> creationalContext)
     {
         //No-operations
     }
     
+    /**
+     * Inject session bean injected fields. It is called from
+     * interceptor.
+     * @param instance bean instance
+     * @param creationalContext creational context instance
+     */
     @SuppressWarnings("unchecked")
     public void injectFieldInInterceptor(Object instance, CreationalContext<?> creationalContext)
     {
         super.injectFields((T)instance, (CreationalContext<T>)creationalContext);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     @SuppressWarnings("unchecked")
     protected T createComponentInstance(CreationalContext<T> creationalContext)
@@ -112,23 +158,43 @@
         return instance;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void destroyComponentInstance(T instance)
     {
+        if(removeStatefulInstance && getEjbType().equals(SessionBeanType.STATEFUL))
+        {
+            //Call remove method
+        }
+        
         this.instance = null;
     }
     
+    /**
+     * Sets session bean type.
+     * @param type session bean type
+     */
     public void setEjbType(SessionBeanType type)
     {
         this.ejbType = type;
         
     }
     
+    /**
+     * Gets ejb name.
+     * @return ejb name
+     */
     public String getEjbName()
     {
         return this.deploymentInfo.getEjbName();
     }
     
+    /**
+     * Gets ejb session type.
+     * @return type of the ejb
+     */
     public SessionBeanType getEjbType()
     {
         return this.ejbType;

Modified: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/creation/EjbBeanCreatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/creation/EjbBeanCreatorImpl.java?rev=797837&r1=797836&r2=797837&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/creation/EjbBeanCreatorImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/component/creation/EjbBeanCreatorImpl.java Sat Jul 25 21:09:32 2009
@@ -13,15 +13,12 @@
  */
 package org.apache.webbeans.ejb.component.creation;
 
-import javax.enterprise.context.ScopeType;
+import java.util.List;
 
 import org.apache.openejb.DeploymentInfo;
-import org.apache.openejb.InterfaceType;
 import org.apache.webbeans.component.creation.AbstractInjectedTargetBeanCreator;
-import org.apache.webbeans.config.DefinitionUtil;
 import org.apache.webbeans.ejb.component.EjbBean;
 import org.apache.webbeans.ejb.util.EjbValidator;
-import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * EjbBeanCreatorImpl.
@@ -54,25 +51,33 @@
     {
         super.defineScopeType(errorMessage);
         EjbValidator.validateEjbScopeType(getBean());
+        EjbValidator.validateGenericBeanType(getBean().getReturnType(), getBean().getScopeType());
     }
     
     
-//    /**
-//     * {@inheritDoc}
-//     */
-//    @Override
-//    public void defineApiType()
-//    {
-//        if(isDefaultMetaDataProvider())
-//        {
-//            DeploymentInfo info = getBean().getDeploymentInfo();
-//            info.geti
-//        }
-//        else
-//        {
-//            //TODO Define Api Types by third party
-//        }
-//    }
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public void defineApiType()
+    {
+        if(isDefaultMetaDataProvider())
+        {
+            DeploymentInfo info = getBean().getDeploymentInfo();
+            List<Class> businessLocals = info.getBusinessLocalInterfaces();
+            for(Class clazz : businessLocals)
+            {
+                getBean().addApiType(clazz);
+            }
+            
+            getBean().addApiType(Object.class);
+        }
+        else
+        {
+            //TODO Define Api Types by third party
+        }
+    }
     
     
     /**

Modified: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java?rev=797837&r1=797836&r2=797837&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java (original)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java Sat Jul 25 21:09:32 2009
@@ -17,10 +17,13 @@
 package org.apache.webbeans.ejb.proxy;
 
 import java.lang.reflect.Method;
+import java.util.List;
 
+import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.SessionBeanType;
 
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.CreationalContextFactory;
@@ -29,19 +32,41 @@
 
 import javassist.util.proxy.MethodHandler;
 
+/**
+ * EJB beans proxy handler.
+ * @version $Rev$ $Date$
+ *
+ */
 @SuppressWarnings("unchecked")
 public class EjbBeanProxyHandler implements MethodHandler
 {
+    /**Proxy ejb bean instance*/
     private EjbBean<?> ejbBean;
     
+    /**
+     * Creates a new instance.
+     * @param ejbBean ejb bean instance
+     */
     public EjbBeanProxyHandler(EjbBean<?> ejbBean)
     {
         this.ejbBean = ejbBean;
     }
     
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Object invoke(Object instance, Method method, Method proceed, Object[] arguments) throws Exception
     {
+        //Check ejb remove method
+        if(this.ejbBean.getEjbType().equals(SessionBeanType.STATEFUL))
+        {
+            if(checkEjbRemoveMethod(method))
+            {
+                this.ejbBean.setRemoveStatefulInstance(true);
+            }
+        }
+        
         OpenWebBeansEjbInterceptor.setThreadLocal(this.ejbBean);
         
         //Context of the bean
@@ -57,5 +82,26 @@
         return result;
     }
     
-
+    /**
+     * Check stateful bean remove method control.
+     * @param method called method
+     * @throws UnsupportedOperationException if not valid call
+     */
+    private boolean checkEjbRemoveMethod(Method method)
+    {
+        List<Method> removeMethods = this.ejbBean.getDeploymentInfo().getRemoveMethods();
+        if(removeMethods.contains(method))
+        {
+            if(this.ejbBean.getScopeType() != Dependent.class)
+            {
+                throw new UnsupportedOperationException("Can not call EJB Statefull Bean Remove Method without scoped @Dependent");
+            }
+            else
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
 }

Propchange: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/proxy/EjbBeanProxyHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/util/EjbValidator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/util/EjbValidator.java?rev=797837&r1=797836&r2=797837&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/util/EjbValidator.java (original)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/util/EjbValidator.java Sat Jul 25 21:09:32 2009
@@ -13,6 +13,8 @@
  */
 package org.apache.webbeans.ejb.util;
 
+import java.lang.annotation.Annotation;
+
 import javax.decorator.Decorator;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.Dependent;
@@ -24,6 +26,7 @@
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.ClassUtil;
 
 /**
  * Validates session beans.
@@ -93,5 +96,24 @@
             throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Interceptor");
         }
     }
+    
+    /**
+     * Check generic type conditions.
+     * @param ejbClass ebj class
+     * @param scopeType scope type
+     */
+    public static void validateGenericBeanType(Class<?> ejbClass, Class<? extends Annotation> scopeType)
+    {
+        Asserts.assertNotNull(ejbClass, "ejbClass parameter can not be null");
+        Asserts.assertNotNull(ejbClass, "scopeType parameter can not be null");
+        
+        if(ClassUtil.isDefinitionConstainsTypeVariables(ejbClass))
+        {
+            if(!scopeType.equals(Dependent.class))
+            {
+                throw new WebBeansConfigurationException("Ejb generic bean class : " + ejbClass.getName() + "scope must be @Dependent");
+            }
+        }
+    }
 
 }
\ No newline at end of file