Class SessionBeanInjectionPoint
- java.lang.Object
-
- org.jboss.weld.ejb.SessionBeanInjectionPoint
-
public class SessionBeanInjectionPoint extends Object
The spec requires that an
InjectionPointof a session bean returns:- a
Beanobject representing the session bean if the session bean is a contextual instance (obtained usingInject) - null if the session bean is a non-contextual instance obtained using @EJB or from JNDI
Each time a contextual instance of a session bean is created we add its bean class to a thread local collection. The class is removed from the collection after instance creation.
If an
InjectionPointof a session bean is about to be injected usingInjectionPointBeanand the session bean class is present in the thread local collection (indicating that it is a contextual instance), we leave theInjectionPointuntouched and inject it. Otherwise, we wrap theInjectionPointwithinSessionBeanInjectionPoint.NonContextualSessionBeanInjectionPointwhich always returns null from getBean().The only known limitation of this approach is that if the same session bean is used both in its contextual and non-contextual form within a single dependency chain (non-contextual instance of Foo injecting another Foo instance using
Inject), the behavior will not be reliable.- Author:
- Jozef Hartinger
- a
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidregisterContextualInstance(org.jboss.weld.ejb.spi.EjbDescriptor<?> descriptor)Indicates that a contextual instance of a session bean is about to be constructed.static voidunregisterContextualInstance(org.jboss.weld.ejb.spi.EjbDescriptor<?> descriptor)Indicates that contextual session bean instance has been constructed.static javax.enterprise.inject.spi.InjectionPointwrapIfNecessary(javax.enterprise.inject.spi.InjectionPoint ip)Returns theInjectionPointpassed in as a parameter if thisInjectionPointbelongs to a contextual instance of a session bean.
-
-
-
Method Detail
-
registerContextualInstance
public static void registerContextualInstance(org.jboss.weld.ejb.spi.EjbDescriptor<?> descriptor)
Indicates that a contextual instance of a session bean is about to be constructed.
-
unregisterContextualInstance
public static void unregisterContextualInstance(org.jboss.weld.ejb.spi.EjbDescriptor<?> descriptor)
Indicates that contextual session bean instance has been constructed.
-
wrapIfNecessary
public static javax.enterprise.inject.spi.InjectionPoint wrapIfNecessary(javax.enterprise.inject.spi.InjectionPoint ip)
Returns theInjectionPointpassed in as a parameter if thisInjectionPointbelongs to a contextual instance of a session bean. Otherwise, the method wraps theInjectionPointto guarantee that getBean() always returns null.
-
-