[jboss-cvs] JBossAS SVN: r68651 - in projects/ejb3/trunk/sandbox: src/main/java/org/jboss/ejb3/sandbox and 10 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jan 7 10:04:24 EST 2008
Author: wolfc
Date: 2008-01-07 10:04:24 -0500 (Mon, 07 Jan 2008)
New Revision: 68651
Added:
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/BusinessMethodInterceptorMethodInterceptor.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainerInterceptorsExecutor.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainersInterceptorsInterceptor.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/InterceptorInvoker.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/LifecycleCallbackInterceptorMethodInterceptor.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/DirectContainer.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/IndirectContainer.java
projects/ejb3/trunk/sandbox/src/test/resources/stateless/
projects/ejb3/trunk/sandbox/src/test/resources/stateless/jboss-aop.xml
Modified:
projects/ejb3/trunk/sandbox/.classpath
projects/ejb3/trunk/sandbox/pom.xml
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/InterceptorContainer.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/local/LocalBusinessInterfaceInterceptor.java
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/stateless/SimpleStatelessBean.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/stateless/unit/SimpleStatelessUnitTestCase.java
projects/ejb3/trunk/sandbox/src/test/resources/log4j.xml
Log:
Using ejb3-interceptors and prototype direct container
Modified: projects/ejb3/trunk/sandbox/.classpath
===================================================================
--- projects/ejb3/trunk/sandbox/.classpath 2008-01-07 11:08:50 UTC (rev 68650)
+++ projects/ejb3/trunk/sandbox/.classpath 2008-01-07 15:04:24 UTC (rev 68651)
@@ -4,18 +4,31 @@
<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="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.1.GA/jboss-common-core-2.2.1.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.1.GA/jboss-common-core-2.2.1.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/aop/jboss-aop/2.0.0.beta1/jboss-aop-2.0.0.beta1.jar" sourcepath="M2_REPO/org/jboss/aop/jboss-aop/2.0.0.beta1/jboss-aop-2.0.0.beta1-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jboss/javaee/jboss-transaction-api/1.0.1.20070913080910/jboss-transaction-api-1.0.1.20070913080910.jar" sourcepath="M2_REPO/org/jboss/javaee/jboss-transaction-api/1.0.1.20070913080910/jboss-transaction-api-1.0.1.20070913080910-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/ejb3/jboss-ejb3-pool/0.11.0-SNAPSHOT/jboss-ejb3-pool-0.11.0-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/ejb3/jboss-ejb3-pool/0.12.0-SNAPSHOT/jboss-ejb3-pool-0.12.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/jboss/ejb3/jboss-ejb3-pool/0.12.0-SNAPSHOT/jboss-ejb3-pool-0.12.0-SNAPSHOT-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.0.2/activation-1.0.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/trove/trove/1.0.2/trove-1.0.2.jar"/>
<classpathentry kind="var" path="M2_REPO/oswego-concurrent/concurrent/1.3.4/concurrent-1.3.4.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/javassist/3.6.0.GA/javassist-3.6.0.GA.jar" sourcepath="M2_REPO/org/jboss/javassist/3.6.0.GA/javassist-3.6.0.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jnpserver/5.0.0.Beta3/jnpserver-5.0.0.Beta3.jar" sourcepath="M2_REPO/org/jboss/jnpserver/5.0.0.Beta3/jnpserver-5.0.0.Beta3-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/ejb3/jboss-ejb3-interceptors/0.12.0-SNAPSHOT/jboss-ejb3-interceptors-0.12.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/jboss/ejb3/jboss-ejb3-interceptors/0.12.0-SNAPSHOT/jboss-ejb3-interceptors-0.12.0-SNAPSHOT-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-container/2.0.0.Beta8/jboss-container-2.0.0.Beta8.jar" sourcepath="M2_REPO/org/jboss/microcontainer/jboss-container/2.0.0.Beta8/jboss-container-2.0.0.Beta8-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/qdox/qdox/1.6/qdox-1.6.jar" sourcepath="M2_REPO/qdox/qdox/1.6/qdox-1.6-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar" sourcepath="M2_REPO/ant/ant/1.6.5/ant-1.6.5-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jbossws/jboss-jaxrpc/1.0.4.GA/jboss-jaxrpc-1.0.4.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.8/log4j-1.2.8.jar"/>
+ <classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
<classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.8/log4j-1.2.8.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jnpserver/5.0.0-SNAPSHOT/jnpserver-5.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/jboss/jnpserver/5.0.0-SNAPSHOT/jnpserver-5.0.0-SNAPSHOT-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jbossws/jboss-jaxrpc/1.0.4.GA/jboss-jaxrpc-1.0.4.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/javaee/jboss-ejb-api/3.0.0.20070913080910/jboss-ejb-api-3.0.0.20070913080910.jar" sourcepath="M2_REPO/org/jboss/javaee/jboss-ejb-api/3.0.0.20070913080910/jboss-ejb-api-3.0.0.20070913080910-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-core/2.0.2.GA/jboss-common-core-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-core/2.0.2.GA/jboss-common-core-2.0.2.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/javaee/jboss-ejb-api/3.0.0.20070913080910/jboss-ejb-api-3.0.0.20070913080910.jar" sourcepath="M2_REPO/org/jboss/javaee/jboss-ejb-api/3.0.0.20070913080910/jboss-ejb-api-3.0.0.20070913080910-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.0.CR4/jbossxb-2.0.0.CR4.jar" sourcepath="M2_REPO/org/jboss/jbossxb/2.0.0.CR4/jbossxb-2.0.0.CR4-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA-sources.jar"/>
</classpath>
\ No newline at end of file
Modified: projects/ejb3/trunk/sandbox/pom.xml
===================================================================
--- projects/ejb3/trunk/sandbox/pom.xml 2008-01-07 11:08:50 UTC (rev 68650)
+++ projects/ejb3/trunk/sandbox/pom.xml 2008-01-07 15:04:24 UTC (rev 68651)
@@ -20,6 +20,10 @@
<!-- internal -->
<dependency>
<groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-interceptors</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-pool</artifactId>
</dependency>
Modified: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/InterceptorContainer.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/InterceptorContainer.java 2008-01-07 11:08:50 UTC (rev 68650)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/InterceptorContainer.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -23,18 +23,16 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.annotation.PostConstruct;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.InvocationContext;
+import javax.interceptor.Interceptors;
+import org.jboss.aop.Advised;
+import org.jboss.ejb3.interceptors.ManagedObject;
+import org.jboss.ejb3.sandbox.interceptorcontainer.impl.ContainersInterceptorsInterceptor;
+import org.jboss.ejb3.sandbox.interceptors.direct.DirectContainer;
+import org.jboss.ejb3.sandbox.interceptors.direct.IndirectContainer;
+
/**
* An interceptor container keeps track of container interceptors
* on a class.
@@ -42,85 +40,30 @@
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
* @version $Revision: $
*/
-public class InterceptorContainer implements AnnotatedElement
+ at Interceptors(ContainersInterceptorsInterceptor.class)
+ at ManagedObject
+public class InterceptorContainer implements AnnotatedElement, IndirectContainer<InterceptorContainer>
{
private Class<?> beanClass;
private Object[] interceptors;
+ private DirectContainer<InterceptorContainer> directContainer;
- public class BeanClassInvocationContext implements InvocationContext
+ private static final Method INVOKE_METHOD;
+
+ static
{
- private Class<? extends Annotation> annotationClass;
- private Method method;
- private Object args[];
-
- private Map<String, Object> contextData = new HashMap<String, Object>();
-
- private Iterator<Object> it = Arrays.asList(interceptors).iterator();
-
- protected BeanClassInvocationContext(Class<? extends Annotation> annotationClass)
+ try
{
- assert annotationClass != null : "annotationClass is null";
-
- this.annotationClass = annotationClass;
+ INVOKE_METHOD = InterceptorContainer.class.getDeclaredMethod("invoke", new Class<?>[] { Method.class, new Object[0].getClass() });
}
-
- protected BeanClassInvocationContext(Class<? extends Annotation> annotationClass, Method method, Object args[])
+ catch (SecurityException e)
{
- this(annotationClass);
-
- assert method != null : "method is null";
- assert args != null : "args is null";
-
- this.method = method;
- this.args = args;
+ throw new RuntimeException(e);
}
-
- public Map<String, Object> getContextData()
+ catch (NoSuchMethodException e)
{
- // Must not return null
- return contextData;
+ throw new RuntimeException(e);
}
-
- public Method getMethod()
- {
- // For lifecycle callback methods, returns null
-
- return method;
- }
-
- public Object[] getParameters()
- {
- if(method == null && args == null)
- {
- // If invoked in a lifecycle callback
- throw new IllegalStateException();
- }
- return args;
- }
-
- public InterceptorContainer getTarget()
- {
- return InterceptorContainer.this;
- }
-
- public Object proceed() throws Exception
- {
- if(!it.hasNext())
- return null;
- Object interceptor = it.next();
- Method callback = findMethod(interceptor.getClass(), annotationClass);
- if(callback == null)
- return proceed();
- Object args[] = { BeanClassInvocationContext.this };
- return callback.invoke(interceptor, args);
- }
-
- public void setParameters(Object[] params)
- {
- // If invoked in a lifecycle callback
- throw new IllegalStateException();
- }
-
}
public InterceptorContainer(Class<?> beanClass) throws Exception
@@ -128,23 +71,6 @@
assert beanClass != null;
this.beanClass = beanClass;
-
- // TODO: use a delegate to get annotations (so we can hook into meta data)
- ContainerInterceptors interceptors = beanClass.getAnnotation(ContainerInterceptors.class);
- if(interceptors == null)
- throw new IllegalArgumentException("Class " + beanClass + " doesn't have any container interceptors");
-
- Class<?> interceptorClasses[] = interceptors.value();
- this.interceptors = new Object[interceptorClasses.length];
- for(int i = 0; i < interceptorClasses.length; i++)
- {
- this.interceptors[i] = interceptorClasses[i].newInstance();
- }
-
- // TODO: inject interceptors
-
- // Post construct
- new BeanClassInvocationContext(PostConstruct.class).proceed();
}
private static <A extends Annotation> Method findMethod(Class<?> cls, Class<A> annotationClass)
@@ -168,8 +94,30 @@
public Object invoke(Method method, Object[] args) throws Throwable
{
- return new BeanClassInvocationContext(AroundInvoke.class, method, args).proceed();
+ //return new BeanClassInvocationContext(AroundInvoke.class, method, args).proceed();
+ //throw new RuntimeException("Interceptor chain does not contain an instance interceptor");
+ // TODO: I actually want to invoke the direct container if we're not already running a chain
+ // and then continue invocation if we are.
+ // I can run in two modes: direct advisement or indirect advisement
+ if(directContainer != null)
+ {
+ // I'm indirectly advised, let's delegate to the direct container
+ Object arguments[] = { method, args };
+ return directContainer.invokeIndirect(this, INVOKE_METHOD, arguments);
+ }
+ else
+ {
+ // I'm directly advised
+ assert this instanceof Advised;
+ return null;
+ }
}
+
+ public void setDirectContainer(DirectContainer<InterceptorContainer> container)
+ {
+ assert container != null : "directContainer is null";
+ this.directContainer = container;
+ }
/*
* Helpers
@@ -190,8 +138,18 @@
return beanClass.getAnnotations();
}
+ public boolean isAnnotationPresent(Class<?> cls, Class<? extends Annotation> annotationClass)
+ {
+ return cls.isAnnotationPresent(annotationClass);
+ }
+
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
{
return beanClass.isAnnotationPresent(annotationClass);
}
+
+ public boolean isAnnotationPresent(Method method, Class<? extends Annotation> annotationClass)
+ {
+ return method.isAnnotationPresent(annotationClass);
+ }
}
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/BusinessMethodInterceptorMethodInterceptor.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/BusinessMethodInterceptorMethodInterceptor.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/BusinessMethodInterceptorMethodInterceptor.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.sandbox.interceptorcontainer.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * Chapter 12.3
+ *
+ * AroundInvoke methods have the following signature:
+ * Object <METHOD>(InvocationContext) throws Exception
+ *
+ * FIXME: merge with org.jboss.ejb3.interceptors.aop.BusinessMethodInterceptorMethodInterceptor
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class BusinessMethodInterceptorMethodInterceptor implements InterceptorInvoker
+{
+ private static final Class<?> PARAMETER_TYPES[] = { InvocationContext.class };
+
+ private Object interceptor;
+ private Method method;
+
+ /**
+ *
+ * @param interceptor an spec interceptor
+ * @param businessMethodInterceptorMethod a business method interceptor on the spec interceptor
+ */
+ public BusinessMethodInterceptorMethodInterceptor(Object interceptor, Method businessMethodInterceptorMethod)
+ {
+ assert interceptor != null : "interceptor is null";
+ assert businessMethodInterceptorMethod != null : "businessMethodInterceptorMethod is null";
+ assert businessMethodInterceptorMethod.getReturnType() == Object.class : "return type must be Object " + businessMethodInterceptorMethod;
+ assert Arrays.equals(businessMethodInterceptorMethod.getParameterTypes(), PARAMETER_TYPES) : "wrong parameter signature";
+ // Ignore throw clause
+
+ this.interceptor = interceptor;
+ this.method = businessMethodInterceptorMethod;
+ }
+
+ public String getName()
+ {
+ return "BusinessMethodInterceptorMethodInterceptor";
+ }
+
+ public Object invoke(final InvocationContext ctx) throws Exception
+ {
+ try
+ {
+ Object args[] = { ctx };
+ return method.invoke(interceptor, args);
+ }
+ catch(IllegalArgumentException e)
+ {
+ throw new IllegalArgumentException(e.getMessage() + " for " + method);
+ }
+ catch(InvocationTargetException e)
+ {
+ Throwable cause = e.getCause();
+ if(cause instanceof Error)
+ throw (Error) cause;
+ if(cause instanceof RuntimeException)
+ throw (RuntimeException) cause;
+ throw e;
+ }
+ }
+
+ public String toString()
+ {
+ return method.toString();
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/BusinessMethodInterceptorMethodInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainerInterceptorsExecutor.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainerInterceptorsExecutor.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainerInterceptorsExecutor.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.sandbox.interceptorcontainer.impl;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.interceptors.lang.ClassHelper;
+import org.jboss.ejb3.sandbox.interceptorcontainer.InterceptorContainer;
+import org.jboss.logging.Logger;
+
+/**
+ * This is the runtime representation of ContainerInterceptors
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ContainerInterceptorsExecutor
+{
+ private static final Logger log = Logger.getLogger(ContainerInterceptorsExecutor.class);
+
+ private List<InterceptorInvoker> preDestroys = new ArrayList<InterceptorInvoker>();
+ private List<InterceptorInvoker> postConstructs = new ArrayList<InterceptorInvoker>();
+ private List<InterceptorInvoker> classInterceptors = new ArrayList<InterceptorInvoker>();
+
+ private static class SubInvocationContext implements InvocationContext
+ {
+ private InvocationContext original;
+ private Iterator<InterceptorInvoker> it;
+
+ protected SubInvocationContext(InvocationContext original, List<InterceptorInvoker> interceptors)
+ {
+ assert original != null : "original is null";
+ assert interceptors != null : "interceptors is null";
+
+ this.original = original;
+ this.it = interceptors.iterator();
+ }
+
+ public Map<String, Object> getContextData()
+ {
+ return original.getContextData();
+ }
+
+ public Method getMethod()
+ {
+ return original.getMethod();
+ }
+
+ public Object[] getParameters()
+ {
+ return original.getParameters();
+ }
+
+ public Object getTarget()
+ {
+ return original.getTarget();
+ }
+
+ public Object proceed() throws Exception
+ {
+ if(!it.hasNext())
+ return original.proceed();
+ InterceptorInvoker interceptor = it.next();
+ return interceptor.invoke(this);
+ }
+
+ public void setParameters(Object[] params)
+ {
+ original.setParameters(params);
+ }
+
+ @Override
+ public String toString()
+ {
+ return original.toString();
+ }
+ }
+
+ protected ContainerInterceptorsExecutor(InterceptorContainer container, Class<?> interceptorClasses[]) throws InstantiationException, IllegalAccessException
+ {
+ assert container != null : "container is null";
+ assert interceptorClasses != null : "interceptorClasses is null";
+ Object interceptors[] = new Object[interceptorClasses.length];
+ for(int i = 0; i < interceptorClasses.length; i++)
+ {
+ Class<?> interceptorClass = interceptorClasses[i];
+ Object interceptor = interceptors[i] = interceptorClass.newInstance();
+ for(Method method : ClassHelper.getAllMethods(interceptorClass))
+ {
+ if(container.isAnnotationPresent(method, PreDestroy.class))
+ {
+ preDestroys.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, method));
+ }
+ if(container.isAnnotationPresent(method, PostConstruct.class))
+ {
+ postConstructs.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, method));
+ }
+ if(container.isAnnotationPresent(method, AroundInvoke.class))
+ {
+ classInterceptors.add(new BusinessMethodInterceptorMethodInterceptor(interceptor, method));
+ }
+ }
+ }
+ log.debug("preDestroys = " + preDestroys);
+ log.debug("postConstructs = " + postConstructs);
+ log.debug("classInterceptors = " + classInterceptors);
+ }
+
+ protected Object aroundInvoke(InvocationContext ctx) throws Exception
+ {
+ SubInvocationContext subCtx = new SubInvocationContext(ctx, classInterceptors);
+ return subCtx.proceed();
+ }
+
+ protected void preDestroy(InvocationContext ctx) throws Exception
+ {
+ SubInvocationContext subCtx = new SubInvocationContext(ctx, preDestroys);
+ subCtx.proceed();
+ }
+
+ protected void postConstruct(InvocationContext ctx) throws Exception
+ {
+ SubInvocationContext subCtx = new SubInvocationContext(ctx, postConstructs);
+ subCtx.proceed();
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainerInterceptorsExecutor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainersInterceptorsInterceptor.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainersInterceptorsInterceptor.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainersInterceptorsInterceptor.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.sandbox.interceptorcontainer.impl;
+
+import java.util.Arrays;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.sandbox.interceptorcontainer.ContainerInterceptors;
+import org.jboss.ejb3.sandbox.interceptorcontainer.InterceptorContainer;
+import org.jboss.logging.Logger;
+
+/**
+ * This is the interceptor that checks for ContainerInterceptors
+ * and executes them.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ContainersInterceptorsInterceptor
+{
+ private static final Logger log = Logger.getLogger(ContainersInterceptorsInterceptor.class);
+
+ private ContainerInterceptorsExecutor executor;
+
+ @AroundInvoke
+ public Object arroundInvoke(InvocationContext ctx) throws Exception
+ {
+ log.debug("ctx = " + ctx);
+ return executor.aroundInvoke(ctx);
+ }
+
+ // FIXME: should be protected (bug in ejb3-interceptors)
+ @PostConstruct
+ public void postConstruct(InvocationContext ctx) throws Exception
+ {
+ InterceptorContainer container = (InterceptorContainer) ctx.getTarget();
+ ContainerInterceptors containerInterceptors = container.getAnnotation(ContainerInterceptors.class);
+ if(containerInterceptors != null)
+ {
+ log.debug("containerInterceptors = " + Arrays.toString(containerInterceptors.value()));
+ //throw new RuntimeException("NYI");
+ //container.addInterceptors(containerInterceptors.value());
+ executor = new ContainerInterceptorsExecutor(container, containerInterceptors.value());
+ executor.postConstruct(ctx);
+ }
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/ContainersInterceptorsInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/InterceptorInvoker.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/InterceptorInvoker.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/InterceptorInvoker.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.sandbox.interceptorcontainer.impl;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface InterceptorInvoker
+{
+ Object invoke(InvocationContext ctx) throws Exception;
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/InterceptorInvoker.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/LifecycleCallbackInterceptorMethodInterceptor.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/LifecycleCallbackInterceptorMethodInterceptor.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/LifecycleCallbackInterceptorMethodInterceptor.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.sandbox.interceptorcontainer.impl;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * Chapter 12.4
+ *
+ * Lifecycle callback interceptor methods defined on an interceptor class have the following signature:
+ * void <METHOD> (InvocationContext)
+ *
+ * FIXME: merge with org.jboss.ejb3.interceptors.aop.LifecycleCallbackInterceptorMethodInterceptor
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class LifecycleCallbackInterceptorMethodInterceptor implements InterceptorInvoker
+{
+ private static final Class<?> PARAMETER_TYPES[] = { InvocationContext.class };
+
+ private Object interceptor;
+ private Method method;
+
+ /**
+ *
+ * @param interceptor an spec interceptor
+ * @param lifecycleCallbackMethod a lifecycle callback on the spec interceptor
+ */
+ public LifecycleCallbackInterceptorMethodInterceptor(Object interceptor, Method lifecycleCallbackMethod)
+ {
+ assert interceptor != null : "interceptor is null";
+ assert lifecycleCallbackMethod != null : "lifecycleCallbackMethod is null";
+ assert lifecycleCallbackMethod.getReturnType() == Void.TYPE : "return type must be void " + lifecycleCallbackMethod;
+ assert Arrays.equals(lifecycleCallbackMethod.getParameterTypes(), PARAMETER_TYPES) : "wrong parameter signature";
+
+ this.interceptor = interceptor;
+ this.method = lifecycleCallbackMethod;
+ }
+
+ public String getName()
+ {
+ return "InvokeCallbackInterceptorMethodInterceptor";
+ }
+
+ public Object invoke(final InvocationContext ctx) throws Exception
+ {
+ Object args[] = { ctx };
+ method.invoke(interceptor, args);
+ // TODO: return null or invokeTarget?
+ return ctx.proceed();
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptorcontainer/impl/LifecycleCallbackInterceptorMethodInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/DirectContainer.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/DirectContainer.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/DirectContainer.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.sandbox.interceptors.direct;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.DomainDefinition;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.ConstructionInvocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.interceptors.proxy.aop.ManagedObjectContainer;
+import org.jboss.logging.Logger;
+
+/**
+ * The direct container invokes interceptors directly on an instance.
+ *
+ * It's useful in an environment where we don't want to fiddle with the
+ * classloader and still have control on how instances are called.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DirectContainer<T>
+{
+ private static final Logger log = Logger.getLogger(DirectContainer.class);
+
+ private ManagedObjectContainer advisor;
+
+ public DirectContainer(String name, Domain domain, Class<? extends T> beanClass)
+ {
+ assert name != null : "name is null";
+ assert domain != null : "domain is null";
+ assert beanClass != null : "beanClass is null";
+
+ this.advisor = new ManagedObjectContainer(name, domain, beanClass);
+ }
+
+ public DirectContainer(String name, String domainName, Class<? extends T> beanClass)
+ {
+ this(name, getDomain(domainName), beanClass);
+ }
+
+ public T construct() throws SecurityException, NoSuchMethodException
+ {
+ return construct(null, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public T construct(Object initargs[], Class<?> parameterTypes[]) throws SecurityException, NoSuchMethodException
+ {
+ Constructor<T> constructor = advisor.getClazz().getConstructor(parameterTypes);
+ int idx = advisor.getConstructorIndex(constructor);
+ assert idx != -1 : "can't find constructor in the advisor";
+ try
+ {
+ T targetObject = (T) advisor.invokeNew(initargs, idx);
+
+ Interceptor interceptors[] = advisor.getConstructionInfos()[idx].getInterceptors();
+ ConstructionInvocation invocation = new ConstructionInvocation(interceptors, constructor, initargs);
+ invocation.setAdvisor(advisor);
+ invocation.setTargetObject(targetObject);
+ invocation.invokeNext();
+
+ if(targetObject instanceof IndirectContainer)
+ ((IndirectContainer<T>) targetObject).setDirectContainer(this);
+
+ return targetObject;
+ }
+ catch(Throwable t)
+ {
+ // TODO: disect
+ if(t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ throw new RuntimeException(t);
+ }
+ }
+
+ /**
+ * Do not call, for use in indirect container implementations.
+ * @return
+ */
+ public Class<?> getBeanClass()
+ {
+ return advisor.getClazz();
+ }
+
+ /*
+ * TODO: this should not be here, it's an AspectManager helper function.
+ */
+ private static final Domain getDomain(String domainName)
+ {
+ DomainDefinition domainDefinition = AspectManager.instance().getContainer(domainName);
+ if(domainDefinition == null)
+ throw new IllegalArgumentException("Domain definition '" + domainName + "' can not be found");
+
+ final Domain domain = (Domain) domainDefinition.getManager();
+ return domain;
+ }
+
+ // FIXME: copy of ProxyContainer.invoke
+ public Object invoke(Object target, Method method, Object arguments[]) throws Throwable
+ {
+ long methodHash = MethodHashing.calculateHash(method);
+ MethodInfo info = advisor.getMethodInfo(methodHash);
+ if(info == null)
+ throw new IllegalArgumentException("method " + method + " is not under advisement by " + this);
+ MethodInvocation invocation = new MethodInvocation(info, info.getInterceptors());
+ invocation.setArguments(arguments);
+ invocation.setTargetObject(target);
+ return invocation.invokeNext();
+ }
+
+ public Object invokeIndirect(Object target, Method method, Object arguments[]) throws Throwable
+ {
+ long methodHash = MethodHashing.calculateHash(method);
+ MethodInfo info = advisor.getMethodInfo(methodHash);
+ if(info == null)
+ throw new IllegalArgumentException("method " + method + " is not under advisement by " + this);
+ MethodInvocation invocation = new MethodInvocation(info, info.getInterceptors())
+ {
+ @Override
+ public Object invokeTarget() throws Throwable
+ {
+ // TODO: invoke the real target in special modus
+ return null;
+ }
+ };
+ invocation.setArguments(arguments);
+ invocation.setTargetObject(target);
+ return invocation.invokeNext();
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/DirectContainer.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/IndirectContainer.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/IndirectContainer.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/IndirectContainer.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.sandbox.interceptors.direct;
+
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface IndirectContainer<T>
+{
+ void setDirectContainer(DirectContainer<T> container);
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/IndirectContainer.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/local/LocalBusinessInterfaceInterceptor.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/local/LocalBusinessInterfaceInterceptor.java 2008-01-07 11:08:50 UTC (rev 68650)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/local/LocalBusinessInterfaceInterceptor.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -45,26 +45,27 @@
private static final Logger log = Logger.getLogger(LocalBusinessInterfaceInterceptor.class);
@PostConstruct
- public void postConstruct(InterceptorContainer.BeanClassInvocationContext ctx) throws Exception
+ public void postConstruct(InvocationContext ctx) throws Exception
{
log.debug("postConstruct " + ctx);
Class<?> businessInterfaces[];
- Local local = ctx.getTarget().getAnnotation(Local.class);
+ InterceptorContainer container = (InterceptorContainer) ctx.getTarget();
+ Local local = container.getAnnotation(Local.class);
if(local != null)
businessInterfaces = local.value();
- else if(ctx.getTarget().getBeanClass().getInterfaces().length == 1)
- businessInterfaces = new Class<?>[] { ctx.getTarget().getBeanClass().getInterfaces()[0] };
+ else if(container.getBeanClass().getInterfaces().length == 1)
+ businessInterfaces = new Class<?>[] { container.getBeanClass().getInterfaces()[0] };
else
throw new IllegalArgumentException("TODO");
// TODO: determine JNDI name
- String jndiName = ctx.getTarget().getBeanClass().getSimpleName() + "/local";
+ String jndiName = container.getBeanClass().getSimpleName() + "/local";
log.debug("jndiName = " + jndiName);
- Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), businessInterfaces, new LocalProxy(ctx.getTarget()));
+ Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), businessInterfaces, new LocalProxy(container));
- Util.createSubcontext(new InitialContext(), ctx.getTarget().getBeanClass().getSimpleName());
+ Util.createSubcontext(new InitialContext(), container.getBeanClass().getSimpleName());
NonSerializableFactory.rebind(new InitialContext(), jndiName, proxy);
ctx.proceed();
Modified: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java 2008-01-07 11:08:50 UTC (rev 68650)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -21,9 +21,13 @@
*/
package org.jboss.ejb3.sandbox.stateless;
+import java.lang.reflect.Method;
+
import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
import org.jboss.ejb3.sandbox.interceptorcontainer.InterceptorContainer;
+import org.jboss.logging.Logger;
/**
* Comment
@@ -33,12 +37,18 @@
*/
public class StatelessInterceptor
{
+ private static final Logger log = Logger.getLogger(StatelessInterceptor.class);
+
@AroundInvoke
- public Object invoke(InterceptorContainer.BeanClassInvocationContext ctx) throws Exception
+ public Object invoke(InvocationContext ctx) throws Exception
{
// TODO: a lot, the pool should be here
- Object instance = ctx.getTarget().getBeanClass().newInstance();
- Object result = ctx.getMethod().invoke(instance, ctx.getParameters());
+ InterceptorContainer container = (InterceptorContainer) ctx.getTarget();
+ Object instance = container.getBeanClass().newInstance();
+ log.debug("ctx = " + ctx);
+ Method method = (Method) ctx.getParameters()[0];
+ Object args[] = (Object[]) ctx.getParameters()[1];
+ Object result = method.invoke(instance, args);
ctx.proceed();
return result;
}
Modified: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/stateless/SimpleStatelessBean.java
===================================================================
Modified: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/stateless/unit/SimpleStatelessUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/stateless/unit/SimpleStatelessUnitTestCase.java 2008-01-07 11:08:50 UTC (rev 68650)
+++ projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/stateless/unit/SimpleStatelessUnitTestCase.java 2008-01-07 15:04:24 UTC (rev 68651)
@@ -21,15 +21,20 @@
*/
package org.jboss.ejb3.test.sandbox.stateless.unit;
+import java.net.URL;
+
import javax.naming.InitialContext;
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectXmlLoader;
import org.jboss.ejb3.sandbox.interceptorcontainer.InterceptorContainer;
+import org.jboss.ejb3.sandbox.interceptors.direct.DirectContainer;
import org.jboss.ejb3.test.sandbox.stateless.SimpleStatelessBean;
import org.jboss.ejb3.test.sandbox.stateless.SimpleStatelessLocal;
+import org.jboss.logging.Logger;
import org.jnp.server.SingletonNamingServer;
-import junit.framework.TestCase;
-
/**
* Comment
*
@@ -38,12 +43,23 @@
*/
public class SimpleStatelessUnitTestCase extends TestCase
{
- public void test1() throws Exception
+ private static final Logger log = Logger.getLogger(SimpleStatelessUnitTestCase.class);
+
+ public void test1() throws Throwable
{
+// AspectManager.verbose = true;
+
SingletonNamingServer namingServer = new SingletonNamingServer();
- //StatelessContainer statelessContainer = new StatelessContainer();
- InterceptorContainer container = new InterceptorContainer(SimpleStatelessBean.class);
+ // Bootstrap AOP
+ URL url = Thread.currentThread().getContextClassLoader().getResource("stateless/jboss-aop.xml");
+ log.info("deploying AOP from " + url);
+ AspectXmlLoader.deployXML(url);
+
+ DirectContainer<InterceptorContainer> interceptorContainerContainer = new DirectContainer<InterceptorContainer>("FIXME", "InterceptorContainer", InterceptorContainer.class);
+ Object args[] = { SimpleStatelessBean.class };
+ Class<?> parameterTypes[] = { Class.class };
+ InterceptorContainer interceptorContainer = interceptorContainerContainer.construct(args, parameterTypes);
InitialContext ctx = new InitialContext();
Modified: projects/ejb3/trunk/sandbox/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/resources/log4j.xml 2008-01-07 11:08:50 UTC (rev 68650)
+++ projects/ejb3/trunk/sandbox/src/test/resources/log4j.xml 2008-01-07 15:04:24 UTC (rev 68651)
@@ -103,6 +103,10 @@
</category>
-->
+ <category name="org.jboss">
+ <priority value="INFO"/>
+ </category>
+
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
Added: projects/ejb3/trunk/sandbox/src/test/resources/stateless/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/resources/stateless/jboss-aop.xml (rev 0)
+++ projects/ejb3/trunk/sandbox/src/test/resources/stateless/jboss-aop.xml 2008-01-07 15:04:24 UTC (rev 68651)
@@ -0,0 +1,77 @@
+<aop>
+ <aspect name="AroundInvokeInterceptor" class="org.jboss.ejb3.interceptors.aop.AroundInvokeInterceptor" scope="PER_INSTANCE"/>
+ <aspect name="InjectInterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory" scope="PER_JOINPOINT"/>
+ <aspect name="InterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InterceptorsFactory" scope="PER_INSTANCE"/>
+ <aspect name="InterceptorsInterceptor" class="org.jboss.ejb3.interceptors.aop.InterceptorsInterceptor" scope="PER_INSTANCE"/>
+ <aspect name="InvocationContextInterceptor" class="org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor" scope="PER_VM"/>
+ <aspect name="PostConstructInterceptor" class="org.jboss.ejb3.interceptors.aop.PostConstructInterceptor" scope="PER_INSTANCE"/>
+
+ <!-- Create AOP interceptors out of spec interceptors -->
+ <aspect name="ClassInterceptors" factory="org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory" scope="PER_INSTANCE">
+ <attribute name="interceptors" value="class"/>
+ </aspect>
+ <aspect name="DefaultInterceptors" factory="org.jboss.ejb3.interceptors.aop.DefaultInterceptorsFactory" scope="PER_INSTANCE"/>
+
+ <!-- TODO: deprecated -->
+ <interceptor name="BootstrapInterceptor" class="org.jboss.ejb3.interceptors.aop.BootstrapInterceptor" scope="PER_VM"/>
+
+ <!-- test only -->
+ <!--
+ <interceptor name="LoggingInterceptor" class="org.jboss.ejb3.test.interceptors.common.aop.LoggingInterceptor" scope="PER_VM"/>
+ -->
+
+ <!-- TODO: this is actually the bootstrap container -->
+ <domain name="InterceptorContainer">
+ <pointcut name="beanAroundInvokeCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.interceptor.AroundInvoke(..))"/>
+ <pointcut name="beanPostConstructCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.interceptor.PostConstruct(..))"/>
+ <pointcut name="beanPreDestroyCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.interceptor.PreDestroy(..))"/>
+
+ <pointcut name="beanLifecycleCallbackMethods" expr="beanAroundInvokeCallbackMethods OR beanPostConstructCallbackMethods OR beanPreDestroyCallbackMethods"/>
+
+ <!-- Prepare for dynamic AOP -->
+ <!-- TODO: optimize, we only need managed objects (and interceptors!) to be aspectized -->
+ <!-- prepare expr="all(*) AND has(@org.jboss.ejb3.interceptors.ManagedObject->new(..))"/ -->
+ <prepare expr="all(*)"/>
+
+ <!-- Make sure we can _preDestroy -->
+ <introduction expr="constructor(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
+ <interfaces>org.jboss.ejb3.interceptors.aop.Destructable</interfaces>
+ </introduction>
+
+ <!-- Setup AOP interceptors based on spec interceptors -->
+ <bind pointcut="construction(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
+ <!-- interceptor-ref name="LoggingInterceptor"/ -->
+ <!-- TODO: we don't need invocation context here -->
+ <!-- TODO: we do until we've seperated the post constructs -->
+ <around name="setup" aspect="InvocationContextInterceptor"/>
+ <around name="invoke" aspect="InterceptorsFactory"/>
+ </bind>
+
+ <!-- Lifecycle Event Callbacks (EJB 3 12.4) -->
+
+ <bind pointcut="construction(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
+ <!-- interceptor-ref name="LoggingInterceptor"/-->
+ <around name="setup" aspect="InvocationContextInterceptor"/>
+ <around name="postConstruct" aspect="InjectInterceptorsFactory"/>
+ </bind>
+
+ <!--
+ <bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..))">
+ <around name="setup" aspect="InvocationContextInterceptor"/>
+ <around name="fillMethod" aspect="InvocationContextInterceptor"/>
+ </bind>
+ -->
+
+ <bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..)) AND !beanLifecycleCallbackMethods">
+ <around name="setup" aspect="InvocationContextInterceptor"/>
+ <around name="fillMethod" aspect="InvocationContextInterceptor"/>
+ <around name="aroundInvoke" aspect="InjectInterceptorsFactory"/>
+ </bind>
+ </domain>
+
+ <domain name="StatelessContainer" extends="InterceptorContainer" inheritBindings="true">
+ <annotation-introduction expr="has(@javax.ejb.Stateless->new(..))">
+ @org.jboss.ejb3.interceptors.ManagedObject
+ </annotation-introduction>
+ </domain>
+</aop>
\ No newline at end of file
Property changes on: projects/ejb3/trunk/sandbox/src/test/resources/stateless/jboss-aop.xml
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list