[jboss-cvs] JBossAS SVN: r96303 - in projects/ejb3/trunk/interceptors: src/main/java/org/jboss/ejb3/interceptors/direct and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 12 04:15:38 EST 2009
Author: wolfc
Date: 2009-11-12 04:15:37 -0500 (Thu, 12 Nov 2009)
New Revision: 96303
Added:
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/Dummy.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyContainerContainer.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyIndirectContainer.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/unit/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/unit/IndirectContainerTestCase.java
Modified:
projects/ejb3/trunk/interceptors/.classpath
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java
Log:
EJBTHREE-1952: fixed setting up the association from indirect container to direct container
Modified: projects/ejb3/trunk/interceptors/.classpath
===================================================================
--- projects/ejb3/trunk/interceptors/.classpath 2009-11-12 08:03:20 UTC (rev 96302)
+++ projects/ejb3/trunk/interceptors/.classpath 2009-11-12 09:15:37 UTC (rev 96303)
@@ -1,9 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
- <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
- <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
- <classpathentry kind="output" path="eclipse-target/classes"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
-</classpath>
\ No newline at end of file
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="eclipse-target/tests-classes" path="src/test/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="eclipse-target/tests-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="eclipse-target/classes"/>
+</classpath>
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java 2009-11-12 08:03:20 UTC (rev 96302)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java 2009-11-12 09:15:37 UTC (rev 96303)
@@ -27,10 +27,10 @@
import org.jboss.aop.ClassAdvisor;
import org.jboss.aop.Domain;
import org.jboss.aop.MethodInfo;
-import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.aop.util.MethodHashing;
import org.jboss.ejb3.interceptors.container.AbstractContainer;
import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
import org.jboss.ejb3.interceptors.lang.ClassHelper;
import org.jboss.ejb3.interceptors.registry.InterceptorRegistry;
import org.jboss.logging.Logger;
@@ -75,8 +75,9 @@
Constructor<T> constructor = advisor.getClazz().getConstructor(parameterTypes);
BeanContext<T> targetObject = construct(constructor, initargs);
- if(targetObject instanceof IndirectContainer)
- ((IndirectContainer<T, C>) targetObject).setDirectContainer((C) this);
+ // If we're advising an indirect container make it aware of this
+ if(targetObject.getInstance() instanceof IndirectContainer)
+ ((IndirectContainer<T, C>) targetObject.getInstance()).setDirectContainer((C) this);
return targetObject;
}
@@ -142,13 +143,13 @@
/**
* Do not call, for use in indirect container implementations.
*/
- public Object invokeIndirect(Object target, Method method, Object arguments[]) throws Throwable
+ public Object invokeIndirect(BeanContext<T> target, Method method, Object arguments[]) throws Throwable
{
long methodHash = MethodHashing.calculateHash(method);
MethodInfo info = getAdvisor().getMethodInfo(methodHash);
if(info == null)
throw new IllegalArgumentException("method " + method + " is not under advisement by " + this);
- MethodInvocation invocation = new MethodInvocation(info, info.getInterceptors())
+ ContainerMethodInvocation invocation = new ContainerMethodInvocation(info, info.getInterceptors())
{
@Override
public Object invokeTarget() throws Throwable
@@ -158,7 +159,7 @@
}
};
invocation.setArguments(arguments);
- invocation.setTargetObject(target);
+ invocation.setBeanContext(target);
return invocation.invokeNext();
}
}
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java 2009-11-12 08:03:20 UTC (rev 96302)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java 2009-11-12 09:15:37 UTC (rev 96303)
@@ -22,10 +22,11 @@
package org.jboss.ejb3.interceptors.direct;
/**
- * Comment
+ * An indirect container has advises itself, but delegates to a direct container
+ * to handle them.
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public interface IndirectContainer<T, C extends AbstractDirectContainer<T, C>>
{
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/Dummy.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/Dummy.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/Dummy.java 2009-11-12 09:15:37 UTC (rev 96303)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.interceptors.test.indirectcontainer;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Dummy
+{
+ void hit();
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyContainerContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyContainerContainer.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyContainerContainer.java 2009-11-12 09:15:37 UTC (rev 96303)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.interceptors.test.indirectcontainer;
+
+import org.jboss.ejb3.interceptors.direct.AbstractDirectContainer;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DummyContainerContainer extends AbstractDirectContainer<DummyIndirectContainer, DummyContainerContainer>
+{
+ public DummyContainerContainer(String name, String domainName, Class<? extends DummyIndirectContainer> beanClass)
+ {
+ super(name, domainName, beanClass);
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyIndirectContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyIndirectContainer.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyIndirectContainer.java 2009-11-12 09:15:37 UTC (rev 96303)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.interceptors.test.indirectcontainer;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import javax.interceptor.Interceptors;
+
+import org.jboss.ejb3.interceptors.ManagedObject;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.direct.IndirectContainer;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Interceptors(DummyInterceptor.class)
+ at ManagedObject
+public class DummyIndirectContainer implements IndirectContainer<DummyIndirectContainer, DummyContainerContainer>, InvocationHandler
+{
+ private DummyContainerContainer directContainer;
+ private BeanContext<DummyIndirectContainer> beanContext;
+
+ private static final Method INVOKE_METHOD;
+
+ static
+ {
+ try
+ {
+ INVOKE_METHOD = InvocationHandler.class.getDeclaredMethod("invoke", new Class<?>[] { Object.class, Method.class, new Object[0].getClass() });
+ }
+ catch (SecurityException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setBeanContext(BeanContext<DummyIndirectContainer> interceptorContainer)
+ {
+ this.beanContext = interceptorContainer;
+ }
+
+ public void setDirectContainer(DummyContainerContainer container)
+ {
+ this.directContainer = container;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ // I'm indirectly advised, let's delegate to the direct container
+ Object arguments[] = { method, args };
+ return directContainer.invokeIndirect(beanContext, INVOKE_METHOD, arguments);
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/DummyInterceptor.java 2009-11-12 09:15:37 UTC (rev 96303)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.interceptors.test.indirectcontainer;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DummyInterceptor
+{
+ private static int invocations = 0;
+
+ @AroundInvoke
+ public Object aroundInvoke(InvocationContext ctx) throws Exception
+ {
+ invocations++;
+ return ctx.proceed();
+ }
+
+ public static int getInvocations()
+ {
+ return invocations;
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/unit/IndirectContainerTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/unit/IndirectContainerTestCase.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/indirectcontainer/unit/IndirectContainerTestCase.java 2009-11-12 09:15:37 UTC (rev 96303)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.interceptors.test.indirectcontainer.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Proxy;
+
+import org.jboss.aspects.common.AOPDeployer;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.test.indirectcontainer.Dummy;
+import org.jboss.ejb3.interceptors.test.indirectcontainer.DummyContainerContainer;
+import org.jboss.ejb3.interceptors.test.indirectcontainer.DummyIndirectContainer;
+import org.jboss.ejb3.interceptors.test.indirectcontainer.DummyInterceptor;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class IndirectContainerTestCase
+{
+ private static final Logger log = Logger.getLogger(IndirectContainerTestCase.class);
+
+ private static AOPDeployer deployer = new AOPDeployer("proxy/jboss-aop.xml");
+
+ @AfterClass
+ public static void afterClass()
+ {
+ log.info(deployer.undeploy());
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ log.info(deployer.deploy());
+ }
+
+ @Test
+ public void test1() throws Exception
+ {
+ int previous = DummyInterceptor.getInvocations();
+
+ DummyContainerContainer containerContainer = new DummyContainerContainer("Test", "InterceptorContainer", DummyIndirectContainer.class);
+ BeanContext<DummyIndirectContainer> interceptorContainer = containerContainer.construct();
+ // TODO: why do we need this explicitly, can't the direct container handle this?
+ interceptorContainer.getInstance().setBeanContext(interceptorContainer);
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> interfaces[] = { Dummy.class };
+ Dummy dummy = (Dummy) Proxy.newProxyInstance(loader, interfaces, interceptorContainer.getInstance());
+ dummy.hit();
+
+ int current = DummyInterceptor.getInvocations();
+
+ assertEquals("DummyInterceptor was not hit", 1, current - previous);
+ }
+}
More information about the jboss-cvs-commits
mailing list