[jboss-cvs] JBossAS SVN: r63096 - trunk/ejb3/src/main/org/jboss/ejb3.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 16 10:29:44 EDT 2007


Author: wolfc
Date: 2007-05-16 10:29:44 -0400 (Wed, 16 May 2007)
New Revision: 63096

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
Log:
EJBTHREE-963: optionally apply PostConstruct to ejbCreate

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2007-05-16 14:11:19 UTC (rev 63095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2007-05-16 14:29:44 UTC (rev 63096)
@@ -21,6 +21,7 @@
  */
 package org.jboss.ejb3;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Member;
 import java.util.ArrayList;
@@ -34,6 +35,7 @@
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
 import javax.annotation.security.DeclareRoles;
 import javax.annotation.security.DenyAll;
 import javax.annotation.security.PermitAll;
@@ -124,6 +126,7 @@
 import org.jboss.ejb.PrePassivateImpl;
 import org.jboss.ejb.RemoteImpl;
 import org.jboss.ejb.RemoveImpl;
+import org.jboss.ejb.ResourceImpl;
 import org.jboss.ejb.RolesAllowedImpl;
 import org.jboss.ejb.RunAsImpl;
 import org.jboss.ejb.StatelessImpl;
@@ -756,10 +759,16 @@
             Method method = new Method();
             method.setEjbName(container.getEjbName());
 
-            Object annotation = new PostConstructImpl();
-            Class annotationClass = javax.annotation.PostConstruct.class;
-            method.setMethodName("ejbCreate");
-            addAnnotations(annotationClass, annotation, container, method);
+            Annotation annotation;
+            Class<? extends Annotation> annotationClass;
+            // EJB3 4.6.2: The class may implement the ejbCreate method(s).
+            if(hasMethod(ejbClass, "ejbCreate"))
+            {
+               annotation = new PostConstructImpl();
+               annotationClass = javax.annotation.PostConstruct.class;
+               method.setMethodName("ejbCreate");
+               addAnnotations(annotationClass, annotation, container, method);
+            }
 
             annotation = new PostActivateImpl();
             annotationClass = javax.ejb.PostActivate.class;
@@ -1996,4 +2005,27 @@
       return sb.toString();
    }
 
+   /**
+    * Verify whether the class has a method with a certain name.
+    * 
+    * @param cls            the class to check
+    * @param methodName     the method to find
+    * @return               true if a method with that name exists on that class
+    */
+   private boolean hasMethod(Class<?> cls, String methodName)
+   {
+      assert cls != null : "cls is null";
+      assert methodName != null : "methodName is null";
+      
+      for(java.lang.reflect.Method m : cls.getDeclaredMethods())
+      {
+         if(m.getName().equals(methodName))
+            return true;
+      }
+      
+      if(cls.getSuperclass() != null)
+         return hasMethod(cls.getSuperclass(), methodName);
+      
+      return false;
+   }
 }




More information about the jboss-cvs-commits mailing list