[jboss-cvs] JBossAS SVN: r72584 - in projects/ejb3/trunk/interceptors/src: main/java/org/jboss/ejb3/interceptors/lang and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 22 15:20:33 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-04-22 15:20:33 -0400 (Tue, 22 Apr 2008)
New Revision: 72584
Added:
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/AnnotatedOverrideBean.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/ClassOverrideInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/MethodOverrideInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlClassOverrideInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlMethodOverrideInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlOverrideBean.java
Modified:
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/unit/InheritanceTestCase.java
projects/ejb3/trunk/interceptors/src/test/resources/inheritance/META-INF/ejb-jar.xml
Log:
[EJBTHREE-1314] Test overridden interceptor/callback methods
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java 2008-04-22 18:19:10 UTC (rev 72583)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -93,10 +93,13 @@
ExtendedAdvisor interceptorAdvisor = ExtendedAdvisorHelper.getExtendedAdvisor(advisor);
for (Method interceptorMethod : ClassHelper.getAllMethods(interceptorClass))
{
- if (interceptorAdvisor
- .isAnnotationPresent(interceptorClass, interceptorMethod, AroundInvoke.class))
+ if (!ClassHelper.isOverridden(interceptorClass, interceptorMethod))
{
- interceptors.add(new EJB3InterceptorInterceptor(interceptorClass, interceptorMethod));
+ if (interceptorAdvisor
+ .isAnnotationPresent(interceptorClass, interceptorMethod, AroundInvoke.class))
+ {
+ interceptors.add(new EJB3InterceptorInterceptor(interceptorClass, interceptorMethod));
+ }
}
}
}
@@ -104,9 +107,12 @@
Class<?> beanClass = advisor.getClazz();
for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
{
- if(advisor.hasAnnotation(beanMethod, AroundInvoke.class))
+ if (!ClassHelper.isOverridden(beanClass, beanMethod))
{
- interceptors.add(new BusinessMethodBeanMethodInterceptor(beanMethod));
+ if(advisor.hasAnnotation(beanMethod, AroundInvoke.class))
+ {
+ interceptors.add(new BusinessMethodBeanMethodInterceptor(beanMethod));
+ }
}
}
return new InterceptorSequencer(interceptors);
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java 2008-04-22 18:19:10 UTC (rev 72583)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -24,8 +24,14 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+
import org.jboss.aop.Advisor;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.advice.PerVmAdvice;
@@ -42,6 +48,7 @@
{
public static Interceptor[] createLifecycleCallbackInterceptors(Advisor advisor, List<Class<?>> lifecycleInterceptorClasses, BeanContext<?> component, Class<? extends Annotation> lifecycleAnnotationType) throws Exception
{
+ HashSet<Class<?>> classes = new HashSet<Class<?>>();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
// 12.7 footnote 57: ignore method level interceptors
// The lifecycle callbacks on the interceptors must be invoked in order
@@ -51,9 +58,14 @@
ExtendedAdvisor interceptorAdvisor = ExtendedAdvisorHelper.getExtendedAdvisor(advisor, interceptor);
for(Method interceptorMethod : ClassHelper.getAllMethods(interceptorClass))
{
- if(interceptorAdvisor.isAnnotationPresent(interceptorClass, interceptorMethod, lifecycleAnnotationType))
+ if (!ClassHelper.isOverridden(interceptorClass, interceptorMethod))
{
- interceptors.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, interceptorMethod));
+ //Only a candidate for a lifecycle method if not overridden
+ if(interceptorAdvisor.isAnnotationPresent(interceptorClass, interceptorMethod, lifecycleAnnotationType)) //For Xml this returns true sometimes
+ {
+ checkClass(classes, interceptorMethod, advisor, lifecycleAnnotationType);
+ interceptors.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, interceptorMethod));
+ }
}
}
}
@@ -62,9 +74,13 @@
Class<?> beanClass = advisor.getClazz();
for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
{
- if(advisor.hasAnnotation(beanMethod, lifecycleAnnotationType))
+ if (!ClassHelper.isOverridden(beanClass, beanMethod))
{
- interceptors.add(new LifecycleCallbackBeanMethodInterceptor(beanMethod));
+ if(advisor.hasAnnotation(beanMethod, lifecycleAnnotationType))
+ {
+ checkClass(classes, beanMethod, advisor, lifecycleAnnotationType);
+ interceptors.add(new LifecycleCallbackBeanMethodInterceptor(beanMethod));
+ }
}
}
@@ -72,4 +88,30 @@
return interceptors.toArray(new Interceptor[0]);
}
+
+ private static void checkClass(HashSet<Class<?>> classes, Method m, Advisor advisor, Class<? extends Annotation> lifecycleAnnotationType)
+ {
+ if (classes.contains(m.getDeclaringClass()))
+ {
+ String type = null;
+ if (lifecycleAnnotationType == PostConstruct.class)
+ {
+ type = "post-construct";
+ }
+ else if (lifecycleAnnotationType == PreDestroy.class)
+ {
+ type = "pre-destroy";
+ }
+ else if (lifecycleAnnotationType == PostActivate.class)
+ {
+ type = "post-activate";
+ }
+ else if (lifecycleAnnotationType == PrePassivate.class)
+ {
+ type = "pre-passivate";
+ }
+ throw new RuntimeException("More than one '" + type + "' method in " + advisor.getName());
+ }
+ classes.add(m.getDeclaringClass());
+ }
}
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java 2008-04-22 18:19:10 UTC (rev 72583)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -82,6 +82,47 @@
}
/**
+ * Returns the method with the specified method name and parameters.
+ *
+ * @param cls
+ * @param methodName
+ * @param params
+ * @return
+ * @throws NoSuchMethodException
+ */
+ public static Method getMethod(Class<?> cls, String methodName, Class<?> ... params) throws NoSuchMethodException
+ {
+ if(cls == null)
+ {
+ throw new NoSuchMethodException("Class is null " + methodName);
+ }
+
+ Method m = getDeclaredMethod(cls, methodName, params);
+ if (m == null)
+ {
+ throw new NoSuchMethodException("No method named " + methodName + " in " + cls + " (or super classes)");
+ }
+ return m;
+ }
+
+ private static Method getDeclaredMethod(Class<?> cls, String methodName, Class<?> ... params)
+ {
+ try
+ {
+ return cls.getDeclaredMethod(methodName, params);
+ }
+ catch (NoSuchMethodException e1)
+ {
+ }
+
+ if (cls == Object.class)
+ {
+ return null;
+ }
+
+ return getDeclaredMethod(cls.getSuperclass(), methodName, params);
+ }
+ /**
* Returns all public, private and package protected methods including
* inherited ones in a map indexed by name.
*
@@ -125,4 +166,21 @@
for(Method method : cls.getDeclaredMethods())
methods.add(method);
}
+
+ public static boolean isOverridden(Class<?> icptr, Method method)
+ {
+ try
+ {
+ Method bottomMethod = getMethod(icptr, method.getName(), method.getParameterTypes());
+ if (bottomMethod.getDeclaringClass() == method.getDeclaringClass())
+ {
+ return false;
+ }
+ return true;
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/AnnotatedOverrideBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/AnnotatedOverrideBean.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/AnnotatedOverrideBean.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -0,0 +1,85 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.test.interceptors.inheritance;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+
+/**
+ * Overrides the interceptor and callback methods from the superclass
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Interceptors(ClassOverrideInterceptor.class)
+public class AnnotatedOverrideBean extends AnnotatedBean
+{
+ @Interceptors(MethodOverrideInterceptor.class)
+ public void method()
+ {
+
+ }
+
+ @AroundInvoke
+ @Override
+ public Object around(InvocationContext ctx) throws Exception
+ {
+ Interceptions.addAroundInvoke(AnnotatedOverrideBean.class);
+ return ctx.proceed();
+ }
+
+ @PostConstruct
+ @Override
+ public void postConstruct()
+ {
+ Interceptions.addPostConstruct(AnnotatedOverrideBean.class);
+ }
+
+ @PreDestroy
+ @Override
+ public void preDestroy()
+ {
+ Interceptions.addPreDestroy(AnnotatedOverrideBean.class);
+ }
+
+ @Override
+ public void basePostConstruct()
+ {
+ throw new RuntimeException("Should never get called");
+ }
+
+ @Override
+ public void basePreDestroy()
+ {
+ throw new RuntimeException("Should never get called");
+ }
+
+ @Override
+ public Object baseAround(InvocationContext ctx) throws Exception
+ {
+ throw new RuntimeException("Should never get called");
+ }
+
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/ClassOverrideInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/ClassOverrideInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/ClassOverrideInterceptor.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -0,0 +1,92 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.test.interceptors.inheritance;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * Overrides the interceptor and callback methods from the superclass
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassOverrideInterceptor extends ClassInterceptor
+{
+ @AroundInvoke
+ @Override
+ public Object around(InvocationContext ctx) throws Exception
+ {
+ Interceptions.addAroundInvoke(ClassOverrideInterceptor.class);
+ return ctx.proceed();
+ }
+
+ @PostConstruct
+ @Override
+ public void postConstruct(InvocationContext ctx)
+ {
+ try
+ {
+ Interceptions.addPostConstruct(ClassOverrideInterceptor.class);
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @PreDestroy
+ @Override
+ public void preDestroy(InvocationContext ctx)
+ {
+ try
+ {
+ Interceptions.addPreDestroy(ClassOverrideInterceptor.class);
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void basePostConstruct(InvocationContext ctx)
+ {
+ throw new RuntimeException("Should never get called");
+ }
+
+ @Override
+ public void basePreDestroy(InvocationContext ctx)
+ {
+ throw new RuntimeException("Should never get called");
+ }
+
+ @Override
+ public Object baseAround(InvocationContext ctx) throws Exception
+ {
+ throw new RuntimeException("Should never get called");
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/MethodOverrideInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/MethodOverrideInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/MethodOverrideInterceptor.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.test.interceptors.inheritance;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MethodOverrideInterceptor extends MethodInterceptor
+{
+ @AroundInvoke
+ @Override
+ public Object around(InvocationContext ctx) throws Exception
+ {
+ Interceptions.addAroundInvoke(MethodOverrideInterceptor.class);
+ return ctx.proceed();
+ }
+
+ @Override
+ public Object baseAround(InvocationContext ctx) throws Exception
+ {
+ throw new RuntimeException("Should never get called");
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlClassOverrideInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlClassOverrideInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlClassOverrideInterceptor.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -0,0 +1,68 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.test.interceptors.inheritance;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class XmlClassOverrideInterceptor extends XmlClassInterceptor
+{
+ @Override
+ public Object around(InvocationContext ctx) throws Exception
+ {
+ Interceptions.addAroundInvoke(XmlClassOverrideInterceptor.class);
+ return ctx.proceed();
+ }
+
+ @Override
+ public void postConstruct(InvocationContext ctx)
+ {
+ try
+ {
+ Interceptions.addPostConstruct(XmlClassOverrideInterceptor.class);
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void preDestroy(InvocationContext ctx)
+ {
+ try
+ {
+ Interceptions.addPreDestroy(XmlClassOverrideInterceptor.class);
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlMethodOverrideInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlMethodOverrideInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlMethodOverrideInterceptor.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.test.interceptors.inheritance;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class XmlMethodOverrideInterceptor extends XmlMethodInterceptor
+{
+ @AroundInvoke
+ @Override
+ public Object around(InvocationContext ctx) throws Exception
+ {
+ Interceptions.addAroundInvoke(XmlMethodOverrideInterceptor.class);
+ return ctx.proceed();
+ }
+
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlOverrideBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlOverrideBean.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/XmlOverrideBean.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -0,0 +1,58 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.test.interceptors.inheritance;
+
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class XmlOverrideBean extends XmlBean
+{
+ @Interceptors(MethodOverrideInterceptor.class)
+ public void method()
+ {
+
+ }
+
+ @Override
+ public Object around(InvocationContext ctx) throws Exception
+ {
+ Interceptions.addAroundInvoke(XmlOverrideBean.class);
+ return ctx.proceed();
+ }
+
+ @Override
+ public void postConstruct()
+ {
+ Interceptions.addPostConstruct(XmlOverrideBean.class);
+ }
+
+ @Override
+ public void preDestroy()
+ {
+ Interceptions.addPreDestroy(XmlOverrideBean.class);
+ }
+}
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/unit/InheritanceTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/unit/InheritanceTestCase.java 2008-04-22 18:19:10 UTC (rev 72583)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/inheritance/unit/InheritanceTestCase.java 2008-04-22 19:20:33 UTC (rev 72584)
@@ -37,7 +37,9 @@
import org.jboss.ejb3.metadata.annotation.AnnotationRepositoryToMetaData;
import org.jboss.ejb3.test.interceptors.inheritance.AnnotatedBase;
import org.jboss.ejb3.test.interceptors.inheritance.AnnotatedBean;
+import org.jboss.ejb3.test.interceptors.inheritance.AnnotatedOverrideBean;
import org.jboss.ejb3.test.interceptors.inheritance.ClassBaseInterceptor;
+import org.jboss.ejb3.test.interceptors.inheritance.ClassOverrideInterceptor;
import org.jboss.ejb3.test.interceptors.inheritance.ClassInterceptor;
import org.jboss.ejb3.test.interceptors.inheritance.Interceptions;
import org.jboss.ejb3.test.interceptors.inheritance.MethodBaseInterceptor;
@@ -47,8 +49,10 @@
import org.jboss.ejb3.test.interceptors.inheritance.XmlBean;
import org.jboss.ejb3.test.interceptors.inheritance.XmlClassBaseInterceptor;
import org.jboss.ejb3.test.interceptors.inheritance.XmlClassInterceptor;
+import org.jboss.ejb3.test.interceptors.inheritance.XmlClassOverrideInterceptor;
import org.jboss.ejb3.test.interceptors.inheritance.XmlMethodBaseInterceptor;
import org.jboss.ejb3.test.interceptors.inheritance.XmlMethodInterceptor;
+import org.jboss.ejb3.test.interceptors.inheritance.XmlOverrideBean;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
@@ -251,6 +255,58 @@
assertEquals(XmlBean.class, preDestroy.get(3));
}
+ public void testAnnotatedOverriddenMethods() throws Throwable
+ {
+ Thread.currentThread().setContextClassLoader(MyInterface.class.getClassLoader());
+
+ JBossEnterpriseBeanMetaData beanMetaData = getJBossEnterpriseBeanMetaData("AnnotatedOverrideBean");
+
+ MyContainer<AnnotatedOverrideBean> container = new MyContainer<AnnotatedOverrideBean>("AnnotatedOverrideBean", "Test", AnnotatedOverrideBean.class, beanMetaData);
+ container.testAdvisor();
+
+ Interceptions.clear();
+
+ BeanContext<AnnotatedOverrideBean> bean = container.construct();
+ ArrayList<Class<?>> postConstructs = Interceptions.getPostConstructs();
+ assertEquals("Wrong number of interceptions " + postConstructs, 2, postConstructs.size());
+ assertEquals(ClassOverrideInterceptor.class, postConstructs.get(0));
+ assertEquals(AnnotatedOverrideBean.class, postConstructs.get(1));
+
+ container.invoke(bean, "method");
+
+ container.destroy(bean);
+ ArrayList<Class<?>> preDestroy = Interceptions.getPreDestroys();
+ assertEquals("Wrong number of interceptions " + preDestroy, 2, preDestroy.size());
+ assertEquals(ClassOverrideInterceptor.class, postConstructs.get(0));
+ assertEquals(AnnotatedOverrideBean.class, postConstructs.get(1));
+ }
+
+ public void testXmlOverriddenMethods() throws Throwable
+ {
+ Thread.currentThread().setContextClassLoader(MyInterface.class.getClassLoader());
+
+ JBossEnterpriseBeanMetaData beanMetaData = getJBossEnterpriseBeanMetaData("XmlOverrideBean");
+
+ MyContainer<XmlOverrideBean> container = new MyContainer<XmlOverrideBean>("XmlOverrideBean", "Test", XmlOverrideBean.class, beanMetaData);
+ container.testAdvisor();
+
+ Interceptions.clear();
+
+ BeanContext<XmlOverrideBean> bean = container.construct();
+ ArrayList<Class<?>> postConstructs = Interceptions.getPostConstructs();
+ assertEquals("Wrong number of interceptions " + postConstructs, 2, postConstructs.size());
+ assertEquals(XmlClassOverrideInterceptor.class, postConstructs.get(0));
+ assertEquals(XmlOverrideBean.class, postConstructs.get(1));
+
+ container.invoke(bean, "method");
+
+ container.destroy(bean);
+ ArrayList<Class<?>> preDestroy = Interceptions.getPreDestroys();
+ assertEquals("Wrong number of interceptions " + preDestroy, 2, preDestroy.size());
+ assertEquals(XmlClassOverrideInterceptor.class, postConstructs.get(0));
+ assertEquals(XmlOverrideBean.class, postConstructs.get(1));
+ }
+
private JBossEnterpriseBeanMetaData getJBossEnterpriseBeanMetaData(String name) throws JBossXBException
{
// Bootstrap metadata
Modified: projects/ejb3/trunk/interceptors/src/test/resources/inheritance/META-INF/ejb-jar.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/inheritance/META-INF/ejb-jar.xml 2008-04-22 18:19:10 UTC (rev 72583)
+++ projects/ejb3/trunk/interceptors/src/test/resources/inheritance/META-INF/ejb-jar.xml 2008-04-22 19:20:33 UTC (rev 72584)
@@ -13,6 +13,9 @@
<ejb-name>AnnotatedBean</ejb-name>
</session>
<session>
+ <ejb-name>AnnotatedOverrideBean</ejb-name>
+ </session>
+ <session>
<ejb-name>XmlBean</ejb-name>
<around-invoke>
<method-name>baseAround</method-name>
@@ -33,6 +36,21 @@
<lifecycle-callback-method>preDestroy</lifecycle-callback-method>
</pre-destroy>
</session>
+ <session>
+ <ejb-name>XmlOverrideBean</ejb-name>
+ <around-invoke>
+ <method-name>baseAround</method-name>
+ </around-invoke>
+ <around-invoke>
+ <method-name>around</method-name>
+ </around-invoke>
+ <post-construct>
+ <lifecycle-callback-method>postConstruct</lifecycle-callback-method>
+ </post-construct>
+ <pre-destroy>
+ <lifecycle-callback-method>preDestroy</lifecycle-callback-method>
+ </pre-destroy>
+ </session>
</enterprise-beans>
<interceptors>
<interceptor>
@@ -65,6 +83,27 @@
<method-name>around</method-name>
</around-invoke>
</interceptor>
+ <interceptor>
+ <interceptor-class>org.jboss.ejb3.test.interceptors.inheritance.XmlClassOverrideInterceptor</interceptor-class>
+ <around-invoke>
+ <method-name>baseAround</method-name>
+ </around-invoke>
+ <around-invoke>
+ <method-name>around</method-name>
+ </around-invoke>
+ <post-construct>
+ <lifecycle-callback-method>postConstruct</lifecycle-callback-method>
+ </post-construct>
+ <pre-destroy>
+ <lifecycle-callback-method>preDestroy</lifecycle-callback-method>
+ </pre-destroy>
+ </interceptor>
+ <interceptor>
+ <interceptor-class>org.jboss.ejb3.test.interceptors.inheritance.XmlMethodOverrideInterceptor</interceptor-class>
+ <around-invoke>
+ <method-name>around</method-name>
+ </around-invoke>
+ </interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
@@ -78,5 +117,16 @@
<method-name>method</method-name>
</method>
</interceptor-binding>
+ <interceptor-binding>
+ <ejb-name>XmlOverrideBean</ejb-name>
+ <interceptor-class>org.jboss.ejb3.test.interceptors.inheritance.XmlClassOverrideInterceptor</interceptor-class>
+ </interceptor-binding>
+ <interceptor-binding>
+ <ejb-name>XmlOverrideBean</ejb-name>
+ <interceptor-class>org.jboss.ejb3.test.interceptors.inheritance.XmlMethodOverrideInterceptor</interceptor-class>
+ <method>
+ <method-name>method</method-name>
+ </method>
+ </interceptor-binding>
</assembly-descriptor>
</ejb-jar>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list