[webbeans-commits] Webbeans SVN: r3613 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/bean and 12 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Aug 27 19:09:33 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-08-27 19:09:32 -0400 (Thu, 27 Aug 2009)
New Revision: 3613
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptors.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptorCache.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/ws/spi/
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java
ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/api/SessionObjectReference.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbDescriptor.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbDescriptor.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
Log:
WBRI-329, big improvement to the way we track enterprise beans
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -62,13 +62,14 @@
import org.jboss.webbeans.bean.DecoratorBean;
import org.jboss.webbeans.bean.EnterpriseBean;
-import org.jboss.webbeans.bean.NewEnterpriseBean;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bean.proxy.ClientProxyProvider;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.CreationalContextImpl;
import org.jboss.webbeans.context.WBCreationalContext;
+import org.jboss.webbeans.ejb.EjbDescriptors;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.el.Namespace;
import org.jboss.webbeans.el.WebBeansELResolver;
import org.jboss.webbeans.introspector.WBAnnotated;
@@ -189,7 +190,7 @@
private transient final Map<String, RIBean<?>> riBeans;
// TODO review this structure
- private transient final Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans;
+ private transient final Map<EjbDescriptor<?>, EnterpriseBean<?>> enterpriseBeans;
// TODO This isn't right, specialization should follow accessibility rules, but I think we can enforce these in resolve()
private transient final Map<Contextual<?>, Contextual<?>> specializedBeans;
@@ -283,7 +284,7 @@
new CopyOnWriteArrayList<DecoratorBean<?>>(),
new CopyOnWriteArrayList<ObserverMethod<?,?>>(),
new CopyOnWriteArrayList<String>(),
- new ConcurrentHashMap<Class<?>, EnterpriseBean<?>>(),
+ new ConcurrentHashMap<EjbDescriptor<?>, EnterpriseBean<?>>(),
new ConcurrentHashMap<String, RIBean<?>>(),
new ClientProxyProvider(),
contexts,
@@ -309,7 +310,7 @@
new CopyOnWriteArrayList<DecoratorBean<?>>(),
new CopyOnWriteArrayList<ObserverMethod<?,?>>(),
new CopyOnWriteArrayList<String>(),
- rootManager.getNewEnterpriseBeanMap(),
+ rootManager.getEnterpriseBeans(),
new ConcurrentHashMap<String, RIBean<?>>(),
rootManager.getClientProxyProvider(),
rootManager.getContexts(),
@@ -343,7 +344,7 @@
parentManager.getDecorators(),
registeredObservers,
namespaces,
- parentManager.getNewEnterpriseBeanMap(),
+ parentManager.getEnterpriseBeans(),
parentManager.getRiBeans(),
parentManager.getClientProxyProvider(),
parentManager.getContexts(),
@@ -367,7 +368,7 @@
List<DecoratorBean<?>> decorators,
List<ObserverMethod<?,?>> observers,
List<String> namespaces,
- Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans,
+ Map<EjbDescriptor<?>, EnterpriseBean<?>> enterpriseBeans,
Map<String, RIBean<?>> riBeans,
ClientProxyProvider clientProxyProvider,
ListMultimap<Class<? extends Annotation>, Context> contexts,
@@ -381,7 +382,7 @@
this.services = serviceRegistry;
this.beans = beans;
this.decorators = decorators;
- this.newEnterpriseBeans = newEnterpriseBeans;
+ this.enterpriseBeans = enterpriseBeans;
this.riBeans = riBeans;
this.clientProxyProvider = clientProxyProvider;
this.contexts = contexts;
@@ -528,12 +529,12 @@
{
return;
}
- if (bean instanceof NewEnterpriseBean)
+ if (bean.getClass().equals(EnterpriseBean.class))
{
- NewEnterpriseBean<?> newEnterpriseBean = (NewEnterpriseBean<?>) bean;
- newEnterpriseBeans.put(newEnterpriseBean.getType(), newEnterpriseBean);
+ EnterpriseBean<?> enterpriseBean = (EnterpriseBean<?>) bean;
+ enterpriseBeans.put(enterpriseBean.getEjbDescriptor(), enterpriseBean);
}
- if (bean instanceof RIBean)
+ if (bean instanceof RIBean<?>)
{
RIBean<?> riBean = (RIBean<?>) bean;
riBeans.put(riBean.getId(), riBean);
@@ -752,9 +753,9 @@
*
* @return The bean map
*/
- public Map<Class<?>, EnterpriseBean<?>> getNewEnterpriseBeanMap()
+ public Map<EjbDescriptor<?>, EnterpriseBean<?>> getEnterpriseBeans()
{
- return newEnterpriseBeans;
+ return enterpriseBeans;
}
/**
@@ -1284,9 +1285,13 @@
public <T> InjectionTarget<T> createInjectionTarget(AnnotatedType<T> type)
{
- // TODO Cache on our side?
return new SimpleInjectionTarget<T>(getServices().get(ClassTransformer.class).loadClass(type), this);
}
+
+ public <T> InjectionTarget<T> createInjectionTarget(EjbDescriptor<T> descriptor)
+ {
+ return getBean(descriptor);
+ }
public <X> Bean<? extends X> getMostSpecializedBean(Bean<X> bean)
{
@@ -1400,4 +1405,14 @@
}
}
+ public <T> EjbDescriptor<T> getEjbDescriptor(String beanName)
+ {
+ return getServices().get(EjbDescriptors.class).get(beanName);
+ }
+
+ public <T> EnterpriseBean<T> getBean(EjbDescriptor<T> descriptor)
+ {
+ return (EnterpriseBean<T>) getEnterpriseBeans().get(descriptor);
+ }
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -42,6 +42,7 @@
import org.jboss.webbeans.injection.FieldInjectionPoint;
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBMethod;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.Beans;
@@ -74,6 +75,8 @@
private Class<T> proxyClassForDecorators;
private final ThreadLocal<Integer> decoratorStackPosition;
+ private WBMethod<?, ?> postConstruct;
+ private WBMethod<?, ?> preDestroy;
/**
* Constructor
@@ -351,6 +354,75 @@
{
return id;
}
+
+ public void postConstruct(T instance)
+ {
+ WBMethod<?, ?> postConstruct = getPostConstruct();
+ if (postConstruct != null)
+ {
+ try
+ {
+ postConstruct.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to invoke " + postConstruct + " on " + instance, e);
+ }
+ }
+ }
+
+ public void preDestroy(T instance)
+ {
+ WBMethod<?, ?> preDestroy = getPreDestroy();
+ if (preDestroy != null)
+ {
+ try
+ {
+ // note: RI supports injection into @PreDestroy
+ preDestroy.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to invoke " + preDestroy + " on " + instance, e);
+ }
+ }
+ }
+
+ /**
+ * Initializes the post-construct method
+ */
+ protected void initPostConstruct()
+ {
+ this.postConstruct = Beans.getPostConstruct(getAnnotatedItem());
+ }
+
+ /**
+ * Initializes the pre-destroy method
+ */
+ protected void initPreDestroy()
+ {
+ this.preDestroy = Beans.getPreDestroy(getAnnotatedItem());
+ }
+
+ /**
+ * Returns the post-construct method
+ *
+ * @return The post-construct method
+ */
+ public WBMethod<?, ?> getPostConstruct()
+ {
+ return postConstruct;
+ }
+
+ /**
+ * Returns the pre-destroy method
+ *
+ * @return The pre-destroy method
+ */
+ public WBMethod<?, ?> getPreDestroy()
+ {
+ return preDestroy;
+ }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -46,10 +46,12 @@
import org.jboss.webbeans.ejb.api.SessionObjectReference;
import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.injection.InjectionContextImpl;
import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.introspector.WBMethod;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.resources.ClassTransformer;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Proxies;
@@ -79,9 +81,10 @@
* @param manager the current manager
* @return An Enterprise Web Bean
*/
- public static <T> EnterpriseBean<T> of(WBClass<T> clazz, BeanManagerImpl manager, BeanDeployerEnvironment environment)
+ public static <T> EnterpriseBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
{
- return new EnterpriseBean<T>(clazz, manager, environment);
+ WBClass<T> type = manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
+ return new EnterpriseBean<T>(type, ejbDescriptor, manager);
}
/**
@@ -90,26 +93,11 @@
* @param type The type of the bean
* @param manager The Web Beans manager
*/
- protected EnterpriseBean(WBClass<T> type, BeanManagerImpl manager, BeanDeployerEnvironment environment)
+ protected EnterpriseBean(WBClass<T> type, InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
{
super(type, manager);
initType();
- Iterable<InternalEjbDescriptor<T>> ejbDescriptors = environment.getEjbDescriptors().get(getType());
- if (ejbDescriptors == null)
- {
- throw new DefinitionException("Not an EJB " + toString());
- }
- for (InternalEjbDescriptor<T> ejbDescriptor : ejbDescriptors)
- {
- if (this.ejbDescriptor == null)
- {
- this.ejbDescriptor = ejbDescriptor;
- }
- else
- {
- throw new RuntimeException("TODO Multiple EJBs have the same bean class! " + getType());
- }
- }
+ this.ejbDescriptor = ejbDescriptor;
initTypes();
initBindings();
}
@@ -195,7 +183,8 @@
protected void preSpecialize(BeanDeployerEnvironment environment)
{
super.preSpecialize(environment);
- if (!environment.getEjbDescriptors().containsKey(getAnnotatedItem().getWBSuperclass().getJavaClass()))
+ // We appear to check this twice?
+ if (!environment.getEjbDescriptors().contains(getAnnotatedItem().getWBSuperclass().getJavaClass()))
{
throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
@@ -209,7 +198,7 @@
throw new IllegalStateException(toString() + " does not specialize a bean");
}
AbstractClassBean<?> specializedBean = environment.getClassBean(getAnnotatedItem().getWBSuperclass());
- if (!(specializedBean instanceof EnterpriseBean))
+ if (!(specializedBean instanceof EnterpriseBean<?>))
{
throw new IllegalStateException(toString() + " doesn't have a session bean as a superclass " + specializedBean);
}
@@ -234,21 +223,21 @@
return instance;
}
- public void inject(T instance, CreationalContext<T> ctx)
+ public void inject(final T instance, final CreationalContext<T> ctx)
{
- throw new UnsupportedOperationException("Unable to perform injection on a session bean");
+ new InjectionContextImpl<T>(getManager(), this, instance)
+ {
+
+ public void proceed()
+ {
+ Beans.injectBoundFields(instance, ctx, getManager(), getInjectableFields());
+ Beans.callInitializers(instance, ctx, getManager(), getInitializerMethods());
+ }
+
+ }.run();
+
}
- public void postConstruct(T instance)
- {
- throw new UnsupportedOperationException("Unable to call postConstruct() on a session bean");
- }
-
- public void preDestroy(T instance)
- {
- throw new UnsupportedOperationException("Unable to call preDestroy() on a session bean");
- }
-
public T produce(CreationalContext<T> ctx)
{
try
@@ -284,15 +273,7 @@
throw new IllegalArgumentException("Cannot destroy session bean instance not created by the container");
}
EnterpriseBeanInstance enterpiseBeanInstance = (EnterpriseBeanInstance) instance;
-
- if (enterpiseBeanInstance.isDestroyed(Marker.INSTANCE))
- {
- return;
- }
- else
- {
- enterpiseBeanInstance.destroy(Marker.INSTANCE, this, creationalContext);
- }
+ enterpiseBeanInstance.destroy(Marker.INSTANCE, this, creationalContext);
creationalContext.release();
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -23,9 +23,10 @@
import javax.enterprise.context.Dependent;
import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.literal.NewLiteral;
+import org.jboss.webbeans.resources.ClassTransformer;
/**
* Represents a @New enterprise bean
@@ -42,9 +43,10 @@
* @param manager The Web Beans manager
* @return a new NewEnterpriseBean instance
*/
- public static <T> NewEnterpriseBean<T> of(WBClass<T> clazz, BeanManagerImpl manager, BeanDeployerEnvironment environment)
+ public static <T> NewEnterpriseBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
{
- return new NewEnterpriseBean<T>(clazz, manager, environment);
+ WBClass<T> type = manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
+ return new NewEnterpriseBean<T>(type, ejbDescriptor, manager);
}
private Set<Annotation> bindings;
@@ -55,9 +57,9 @@
* @param type An annotated class
* @param manager The Web Beans manager
*/
- protected NewEnterpriseBean(final WBClass<T> type, BeanManagerImpl manager, BeanDeployerEnvironment environment)
+ protected NewEnterpriseBean(final WBClass<T> type, InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
{
- super(type, manager, environment);
+ super(type, ejbDescriptor, manager);
this.bindings = new HashSet<Annotation>();
this.bindings.add(new NewLiteral()
{
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -55,11 +55,6 @@
// The constructor
private ConstructorInjectionPoint<T> constructor;
- // The post-construct method
- private WBMethod<?, ?> postConstruct;
- // The pre-destroy method
- private WBMethod<?, ?> preDestroy;
-
private Set<WBInjectionPoint<?, ?>> ejbInjectionPoints;
private Set<WBInjectionPoint<?, ?>> persistenceContextInjectionPoints;
private Set<WBInjectionPoint<?, ?>> persistenceUnitInjectionPoints;
@@ -146,41 +141,6 @@
}
- public void postConstruct(T instance)
- {
- WBMethod<?, ?> postConstruct = getPostConstruct();
- if (postConstruct != null)
- {
- try
- {
- postConstruct.invoke(instance);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unable to invoke " + postConstruct + " on " + instance, e);
- }
- }
- }
-
- public void preDestroy(T instance)
- {
- WBMethod<?, ?> preDestroy = getPreDestroy();
- if (preDestroy != null)
- {
- try
- {
- // note: RI supports injection into @PreDestroy
- preDestroy.invoke(instance);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unable to invoke " + preDestroy + " on " + instance, e);
- }
- }
- }
-
-
-
protected InjectionPoint attachCorrectInjectionPoint()
{
Decorator<?> decorator = getDecorators().get(getDecorators().size() - 1);
@@ -313,7 +273,7 @@
protected void preSpecialize(BeanDeployerEnvironment environment)
{
super.preSpecialize(environment);
- if (environment.getEjbDescriptors().containsKey(getAnnotatedItem().getWBSuperclass().getJavaClass()))
+ if (environment.getEjbDescriptors().contains(getAnnotatedItem().getWBSuperclass().getJavaClass()))
{
throw new DefinitionException("Simple bean must specialize a simple bean");
}
@@ -349,22 +309,6 @@
}
/**
- * Initializes the post-construct method
- */
- protected void initPostConstruct()
- {
- this.postConstruct = Beans.getPostConstruct(getAnnotatedItem());
- }
-
- /**
- * Initializes the pre-destroy method
- */
- protected void initPreDestroy()
- {
- this.preDestroy = Beans.getPreDestroy(getAnnotatedItem());
- }
-
- /**
* Returns the constructor
*
* @return The constructor
@@ -375,26 +319,6 @@
}
/**
- * Returns the post-construct method
- *
- * @return The post-construct method
- */
- public WBMethod<?, ?> getPostConstruct()
- {
- return postConstruct;
- }
-
- /**
- * Returns the pre-destroy method
- *
- * @return The pre-destroy method
- */
- public WBMethod<?, ?> getPreDestroy()
- {
- return preDestroy;
- }
-
- /**
* Gets a string representation
*
* @return The string representation
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -19,7 +19,6 @@
import javax.enterprise.context.spi.CreationalContext;
import org.jboss.webbeans.bean.EnterpriseBean;
-import org.jboss.webbeans.ejb.api.SessionObjectReference;
/**
* Interface implemented by all enterprise bean proxies to query/control the proxy
@@ -30,17 +29,6 @@
public interface EnterpriseBeanInstance
{
- /**
- * Indicated if a remove method has been invoked by the application
- *
- * @return True if invoked, false otherwise
- */
- public boolean isDestroyed(Marker marker);
-
- public void setDestroyed(Marker marker, boolean destroyed);
-
public void destroy(Marker marker, EnterpriseBean<?> enterpriseBean, CreationalContext<?> creationalContext);
- public SessionObjectReference getSessionObjectReference(Marker marker);
-
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -46,42 +46,11 @@
// The log provider
static final transient Log log = Logging.getLog(EnterpriseBeanProxyMethodHandler.class);
-
- private static final ThreadLocal<EnterpriseBean<?>> enterpriseBean;
-
- private static final ThreadLocal<CreationalContext<?>> enterpriseBeanCreationalContext;
-
- static
- {
- enterpriseBean = new ThreadLocal<EnterpriseBean<?>>();
- enterpriseBeanCreationalContext = new ThreadLocal<CreationalContext<?>>();
- }
-
- public static EnterpriseBean<?> getEnterpriseBean()
- {
- return enterpriseBean.get();
- }
-
- /**
- * @return the enterpriseBeanCreationalContext
- */
- public static CreationalContext<?> getEnterpriseBeanCreationalContext()
- {
- return enterpriseBeanCreationalContext.get();
- }
-
- private static <T> void setEnterpriseBean(EnterpriseBean<T> bean, CreationalContext<T> creationalContext)
- {
- enterpriseBean.set(bean);
- enterpriseBeanCreationalContext.set(creationalContext);
- }
private final SessionObjectReference reference;
private final Class<?> objectInterface;
private final Collection<MethodSignature> removeMethodSignatures;
private final boolean clientCanCallRemoveMethods;
-
- private boolean destroyed;
/**
* Constructor
@@ -92,19 +61,10 @@
*/
public EnterpriseBeanProxyMethodHandler(EnterpriseBean<T> bean, CreationalContext<T> creationalContext)
{
- this.destroyed = false;
this.objectInterface = bean.getEjbDescriptor().getObjectInterface();
this.removeMethodSignatures = bean.getEjbDescriptor().getRemoveMethodSignatures();
this.clientCanCallRemoveMethods = bean.isClientCanCallRemoveMethods();
- try
- {
- setEnterpriseBean(bean, creationalContext);
- this.reference = bean.createReference();
- }
- finally
- {
- setEnterpriseBean(null, null);
- }
+ this.reference = bean.createReference();
log.trace("Created enterprise bean proxy method handler for " + bean);
}
@@ -127,29 +87,10 @@
*/
public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable
{
- // EnterpriseBeanInstance methods
- if ("isDestroyed".equals(method.getName()) && Marker.isMarker(0, method, args))
+ if (reference.isRemoved())
{
- return destroyed;
- }
- else if ("setDestroyed".equals(method.getName()) && Marker.isMarker(0, method, args))
- {
- if (args.length != 2)
- {
- throw new IllegalArgumentException("enterpriseBeanInstance.setDestroyed() called with >2 argument");
- }
- if (!(args[1].getClass().equals(boolean.class) || args[1].getClass().equals(Boolean.class)))
- {
- throw new IllegalArgumentException("enterpriseBeanInstance.setDestroyed() called with non-boolean argument");
- }
- destroyed = ((Boolean) args[1]).booleanValue();
- }
-
- if (destroyed)
- {
return null;
}
-
if ("destroy".equals(method.getName()) && Marker.isMarker(0, method, args))
{
reference.remove();
@@ -165,22 +106,25 @@
throw new UnsupportedOperationException("Cannot call EJB remove method directly on non-dependent scoped bean " + method );
}
}
-
+ Class<?> businessInterface = getBusinessInterface(method);
+ Object proxiedInstance = reference.getBusinessObject(businessInterface);
+ Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
+ Object returnValue = Reflections.invokeAndWrap(proxiedMethod, proxiedInstance, args);
+ log.trace("Executed " + method + " on " + proxiedInstance + " with parameters " + args + " and got return value " + returnValue);
+ return returnValue;
+ }
+
+ private Class<?> getBusinessInterface(Method method)
+ {
Class<?> businessInterface = method.getDeclaringClass();
if (businessInterface.equals(Object.class))
{
- businessInterface = objectInterface;
+ return objectInterface;
}
- Object proxiedInstance = reference.getBusinessObject(businessInterface);
- if (proxiedInstance == null)
+ else
{
- throw new IllegalStateException("No EJB can be found in the EJB container for " + reference + ". Make sure you are running an EJB container.");
+ return businessInterface;
}
- Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
- Object returnValue = Reflections.invokeAndWrap(proxiedMethod, proxiedInstance, args);
- log.trace("Executed " + method + " on " + proxiedInstance + " with parameters " + args + " and got return value " + returnValue);
- return returnValue;
-
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -40,6 +40,7 @@
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
+import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.event.ObserverFactory;
import org.jboss.webbeans.event.ObserverMethodImpl;
import org.jboss.webbeans.introspector.WBClass;
@@ -193,13 +194,13 @@
getEnvironment().addBean(bean);
}
- protected <T> void createEnterpriseBean(WBClass<T> annotatedClass)
+ protected <T> void createEnterpriseBean(InternalEjbDescriptor<T> ejbDescriptor)
{
// TODO Don't create enterprise bean if it has no local interfaces!
- EnterpriseBean<T> bean = EnterpriseBean.of(annotatedClass, manager, getEnvironment());
+ EnterpriseBean<T> bean = EnterpriseBean.of(ejbDescriptor, manager);
getEnvironment().addBean(bean);
createSubBeans(bean);
- getEnvironment().addBean(NewEnterpriseBean.of(annotatedClass, manager, getEnvironment()));
+ getEnvironment().addBean(NewEnterpriseBean.of(ejbDescriptor, manager));
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -24,7 +24,8 @@
import javax.interceptor.Interceptor;
import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.ejb.EjbDescriptors;
+import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.resources.ClassTransformer;
@@ -43,7 +44,7 @@
* @param manager
* @param ejbDescriptors
*/
- public BeanDeployer(BeanManagerImpl manager, BeanManagerImpl deploymentManager, EjbDescriptorCache ejbDescriptors)
+ public BeanDeployer(BeanManagerImpl manager, BeanManagerImpl deploymentManager, EjbDescriptors ejbDescriptors)
{
super(manager, new BeanDeployerEnvironment(ejbDescriptors, manager));
this.classes = new HashSet<WBClass<?>>();
@@ -99,27 +100,24 @@
{
for (WBClass<?> clazz : classes)
{
- if (getEnvironment().getEjbDescriptors().containsKey(clazz.getJavaClass()))
+ boolean managedBeanOrDecorator = !getEnvironment().getEjbDescriptors().contains(clazz.getJavaClass()) && isTypeManagedBeanOrDecorator(clazz);
+ if (managedBeanOrDecorator && clazz.isAnnotationPresent(Decorator.class))
{
- createEnterpriseBean(clazz);
+ createDecorator(clazz);
}
- else
+ else if (managedBeanOrDecorator && clazz.isAnnotationPresent(Interceptor.class))
{
- boolean managedBeanOrDecorator = isTypeManagedBeanOrDecorator(clazz);
- if (managedBeanOrDecorator && clazz.isAnnotationPresent(Decorator.class))
- {
- createDecorator(clazz);
- }
- else if (managedBeanOrDecorator && clazz.isAnnotationPresent(Interceptor.class))
- {
- //createInterceptor(clazz);
- }
- else if (managedBeanOrDecorator && !clazz.isAbstract())
- {
- createSimpleBean(clazz);
- }
+ //createInterceptor(clazz);
}
+ else if (managedBeanOrDecorator && !clazz.isAbstract())
+ {
+ createSimpleBean(clazz);
+ }
}
+ for (InternalEjbDescriptor<?> ejbDescriptor : getEnvironment().getEjbDescriptors())
+ {
+ createEnterpriseBean(ejbDescriptor);
+ }
return this;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -36,7 +36,7 @@
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bean.builtin.AbstractBuiltInBean;
import org.jboss.webbeans.bean.builtin.ExtensionBean;
-import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.ejb.EjbDescriptors;
import org.jboss.webbeans.event.ObserverMethodImpl;
import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.introspector.WBMethod;
@@ -53,10 +53,10 @@
private final List<DisposalMethodBean<?>> allDisposalBeans;
private final Set<DisposalMethodBean<?>> resolvedDisposalBeans;
private final Set<DecoratorBean<?>> decorators;
- private final EjbDescriptorCache ejbDescriptors;
+ private final EjbDescriptors ejbDescriptors;
private final TypeSafeDisposerResolver disposalMethodResolver;
- public BeanDeployerEnvironment(EjbDescriptorCache ejbDescriptors, BeanManagerImpl manager)
+ public BeanDeployerEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl manager)
{
this.classBeanMap = new HashMap<WBClass<?>, AbstractClassBean<?>>();
this.producerMethodBeanMap = new HashMap<WBMethod<?, ?>, ProducerMethodBean<?>>();
@@ -165,7 +165,7 @@
return Collections.unmodifiableSet(beans);
}
- public EjbDescriptorCache getEjbDescriptors()
+ public EjbDescriptors getEjbDescriptors()
{
return ejbDescriptors;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -34,7 +34,7 @@
import org.jboss.webbeans.conversation.JavaSEConversationTerminator;
import org.jboss.webbeans.conversation.NumericConversationIdGenerator;
import org.jboss.webbeans.conversation.ServletConversationManager;
-import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.ejb.EjbDescriptors;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
@@ -61,11 +61,12 @@
public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerImpl deploymentManager)
{
this.beanDeploymentArchive = beanDeploymentArchive;
+ EjbDescriptors ejbDescriptors = new EjbDescriptors();
+ beanDeploymentArchive.getServices().add(EjbDescriptors.class, ejbDescriptors);
ServiceRegistry services = new SimpleServiceRegistry();
services.addAll(deploymentManager.getServices().entrySet());
services.addAll(beanDeploymentArchive.getServices().entrySet());
this.beanManager = BeanManagerImpl.newManager(deploymentManager, services);
- EjbDescriptorCache ejbDescriptors = new EjbDescriptorCache();
if (beanManager.getServices().contains(EjbServices.class))
{
// Must populate EJB cache first, as we need it to detect whether a
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -23,7 +23,7 @@
import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.bean.builtin.ExtensionBean;
-import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.ejb.EjbDescriptors;
import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.resources.ClassTransformer;
@@ -38,7 +38,7 @@
public ExtensionBeanDeployer(BeanManagerImpl manager)
{
- super(manager, new BeanDeployerEnvironment(new EjbDescriptorCache(), manager));
+ super(manager, new BeanDeployerEnvironment(new EjbDescriptors(), manager));
this.extensions = new HashSet<Extension>();
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -48,9 +48,6 @@
import org.jboss.webbeans.context.SessionContext;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
-import org.jboss.webbeans.ejb.spi.EjbServices;
-import org.jboss.webbeans.injection.spi.JpaInjectionServices;
-import org.jboss.webbeans.injection.spi.ResourceInjectionServices;
import org.jboss.webbeans.jsf.JsfApiAbstraction;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
@@ -162,18 +159,19 @@
{
log.info("Transactional services not available. Injection of @Current UserTransaction not available. Transactional observers will be invoked synchronously.");
}
- if (!deployment.getServices().contains(EjbServices.class))
- {
- log.info("EJB services not available. Session beans will be simple beans, CDI-style injection into non-contextual EJBs, injection of remote EJBs and injection of @EJB in simple beans will not be available");
- }
- if (!deployment.getServices().contains(JpaInjectionServices.class))
- {
- log.info("JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.");
- }
- if (!deployment.getServices().contains(ResourceInjectionServices.class))
- {
- log.info("@Resource injection not available.");
- }
+ // TODO Reinstate if we can find a good way to detect.
+// if (!deployment.getServices().contains(EjbServices.class))
+// {
+// log.info("EJB services not available. Session beans will be simple beans, CDI-style injection into non-contextual EJBs, injection of remote EJBs and injection of @EJB in simple beans will not be available");
+// }
+// if (!deployment.getServices().contains(JpaInjectionServices.class))
+// {
+// log.info("JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.");
+// }
+// if (!deployment.getServices().contains(ResourceInjectionServices.class))
+// {
+// log.info("@Resource injection not available.");
+// }
if (applicationBeanStore == null)
{
throw new IllegalStateException("No application context BeanStore set");
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptorCache.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptorCache.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptorCache.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -1,111 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.webbeans.ejb;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import org.jboss.webbeans.ejb.spi.EjbDescriptor;
-
-/**
- * EJB descriptors by EJB implementation class or name
- *
- * @author Pete Muir
- *
- */
-public class EjbDescriptorCache
-{
- // EJB implementation class -> EJB descriptors map
- private Map<Class<?>, Set<InternalEjbDescriptor<?>>> ejbsByBeanClass;
-
- /**
- * Constructor
- */
- public EjbDescriptorCache()
- {
- this.ejbsByBeanClass = new HashMap<Class<?>, Set<InternalEjbDescriptor<?>>>();
- }
-
- /**
- * Gets an iterator to the EJB descriptors for an EJB implementation class
- *
- * @param beanClass The EJB class
- * @return An iterator
- */
- @SuppressWarnings("unchecked")
- public <T> Iterable<InternalEjbDescriptor<T>> get(Class<T> beanClass)
- {
- return (Iterable) ejbsByBeanClass.get(beanClass);
- }
-
- /**
- * Adds an EJB descriptor to the maps
- *
- * @param ejbDescriptor The EJB descriptor to add
- */
- public <T> void add(EjbDescriptor<T> ejbDescriptor)
- {
- InternalEjbDescriptor<T> internalEjbDescriptor = new InternalEjbDescriptor<T>(ejbDescriptor);
- if (!ejbsByBeanClass.containsKey(ejbDescriptor.getBeanClass()))
- {
- ejbsByBeanClass.put(ejbDescriptor.getBeanClass(), new CopyOnWriteArraySet<InternalEjbDescriptor<?>>());
- }
- ejbsByBeanClass.get(ejbDescriptor.getBeanClass()).add(internalEjbDescriptor);
- }
-
- /**
- * Indicates if there are EJB descriptors available for an EJB implementation
- * class
- *
- * @param beanClass The class to match
- * @return True if present, otherwise false
- */
- public boolean containsKey(Class<?> beanClass)
- {
- return ejbsByBeanClass.containsKey(beanClass);
- }
-
- /**
- * Adds all EJB descriptors to the maps
- *
- * @param ejbDescriptors The descriptors to add
- */
- public void addAll(Iterable<EjbDescriptor<?>> ejbDescriptors)
- {
- for (EjbDescriptor<?> ejbDescriptor : ejbDescriptors)
- {
- add(ejbDescriptor);
- }
- }
-
- /**
- * Clears both maps
- */
- public void clear()
- {
- ejbsByBeanClass.clear();
- }
-
- @Override
- public String toString()
- {
- return "EJB Descriptor cache has indexed " + ejbsByBeanClass.size() + " EJBs by class";
- }
-
-}
Copied: ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptors.java (from rev 3567, ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptorCache.java)
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptors.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/EjbDescriptors.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.ejb;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.jboss.webbeans.bootstrap.api.Service;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+
+/**
+ * EJB descriptors by EJB implementation class or name
+ *
+ * @author Pete Muir
+ *
+ */
+public class EjbDescriptors implements Service, Iterable<InternalEjbDescriptor<?>>
+{
+ // EJB name -> EJB descriptors map
+ private final Map<String, InternalEjbDescriptor<?>> ejbs;
+
+ private final Collection<Class<?>> ejbClasses;
+
+ /**
+ * Constructor
+ */
+ public EjbDescriptors()
+ {
+ this.ejbs = new HashMap<String, InternalEjbDescriptor<?>>();
+ this.ejbClasses = new HashSet<Class<?>>();
+ }
+
+ /**
+ * Gets an iterator to the EJB descriptors for an EJB implementation class
+ *
+ * @param beanClass The EJB class
+ * @return An iterator
+ */
+ @SuppressWarnings("unchecked")
+ public <T> InternalEjbDescriptor<T> get(String beanName)
+ {
+ return (InternalEjbDescriptor<T>) ejbs.get(beanName);
+ }
+
+ /**
+ * Adds an EJB descriptor to the maps
+ *
+ * @param ejbDescriptor The EJB descriptor to add
+ */
+ public <T> void add(EjbDescriptor<T> ejbDescriptor)
+ {
+ InternalEjbDescriptor<T> internalEjbDescriptor = new InternalEjbDescriptor<T>(ejbDescriptor);
+ ejbs.put(ejbDescriptor.getEjbName(), internalEjbDescriptor);
+ ejbClasses.add(ejbDescriptor.getBeanClass());
+ }
+
+ /**
+ * Indicates if there are EJB descriptors available for an EJB implementation
+ * class
+ *
+ * @param beanClass The class to match
+ * @return True if present, otherwise false
+ */
+ public boolean contains(String beanName)
+ {
+ return ejbs.containsKey(beanName);
+ }
+
+ /**
+ * Indicates if there are EJB descriptors available for an EJB implementation
+ * class
+ *
+ * @param beanClass The class to match
+ * @return True if present, otherwise false
+ */
+ public boolean contains(Class<?> beanClass)
+ {
+ return ejbClasses.contains(beanClass);
+ }
+
+ /**
+ * Adds all EJB descriptors to the maps
+ *
+ * @param ejbDescriptors The descriptors to add
+ */
+ public void addAll(Iterable<EjbDescriptor<?>> ejbDescriptors)
+ {
+ for (EjbDescriptor<?> ejbDescriptor : ejbDescriptors)
+ {
+ add(ejbDescriptor);
+ }
+ }
+
+ /**
+ * Clears both maps
+ */
+ public void clear()
+ {
+ ejbs.clear();
+ }
+
+ public Iterator<InternalEjbDescriptor<?>> iterator()
+ {
+ return ejbs.values().iterator();
+ }
+
+}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -16,24 +16,8 @@
*/
package org.jboss.webbeans.ejb;
-import java.io.IOException;
-import java.io.ObjectInputStream;
import java.io.Serializable;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.interceptor.InvocationContext;
-
-import org.jboss.webbeans.ContextualIdStore;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.bean.EnterpriseBean;
-import org.jboss.webbeans.bean.proxy.EnterpriseBeanInstance;
-import org.jboss.webbeans.bean.proxy.EnterpriseBeanProxyMethodHandler;
-import org.jboss.webbeans.bean.proxy.Marker;
-import org.jboss.webbeans.log.Log;
-import org.jboss.webbeans.log.Logging;
-
/**
* Interceptor for handling EJB post-construct tasks
*
@@ -43,107 +27,6 @@
{
private static final long serialVersionUID = 7327757031821596782L;
- private transient Log log = Logging.getLog(SessionBeanInterceptor.class);
-
- private transient EnterpriseBean<Object> bean;
- private transient CreationalContext<Object> creationalContext;
-
- private Integer beanId;
- private boolean contextual;
-
- /**
- * Gets the underlying target and calls the post-construct method
- *
- * @param invocationContext The invocation context
- * @throws Exception
- */
- @PostConstruct
- public void postConstruct(InvocationContext invocationContext) throws Exception
- {
- Object target = invocationContext.getTarget();
- initBean(target.getClass());
- bean.postConstruct(target, creationalContext);
- invocationContext.proceed();
- }
-
- /**
- * Gets the underlying target and calls the pre-destroy method
- *
- * @param invocationContext The invocation context
- * @throws Exception
- */
- @PreDestroy
- public void preDestroy(InvocationContext invocationContext) throws Exception
- {
- Object target = invocationContext.getTarget();
- initBean(target.getClass());
- if (contextual)
- {
- bean.preDestroy(creationalContext);
- EnterpriseBeanInstance instance = getEnterpriseBeanInstance(bean);
- if (instance != null)
- {
- instance.setDestroyed(Marker.INSTANCE, true);
- }
- }
- invocationContext.proceed();
- }
-
- /**
- * Gets a bean based on the target in the invocation context
- *
- * @param invocationContext The invocation context
- * @return The found bean or null if the bean was not an enterprise bean
- */
- private void initBean(Class<? extends Object> beanClass)
- {
- EnterpriseBean<Object> bean = (EnterpriseBean<Object>) EnterpriseBeanProxyMethodHandler.getEnterpriseBean();
- if (bean != null && bean.getType().equals(beanClass))
- {
- this.bean = bean;
- this.contextual = true;
- this.creationalContext = (CreationalContext<Object>) EnterpriseBeanProxyMethodHandler.getEnterpriseBeanCreationalContext();
- }
- else
- {
- this.bean = (EnterpriseBean<Object>) CurrentManager.rootManager().getNewEnterpriseBeanMap().get(beanClass);
- this.contextual = false;
- this.creationalContext = CurrentManager.rootManager().createCreationalContext(bean);
- }
- this.beanId = CurrentManager.rootManager().getServices().get(ContextualIdStore.class).getId(this.bean);
- }
-
- private static <T> EnterpriseBeanInstance getEnterpriseBeanInstance(EnterpriseBean<T> bean)
- {
- T instance = CurrentManager.rootManager().getContext(bean.getScopeType()).get(bean);
- if (instance instanceof EnterpriseBeanInstance)
- {
- return (EnterpriseBeanInstance) instance;
- }
- else if (instance == null)
- {
- return null;
- }
- else
- {
- throw new IllegalStateException("Contextual instance not an session bean created by the container");
- }
- }
-
- private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
- {
- ois.defaultReadObject();
- if (beanId != null)
- {
- bean = (EnterpriseBean<Object>) CurrentManager.rootManager().getServices().get(ContextualIdStore.class).getContextual(beanId);
- }
- }
-
- protected EnterpriseBean<Object> getBean()
- {
- return bean;
- }
-
}
\ No newline at end of file
Modified: ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java
===================================================================
--- ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -1,10 +1,6 @@
package org.jboss.webbeans.tck;
-import javax.enterprise.inject.spi.Bean;
-
import org.jboss.jsr299.tck.spi.Beans;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.util.Proxies;
/**
@@ -18,63 +14,9 @@
public class BeansImpl implements Beans
{
- public boolean isEnterpriseBean(Class<?> clazz)
- {
- return CurrentManager.rootManager().getNewEnterpriseBeanMap().containsKey(clazz);
- }
-
- public boolean isEntityBean(Class<?> clazz)
- {
- if (CurrentManager.rootManager().getNewEnterpriseBeanMap().containsKey(clazz))
- {
- EjbDescriptor<?> ejbDescriptor = CurrentManager.rootManager().getNewEnterpriseBeanMap().get(clazz).getEjbDescriptor();
- if (!ejbDescriptor.isMessageDriven() && !ejbDescriptor.isSingleton() && !ejbDescriptor.isStateful() && !ejbDescriptor.isStateless())
- {
- return true;
- }
- }
- return false;
- }
-
- public boolean isStatefulBean(Class<?> clazz)
- {
- if (CurrentManager.rootManager().getNewEnterpriseBeanMap().containsKey(clazz))
- {
- EjbDescriptor<?> ejbDescriptor = CurrentManager.rootManager().getNewEnterpriseBeanMap().get(clazz).getEjbDescriptor();
- if (ejbDescriptor.isStateful())
- {
- return true;
- }
- }
- return false;
- }
-
- public boolean isStatelessBean(Class<?> clazz)
- {
- if (CurrentManager.rootManager().getNewEnterpriseBeanMap().containsKey(clazz))
- {
- EjbDescriptor<?> ejbDescriptor = CurrentManager.rootManager().getNewEnterpriseBeanMap().get(clazz).getEjbDescriptor();
- if (ejbDescriptor.isStateless())
- {
- return true;
- }
- }
- return false;
- }
-
public boolean isProxy(Object instance)
{
return Proxies.isProxy(instance);
}
- public <T> T getEnterpriseBean(Class<? extends T> beanType, Class<T> localInterface)
- {
- throw new UnsupportedOperationException();
- }
-
- public <T> T createBeanInstance(Bean<T> bean)
- {
- return (T) CurrentManager.rootManager().getCurrent().getReference(bean, Object.class, CurrentManager.rootManager().getCurrent().createCreationalContext(bean));
- }
-
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/api/SessionObjectReference.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/api/SessionObjectReference.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/api/SessionObjectReference.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -50,5 +50,12 @@
* @throws NoSuchEJBException if the session object has already been removed
*/
public void remove();
+
+ /**
+ * Determine whether the session object has been removed
+ *
+ * @return true if the session object has been removed
+ */
+ public boolean isRemoved();
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbDescriptor.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbDescriptor.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbDescriptor.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -45,6 +45,8 @@
*/
public Collection<BusinessInterfaceDescriptor<?>> getLocalBusinessInterfaces();
+ public String getEjbName();
+
/**
* Get the remove methods of the EJB
*
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbDescriptor.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbDescriptor.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbDescriptor.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -37,6 +37,11 @@
return delegate().getBeanClass();
}
+ public String getEjbName()
+ {
+ return delegate().getEjbName();
+ }
+
public boolean isMessageDriven()
{
return delegate().isMessageDriven();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -21,8 +21,12 @@
import java.lang.annotation.Annotation;
import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+
/**
* Functionality provided by the Web Beans Manager over and above the JSR-299
* Manager.
@@ -58,5 +62,19 @@
* if the given scope is not a normal scope
*/
public WebBeansManager setCurrent(Class<? extends Annotation> scopeType);
+
+ /**
+ * The injection target for the given EJB, or null if Web Beans was not
+ * given this descriptor in the deployment.
+ *
+ * @param <T>
+ * @param descriptor
+ * @return
+ */
+ public <T> InjectionTarget<T> createInjectionTarget(EjbDescriptor<T> descriptor);
+
+ public <T> Bean<T> getBean(EjbDescriptor<T> descriptor);
+
+ public <T> EjbDescriptor<T> getEjbDescriptor(String beanName);
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -3,8 +3,6 @@
*/
package org.jboss.webbeans.mock;
-import javax.enterprise.inject.spi.InjectionPoint;
-
import org.jboss.webbeans.ejb.api.SessionObjectReference;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
@@ -19,6 +17,8 @@
return new SessionObjectReference()
{
+ private static final long serialVersionUID = 1L;
+
public <S> S getBusinessObject(Class<S> businessInterfaceType)
{
// TODO Auto-generated method stub
@@ -31,10 +31,10 @@
}
- public Object getFieldValue(Class<?> declaringClass, String fieldName)
+ public boolean isRemoved()
{
// TODO Auto-generated method stub
- return null;
+ return false;
}
};
Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java 2009-08-27 23:07:26 UTC (rev 3612)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java 2009-08-27 23:09:32 UTC (rev 3613)
@@ -11,7 +11,7 @@
import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
-import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.ejb.EjbDescriptors;
import org.jboss.webbeans.introspector.WBClass;
import org.jboss.webbeans.introspector.jlr.WBClassImpl;
import org.jboss.webbeans.metadata.TypeStore;
@@ -40,7 +40,7 @@
WBClass<?> clazz = WBClassImpl.of(c, classTransformer);
RIBean<?> bean = SimpleBean.of(clazz, manager);
manager.addBean(bean);
- BeanDeployerEnvironment environment = new BeanDeployerEnvironment(new EjbDescriptorCache(), manager);
+ BeanDeployerEnvironment environment = new BeanDeployerEnvironment(new EjbDescriptors(), manager);
bean.initialize(environment);
}
More information about the weld-commits
mailing list