You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ge...@apache.org on 2011/05/26 05:42:41 UTC

svn commit: r1127775 - /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java

Author: genspring
Date: Thu May 26 03:42:40 2011
New Revision: 1127775

URL: http://svn.apache.org/viewvc?rev=1127775&view=rev
Log:
OPENEJB-1559 if the stateless session bean instance has an ejbCreate method, the container should treat the ejbCreate method as the instance's PostConstruct method

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java?rev=1127775&r1=1127774&r2=1127775&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java Thu May 26 03:42:40 2011
@@ -96,6 +96,34 @@ public class InterceptorBindingBuilder {
         Class clazz = beanContext.getBeanClass();
 
         InterceptorData beanAsInterceptor = new InterceptorData(clazz);
+        
+        
+
+        if (beanInfo instanceof StatelessBeanInfo) {
+            /*
+             * 4.3.10.2 If the stateless session bean instance has an ejbCreate method, 
+             * the container treats the ejbCreate method as the instance’s PostConstruct method,
+             *  and, in this case, the PostConstruct annotation (or deployment descriptor metadata)
+             *  can only be applied to the bean’s ejbCreate method.
+             */
+            NamedMethodInfo info = new NamedMethodInfo();
+            info.className = clazz.getName();
+            info.methodName = "ejbCreate";
+            info.methodParams = new ArrayList<String>();
+            
+            try {
+                Method ejbcreate = MethodInfoUtil.toMethod(clazz, info);
+                if (ejbcreate != null) {
+                    CallbackInfo ejbcreateAsPostConstruct = new CallbackInfo();
+                    ejbcreateAsPostConstruct.className = ejbcreate.getDeclaringClass().getName();
+                    ejbcreateAsPostConstruct.method = "ejbCreate";
+                    beanInfo.postConstruct.add(ejbcreateAsPostConstruct);
+                }
+            } catch (IllegalStateException e) {
+                // there's no ejbCreate method in stateless bean.
+            }
+
+        }
 
         toMethods(clazz, beanInfo.aroundInvoke, beanAsInterceptor.getAroundInvoke());
         toCallback(clazz, beanInfo.postConstruct, beanAsInterceptor.getPostConstruct());
@@ -272,10 +300,10 @@ public class InterceptorBindingBuilder {
         for (CallbackInfo callbackInfo : callbackInfos) {
             try {
                 Method method = getMethod(clazz, callbackInfo.method, InvocationContext.class);
-                if (callbackInfo.className == null && method.getDeclaringClass().equals(clazz)){
+                if (callbackInfo.className == null && method.getDeclaringClass().equals(clazz) && !methods.contains(method)){
                     methods.add(method);
                 }
-                if (method.getDeclaringClass().getName().equals(callbackInfo.className)){
+                if (method.getDeclaringClass().getName().equals(callbackInfo.className) && !methods.contains(method)){
                     methods.add(method);
                 }  else {
                     // check for a private method on the declared class
@@ -289,7 +317,7 @@ public class InterceptorBindingBuilder {
                         try {
                             method = getMethod(c, callbackInfo.method, InvocationContext.class);
                             // make sure it is private
-                            if (Modifier.isPrivate(method.getModifiers())) {
+                            if (Modifier.isPrivate(method.getModifiers()) && !methods.contains(method)) {
                                 SetAccessible.on(method);
                                 methods.add(method);
                             }
@@ -330,9 +358,9 @@ public class InterceptorBindingBuilder {
         for (CallbackInfo callbackInfo : callbackInfos) {
             try {
                 Method method = getMethod(clazz, callbackInfo.method, parameterTypes);
-                if (callbackInfo.className == null){
+                if (callbackInfo.className == null && !methods.contains(method)){
                     methods.add(method);
-                } else if (method.getDeclaringClass().getName().equals(callbackInfo.className)){
+                } else if (method.getDeclaringClass().getName().equals(callbackInfo.className) && !methods.contains(method)){
                     methods.add(method);
                 } else {
                     // check for a private method on the declared class
@@ -346,7 +374,7 @@ public class InterceptorBindingBuilder {
                         try {
                             method = c.getDeclaredMethod(callbackInfo.method);
                             // make sure it is private
-                            if (Modifier.isPrivate(method.getModifiers())) {
+                            if (Modifier.isPrivate(method.getModifiers()) && !methods.contains(method)) {
                                 SetAccessible.on(method);
                                 methods.add(method);
                             }