Package org.apache.struts2.cdi
Class CdiObjectFactory
java.lang.Object
org.apache.struts2.ObjectFactory
org.apache.struts2.cdi.CdiObjectFactory
- All Implemented Interfaces:
Serializable
CdiObjectFactory allows Struts 2 managed objects, like Actions, Interceptors or Results, to be injected by a Contexts
and Dependency Injection container (JSR299 / WebBeans).
The BeanManager instance will be searched in the container's JNDI context, according to following algorithm:
- if a value for configuration constant
struts.objectFactory.cdi.jndiKey
is given, this key will be looked up - if no BeanManager found so far, look under
CDI_JNDIKEY_BEANMANAGER_COMP
- if no BeanManager found so far, look under
CDI_JNDIKEY_BEANMANAGER_APP
- if no BeanManager found so far, look under
CDI_JNDIKEY_BEANMANAGER_COMP_ENV
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected jakarta.enterprise.inject.spi.BeanManager
static final String
The key under which the BeanManager can be found according to JBoss Weld docsstatic final String
The key under which the BeanManager can be found according to CDI API docsstatic final String
The key under which the BeanManager can be found in pure Servlet containers according to JBoss Weld docs.static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected jakarta.enterprise.context.spi.CreationalContext
buildNonContextualCreationalContext
(jakarta.enterprise.inject.spi.BeanManager beanManager) Simple wrapper for CreationalContext creation.protected jakarta.enterprise.inject.spi.BeanManager
Try to find the CDI BeanManager from JNDI context.protected jakarta.enterprise.inject.spi.InjectionTarget<?>
getInjectionTarget
(Class<?> clazz) Get a InjectionTarget instance for a given class.boolean
Allow constructor injectionprotected jakarta.enterprise.inject.spi.BeanManager
Lookup the given JNDI key in the given context.void
setJndiKey
(String jndiKey) Methods inherited from class org.apache.struts2.ObjectFactory
buildAction, buildBean, buildBean, buildConverter, buildInterceptor, buildResult, buildUnknownHandler, buildValidator, getClassInstance, injectInternalBeans, setActionFactory, setClassLoader, setContainer, setConverterFactory, setInterceptorFactory, setResultFactory, setUnknownHandlerFactory, setValidatorFactory
-
Field Details
-
CDI_JNDIKEY_BEANMANAGER_COMP
The key under which the BeanManager can be found according to CDI API docs- See Also:
-
CDI_JNDIKEY_BEANMANAGER_APP
The key under which the BeanManager can be found according to JBoss Weld docs- See Also:
-
CDI_JNDIKEY_BEANMANAGER_COMP_ENV
The key under which the BeanManager can be found in pure Servlet containers according to JBoss Weld docs.- See Also:
-
STRUTS_OBJECT_FACTORY_CDI_JNDI_KEY
- See Also:
-
beanManager
protected jakarta.enterprise.inject.spi.BeanManager beanManager
-
-
Constructor Details
-
CdiObjectFactory
public CdiObjectFactory()
-
-
Method Details
-
setJndiKey
-
findBeanManager
protected jakarta.enterprise.inject.spi.BeanManager findBeanManager()Try to find the CDI BeanManager from JNDI context. First, if provided, the key given by struts.objectFactory.cdi.jndiKey will be checked. Then, if nothing was found or no explicit configuration was given, the keyCDI_JNDIKEY_BEANMANAGER_COMP
will be tested. If nothing is found there, the keyCDI_JNDIKEY_BEANMANAGER_APP
will be checked. If still nothing is found there, the keyCDI_JNDIKEY_BEANMANAGER_COMP_ENV
will be checked.- Returns:
- the BeanManager, if found. null otherwise.
-
lookup
Lookup the given JNDI key in the given context.- Parameters:
context
- the context to use for lookup.jndiKeyToCheck
- the key to lookup.- Returns:
- the BeanManager, if found; null if not found or
NamingException
was thrown.
-
buildBean
public Object buildBean(String className, Map<String, Object> extraContext, boolean injectInternal) throws Exception- Overrides:
buildBean
in classObjectFactory
- Throws:
Exception
-
getInjectionTarget
Get a InjectionTarget instance for a given class. If the appropriate target is not found in cache, a nw instance will be created.- Parameters:
clazz
- The class to get a InjectionTarget instance for.- Returns:
- if found in cache, an existing instance. A new instance otherwise.
-
buildNonContextualCreationalContext
protected jakarta.enterprise.context.spi.CreationalContext buildNonContextualCreationalContext(jakarta.enterprise.inject.spi.BeanManager beanManager) Simple wrapper for CreationalContext creation.- Parameters:
beanManager
- the BeanManager to use for creating the context.- Returns:
- the context to use, if given BeanManager was not null. null otherwise.
-
isNoArgConstructorRequired
public boolean isNoArgConstructorRequired()Allow constructor injection- Overrides:
isNoArgConstructorRequired
in classObjectFactory
-