[jboss-cvs] JBossAS SVN: r77860 - in projects/ejb3/trunk/interceptors/src: test/java/org/jboss/ejb3/test/interceptors/common/aop and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 3 13:59:17 EDT 2008
Author: wolfc
Date: 2008-09-03 13:59:17 -0400 (Wed, 03 Sep 2008)
New Revision: 77860
Added:
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/DoNotInvokeInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/InvocationCounterInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/DynamicLifecycleStackTestCase.java
Modified:
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java
projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml
Log:
EJBTHREE-1480: use stack named LifecycleCallbackStack to instantiate interceptor chain
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-09-03 17:55:34 UTC (rev 77859)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java 2008-09-03 17:59:17 UTC (rev 77860)
@@ -24,6 +24,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -33,11 +34,15 @@
import javax.ejb.PrePassivate;
import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.advice.AdviceStack;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.advice.PerVmAdvice;
import org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor;
import org.jboss.ejb3.interceptors.container.BeanContext;
import org.jboss.ejb3.interceptors.lang.ClassHelper;
+import org.jboss.logging.Logger;
/**
* The common logic for lifecycle callbacks.
@@ -47,13 +52,23 @@
*/
public class LifecycleCallbacks
{
+ private static final Logger log = Logger.getLogger(LifecycleCallbacks.class);
+
public static Interceptor[] createLifecycleCallbackInterceptors(Advisor advisor, List<Class<?>> lifecycleInterceptorClasses, BeanContext<?> component, Class<? extends Annotation> lifecycleAnnotationType) throws Exception
{
List<Interceptor> interceptors = new ArrayList<Interceptor>();
- // TODO: these should come from aop.xml
- interceptors.add(new CurrentInvocationInterceptor());
- interceptors.add(PerVmAdvice.generateInterceptor(null, new InvocationContextInterceptor(), "setup"));
+ AdviceStack stack = advisor.getManager().getAdviceStack("LifecycleCallbackStack");
+ if(stack == null)
+ {
+ log.warn("EJBTHREE-1480: LifecycleCallbackStack has not been defined for " + toString(advisor.getManager()));
+ interceptors.add(new CurrentInvocationInterceptor());
+ interceptors.add(PerVmAdvice.generateInterceptor(null, new InvocationContextInterceptor(), "setup"));
+ }
+ else
+ {
+ interceptors.addAll(Arrays.asList(stack.createInterceptors(advisor, null)));
+ }
// 12.7 footnote 57: ignore method level interceptors
// The lifecycle callbacks on the interceptors must be invoked in order
@@ -127,4 +142,11 @@
classes.add(m.getDeclaringClass());
return classes;
}
+
+ private static String toString(AspectManager manager)
+ {
+ if(manager instanceof Domain)
+ return "domain '" + ((Domain) manager).getDomainName() + "'";
+ return manager.toString();
+ }
}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/DoNotInvokeInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/DoNotInvokeInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/DoNotInvokeInterceptor.java 2008-09-03 17:59:17 UTC (rev 77860)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.aop;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DoNotInvokeInterceptor implements Interceptor
+{
+ public String getName()
+ {
+ return getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ throw new IllegalStateException("Do not invoke this interceptor");
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/InvocationCounterInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/InvocationCounterInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/common/aop/InvocationCounterInterceptor.java 2008-09-03 17:59:17 UTC (rev 77860)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.aop;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InvocationCounterInterceptor implements Interceptor
+{
+ public static int counter = 0;
+
+ public String getName()
+ {
+ return getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ counter++;
+ return invocation.invokeNext();
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/DynamicLifecycleStackTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/DynamicLifecycleStackTestCase.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/DynamicLifecycleStackTestCase.java 2008-09-03 17:59:17 UTC (rev 77860)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.lifecycle.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.aspects.common.AOPDeployer;
+import org.jboss.ejb3.interceptors.proxy.ProxyContainer;
+import org.jboss.ejb3.test.interceptors.common.aop.InvocationCounterInterceptor;
+import org.jboss.ejb3.test.interceptors.proxy.MyInterface;
+import org.jboss.ejb3.test.interceptors.proxy.ProxiedBean;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Make sure we can override the interceptor chain which gets invoked for
+ * lifecycle callbacks.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DynamicLifecycleStackTestCase
+{
+ private static final Logger log = Logger.getLogger(DynamicLifecycleStackTestCase.class);
+
+ private static AOPDeployer deployer = new AOPDeployer("proxy/jboss-aop.xml");
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception
+ {
+ log.info(deployer.deploy());
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception
+ {
+ log.info(deployer.undeploy());
+ }
+
+ @Before
+ public void setUp() throws Exception
+ {
+ InvocationCounterInterceptor.counter = 0;
+ }
+
+ @After
+ public void tearDown() throws Exception
+ {
+ }
+
+ @Test
+ public void test1() throws Throwable
+ {
+ Thread.currentThread().setContextClassLoader(MyInterface.class.getClassLoader());
+
+ ProxyContainer<ProxiedBean> container = new ProxyContainer<ProxiedBean>("ProxyTestCase", "InterceptorContainer", ProxiedBean.class);
+
+ Class<?> interfaces[] = { MyInterface.class };
+ MyInterface proxy = container.constructProxy(interfaces);
+
+ String result = proxy.sayHi("Me");
+ assertEquals("Hi Me", result);
+
+ assertEquals(1, InvocationCounterInterceptor.counter);
+ }
+}
Modified: projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml 2008-09-03 17:55:34 UTC (rev 77859)
+++ projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml 2008-09-03 17:59:17 UTC (rev 77860)
@@ -18,8 +18,24 @@
<!-- test only -->
<interceptor name="LoggingInterceptor" class="org.jboss.ejb3.test.interceptors.common.aop.LoggingInterceptor" scope="PER_VM"/>
+ <interceptor name="CurrentInvocation" class="org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor" scope="PER_VM"/>
+
+ <!-- define a stack outside of the domain -->
+ <stack name="LifecycleCallbackStack">
+ <interceptor-ref name="CurrentInvocation"/>
+ <advice name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor class="org.jboss.ejb3.test.interceptors.common.aop.DoNotInvokeInterceptor"/>
+ </stack>
+
<!-- TODO: this is actually the bootstrap container -->
<domain name="InterceptorContainer">
+ <!-- define a stack outside of the domain -->
+ <stack name="LifecycleCallbackStack">
+ <interceptor-ref name="CurrentInvocation"/>
+ <advice name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor class="org.jboss.ejb3.test.interceptors.common.aop.InvocationCounterInterceptor"/>
+ </stack>
+
<pointcut name="beanAroundInvokeCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.interceptor.AroundInvoke(..))"/>
<pointcut name="beanPostConstructCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.annotation.PostConstruct(..))"/>
<pointcut name="beanPreDestroyCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.annotation.PreDestroy(..))"/>
More information about the jboss-cvs-commits
mailing list