[jboss-cvs] JBossAS SVN: r63298 - in branches/Branch_4_2/ejb3/src/main/org/jboss: ejb3/interceptor and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 1 08:23:19 EDT 2007
Author: wolfc
Date: 2007-06-01 08:23:19 -0400 (Fri, 01 Jun 2007)
New Revision: 63298
Modified:
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java
branches/Branch_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java
Log:
EJBTHREE-959: deploy an EJB 2.1 sfsb
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2007-06-01 10:56:51 UTC (rev 63297)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2007-06-01 12:23:19 UTC (rev 63298)
@@ -21,6 +21,7 @@
*/
package org.jboss.ejb3;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import javassist.bytecode.ClassFile;
@@ -91,6 +92,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;
@@ -136,6 +138,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;
@@ -348,7 +351,7 @@
addInterfaces(container, enterpriseBean);
- addDescriptorAnnotations(container, enterpriseBean, ejbName);
+ addDescriptorAnnotations(container, enterpriseBean, ejbName, true);
return container;
}
@@ -518,6 +521,11 @@
return super.isEjb() || super.isJBossBeanType();
}
+ private boolean isStateful(EnterpriseBean enterpriseBean)
+ {
+ return ejbType == EJB_TYPE.STATEFUL;
+ }
+
private void addMDBAnnotations(MDB container, String ejbName,
EnterpriseBean enterpriseBean)
{
@@ -687,8 +695,21 @@
}
}
+ /**
+ * Add descriptor annotations on non stateful session beans.
+ *
+ * @param container
+ * @param enterpriseBean
+ * @param ejbName
+ * @throws Exception
+ */
+ private void addDescriptorAnnotations(EJBContainer container, EnterpriseBean enterpriseBean, String ejbName) throws Exception
+ {
+ addDescriptorAnnotations(container, enterpriseBean, ejbName, false);
+ }
+
private void addDescriptorAnnotations(EJBContainer container,
- EnterpriseBean enterpriseBean, String ejbName) throws Exception
+ EnterpriseBean enterpriseBean, String ejbName, boolean isStateful) throws Exception
{
container.setXml(enterpriseBean);
@@ -700,10 +721,20 @@
addEjbAnnotations(container, enterpriseBean);
- addEjb21Annotations(container);
+ addEjb21Annotations(container, isStateful);
}
- private void addEjb21Annotations(EJBContainer container) throws Exception
+ /**
+ * EJB3 4.3.5
+ * On a 2.1 session bean the ejbRemove is treated as PreDestroy, ejbActivate as PostActivate,
+ * and ejbPassivate as PrePassivate. If it is a stateless session bean the ejbCreate is treated
+ * as PostConstruct, if it is stateful the ejbCreate is treated as Init.
+ *
+ * @param container
+ * @param enterpriseBean
+ * @throws Exception
+ */
+ private void addEjb21Annotations(EJBContainer container, boolean isStateful) throws Exception
{
Class[] interfaces = ejbClass.getInterfaces();
for (Class beanInterface : interfaces)
@@ -713,8 +744,16 @@
Method method = new Method();
method.setEjbName(container.getEjbName());
- Object annotation = new PostConstructImpl();
- Class annotationClass = javax.annotation.PostConstruct.class;
+ Annotation annotation;
+ if(isStateful)
+ {
+ annotation = new InitImpl();
+ }
+ else
+ {
+ annotation = new PostConstructImpl();
+ }
+ Class<? extends Annotation> annotationClass = annotation.annotationType();
method.setMethodName("ejbCreate");
addAnnotations(annotationClass, annotation, container, method);
@@ -732,6 +771,12 @@
annotationClass = javax.annotation.PreDestroy.class;
method.setMethodName("ejbRemove");
addAnnotations(annotationClass, annotation, container, method);
+
+ annotation = new ResourceImpl();
+ annotationClass = Resource.class;
+ method.setMethodName("setSessionContext");
+ // TODO: set param?
+ addAnnotations(annotationClass, annotation, container, method);
}
}
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java 2007-06-01 10:56:51 UTC (rev 63297)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java 2007-06-01 12:23:19 UTC (rev 63298)
@@ -30,6 +30,7 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import javax.ejb.CreateException;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.interceptor.AroundInvoke;
@@ -39,6 +40,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.rmi.RemoteException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -508,6 +510,25 @@
}
}
+ private static boolean checkExceptions(Class<?> allowedExceptions[], Method method)
+ {
+ for(Class<?> exception : method.getExceptionTypes())
+ {
+ boolean isAllowed = false;
+ for(Class<?> allowed : allowedExceptions)
+ {
+ if(allowed.isAssignableFrom(exception))
+ isAllowed = true;
+ }
+ if(!isAllowed)
+ {
+ log.warn("Illegal exception '" + exception.getName() + "' in lifecycle signature (EJB3 12.4.2): " + method);
+ return false;
+ }
+ }
+ return true;
+ }
+
public static boolean checkValidBusinessSignature(Method method)
{
int modifiers = method.getModifiers();
@@ -548,19 +569,33 @@
return false;
}
+ /**
+ * EJB3 12.4
+ * Lifecycle methods may throw runtime exceptions, but not application exceptions.
+ * Note that for 2.1 beans CreateException (on ejbCreate) and RemoteException should pass.
+ *
+ * @param method
+ * @return
+ */
public static boolean checkValidBeanLifecycleSignature(Method method)
{
int modifiers = method.getModifiers();
if (method.getName().equals("ejbCreate"))
{
- // for public void ejbCreate() throws javax.ejb.CreateException
+ // for public void ejbCreate(...) throws javax.ejb.CreateException
if (!Modifier.isStatic(modifiers) && method.getReturnType().equals(Void.TYPE)
- && method.getParameterTypes().length == 0 && method.getExceptionTypes().length <= 1)
+ && method.getExceptionTypes().length <= 1)
+ {
+ if(!checkExceptions(new Class<?>[] { RuntimeException.class, CreateException.class, RemoteException.class }, method))
+ return false;
return true;
+ }
}
else if (!Modifier.isStatic(modifiers) && method.getReturnType().equals(Void.TYPE)
- && method.getParameterTypes().length == 0 && method.getExceptionTypes().length == 0)
+ && method.getParameterTypes().length == 0)
{
+ if(!checkExceptions(new Class<?>[] { RuntimeException.class, RemoteException.class }, method))
+ return false;
return true;
}
return false;
@@ -744,13 +779,6 @@
{
if (!signatureValidator.checkValidLifecycle(method))
{
- // FIXME: JBCTS-322
- // This is just a hack that prevents the RTE below. Please fix appropriately.
- if (ann.annotationType() == PostConstruct.class && method.getName().equals("ejbCreate"))
- {
- return method;
- }
-
throw new RuntimeException("@" + ann.annotationType().getName()
+ " annotated method has the wrong signature - " + method);
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java 2007-06-01 10:56:51 UTC (rev 63297)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java 2007-06-01 12:23:19 UTC (rev 63298)
@@ -220,7 +220,7 @@
public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
{
- Resource ref = method.getAnnotation(Resource.class);
+ Resource ref = container.getAnnotation(Resource.class, method);
if (ref == null) return;
log.trace("method " + method + " has @Resource");
@@ -317,7 +317,7 @@
public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
{
- Resource ref = field.getAnnotation(Resource.class);
+ Resource ref = container.getAnnotation(Resource.class, field);
if (ref == null) return;
log.trace("field " + field + " has @Resource");
More information about the jboss-cvs-commits
mailing list