[jboss-cvs] JBossAS SVN: r77542 - in projects/ejb3/trunk/core/src: main/java/org/jboss/ejb3/injection and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 27 11:13:45 EDT 2008
Author: wolfc
Date: 2008-08-27 11:13:45 -0400 (Wed, 27 Aug 2008)
New Revision: 77542
Added:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/injection/InjectionInvocation.java
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContextImpl.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockContainer.java
Log:
EJBTHREE-1474: hack for checking injection invocations
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java 2008-08-27 15:12:48 UTC (rev 77541)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java 2008-08-27 15:13:45 UTC (rev 77542)
@@ -22,6 +22,7 @@
package org.jboss.ejb3;
import java.util.Hashtable;
+
import javax.ejb.TimerService;
import javax.management.ObjectName;
import javax.naming.Context;
@@ -70,6 +71,8 @@
Pool getPool();
+ void injectBeanContext(BeanContext<?> beanContext);
+
void invokePostConstruct(BeanContext beanContext, Object[] params);
void invokePreDestroy(BeanContext beanContext);
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-08-27 15:12:48 UTC (rev 77541)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2008-08-27 15:13:45 UTC (rev 77542)
@@ -65,6 +65,7 @@
import org.jboss.aop.annotation.AnnotationRepository;
import org.jboss.aop.joinpoint.ConstructionInvocation;
import org.jboss.aop.util.MethodHashing;
+import org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor;
import org.jboss.ejb.AllowedOperationsAssociation;
import org.jboss.ejb3.annotation.Clustered;
import org.jboss.ejb3.annotation.SecurityDomain;
@@ -72,6 +73,7 @@
import org.jboss.ejb3.aop.BeanContainer;
import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.ejb3.injection.InjectionInvocation;
import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
import org.jboss.ejb3.interceptor.InterceptorInjector;
import org.jboss.ejb3.interceptors.aop.LifecycleCallbacks;
@@ -84,7 +86,6 @@
import org.jboss.ejb3.pool.Pool;
import org.jboss.ejb3.pool.PoolFactory;
import org.jboss.ejb3.pool.PoolFactoryRegistry;
-import org.jboss.ejb3.proxy.container.InvokableContext;
import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
import org.jboss.ejb3.security.SecurityDomainManager;
import org.jboss.ejb3.statistics.InvocationStatistics;
@@ -187,6 +188,8 @@
// To support clean startup/shutdown
private ReadWriteLock containerLock = new ReentrantReadWriteLock();
+ private static final Interceptor[] currentInvocationStack = new Interceptor[] { new CurrentInvocationInterceptor() };
+
/**
* @param name Advisor name
* @param manager Domain to get interceptor bindings from
@@ -1032,6 +1035,37 @@
}
/**
+ * Note this method is a WIP.
+ *
+ * In actuality ejb3-interceptors should perform the injection itself,
+ * but this requires a rewrite of all injectors.
+ */
+ public void injectBeanContext(BeanContext<?> beanContext)
+ {
+ try
+ {
+ if(injectors == null)
+ return;
+ Advisor advisor = getAdvisor();
+ for (Injector injector : injectors)
+ {
+ InjectionInvocation invocation = new InjectionInvocation(beanContext, injector, currentInvocationStack);
+ invocation.setAdvisor(advisor);
+ invocation.setTargetObject(beanContext.getInstance());
+ invocation.invokeNext();
+ }
+ }
+ catch(Throwable t)
+ {
+ if(t instanceof Error)
+ throw (Error) t;
+ if(t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ throw new RuntimeException(t);
+ }
+ }
+
+ /**
* Note that this method is a WIP.
*
* @param beanContext
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContextImpl.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContextImpl.java 2008-08-27 15:12:48 UTC (rev 77541)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContextImpl.java 2008-08-27 15:13:45 UTC (rev 77542)
@@ -34,7 +34,10 @@
import javax.naming.NamingException;
import javax.transaction.UserTransaction;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aspects.currentinvocation.CurrentInvocation;
import org.jboss.ejb3.annotation.SecurityDomain;
+import org.jboss.ejb3.interceptors.container.InvocationHelper;
import org.jboss.ejb3.security.helpers.EJBContextHelper;
import org.jboss.ejb3.tx.TxUtil;
import org.jboss.logging.Logger;
@@ -171,6 +174,9 @@
public TimerService getTimerService() throws IllegalStateException
{
+ Invocation invocation = CurrentInvocation.getCurrentInvocation();
+ if(InvocationHelper.isInjection(invocation))
+ throw new IllegalStateException("getTimerService() not allowed during injection (EJB3 4.5.2)");
return getContainer().getTimerService();
}
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/injection/InjectionInvocation.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/injection/InjectionInvocation.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/injection/InjectionInvocation.java 2008-08-27 15:13:45 UTC (rev 77542)
@@ -0,0 +1,92 @@
+/*
+ * 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.injection;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationBase;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.injection.Injector;
+
+/**
+ * Perform injection via an interceptor chain.
+ *
+ * This should be part of ejb3-interceptors.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InjectionInvocation extends InvocationBase
+ implements org.jboss.ejb3.interceptors.container.InjectionInvocation
+{
+ private static final long serialVersionUID = 1L;
+
+ private BeanContext<?> ctx;
+ private Injector injector;
+
+ public InjectionInvocation(BeanContext<?> ctx, Injector injector, Interceptor interceptors[])
+ {
+ super(interceptors);
+
+ assert ctx != null : "ctx is null";
+ assert injector != null : "injector is null";
+
+ this.ctx = ctx;
+ this.injector = injector;
+ }
+
+ public Invocation copy()
+ {
+ throw new RuntimeException("NYI");
+ }
+
+ public Invocation getWrapper(Interceptor[] newchain)
+ {
+ throw new RuntimeException("NYI");
+ }
+
+ @Override
+ 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--;
+ }
+ }
+
+ return invokeTarget();
+ }
+
+ @Override
+ public Object invokeTarget() throws Throwable
+ {
+ injector.inject(ctx);
+ return null;
+ }
+}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java 2008-08-27 15:12:48 UTC (rev 77541)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java 2008-08-27 15:13:45 UTC (rev 77542)
@@ -80,13 +80,7 @@
container.pushContext(ctx);
try
{
- if (injectors != null)
- {
- for (int i = 0; i < injectors.length; i++)
- {
- injectors[i].inject(ctx);
- }
- }
+ container.injectBeanContext(ctx);
ctx.initialiseInterceptorInstances();
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-08-27 15:12:48 UTC (rev 77541)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2008-08-27 15:13:45 UTC (rev 77542)
@@ -26,14 +26,11 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.rmi.NoSuchObjectException;
-import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Map;
import javax.ejb.EJBHome;
-import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
import javax.ejb.Handle;
@@ -55,14 +52,12 @@
import org.jboss.aop.util.PayloadKey;
import org.jboss.aspects.asynch.FutureHolder;
import org.jboss.ejb3.BeanContext;
-import org.jboss.ejb3.EJBContainerInvocation;
import org.jboss.ejb3.Ejb3Deployment;
import org.jboss.ejb3.annotation.Cache;
import org.jboss.ejb3.annotation.CacheConfig;
import org.jboss.ejb3.annotation.Clustered;
import org.jboss.ejb3.annotation.LocalBinding;
import org.jboss.ejb3.annotation.RemoteBinding;
-import org.jboss.ejb3.annotation.RemoteBindings;
import org.jboss.ejb3.cache.CacheFactoryRegistry;
import org.jboss.ejb3.cache.Ejb3CacheFactory;
import org.jboss.ejb3.cache.StatefulCache;
@@ -70,7 +65,6 @@
import org.jboss.ejb3.common.lang.SerializableMethod;
import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
import org.jboss.ejb3.interceptors.container.StatefulSessionContainerMethodInvocation;
-import org.jboss.ejb3.proxy.ProxyFactory;
import org.jboss.ejb3.proxy.ProxyUtils;
import org.jboss.ejb3.proxy.clustered.objectstore.ClusteredObjectStoreBindings;
import org.jboss.ejb3.proxy.container.StatefulSessionInvokableContext;
@@ -135,13 +129,7 @@
pushContext(sfctx);
try
{
- if (injectors != null)
- {
- for (Injector injector : injectors)
- {
- injector.inject(sfctx);
- }
- }
+ injectBeanContext(sfctx);
sfctx.initialiseInterceptorInstances();
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockContainer.java 2008-08-27 15:12:48 UTC (rev 77541)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/threadlocal/MockContainer.java 2008-08-27 15:13:45 UTC (rev 77542)
@@ -184,6 +184,15 @@
}
/* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#injectContext(org.jboss.ejb3.BeanContext)
+ */
+ public void injectBeanContext(BeanContext<?> beanContext)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.ejb3.Container#invokeInit(java.lang.Object)
*/
public void invokeInit(Object bean)
More information about the jboss-cvs-commits
mailing list