[jboss-cvs] JBossAS SVN: r71802 - in projects/ejb3/trunk/interceptors: src/main/java/org/jboss/ejb3/interceptors and 15 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 8 14:54:09 EDT 2008
Author: wolfc
Date: 2008-04-08 14:54:09 -0400 (Tue, 08 Apr 2008)
New Revision: 71802
Added:
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorInterceptor.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorsInterceptor.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContext.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocationWrapper.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/DummyBeanContext.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/SimpleBean.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptor.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptorInterface.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/unit/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/unit/InterceptorInstancesTestCase.java
Modified:
projects/ejb3/trunk/interceptors/pom.xml
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/BusinessMethodInterceptorMethodInterceptor.java
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/container/AbstractContainer.java
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/proxy/ProxyContainer.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/additive/unit/AdditiveTestCase.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicBean.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestRunner.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/DirectTestCase.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/signature/unit/SignatureTestCase.java
Log:
EJBTHREE-1246: created BeanContext
Modified: projects/ejb3/trunk/interceptors/pom.xml
===================================================================
--- projects/ejb3/trunk/interceptors/pom.xml 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/pom.xml 2008-04-08 18:54:09 UTC (rev 71802)
@@ -52,7 +52,8 @@
</dependency>
<dependency>
<groupId>jboss</groupId>
- <artifactId>jboss-logging-log4j</artifactId>
+ <artifactId>jboss-common-logging-log4j</artifactId>
+ <version>2.0.4.GA</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -72,12 +73,17 @@
<groupId>org.jboss.javaee</groupId>
<artifactId>jboss-ejb-api</artifactId>
</dependency>
-
- <!-- broken transitive dependencies of AOP -->
<dependency>
<groupId>org.jboss.microcontainer</groupId>
- <artifactId>jboss-container</artifactId>
- <version>2.0.0.Beta8</version> <!-- FIXME: move to build -->
+ <artifactId>jboss-kernel</artifactId>
+ <version>2.0.0.Beta12</version>
+ <scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>2.0.0.Beta10</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/BusinessMethodInterceptorMethodInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/BusinessMethodInterceptorMethodInterceptor.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/BusinessMethodInterceptorMethodInterceptor.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -37,7 +37,7 @@
* Object <METHOD>(InvocationContext) throws Exception
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class BusinessMethodInterceptorMethodInterceptor implements Interceptor
{
@@ -68,6 +68,11 @@
return "BusinessMethodInterceptorMethodInterceptor";
}
+ public Class<?> getRealClass()
+ {
+ return interceptor.getClass();
+ }
+
public Object invoke(final Invocation invocation) throws Throwable
{
InvocationContext ctx = InvocationContextInterceptor.getInvocationContext(invocation);
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorInterceptor.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,66 @@
+/*
+ * 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.interceptors.aop;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EJB3InterceptorInterceptor implements Interceptor
+{
+ private Class<?> interceptorClass;
+
+ /**
+ * @param interceptorClass
+ */
+ EJB3InterceptorInterceptor(Class<?> interceptorClass)
+ {
+ assert interceptorClass != null : "interceptorClass is null";
+
+ this.interceptorClass = interceptorClass;
+ }
+
+ public String getName()
+ {
+ return EJB3InterceptorInterceptor.class.getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ Object instances[] = ContainerMethodInvocation.getContainerMethodInvocation(invocation).getBeanContext().getInterceptors();
+ for(Object instance : instances)
+ {
+ // FIXME
+ BusinessMethodInterceptorMethodInterceptor interceptor = (BusinessMethodInterceptorMethodInterceptor) instance;
+ if(interceptor.getRealClass().equals(interceptorClass))
+ return interceptor.invoke(invocation);
+ }
+ //throw new IllegalStateException("Can't find an interceptor instance for " + interceptorClass + " among " + Arrays.toString(instances));
+ // The business method interceptor method interceptor only exists when there is an aroundInvoke
+ return invocation.invokeNext();
+ }
+
+}
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorsInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorsInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorsInterceptor.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,51 @@
+/*
+ * 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.interceptors.aop;
+
+import java.util.List;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EJB3InterceptorsInterceptor implements Interceptor
+{
+ public EJB3InterceptorsInterceptor(List<Class<?>> applicableInterceptorClasses)
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ public String getName()
+ {
+ return EJB3InterceptorsInterceptor.class.getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ ContainerMethodInvocation.getContainerMethodInvocation(invocation).getBeanContext().getInterceptors();
+ return null;
+ }
+}
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-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -27,6 +27,7 @@
import java.util.List;
import javax.annotation.PostConstruct;
+import javax.interceptor.AroundInvoke;
import javax.interceptor.ExcludeClassInterceptors;
import javax.interceptor.ExcludeDefaultInterceptors;
@@ -36,13 +37,16 @@
import org.jboss.aop.joinpoint.ConstructorJoinpoint;
import org.jboss.aop.joinpoint.Joinpoint;
import org.jboss.aop.joinpoint.MethodJoinpoint;
+import org.jboss.ejb3.interceptors.container.AbstractContainer;
+import org.jboss.ejb3.interceptors.container.ManagedObjectAdvisor;
+import org.jboss.ejb3.interceptors.lang.ClassHelper;
import org.jboss.logging.Logger;
/**
* Comment
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class InjectInterceptorsFactory extends AbstractInterceptorFactory
{
@@ -77,6 +81,26 @@
Method method = ((MethodJoinpoint) jp).getMethod();
+ if(advisor instanceof ManagedObjectAdvisor)
+ {
+ AbstractContainer<?, ?> container = AbstractContainer.getContainer(advisor);
+ List<Class<?>> interceptorClasses = container.getInterceptorRegistry().getApplicableInterceptorClasses(method);
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ for(Class<?> interceptorClass : interceptorClasses)
+ {
+ interceptors.add(new EJB3InterceptorInterceptor(interceptorClass));
+ }
+ Class<?> beanClass = advisor.getClazz();
+ for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
+ {
+ if(advisor.hasAnnotation(beanMethod, AroundInvoke.class))
+ {
+ interceptors.add(new BusinessMethodBeanMethodInterceptor(beanMethod));
+ }
+ }
+ return new InterceptorSequencer(interceptors);
+ }
+
List<Interceptor> interceptors = new ArrayList<Interceptor>() {
private static final long serialVersionUID = 1L;
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -26,6 +26,8 @@
import java.util.ArrayList;
import java.util.List;
+import javax.interceptor.AroundInvoke;
+
import org.jboss.aop.Advisor;
import org.jboss.aop.AspectManager;
import org.jboss.aop.Domain;
@@ -35,14 +37,18 @@
import org.jboss.aop.advice.PerVmAdvice;
import org.jboss.aop.annotation.AnnotationRepository;
import org.jboss.aop.joinpoint.ConstructionInvocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.interceptors.InterceptorFactory;
import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisor;
import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisorSupport;
+import org.jboss.ejb3.interceptors.aop.BusinessMethodInterceptorMethodInterceptor;
+import org.jboss.ejb3.interceptors.aop.ExtendedAdvisor;
+import org.jboss.ejb3.interceptors.aop.ExtendedAdvisorHelper;
import org.jboss.ejb3.interceptors.aop.InterceptorsFactory;
import org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor;
import org.jboss.ejb3.interceptors.lang.ClassHelper;
+import org.jboss.ejb3.interceptors.registry.InterceptorRegistry;
import org.jboss.logging.Logger;
/**
@@ -60,6 +66,8 @@
private ManagedObjectAdvisor<T, C> advisor;
+ private InterceptorRegistry interceptorRegistry;
+
/**
* For a completely customized startup.
*
@@ -80,12 +88,34 @@
this(name, getDomain(domainName), beanClass);
}
- protected T construct(Constructor<? extends T> constructor, Object ... initargs)
+ protected BeanContext<T> construct(Constructor<? extends T> constructor, Object ... initargs)
{
int idx = advisor.getConstructorIndex(constructor);
assert idx != -1 : "can't find constructor in the advisor";
try
{
+ // TODO: ask the BeanFactory<BeanContext> for a new ctx
+
+ InterceptorFactoryRef interceptorFactoryRef = (InterceptorFactoryRef) advisor.resolveAnnotation(InterceptorFactoryRef.class);
+ if(interceptorFactoryRef == null)
+ throw new IllegalStateException("No InterceptorFactory specified on " + advisor.getName());
+ log.debug("interceptor factory class = " + interceptorFactoryRef.value());
+ InterceptorFactory interceptorFactory = interceptorFactoryRef.value().newInstance();
+
+ List<Interceptor> ejb3Interceptors = new ArrayList<Interceptor>();
+ for(Class<?> interceptorClass : getInterceptorRegistry().getInterceptorClasses())
+ {
+ Object interceptor = interceptorFactory.create(advisor, interceptorClass);
+ ExtendedAdvisor interceptorAdvisor = ExtendedAdvisorHelper.getExtendedAdvisor(advisor, interceptor);
+ for(Method method : ClassHelper.getAllMethods(interceptorClass))
+ {
+ if(interceptorAdvisor.isAnnotationPresent(interceptorClass, method, AroundInvoke.class))
+ {
+ ejb3Interceptors.add(new BusinessMethodInterceptorMethodInterceptor(interceptor, method));
+ }
+ }
+ }
+
T targetObject = (T) advisor.invokeNew(initargs, idx);
Interceptor interceptors[] = advisor.getConstructionInfos()[idx].getInterceptors();
@@ -94,7 +124,7 @@
invocation.setTargetObject(targetObject);
invocation.invokeNext();
- return targetObject;
+ return new DummyBeanContext(targetObject, ejb3Interceptors);
}
catch(Throwable t)
{
@@ -110,7 +140,7 @@
return interceptorClass.newInstance();
}
- protected void destroy(T bean)
+ protected void destroy(BeanContext<T> bean)
{
try
{
@@ -120,7 +150,7 @@
DestructionInvocation invocation = new DestructionInvocation(interceptors.toArray(new Interceptor[0]));
invocation.setAdvisor(advisor);
- invocation.setTargetObject(bean);
+ invocation.setTargetObject(bean.getInstance());
invocation.invokeNext();
}
catch(Throwable t)
@@ -190,6 +220,19 @@
return domain;
}
+ public InterceptorRegistry getInterceptorRegistry()
+ {
+ if(interceptorRegistry == null)
+ {
+ synchronized (this)
+ {
+ if(interceptorRegistry == null)
+ interceptorRegistry = new InterceptorRegistry(getAdvisor());
+ }
+ }
+ return interceptorRegistry;
+ }
+
/**
* Call a method upon a target object with all interceptors in place.
*
@@ -199,15 +242,13 @@
* @return return value of the method
* @throws Throwable if anything goes wrong
*/
- protected Object invoke(T target, Method method, Object arguments[]) throws Throwable
+ protected Object invoke(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());
- invocation.setArguments(arguments);
- invocation.setTargetObject(target);
+ ContainerMethodInvocation invocation = new ContainerMethodInvocation(info, target, arguments);
return invocation.invokeNext();
}
@@ -224,9 +265,9 @@
* @throws Throwable if anything goes wrong
*/
@SuppressWarnings("unchecked")
- protected <R> R invoke(T target, String methodName, Object ... args) throws Throwable
+ protected <R> R invoke(BeanContext<T> target, String methodName, Object ... args) throws Throwable
{
- Method method = ClassHelper.getMethod(target.getClass(), methodName);
+ Method method = ClassHelper.getMethod(target.getInstance().getClass(), methodName);
return (R) invoke(target, method, args);
}
}
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContext.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContext.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContext.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,33 @@
+/*
+ * 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.interceptors.container;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface BeanContext<T>
+{
+ T getInstance();
+
+ Object[] getInterceptors();
+}
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,76 @@
+/*
+ * 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.interceptors.container;
+
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ * A method invocation on a intercepting container.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ContainerMethodInvocation extends MethodInvocation
+{
+ private BeanContext<?> beanContext;
+
+ ContainerMethodInvocation(MethodInfo info, BeanContext<?> beanContext, Object arguments[])
+ {
+ super(info, info.getInterceptors());
+
+ assert beanContext != null : "beanContext is null";
+
+ setArguments(arguments);
+ setTargetObject(beanContext.getInstance());
+
+ this.beanContext = beanContext;
+ }
+
+ /**
+ * @param newchain
+ */
+ protected ContainerMethodInvocation(Interceptor[] newchain)
+ {
+ super(newchain);
+ }
+
+ public BeanContext<?> getBeanContext()
+ {
+ return beanContext;
+ }
+
+ public static ContainerMethodInvocation getContainerMethodInvocation(Invocation invocation)
+ {
+ if(invocation instanceof ContainerMethodInvocation)
+ return (ContainerMethodInvocation) invocation;
+ throw new IllegalArgumentException("invocation " + invocation + " is not done through AbstractContainer");
+ }
+
+ @Override
+ public Invocation getWrapper(Interceptor[] newchain)
+ {
+ return new ContainerMethodInvocationWrapper(this, newchain);
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocationWrapper.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocationWrapper.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocationWrapper.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,169 @@
+/*
+ * 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.interceptors.container;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.metadata.MetaDataResolver;
+import org.jboss.aop.metadata.SimpleMetaData;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ContainerMethodInvocationWrapper extends ContainerMethodInvocation
+{
+ private ContainerMethodInvocation wrapped;
+
+ /**
+ * @param containerMethodInvocation
+ * @param newchain
+ */
+ public ContainerMethodInvocationWrapper(ContainerMethodInvocation wrapped, Interceptor[] newchain)
+ {
+ super(newchain);
+ this.wrapped = wrapped;
+ }
+
+ public Object getMetaData(Object group, Object attr)
+ {
+ return wrapped.getMetaData(group, attr);
+ }
+
+ public Object invokeNext() throws Throwable
+ {
+ if (interceptors != null && currentInterceptor < interceptors.length)
+ {
+ try
+ {
+ return interceptors[currentInterceptor++].invoke(this);
+ }
+ finally
+ {
+ // so that interceptors like clustering can reinvoke down the chain
+ currentInterceptor--;
+ }
+ }
+ try
+ {
+ return wrapped.invokeNext();
+ }
+ finally
+ {
+ responseContextInfo = wrapped.getResponseContextInfo();
+ }
+ }
+
+ public MetaDataResolver getInstanceResolver()
+ {
+ return wrapped.getInstanceResolver();
+ }
+
+ public Object[] getArguments()
+ {
+ return wrapped.getArguments();
+ }
+
+ @Override
+ public BeanContext<?> getBeanContext()
+ {
+ return wrapped.getBeanContext();
+ }
+
+ public void setArguments(Object[] args)
+ {
+ wrapped.setArguments(args);
+ }
+
+ public Object getTargetObject()
+ {
+ return wrapped.getTargetObject();
+ }
+
+ public Invocation copy()
+ {
+// MethodInvocationWrapper invocation = new MethodInvocationWrapper((MethodInvocation)wrapped.copy(), interceptors);
+// invocation.currentInterceptor = this.currentInterceptor;
+// return invocation;
+ throw new RuntimeException("NYI");
+ }
+
+ public Method getMethod()
+ {
+ return wrapped.getMethod();
+ }
+
+ public Method getActualMethod()
+ {
+ return wrapped.getActualMethod();
+ }
+
+ public long getMethodHash()
+ {
+ return wrapped.getMethodHash();
+ }
+
+ public Advisor getAdvisor()
+ {
+ return wrapped.getAdvisor();
+ }
+
+ public Map getResponseContextInfo()
+ {
+ return wrapped.getResponseContextInfo();
+ }
+
+ public void setResponseContextInfo(Map responseContextInfo)
+ {
+ wrapped.setResponseContextInfo(responseContextInfo);
+ }
+
+ public Object getResponseAttachment(Object key)
+ {
+ return wrapped.getResponseAttachment(key);
+ }
+
+ public void addResponseAttachment(Object key, Object val)
+ {
+ wrapped.addResponseAttachment(key, val);
+ }
+
+ public SimpleMetaData getMetaData()
+ {
+ return wrapped.getMetaData();
+ }
+
+ public void setMetaData(SimpleMetaData data)
+ {
+ wrapped.setMetaData(data);
+ }
+
+ public void setTargetObject(Object targetObject)
+ {
+ wrapped.setTargetObject(targetObject);
+ }
+
+}
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/DummyBeanContext.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/DummyBeanContext.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/DummyBeanContext.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,55 @@
+/*
+ * 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.interceptors.container;
+
+import java.util.List;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DummyBeanContext<T> implements BeanContext<T>
+{
+ private T instance;
+ private Object interceptors[];
+
+ public DummyBeanContext(T instance, List<Object> interceptors)
+ {
+ assert instance != null : "instance is null";
+ assert interceptors != null : "interceptors is null";
+ this.instance = instance;
+ this.interceptors = interceptors.toArray(new Interceptor[0]);
+ }
+
+ public T getInstance()
+ {
+ return instance;
+ }
+
+ public Object[] getInterceptors()
+ {
+ return interceptors;
+ }
+
+}
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 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -30,7 +30,9 @@
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.lang.ClassHelper;
+import org.jboss.ejb3.interceptors.registry.InterceptorRegistry;
import org.jboss.logging.Logger;
/**
@@ -61,17 +63,17 @@
super(name, domainName, beanClass);
}
- public T construct() throws SecurityException, NoSuchMethodException
+ public BeanContext<T> construct() throws SecurityException, NoSuchMethodException
{
return construct((Object[]) null, null);
}
@SuppressWarnings("unchecked")
- public T construct(Object initargs[], Class<?> parameterTypes[]) throws SecurityException, NoSuchMethodException
+ public BeanContext<T> construct(Object initargs[], Class<?> parameterTypes[]) throws SecurityException, NoSuchMethodException
{
ClassAdvisor advisor = getAdvisor();
Constructor<T> constructor = advisor.getClazz().getConstructor(parameterTypes);
- T targetObject = construct(constructor, initargs);
+ BeanContext<T> targetObject = construct(constructor, initargs);
if(targetObject instanceof IndirectContainer)
((IndirectContainer<T, C>) targetObject).setDirectContainer((C) this);
@@ -80,7 +82,7 @@
}
@Override
- public void destroy(T bean)
+ public void destroy(BeanContext<T> bean)
{
super.destroy(bean);
}
@@ -94,9 +96,16 @@
return super.getBeanClass();
}
+ // expose the interceptor registry
+ @Override
+ public InterceptorRegistry getInterceptorRegistry()
+ {
+ return super.getInterceptorRegistry();
+ }
+
// expose the invoke method
@Override
- public Object invoke(T target, Method method, Object[] arguments) throws Throwable
+ public Object invoke(BeanContext<T> target, Method method, Object[] arguments) throws Throwable
{
return super.invoke(target, method, arguments);
}
@@ -115,9 +124,9 @@
* @throws Throwable if anything goes wrong
*/
@SuppressWarnings("unchecked")
- public <R> R invoke(T target, String methodName, Object ... args) throws Throwable
+ public <R> R invoke(BeanContext<T> target, String methodName, Object ... args) throws Throwable
{
- Method method = ClassHelper.getMethod(target.getClass(), methodName);
+ Method method = ClassHelper.getMethod(target.getInstance().getClass(), methodName);
return (R) invoke(target, method, args);
}
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -28,6 +28,7 @@
import org.jboss.aop.Domain;
import org.jboss.ejb3.interceptors.container.AbstractContainer;
+import org.jboss.ejb3.interceptors.container.BeanContext;
import org.jboss.logging.Logger;
/**
@@ -37,7 +38,7 @@
* Advisor life-cycle is controlled.
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class ProxyContainer<T> extends AbstractContainer<T, ProxyContainer<T>>
{
@@ -45,9 +46,9 @@
private class ProxyInvocationHandler implements InvocationHandler
{
- private T target;
+ private BeanContext<T> target;
- public ProxyInvocationHandler(T target)
+ public ProxyInvocationHandler(BeanContext<T> target)
{
assert target != null : "target is null";
@@ -74,7 +75,7 @@
public <I> I constructProxy(Class<?> interfaces[]) throws Throwable
{
Constructor<? extends T> constructor = getBeanClass().getConstructor();
- T instance = construct(constructor);
+ BeanContext<T> instance = construct(constructor);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
//Class<?> interfaces[] = { intf };
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,141 @@
+/*
+ * 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.interceptors.registry;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.ExcludeDefaultInterceptors;
+import javax.interceptor.Interceptors;
+
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.interceptors.aop.annotation.DefaultInterceptors;
+import org.jboss.ejb3.interceptors.lang.ClassHelper;
+import org.jboss.logging.Logger;
+
+/**
+ * The interceptor registry for a given EJB.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorRegistry
+{
+ private static final Logger log = Logger.getLogger(InterceptorRegistry.class);
+
+ private Advisor advisor;
+
+ private List<Class<?>> interceptorClasses = new ArrayList<Class<?>>();
+ private List<Class<?>> readOnlyInterceptorClasses = Collections.unmodifiableList(interceptorClasses);
+ private Map<Method, List<Class<?>>> applicableInterceptorClasses = new HashMap<Method, List<Class<?>>>();
+
+ public InterceptorRegistry(Advisor advisor)
+ {
+ assert advisor != null : "advisor is null";
+
+ this.advisor = advisor;
+
+ initialize();
+ }
+
+ public List<Class<?>> getApplicableInterceptorClasses(Method method)
+ {
+ List<Class<?>> methodApplicableInterceptorClasses = applicableInterceptorClasses.get(method);
+ assert methodApplicableInterceptorClasses != null;
+ return methodApplicableInterceptorClasses;
+ }
+
+ public List<Class<?>> getInterceptorClasses()
+ {
+ return readOnlyInterceptorClasses;
+ }
+
+ private void initialize()
+ {
+ DefaultInterceptors defaultInterceptorsAnnotation = (DefaultInterceptors) advisor.resolveAnnotation(DefaultInterceptors.class);
+ List<Class<?>> defaultInterceptorClasses = new ArrayList<Class<?>>();
+ if(defaultInterceptorsAnnotation != null)
+ {
+ for(Class<?> defaultInterceptorClass : defaultInterceptorsAnnotation.value())
+ defaultInterceptorClasses.add(defaultInterceptorClass);
+ }
+ log.debug("Found default interceptors " + defaultInterceptorClasses);
+ interceptorClasses.addAll(defaultInterceptorClasses);
+
+ Interceptors interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(Interceptors.class);
+ List<Class<?>> classInterceptorClasses = new ArrayList<Class<?>>();
+ if(interceptorsAnnotation != null)
+ {
+ for(Class<?> classInterceptorClass : interceptorsAnnotation.value())
+ {
+ classInterceptorClasses.add(classInterceptorClass);
+ if(!interceptorClasses.contains(classInterceptorClass))
+ interceptorClasses.add(classInterceptorClass);
+ }
+ }
+ log.debug("Found class interceptors " + classInterceptorClasses);
+
+ Class<?> beanClass = advisor.getClazz();
+ for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
+ {
+ interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(beanMethod, Interceptors.class);
+ List<Class<?>> methodInterceptorClasses = new ArrayList<Class<?>>();
+ if(interceptorsAnnotation != null)
+ {
+ for(Class<?> interceptorClass : interceptorsAnnotation.value())
+ {
+ methodInterceptorClasses.add(interceptorClass);
+ if(!interceptorClasses.contains(interceptorClass))
+ interceptorClasses.add(interceptorClass);
+ }
+ }
+
+ // Interceptors applicable for this bean method
+ List<Class<?>> methodApplicableInterceptorClasses = new ArrayList<Class<?>>();
+ if(!isExcludeDefaultInterceptors(advisor, beanMethod))
+ methodApplicableInterceptorClasses.addAll(defaultInterceptorClasses);
+ if(!isExcludeClassInterceptors(advisor, beanMethod))
+ methodApplicableInterceptorClasses.addAll(classInterceptorClasses);
+ methodApplicableInterceptorClasses.addAll(methodInterceptorClasses);
+
+ // TODO: remove duplicates
+ // TODO: total ordering (EJB 3 12.8.2.1 and @Interceptors with all)
+
+ applicableInterceptorClasses.put(beanMethod, methodApplicableInterceptorClasses);
+ }
+ }
+
+ private static final boolean isExcludeClassInterceptors(Advisor advisor, Method method)
+ {
+ return advisor.hasAnnotation(method, ExcludeClassInterceptors.class) || advisor.resolveAnnotation(ExcludeClassInterceptors.class) != null;
+ }
+
+ private static final boolean isExcludeDefaultInterceptors(Advisor advisor, Method method)
+ {
+ return advisor.hasAnnotation(method, ExcludeDefaultInterceptors.class) || advisor.resolveAnnotation(ExcludeDefaultInterceptors.class) != null;
+ }
+}
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/additive/unit/AdditiveTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/additive/unit/AdditiveTestCase.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/additive/unit/AdditiveTestCase.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -29,6 +29,7 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.container.BeanContext;
import org.jboss.ejb3.interceptors.direct.AbstractDirectContainer;
import org.jboss.ejb3.interceptors.metadata.AdditiveBeanInterceptorMetaDataBridge;
import org.jboss.ejb3.interceptors.metadata.InterceptorComponentMetaDataLoaderFactory;
@@ -138,7 +139,7 @@
MyContainer<MySessionBean> container = new MyContainer<MySessionBean>("MySessionBean", "Test", MySessionBean.class, beanMetaData);
- MySessionBean bean = container.construct();
+ BeanContext<MySessionBean> bean = container.construct();
List<Class<?>> visits = new ArrayList<Class<?>>();
container.invoke(bean, "doIt", visits);
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicBean.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicBean.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -25,6 +25,7 @@
import javax.interceptor.Interceptors;
import javax.interceptor.InvocationContext;
+import org.jboss.ejb3.test.interceptors.instances.StatefulInterceptor;
import org.jboss.logging.Logger;
/**
@@ -35,7 +36,7 @@
* And it has bean method interceptors: aroundInvoke
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
@Interceptors(BasicInterceptor.class)
public class BasicBean
@@ -73,4 +74,18 @@
{
log.debug("intercept");
}
+
+ // State check
+
+ @Interceptors(StatefulInterceptor.class)
+ public int getState()
+ {
+ throw new RuntimeException("Should not get here");
+ }
+
+ @Interceptors(StatefulInterceptor.class)
+ public void setState(int state)
+ {
+ throw new RuntimeException("Should not get here");
+ }
}
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestRunner.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestRunner.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestRunner.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -36,7 +36,7 @@
* Named TestRunner, so surefire does not pick it up.
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class BasicTestRunner extends TestCase
{
@@ -70,4 +70,16 @@
//((Destructable) bean)._preDestroy();
bean = null;
}
+
+ public void testInstances() throws Exception
+ {
+ BasicBean bean1 = new BasicBean();
+ BasicBean bean2 = new BasicBean();
+
+ bean1.setState(1);
+ bean2.setState(2);
+
+ assertEquals(1, bean1.getState());
+ assertEquals(2, bean2.getState());
+ }
}
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/DirectTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/DirectTestCase.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/DirectTestCase.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -28,6 +28,7 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.container.BeanContext;
import org.jboss.ejb3.interceptors.container.ManagedObjectAdvisor;
import org.jboss.ejb3.interceptors.direct.DirectContainer;
import org.jboss.ejb3.test.interceptors.direct.DirectBean;
@@ -80,7 +81,7 @@
MyContainer<DirectBean> container = new MyContainer<DirectBean>("DirectBean", "Test", DirectBean.class);
container.testAdvisor();
- DirectBean bean = container.construct();
+ BeanContext<DirectBean> bean = container.construct();
assertEquals("DirectInterceptor postConstruct must have been called once", 1, DirectInterceptor.postConstructs);
assertEquals("DirectBean postConstruct must have been called once", 1, DirectBean.postConstructs);
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/SimpleBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/SimpleBean.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/SimpleBean.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,52 @@
+/*
+ * 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.test.interceptors.instances;
+
+import javax.interceptor.Interceptors;
+
+import org.jboss.ejb3.interceptors.ManagedObject;
+
+/**
+ * By constructing multiple instances of this bean we can
+ * make sure we get 1 StatefulInterceptor instance per SimpleBean instance.
+ *
+ * The methods on StatefulInterceptorInterface should be intercepted
+ * by the StatefulInterceptor.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at ManagedObject
+ at Interceptors(StatefulInterceptor.class)
+public class SimpleBean implements StatefulInterceptorInterface
+{
+ public int getState()
+ {
+ throw new RuntimeException("should not get here");
+ }
+
+ public void setState(int state)
+ {
+ throw new RuntimeException("should not get here");
+ }
+
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptor.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,65 @@
+/*
+ * 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.test.interceptors.instances;
+
+import java.lang.reflect.Method;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * The stateful interceptor will retain state, so we can make
+ * sure we have one instance per bean.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StatefulInterceptor
+{
+ private int state;
+
+ @AroundInvoke
+ public Object aroundInvoke(InvocationContext ctx) throws Exception
+ {
+ Method method = ctx.getMethod();
+ String methodName = method.getName();
+ if(methodName.equals("getState"))
+ return getState();
+ else if(methodName.equals("setState"))
+ {
+ setState((Integer) ctx.getParameters()[0]);
+ return null;
+ }
+ else
+ return ctx.proceed();
+ }
+
+ private int getState()
+ {
+ return state;
+ }
+
+ private void setState(int state)
+ {
+ this.state = state;
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptorInterface.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptorInterface.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/StatefulInterceptorInterface.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,36 @@
+/*
+ * 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.test.interceptors.instances;
+
+/**
+ * These methods are intercepted by the StatefulInterceptor, they
+ * never arrive at the bean.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface StatefulInterceptorInterface
+{
+ int getState();
+
+ void setState(int state);
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/unit/InterceptorInstancesTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/unit/InterceptorInstancesTestCase.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/instances/unit/InterceptorInstancesTestCase.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -0,0 +1,68 @@
+/*
+ * 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.test.interceptors.instances.unit;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.proxy.ProxyContainer;
+import org.jboss.ejb3.test.interceptors.instances.SimpleBean;
+import org.jboss.ejb3.test.interceptors.instances.StatefulInterceptorInterface;
+import org.jboss.logging.Logger;
+
+/**
+ * EJB 3 12.2: Interceptor Life Cycle
+ * The lifecycle of an interceptor instance is the same as that of the bean instance with
+ * which it is associated.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorInstancesTestCase extends TestCase
+{
+ private static final Logger log = Logger.getLogger(InterceptorInstancesTestCase.class);
+
+ public void test1() throws Throwable
+ {
+ //AspectManager.verbose = true;
+
+ // Bootstrap AOP
+ URL url = Thread.currentThread().getContextClassLoader().getResource("proxy/jboss-aop.xml");
+ log.info("deploying AOP from " + url);
+ AspectXmlLoader.deployXML(url);
+
+ Thread.currentThread().setContextClassLoader(StatefulInterceptorInterface.class.getClassLoader());
+
+ ProxyContainer<SimpleBean> container = new ProxyContainer<SimpleBean>("InterceptorInstancesTestCase", "InterceptorContainer", SimpleBean.class);
+
+ StatefulInterceptorInterface bean1 = container.constructProxy(new Class[] { StatefulInterceptorInterface.class });
+ StatefulInterceptorInterface bean2 = container.constructProxy(new Class[] { StatefulInterceptorInterface.class });
+
+ bean1.setState(1);
+ bean2.setState(2);
+
+ assertEquals(1, bean1.getState());
+ assertEquals(2, bean2.getState());
+ }
+}
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -29,6 +29,7 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.container.BeanContext;
import org.jboss.ejb3.interceptors.direct.AbstractDirectContainer;
import org.jboss.ejb3.interceptors.metadata.BeanInterceptorMetaDataBridge;
import org.jboss.ejb3.interceptors.metadata.InterceptorComponentMetaDataLoaderFactory;
@@ -129,7 +130,7 @@
MyContainer<SessionBeanCallbackBean> container = new MyContainer<SessionBeanCallbackBean>("SessionBeanCallbackBean", "Test", SessionBeanCallbackBean.class, beanMetaData);
- SessionBeanCallbackBean bean = container.construct();
+ BeanContext<SessionBeanCallbackBean> bean = container.construct();
assertEquals("SessionBeanCallbackBean ejbCreate must have been called once", 1, SessionBeanCallbackBean.postConstructs);
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -30,6 +30,7 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.container.BeanContext;
import org.jboss.ejb3.interceptors.direct.AbstractDirectContainer;
import org.jboss.ejb3.interceptors.metadata.BeanInterceptorMetaDataBridge;
import org.jboss.ejb3.interceptors.metadata.InterceptorComponentMetaDataLoaderFactory;
@@ -142,7 +143,7 @@
MyContainer<MetadataBean> container = new MyContainer<MetadataBean>("MetadataBean", "Test", MetadataBean.class, beanMetaData);
container.testAdvisor();
- MetadataBean bean = container.construct();
+ BeanContext<MetadataBean> bean = container.construct();
assertEquals("CommonInterceptor postConstruct must have been called once", 1, CommonInterceptor.postConstructs);
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/signature/unit/SignatureTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/signature/unit/SignatureTestCase.java 2008-04-08 18:42:59 UTC (rev 71801)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/signature/unit/SignatureTestCase.java 2008-04-08 18:54:09 UTC (rev 71802)
@@ -30,6 +30,7 @@
import junit.framework.TestCase;
import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.container.BeanContext;
import org.jboss.ejb3.interceptors.direct.DirectContainer;
import org.jboss.ejb3.test.interceptors.signature.PackageProtectedInterceptor;
import org.jboss.ejb3.test.interceptors.signature.SignatureTestBean;
@@ -39,7 +40,7 @@
* Comment
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class SignatureTestCase extends TestCase
{
@@ -69,7 +70,7 @@
DirectContainer<SignatureTestBean> container = new DirectContainer<SignatureTestBean>("SignatureTestBean", "Test", SignatureTestBean.class);
- SignatureTestBean bean = container.construct();
+ BeanContext<SignatureTestBean> bean = container.construct();
List<String> expectedLifeCycleVisits = Arrays.asList("org.jboss.ejb3.test.interceptors.signature.PackageProtectedInterceptor.postConstruct");
assertEquals(expectedLifeCycleVisits, lifeCycleVisits);
More information about the jboss-cvs-commits
mailing list