[jboss-cvs] JBossAS SVN: r71938 - in projects/ejb3/trunk: core/src/main/java/org/jboss/ejb3 and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 10 11:10:13 EDT 2008
Author: wolfc
Date: 2008-04-10 11:10:13 -0400 (Thu, 10 Apr 2008)
New Revision: 71938
Added:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainerBeanContextFactory.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java
Modified:
projects/ejb3/trunk/core/pom.xml
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BaseContext.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BeanContext.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocation.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocationWrapper.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockBeanContext.java
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/container/AbstractContainer.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContextFactory.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/SimpleBeanContextFactory.java
Log:
EJBTHREE-1246: integration into core
Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/pom.xml 2008-04-10 15:10:13 UTC (rev 71938)
@@ -255,6 +255,18 @@
<dependencies>
<dependency>
+ <groupId>javax.xml.soap</groupId>
+ <artifactId>saaj-api</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version> <!-- Only used here, for Unit Tests -->
@@ -349,7 +361,7 @@
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-interceptors</artifactId>
- <version>0.12.0-SNAPSHOT</version>
+ <version>0.13.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.ejb3</groupId>
@@ -445,18 +457,6 @@
<groupId>trove</groupId>
<artifactId>trove</artifactId>
</dependency>
- <dependency>
- <groupId>javax.xml.soap</groupId>
- <artifactId>saaj-api</artifactId>
- <version>1.3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- <version>1.4</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BaseContext.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BaseContext.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BaseContext.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -21,7 +21,9 @@
*/
package org.jboss.ejb3;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import org.jboss.aop.metadata.SimpleMetaData;
import org.jboss.ejb3.interceptor.InterceptorInfo;
@@ -43,6 +45,7 @@
protected SimpleMetaData metadata;
protected HashMap<Class, Object> interceptorInstances;
+ private Object interceptors[];
/**
* Use with extreme caution, must not break getInstance post condition.
@@ -89,31 +92,27 @@
return metadata;
}
- @Deprecated
public void initialiseInterceptorInstances()
{
- /*
- HashSet<InterceptorInfo> interceptors = ((EJBContainer)container).getApplicableInterceptors();
- if (interceptors != null && interceptors.size() > 0 && interceptorInstances == null)
+ try
{
- HashMap<Class,InterceptorInjector> interceptorInjectors = ((EJBContainer)container).getInterceptorInjectors();
- interceptorInstances = new HashMap<Class, Object>();
- for (InterceptorInfo info : interceptors)
+ EJBContainer c = (EJBContainer) container;
+ List<Class<?>> interceptorClasses = c.getBeanContainer().getInterceptorClasses();
+ List<Object> interceptors = new ArrayList<Object>();
+ for(Class<?> interceptorClass : interceptorClasses)
{
- try
- {
- Object instance = info.getClazz().newInstance();
- interceptorInstances.put(info.getClazz(), instance);
- interceptorInjectors.get(info.getClazz()).inject(this, instance);
- }
- catch (Exception e)
- {
- log.warn("Interceptors must have a public noargs constructor: " + info.getClazz().getName());
- }
+ interceptors.add(c.createInterceptor(interceptorClass));
}
+ this.interceptors = interceptors.toArray(new Object[0]);
}
- */
- log.warn("FIXME: don't call BaseContext.initialiseInterceptorInstances (EJBTHREE-1174)");
+ catch(IllegalAccessException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new RuntimeException(e.getCause());
+ }
}
@Deprecated
@@ -132,4 +131,9 @@
{
return container;
}
+
+ public Object[] getInterceptors()
+ {
+ return interceptors;
+ }
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BeanContext.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BeanContext.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/BeanContext.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -33,7 +33,7 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public interface BeanContext<T extends Container>
+public interface BeanContext<T extends Container> extends org.jboss.ejb3.interceptors.container.BeanContext<Object>
{
Object getInstance();
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -25,6 +25,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -56,23 +57,20 @@
import org.jboss.aop.Advisor;
import org.jboss.aop.Domain;
-import org.jboss.aop.InstanceAdvisor;
import org.jboss.aop.MethodInfo;
import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.advice.PerVmAdvice;
import org.jboss.aop.annotation.AnnotationRepository;
+import org.jboss.aop.joinpoint.ConstructionInvocation;
import org.jboss.aop.util.MethodHashing;
import org.jboss.ejb3.annotation.Clustered;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.jboss.ejb3.annotation.defaults.PoolDefaults;
import org.jboss.ejb3.aop.BeanContainer;
-import org.jboss.ejb3.aop.LifeCycleInvocation;
import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
import org.jboss.ejb3.interceptor.InterceptorInjector;
-import org.jboss.ejb3.interceptors.aop.InterceptorsFactory;
-import org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor;
+import org.jboss.ejb3.interceptors.aop.LifecycleCallbacks;
import org.jboss.ejb3.interceptors.container.ManagedObjectAdvisor;
import org.jboss.ejb3.interceptors.direct.DirectContainer;
import org.jboss.ejb3.interceptors.direct.IndirectContainer;
@@ -780,49 +778,28 @@
protected Object construct()
{
/*
- Interceptor[] cInterceptors = constructorInterceptors[defaultConstructorIndex];
- if (cInterceptors == null)
+ try
{
- try
- {
- return constructors[defaultConstructorIndex].newInstance();
- }
- catch (InstantiationException e)
- {
- throw new RuntimeException(e);
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(e);
- }
- catch (InvocationTargetException e)
- {
- throw new RuntimeException(e);
- }
+ return beanContainer.construct();
}
- ConstructorInvocation invocation = new ConstructorInvocation(
- cInterceptors);
-
- invocation.setAdvisor(this);
- invocation.setConstructor(constructors[defaultConstructorIndex]);
- try
+ catch (SecurityException e)
{
- return invocation.invokeNext();
+ throw new RuntimeException(e);
}
- catch (Throwable throwable)
+ catch (NoSuchMethodException e)
{
- throw new RuntimeException(throwable);
+ throw new RuntimeException(e);
}
*/
try
{
- return beanContainer.construct();
+ return beanClass.newInstance();
}
- catch (SecurityException e)
+ catch (InstantiationException e)
{
throw new RuntimeException(e);
}
- catch (NoSuchMethodException e)
+ catch (IllegalAccessException e)
{
throw new RuntimeException(e);
}
@@ -1038,11 +1015,15 @@
{
try
{
- List<Interceptor> interceptors = new ArrayList<Interceptor>(InterceptorsFactory.getLifeCycleInterceptors((InstanceAdvisor) getAdvisor(), callbackAnnotationClass));
- interceptors.add(0, PerVmAdvice.generateInterceptor(null, new InvocationContextInterceptor(), "setup"));
+ // Do lifecycle callbacks
+ List<Class<?>> lifecycleInterceptorClasses = beanContainer.getInterceptorRegistry().getLifecycleInterceptorClasses();
+ Advisor advisor = getAdvisor();
+ Interceptor interceptors[] = LifecycleCallbacks.createLifecycleCallbackInterceptors(advisor, lifecycleInterceptorClasses, beanContext, callbackAnnotationClass);
- LifeCycleInvocation invocation = new LifeCycleInvocation(interceptors.toArray(new Interceptor[0]));
- invocation.setAdvisor(getAdvisor());
+ Constructor<?> constructor = beanClass.getConstructor();
+ Object initargs[] = null;
+ ConstructionInvocation invocation = new ConstructionInvocation(interceptors, constructor, initargs);
+ invocation.setAdvisor(advisor);
invocation.setTargetObject(beanContext.getInstance());
invocation.invokeNext();
}
@@ -1067,7 +1048,7 @@
{
// This is the correct way to destroy an instance, do
// not call invokeCallback here.
- beanContainer.destroy(beanContext.getInstance());
+ beanContainer.destroy(beanContext);
}
public void invokePostActivate(BeanContext beanContext)
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocation.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocation.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocation.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -22,11 +22,12 @@
package org.jboss.ejb3;
import java.lang.reflect.Method;
+
import org.jboss.aop.Advisor;
import org.jboss.aop.MethodInfo;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
/**
* Representation of an EJB invocation on the serverside
@@ -34,16 +35,15 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class EJBContainerInvocation<A extends EJBContainer, T extends BeanContext> extends MethodInvocation
+public class EJBContainerInvocation<A extends EJBContainer, T extends BeanContext<?>> extends ContainerMethodInvocation
{
private static final long serialVersionUID = 4941832732679380382L;
- protected T ctx;
private BeanContextLifecycleCallback<T> callback;
public EJBContainerInvocation(MethodInfo info)
{
- super(info, info.getInterceptors());
+ super(info);
}
public EJBContainerInvocation(Interceptor[] interceptors, long methodHash, Method advisedMethod, Method unadvisedMethod, Advisor advisor)
@@ -56,37 +56,31 @@
super(null, null);
}
- /*
- @SuppressWarnings("unchecked")
- public A getAdvisor()
+ @Override
+ public T getBeanContext()
{
- return (A) super.getAdvisor();
+ return (T) super.getBeanContext();
}
- */
- public T getBeanContext()
+ @Override
+ public void setBeanContext(org.jboss.ejb3.interceptors.container.BeanContext<?> beanCtx)
{
- return ctx;
- }
-
- public void setBeanContext(T beanCtx)
- {
if(beanCtx != null)
{
- ctx = beanCtx;
+ super.setBeanContext(beanCtx);
if(callback != null)
- callback.attached(beanCtx);
+ callback.attached((T) beanCtx);
}
else
{
if(callback != null)
- callback.released(ctx);
+ callback.released(getBeanContext());
- ctx = null;
+ super.setBeanContext(beanCtx);
}
}
-
+
public Invocation getWrapper(Interceptor[] newchain)
{
return new EJBContainerInvocationWrapper<A, T>(this, newchain);
@@ -97,9 +91,9 @@
EJBContainerInvocation<A, T> wrapper = new EJBContainerInvocation<A, T>(interceptors, methodHash, advisedMethod, unadvisedMethod, advisor);
wrapper.metadata = this.metadata;
wrapper.currentInterceptor = this.currentInterceptor;
- wrapper.setTargetObject(this.getTargetObject());
+ //wrapper.setTargetObject(this.getTargetObject());
wrapper.setArguments(this.getArguments());
- wrapper.setBeanContext(this.ctx);
+ wrapper.setBeanContext(getBeanContext());
wrapper.callback = this.callback;
return wrapper;
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocationWrapper.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocationWrapper.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainerInvocationWrapper.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -36,7 +36,7 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class EJBContainerInvocationWrapper<A extends EJBContainer, T extends BeanContext> extends EJBContainerInvocation<A, T>
+public class EJBContainerInvocationWrapper<A extends EJBContainer, T extends BeanContext<?>> extends EJBContainerInvocation<A, T>
{
private static final long serialVersionUID = 5402917625526438235L;
@@ -173,4 +173,16 @@
{
return wrapped.getAdvisor();
}
+
+ @Override
+ public T getBeanContext()
+ {
+ return wrapped.getBeanContext();
+ }
+
+ @Override
+ public void setBeanContext(org.jboss.ejb3.interceptors.container.BeanContext<?> beanCtx)
+ {
+ wrapped.setBeanContext(beanCtx);
+ }
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainer.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainer.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -31,10 +31,7 @@
import org.jboss.aop.Advisor;
import org.jboss.aop.Domain;
-import org.jboss.aop.MethodInfo;
import org.jboss.aop.annotation.AnnotationRepository;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.aop.util.MethodHashing;
import org.jboss.ejb3.EJBContainer;
import org.jboss.ejb3.cluster.metadata.ClusteredMetaDataBridge;
import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
@@ -68,15 +65,9 @@
super();
assert container != null : "container is null";
this.container = container;
+ setBeanContextFactoryClass(BeanContainerBeanContextFactory.class);
}
- public BeanContainer(EJBContainer container, String name, String domainName, Class<? extends Object> beanClass)
- {
- super(name, domainName, beanClass);
- assert container != null : "container is null";
- this.container = container;
- }
-
private static void addInterceptorClasses(List<Class<?>> interceptorClasses, Class<?> interceptors[])
{
if(interceptors != null)
@@ -264,6 +255,7 @@
advisor.initialize(beanClass);
}
+ /*
@Override
public Object invoke(Object target, Method method, Object[] arguments) throws Throwable
{
@@ -277,6 +269,7 @@
invocation.setTargetObject(target);
return invocation.invokeNext();
}
+ */
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainerBeanContextFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainerBeanContextFactory.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/aop/BeanContainerBeanContextFactory.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -0,0 +1,56 @@
+/*
+ * 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.aop;
+
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.container.BeanContextFactory;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class BeanContainerBeanContextFactory implements BeanContextFactory<Object, BeanContainer>
+{
+ private BeanContainer container;
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.interceptors.container.BeanContextFactory#createBean()
+ */
+ public BeanContext<Object> createBean() throws Exception
+ {
+ return container.getEJBContainer().createBeanContext();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.interceptors.container.BeanContextFactory#destroyBean(org.jboss.ejb3.interceptors.container.BeanContext)
+ */
+ public void destroyBean(BeanContext<Object> bean)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setContainer(BeanContainer container)
+ {
+ this.container = container;
+ }
+}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -49,7 +49,6 @@
import org.jboss.aop.MethodInfo;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.advice.PerVmAdvice;
-import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.InvocationResponse;
import org.jboss.aop.util.MethodHashing;
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -35,7 +35,7 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class StatefulContainerInvocation extends EJBContainerInvocation
+public class StatefulContainerInvocation extends EJBContainerInvocation<StatefulContainer, StatefulBeanContext>
{
private static final long serialVersionUID = -7636489066612082373L;
@@ -67,9 +67,9 @@
StatefulContainerInvocation wrapper = new StatefulContainerInvocation(interceptors, methodHash, advisedMethod, unadvisedMethod, advisor, id);
wrapper.metadata = this.metadata;
wrapper.currentInterceptor = this.currentInterceptor;
- wrapper.setTargetObject(this.getTargetObject());
+ //wrapper.setTargetObject(this.getTargetObject());
wrapper.setArguments(this.getArguments());
- wrapper.setBeanContext(this.ctx);
+ wrapper.setBeanContext(getBeanContext());
return wrapper;
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -23,19 +23,14 @@
import java.rmi.RemoteException;
-import javax.ejb.ApplicationException;
import javax.ejb.ConcurrentAccessException;
import javax.ejb.EJBException;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.ejb3.EJBContainer;
import org.jboss.ejb3.annotation.SerializedConcurrentAccess;
import org.jboss.ejb3.aop.AbstractInterceptor;
import org.jboss.logging.Logger;
-import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
-import org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData;
-import org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData;
/**
* Comment
@@ -77,7 +72,6 @@
target.setInInvocation(true);
}
}
- ejb.setTargetObject(target.getInstance());
ejb.setBeanContext(target);
StatefulBeanContext.currentBean.push(target);
container.pushContext(target);
@@ -103,6 +97,7 @@
{
container.popContext();
StatefulBeanContext.currentBean.pop();
+ ejb.setBeanContext(null);
synchronized (target)
{
target.setInInvocation(false);
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -26,7 +26,11 @@
import java.util.Hashtable;
import java.util.Map;
-import javax.ejb.*;
+import javax.ejb.EJBContext;
+import javax.ejb.EJBException;
+import javax.ejb.Handle;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
import javax.naming.NamingException;
import org.jboss.aop.Domain;
@@ -52,19 +56,19 @@
import org.jboss.ejb3.session.SessionContainer;
import org.jboss.ejb3.timerservice.TimedObjectInvoker;
import org.jboss.ejb3.timerservice.TimerServiceFactory;
+import org.jboss.injection.lang.reflect.BeanProperty;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
import org.jboss.proxy.ejb.handle.HomeHandleImpl;
import org.jboss.proxy.ejb.handle.StatelessHandleImpl;
-import org.jboss.wsf.spi.invocation.integration.ServiceEndpointContainer;
-import org.jboss.wsf.spi.invocation.integration.InvocationContextCallback;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.invocation.ExtensibleWebServiceContext;
+import org.jboss.wsf.spi.invocation.InvocationType;
import org.jboss.wsf.spi.invocation.WebServiceContextFactory;
-import org.jboss.wsf.spi.invocation.InvocationType;
-import org.jboss.wsf.spi.SPIProvider;
-import org.jboss.wsf.spi.SPIProviderResolver;
-import org.jboss.injection.lang.reflect.BeanProperty;
+import org.jboss.wsf.spi.invocation.integration.InvocationContextCallback;
+import org.jboss.wsf.spi.invocation.integration.ServiceEndpointContainer;
/**
@@ -321,7 +325,7 @@
EJBContainerInvocation newSi = null;
- newSi = new EJBContainerInvocation(info);
+ newSi = new EJBContainerInvocation<StatelessContainer, StatelessBeanContext>(info);
newSi.setArguments(si.getArguments());
newSi.setMetaData(si.getMetaData());
newSi.setAdvisor(getAdvisor());
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -52,11 +52,12 @@
public Object invoke(Invocation invocation) throws Throwable
{
- EJBContainerInvocation ejb = (EJBContainerInvocation) invocation;
+ EJBContainerInvocation<StatelessContainer, StatelessBeanContext> ejb = (EJBContainerInvocation<StatelessContainer, StatelessBeanContext>) invocation;
EJBContainer container = getEJBContainer(invocation);
Pool pool = container.getPool();
BeanContext<?> ctx = pool.get();
- ejb.setTargetObject(ctx.getInstance());
+ assert ctx != null : "pool returned null instance";
+ //ejb.setTargetObject(ctx.getInstance());
ejb.setBeanContext(ctx);
container.pushContext(ctx);
@@ -75,7 +76,7 @@
finally
{
container.popContext();
- ejb.setTargetObject(null);
+ //ejb.setTargetObject(null);
ejb.setBeanContext(null);
if (discard) pool.discard(ctx);
else pool.release(ctx);
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockBeanContext.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockBeanContext.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockBeanContext.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -33,7 +33,7 @@
* Comment
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class MockBeanContext implements BeanContext
{
@@ -92,6 +92,15 @@
}
/* (non-Javadoc)
+ * @see org.jboss.ejb3.interceptors.container.BeanContext#getInterceptors()
+ */
+ public Object[] getInterceptors()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.ejb3.BeanContext#getInvokedMethodKey()
*/
public Object getInvokedMethodKey()
Modified: 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 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/EJB3InterceptorInterceptor.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -68,10 +68,13 @@
{
// TODO: speed up
Object interceptors[] = ContainerMethodInvocation.getContainerMethodInvocation(invocation).getBeanContext().getInterceptors();
- for(Object interceptor : interceptors)
+ if(interceptors != null)
{
- if(interceptor.getClass().equals(interceptorClass))
- return invoke(interceptor, invocation);
+ for(Object interceptor : interceptors)
+ {
+ if(interceptor.getClass().equals(interceptorClass))
+ return invoke(interceptor, 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
Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/LifecycleCallbacks.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -0,0 +1,74 @@
+/*
+ * 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.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.advice.PerVmAdvice;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.lang.ClassHelper;
+
+/**
+ * The common logic for lifecycle callbacks.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class LifecycleCallbacks
+{
+ public static Interceptor[] createLifecycleCallbackInterceptors(Advisor advisor, List<Class<?>> lifecycleInterceptorClasses, BeanContext<?> component, Class<? extends Annotation> lifecycleAnnotationType) throws Exception
+ {
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ Object ejb3Interceptors[] = component.getInterceptors();
+ for(Object interceptor : ejb3Interceptors)
+ {
+ // 12.7 footnote 57: ignore method level interceptors
+ Class<?> interceptorClass = interceptor.getClass();
+ if(!lifecycleInterceptorClasses.contains(interceptorClass))
+ continue;
+ ExtendedAdvisor interceptorAdvisor = ExtendedAdvisorHelper.getExtendedAdvisor(advisor, interceptor);
+ for(Method interceptorMethod : ClassHelper.getAllMethods(interceptorClass))
+ {
+ if(interceptorAdvisor.isAnnotationPresent(interceptorClass, interceptorMethod, lifecycleAnnotationType))
+ {
+ interceptors.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, interceptorMethod));
+ }
+ }
+ }
+ Class<?> beanClass = advisor.getClazz();
+ for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
+ {
+ if(advisor.hasAnnotation(beanMethod, lifecycleAnnotationType))
+ {
+ interceptors.add(new LifecycleCallbackBeanMethodInterceptor(beanMethod));
+ }
+ }
+ interceptors.add(0, PerVmAdvice.generateInterceptor(null, new InvocationContextInterceptor(), "setup"));
+
+ return interceptors.toArray(new Interceptor[0]);
+ }
+}
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-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -85,32 +85,6 @@
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<Object> ejb3Interceptors = new ArrayList<Object>();
- for(Class<?> interceptorClass : getInterceptorRegistry().getInterceptorClasses())
- {
- Object interceptor = interceptorFactory.create(advisor, interceptorClass);
- ejb3Interceptors.add(interceptor);
- }
-
- T targetObject = getBeanClass().cast(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();
-
- return new DummyBeanContext<T>(targetObject, ejb3Interceptors);
- */
return getBeanContextFactory().createBean();
}
catch(Throwable t)
@@ -129,26 +103,6 @@
protected void destroy(BeanContext<T> bean)
{
- /*
- try
- {
- // TODO: speed up
- List<Interceptor> interceptors = new ArrayList<Interceptor>(InterceptorsFactory.getPreDestroys(advisor));
- interceptors.add(0, PerVmAdvice.generateInterceptor(null, new InvocationContextInterceptor(), "setup"));
-
- DestructionInvocation invocation = new DestructionInvocation(interceptors.toArray(new Interceptor[0]));
- invocation.setAdvisor(advisor);
- invocation.setTargetObject(bean.getInstance());
- invocation.invokeNext();
- }
- catch(Throwable t)
- {
- // TODO: disect
- if(t instanceof RuntimeException)
- throw (RuntimeException) t;
- throw new RuntimeException(t);
- }
- */
getBeanContextFactory().destroyBean(bean);
}
@@ -165,7 +119,7 @@
try
{
beanContextFactory = beanContextFactoryClass.newInstance();
- beanContextFactory.setContainer(this);
+ beanContextFactory.setContainer((C) this);
}
catch (InstantiationException e)
{
@@ -290,7 +244,7 @@
return (R) invoke(target, method, args);
}
- public void setBeanContextFactoryClass(Class<BeanContextFactory<T, C>> beanContextFactoryClass)
+ public void setBeanContextFactoryClass(Class<? extends BeanContextFactory<T, C>> beanContextFactoryClass)
{
this.beanContextFactoryClass = beanContextFactoryClass;
}
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContextFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContextFactory.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/BeanContextFactory.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -35,5 +35,5 @@
void destroyBean(BeanContext<T> bean);
- void setContainer(AbstractContainer<T, C> container);
+ void setContainer(C container);
}
Modified: 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 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -21,6 +21,9 @@
*/
package org.jboss.ejb3.interceptors.container;
+import java.lang.reflect.Method;
+
+import org.jboss.aop.Advisor;
import org.jboss.aop.MethodInfo;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
@@ -34,8 +37,34 @@
*/
public class ContainerMethodInvocation extends MethodInvocation
{
+ private static final long serialVersionUID = 1L;
+
private BeanContext<?> beanContext;
+ /**
+ * Meant for use in the EJB container, which does a late beanContext
+ * association using an instance interceptor.
+ */
+ protected ContainerMethodInvocation(MethodInfo info)
+ {
+ super(info, info.getInterceptors());
+ }
+
+ protected ContainerMethodInvocation(Interceptor[] interceptors, long methodHash, Method advisedMethod, Method unadvisedMethod, Advisor advisor)
+ {
+ super(interceptors, methodHash, advisedMethod, unadvisedMethod, advisor);
+ }
+
+ protected ContainerMethodInvocation()
+ {
+ super();
+ }
+
+ protected ContainerMethodInvocation(MethodInfo info, Interceptor[] interceptors)
+ {
+ super(info, interceptors);
+ }
+
ContainerMethodInvocation(MethodInfo info, BeanContext<?> beanContext, Object arguments[])
{
super(info, info.getInterceptors());
@@ -43,9 +72,7 @@
assert beanContext != null : "beanContext is null";
setArguments(arguments);
- setTargetObject(beanContext.getInstance());
-
- this.beanContext = beanContext;
+ setBeanContext(beanContext);
}
/**
@@ -58,6 +85,7 @@
public BeanContext<?> getBeanContext()
{
+ assert beanContext != null : "beanContext has not been set";
return beanContext;
}
@@ -73,4 +101,22 @@
{
return new ContainerMethodInvocationWrapper(this, newchain);
}
+
+ /**
+ * @param beanContext the beanContext to set or null for disassociation
+ */
+ public void setBeanContext(BeanContext<?> beanContext)
+ {
+ this.beanContext = beanContext;
+ if(beanContext != null)
+ super.setTargetObject(beanContext.getInstance());
+ else
+ super.setTargetObject(null);
+ }
+
+ @Override
+ public void setTargetObject(Object targetObject)
+ {
+ throw new RuntimeException("Call setBeanContext, not setTargetObject");
+ }
}
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/SimpleBeanContextFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/SimpleBeanContextFactory.java 2008-04-10 15:03:33 UTC (rev 71937)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/SimpleBeanContextFactory.java 2008-04-10 15:10:13 UTC (rev 71938)
@@ -23,7 +23,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -33,16 +32,10 @@
import org.jboss.aop.Advisor;
import org.jboss.aop.ClassAdvisor;
import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.advice.PerVmAdvice;
import org.jboss.aop.joinpoint.ConstructionInvocation;
import org.jboss.ejb3.interceptors.InterceptorFactory;
import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
-import org.jboss.ejb3.interceptors.aop.ExtendedAdvisor;
-import org.jboss.ejb3.interceptors.aop.ExtendedAdvisorHelper;
-import org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor;
-import org.jboss.ejb3.interceptors.aop.LifecycleCallbackBeanMethodInterceptor;
-import org.jboss.ejb3.interceptors.aop.LifecycleCallbackInterceptorMethodInterceptor;
-import org.jboss.ejb3.interceptors.lang.ClassHelper;
+import org.jboss.ejb3.interceptors.aop.LifecycleCallbacks;
import org.jboss.logging.Logger;
/**
@@ -53,7 +46,7 @@
{
private static final Logger log = Logger.getLogger(SimpleBeanContextFactory.class);
- private AbstractContainer<T, C> container;
+ private C container;
public BeanContext<T> createBean() throws Exception
{
@@ -126,37 +119,10 @@
{
List<Class<?>> lifecycleInterceptorClasses = container.getInterceptorRegistry().getLifecycleInterceptorClasses();
Advisor advisor = container.getAdvisor();
- List<Interceptor> interceptors = new ArrayList<Interceptor>();
- Object ejb3Interceptors[] = component.getInterceptors();
- for(Object interceptor : ejb3Interceptors)
- {
- // 12.7 footnote 57: ignore method level interceptors
- Class<?> interceptorClass = interceptor.getClass();
- if(!lifecycleInterceptorClasses.contains(interceptorClass))
- continue;
- ExtendedAdvisor interceptorAdvisor = ExtendedAdvisorHelper.getExtendedAdvisor(advisor, interceptor);
- for(Method interceptorMethod : ClassHelper.getAllMethods(interceptorClass))
- {
- if(interceptorAdvisor.isAnnotationPresent(interceptorClass, interceptorMethod, lifecycleAnnotationType))
- {
- interceptors.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, interceptorMethod));
- }
- }
- }
- Class<?> beanClass = container.getBeanClass();
- for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
- {
- if(advisor.hasAnnotation(beanMethod, lifecycleAnnotationType))
- {
- interceptors.add(new LifecycleCallbackBeanMethodInterceptor(beanMethod));
- }
- }
- interceptors.add(0, PerVmAdvice.generateInterceptor(null, new InvocationContextInterceptor(), "setup"));
-
- return interceptors.toArray(new Interceptor[0]);
+ return LifecycleCallbacks.createLifecycleCallbackInterceptors(advisor, lifecycleInterceptorClasses, component, lifecycleAnnotationType);
}
- public void setContainer(AbstractContainer<T, C> container)
+ public void setContainer(C container)
{
this.container = container;
}
More information about the jboss-cvs-commits
mailing list