You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2009/12/02 11:48:52 UTC
svn commit: r886112 - in /incubator/openwebbeans/trunk:
webbeans-ejb/src/main/java/org/apache/webbeans/ejb/
webbeans-ejb/src/test/java/org/apache/webbeans/ejb/
webbeans-impl/src/main/java/org/apache/webbeans/plugins/
webbeans-impl/src/main/java/org/apa...
Author: struberg
Date: Wed Dec 2 10:48:43 2009
New Revision: 886112
URL: http://svn.apache.org/viewvc?rev=886112&view=rev
Log:
OWB-127 @Stateful EJBs have to be handled as being passivation capable
I added a plugable solution for the passivation capable check and
implemented it in the EjbPlugin
Modified:
incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
incubator/openwebbeans/trunk/webbeans-ejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/AbstractOpenWebBeansPlugin.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Modified: incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java?rev=886112&r1=886111&r2=886112&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java (original)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java Wed Dec 2 10:48:43 2009
@@ -18,10 +18,14 @@
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;
@@ -33,8 +37,10 @@
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.OpenWebBeansEjbPlugin;
+import org.apache.webbeans.util.AnnotationUtil;
/**
* EJB related stuff.
@@ -59,6 +65,31 @@
}
+ /** @{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)
{
Modified: incubator/openwebbeans/trunk/webbeans-ejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-ejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java?rev=886112&r1=886111&r2=886112&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-ejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java (original)
+++ incubator/openwebbeans/trunk/webbeans-ejb/src/test/java/org/apache/webbeans/ejb/EjbTestContext.java Wed Dec 2 10:48:43 2009
@@ -39,9 +39,7 @@
System.out.println("INIT EJB");
OpenEJB.init(System.getProperties());
-
-
- }catch(Exception e)
+ } catch(Exception e)
{
e.printStackTrace();
}
@@ -55,9 +53,9 @@
OpenEJB.destroy();
- }catch(Exception e)
+ } catch(Exception e)
{
-
+ e.printStackTrace();
}
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/AbstractOpenWebBeansPlugin.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/AbstractOpenWebBeansPlugin.java?rev=886112&r1=886111&r2=886112&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/AbstractOpenWebBeansPlugin.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/AbstractOpenWebBeansPlugin.java Wed Dec 2 10:48:43 2009
@@ -19,7 +19,10 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.enterprise.inject.spi.Bean;
+
import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansPassivationException;
/**
* Abstract imlpementation of the {@link OpenWebBeansPlugin} interface
@@ -38,58 +41,48 @@
}
- /* (non-Javadoc)
- * @see org.apache.webbeans.plugins.OpenWebBeansPlugin#checkForValidResources(java.lang.reflect.Type, java.lang.Class, java.lang.String, java.lang.annotation.Annotation[])
- */
+ /** @{inheritDoc} */
public void checkForValidResources(Type type, Class<?> clazz, String name, Annotation[] annotations)
{
}
- /* (non-Javadoc)
- * @see org.apache.webbeans.plugins.OpenWebBeansPlugin#injectResource(java.lang.reflect.Type, java.lang.annotation.Annotation[])
- */
+ /** @{inheritDoc} */
public Object injectResource(Type type, Annotation[] annotations)
{
-
return null;
}
- /* (non-Javadoc)
- * @see org.apache.webbeans.plugins.OpenWebBeansPlugin#isResourceAnnotation(java.lang.Class)
- */
+ /** @{inheritDoc} */
public boolean isResourceAnnotation(Class<? extends Annotation> annotationClass)
{
-
return false;
}
- /* (non-Javadoc)
- * @see org.apache.webbeans.plugins.OpenWebBeansPlugin#isSimpleBeanClass(java.lang.Class)
- */
+ /** @{inheritDoc} */
+ public boolean isPassivationCapable(Bean<?> component) throws WebBeansPassivationException
+ {
+ return false;
+ }
+
+ /** @{inheritDoc} */
public void isManagedBean(Class<?> clazz) throws WebBeansConfigurationException
{
-
}
- /* (non-Javadoc)
- * @see org.apache.webbeans.plugins.OpenWebBeansPlugin#shutDown()
- */
+ /** @{inheritDoc} */
public void shutDown() throws WebBeansConfigurationException
{
-
}
- /* (non-Javadoc)
- * @see org.apache.webbeans.plugins.OpenWebBeansPlugin#startUp()
- */
+ /** @{inheritDoc} */
public void startUp() throws WebBeansConfigurationException
{
-
}
+
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java?rev=886112&r1=886111&r2=886112&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java Wed Dec 2 10:48:43 2009
@@ -16,7 +16,10 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.enterprise.inject.spi.Bean;
+
import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansPassivationException;
/**
* <p>Interface which all OpenWebBeans plugins has to implement to
@@ -78,6 +81,21 @@
public boolean isResourceAnnotation(Class<? extends Annotation> annotationClass);
/**
+ * Check whether the given beans passivation capabilities are enough.
+ * This function will be called if a bean has a lifecycle (scope) which
+ * requires that the bean must be passivation capable.
+ *
+ * Usually beans of such scopes have to be {@link java.io.Serializable}.
+ * For specific beans, like e.g. EJB Beans, there might be other criterias.
+ *
+ * @param annotationClass which should be ckecked
+ * @return <code>true</code> if this plugin handles the bean and all is ok, <code>false</code>
+ * if the plugin doesn't handle this type of component
+ * @throws WebBeansPassivationException if the component should be able to be passivated
+ */
+ public boolean isPassivationCapable(Bean<?> component) throws WebBeansPassivationException;
+
+ /**
* Check conditions for the resources.
*
* @param type
@@ -101,5 +119,4 @@
*/
public Object injectResource(Type type, Annotation[] annotations);
-
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=886112&r1=886111&r2=886112&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Wed Dec 2 10:48:43 2009
@@ -1702,10 +1702,24 @@
if (passivating)
{
+ List<OpenWebBeansPlugin> plugins = PluginLoader.getInstance().getPlugins();
+ for (OpenWebBeansPlugin plugin : plugins)
+ {
+ if (plugin.isPassivationCapable(component))
+ {
+ // passivation capabilities are ok.
+ return;
+ }
+ }
+
+ // if no plugin did check some special conditions, the bean must be Serializable
if (!component.isSerializable())
{
throw new WebBeansPassivationException("WebBeans component implementation class : " + clazz.getName() + " with passivating scope @" + scope.annotationType().getName() + " must be Serializable");
}
+
+ //X TODO we might check the non-transient childs of the bean for serializability?
+
}
}
}