tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r675771 - in /openejb/trunk/openejb3/container: openejb-core/src/main/java/org/apache/openejb/config/rules/ openejb-core/src/main/resources/org/apache/openejb/config/rules/ openejb-jee/src/main/java/org/apache/openejb/jee/
Date Thu, 10 Jul 2008 21:43:50 GMT
Author: dblevins
Date: Thu Jul 10 14:43:49 2008
New Revision: 675771

URL: http://svn.apache.org/viewvc?rev=675771&view=rev
Log:
OPENEJB-855: Validation: Init/Remove annotations not used on MessageDriven, Stateless, or
Singleton beans
OPENEJB-846: Validation: Singleton mistakenly using @PrePassivate and @PostActivate
OPENEJB-677: Validation: PrePassivate/PostActivate not used on MessageDriven or Stateless

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
    openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionType.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java?rev=675771&r1=675770&r2=675771&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
Thu Jul 10 14:43:49 2008
@@ -25,9 +25,18 @@
 import org.apache.openejb.jee.Interceptor;
 import org.apache.openejb.jee.TimerConsumer;
 import org.apache.openejb.jee.NamedMethod;
+import org.apache.openejb.jee.SessionBean;
+import org.apache.openejb.jee.SessionType;
+import org.apache.openejb.jee.RemoveMethod;
+import org.apache.openejb.jee.InitMethod;
 import org.apache.openejb.OpenEJBException;
+import org.apache.xbean.finder.ClassFinder;
 
 import javax.interceptor.InvocationContext;
+import javax.ejb.PrePassivate;
+import javax.ejb.PostActivate;
+import javax.ejb.Remove;
+import javax.ejb.Init;
 import java.lang.reflect.Method;
 import java.util.List;
 import java.util.ArrayList;
@@ -58,17 +67,53 @@
                 checkCallback(ejbClass, "PreDestroy", callback, bean);
             }
 
-            if (bean instanceof Session) {
-                Session session = (Session) bean;
+            if (bean instanceof Session ) {
+                SessionBean session = (SessionBean) bean;
 
-                for (LifecycleCallback callback : session.getPrePassivate()) {
-                    checkCallback(ejbClass, "PrePassivate", callback, bean);
+                if (session.getSessionType() == SessionType.STATEFUL ) {
+
+                    for (LifecycleCallback callback : session.getPrePassivate()) {
+                        checkCallback(ejbClass, "PrePassivate", callback, bean);
+                    }
+
+                    for (LifecycleCallback callback : session.getPostActivate()) {
+                        checkCallback(ejbClass, "PostActivate", callback, bean);
+                    }
+                } else {
+                    for (LifecycleCallback callback : session.getPrePassivate()) {
+                        ignoredStatefulAnnotation("PrePassivate", bean, callback.getMethodName(),
session.getSessionType().getName());
+                    }
+
+                    for (LifecycleCallback callback : session.getPostActivate()) {
+                        ignoredStatefulAnnotation("PostActivate", bean, callback.getMethodName(),
session.getSessionType().getName());
+                    }
+
+                    for (RemoveMethod method : session.getRemoveMethod()) {
+                        ignoredStatefulAnnotation("Remove", bean, method.getBeanMethod().getMethodName(),
session.getSessionType().getName());
+                    }
+
+                    for (InitMethod method : session.getInitMethod()) {
+                        ignoredStatefulAnnotation("Init", bean, method.getBeanMethod().getMethodName(),
session.getSessionType().getName());
+                    }
                 }
+            } else {
+                ClassFinder finder = new ClassFinder(ejbClass);
 
-                for (LifecycleCallback callback : session.getPostActivate()) {
-                    checkCallback(ejbClass, "PostActivate", callback, bean);
+                for (Method method : finder.findAnnotatedMethods(PrePassivate.class)) {
+                    ignoredStatefulAnnotation("PrePassivate", bean, method.getName(), bean.getClass().getSimpleName());
                 }
 
+                for (Method method : finder.findAnnotatedMethods(PostActivate.class)) {
+                    ignoredStatefulAnnotation("PostActivate", bean, method.getName(), bean.getClass().getSimpleName());
+                }
+
+                for (Method method : finder.findAnnotatedMethods(Remove.class)) {
+                    ignoredStatefulAnnotation("Remove", bean, method.getName(), bean.getClass().getSimpleName());
+                }
+
+                for (Method method : finder.findAnnotatedMethods(Init.class)) {
+                    ignoredStatefulAnnotation("Init", bean, method.getName(), bean.getClass().getSimpleName());
+                }
             }
 
             if (bean instanceof TimerConsumer) {
@@ -141,6 +186,10 @@
         }
     }
 
+    private void ignoredStatefulAnnotation(String annotationType, EnterpriseBean bean, String
methodName, String beanType) {
+        warn(bean, "ignoredStatefulAnnotation", annotationType, beanType, methodName);
+    }
+
     private void checkCallback(Class ejbClass, String type, CallbackMethod callback, EnterpriseBean
bean) {
         try {
             Method method = getMethod(ejbClass, callback.getMethodName());

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=675771&r1=675770&r2=675771&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
Thu Jul 10 14:43:49 2008
@@ -304,26 +304,31 @@
 2.ann.remoteOrLocal.ejbLocalObject = @{0} used in bean class lists a javax.ejb.EJBLocalObject
interface. Use @LocalHome with home interface of "{1}".
 3.ann.remoteOrLocal.ejbLocalObject = When applied to a bean class, the @{0} annotation must
only list business interfaces and cannot list legacy EJBLocalObject interfaces.  The EJBLocalHome
of interface for "{1}" can be annotated on the bean class with @LocalHome
 
-# fail(ejbName, "xml.remoteOrLocal.ejbHome", tagName, interfce.getName());
+# fail(ejbName, "xml.businessRemoteOrLocal.ejbHome", tagName, interfce.getName());
 1.xml.businessRemoteOrLocal.ejbHome = javax.ejb.EJBHome interface declared as {0}.
 2.xml.businessRemoteOrLocal.ejbHome = javax.ejb.EJBHome interface declared as {0}. Use <home>{1}</home>
 3.xml.businessRemoteOrLocal.ejbHome = Interfaces extending javax.ejb.EJBHome pre-date the
concept of EJB 3.0 simplified business interfaces and must not use the {0} tag when declared
in the ejb-jar.xml.  Declare this interface as <home>{1}</home>.
 
-# fail(ejbName, "xml.remoteOrLocal.ejbLocalHome", tagName, interfce.getName());
+# fail(ejbName, "xml.businessRemoteOrLocal.ejbLocalHome", tagName, interfce.getName());
 1.xml.businessRemoteOrLocal.ejbLocalHome = javax.ejb.EJBLocalHome interface declared as {0}.
 2.xml.businessRemoteOrLocal.ejbLocalHome = javax.ejb.EJBLocalHome interface declared as {0}.
Use <local-home>{1}</local-home>
 3.xml.businessRemoteOrLocal.ejbLocalHome = Interfaces extending javax.ejb.EJBLocalHome pre-date
the concept of EJB 3.0 simplified business interfaces and must not use the {0} tag when declared
in the ejb-jar.xml.  Declare this interface as <local-home>{1}</local-home>.
 
-# fail(ejbName, "xml.remoteOrLocal.ejbObject", tagName, interfce.getName());
+# fail(ejbName, "xml.businessRemoteOrLocal.ejbObject", tagName, interfce.getName());
 1.xml.businessRemoteOrLocal.ejbObject = javax.ejb.EJBObject interface declared as {0}.
 2.xml.businessRemoteOrLocal.ejbObject = javax.ejb.EJBObject interface declared as {0}. Use
<remote>{1}</remote>
 3.xml.businessRemoteOrLocal.ejbObject = Interfaces extending javax.ejb.EJBObject pre-date
the concept of EJB 3.0 simplified business interfaces and must not use the {0} tag when declared
in the ejb-jar.xml.  Declare this interface as <remote>{1}</remote>.
 
-# fail(ejbName, "xml.remoteOrLocal.ejbLocalObject", tagName, interfce.getName());
+# fail(ejbName, "xml.businessRemoteOrLocal.ejbLocalObject", tagName, interfce.getName());
 1.xml.businessRemoteOrLocal.ejbLocalObject = javax.ejb.EJBLocalObject interface declared
as {0}.
 2.xml.businessRemoteOrLocal.ejbLocalObject = javax.ejb.EJBLocalObject interface declared
as {0}. Use <local>{1}</local>
 3.xml.businessRemoteOrLocal.ejbLocalObject = Interfaces extending javax.ejb.EJBLocalObject
pre-date the concept of EJB 3.0 simplified business interfaces and must not use the {0} tag
when declared in the ejb-jar.xml.  Declare this interface as <local>{1}</local>.
 
+# warn(bean, "ignoredStatefulAnnotation", annotationType, beanType, methodName);
+1.ignoredStatefulAnnotation = @{0} is ignored for beans of type {1}
+2.ignoredStatefulAnnotation = @{0} is ignored for beans of type {1}.  Method: {2}
+3.ignoredStatefulAnnotation = Beans of type {1} are not allowed to use the @{0} annotation.
 This annotation is only permitted on Stateful SessionBeans.  The usage of @{0} on bean method
{2} will be ignored and the annotation should be removed.
+
 # fail(bean, "persistenceContextExtented.nonStateful", refName, beanType);
 1.persistenceContextExtented.nonStateful = Non-Stateful use of PersistenceContextType.EXTENDED
 2.persistenceContextExtented.nonStateful = Non-Stateful use of PersistenceContextType.EXTENDED
in ref {0}

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionType.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionType.java?rev=675771&r1=675770&r2=675771&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionType.java
(original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionType.java
Thu Jul 10 14:43:49 2008
@@ -21,7 +21,17 @@
 import javax.xml.bind.annotation.XmlEnumValue;
 
 public enum SessionType {
-    @XmlEnumValue("Stateful") STATEFUL,
-    @XmlEnumValue("Stateless") STATELESS,
-    @XmlEnumValue("Singleton") SINGLETON
+    @XmlEnumValue("Stateful") STATEFUL("Stateful"),
+    @XmlEnumValue("Stateless") STATELESS("Stateless"),
+    @XmlEnumValue("Singleton") SINGLETON("Singleton");
+
+    private final String name;
+
+    SessionType(String name) {
+       this.name = name;
+   }
+
+    public String getName() {
+        return name;
+    }
 }



Mime
View raw message