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.jndiKeyis 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 SummaryFieldsModifier and TypeFieldDescriptionprotected jakarta.enterprise.inject.spi.BeanManagerstatic final StringThe key under which the BeanManager can be found according to JBoss Weld docsstatic final StringThe key under which the BeanManager can be found according to CDI API docsstatic final StringThe key under which the BeanManager can be found in pure Servlet containers according to JBoss Weld docs.static final String
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected jakarta.enterprise.context.spi.CreationalContextbuildNonContextualCreationalContext(jakarta.enterprise.inject.spi.BeanManager beanManager) Simple wrapper for CreationalContext creation.protected jakarta.enterprise.inject.spi.BeanManagerTry 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.booleanAllow constructor injectionprotected jakarta.enterprise.inject.spi.BeanManagerLookup the given JNDI key in the given context.voidsetJndiKey(String jndiKey) Methods inherited from class org.apache.struts2.ObjectFactorybuildAction, buildBean, buildBean, buildConverter, buildInterceptor, buildResult, buildUnknownHandler, buildValidator, getClassInstance, injectInternalBeans, setActionFactory, setClassLoader, setContainer, setConverterFactory, setInterceptorFactory, setResultFactory, setUnknownHandlerFactory, setValidatorFactory
- 
Field Details- 
CDI_JNDIKEY_BEANMANAGER_COMPThe key under which the BeanManager can be found according to CDI API docs- See Also:
 
- 
CDI_JNDIKEY_BEANMANAGER_APPThe key under which the BeanManager can be found according to JBoss Weld docs- See Also:
 
- 
CDI_JNDIKEY_BEANMANAGER_COMP_ENVThe 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:
 
- 
beanManagerprotected jakarta.enterprise.inject.spi.BeanManager beanManager
 
- 
- 
Constructor Details- 
CdiObjectFactorypublic CdiObjectFactory()
 
- 
- 
Method Details- 
setJndiKey
- 
findBeanManagerprotected 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_COMPwill be tested. If nothing is found there, the keyCDI_JNDIKEY_BEANMANAGER_APPwill be checked. If still nothing is found there, the keyCDI_JNDIKEY_BEANMANAGER_COMP_ENVwill be checked.- Returns:
- the BeanManager, if found. null otherwise.
 
- 
lookupLookup 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 NamingExceptionwas thrown.
 
- 
buildBeanpublic Object buildBean(String className, Map<String, Object> extraContext, boolean injectInternal) throws Exception- Overrides:
- buildBeanin class- ObjectFactory
- Throws:
- Exception
 
- 
getInjectionTargetGet 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.
 
- 
buildNonContextualCreationalContextprotected 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.
 
- 
isNoArgConstructorRequiredpublic boolean isNoArgConstructorRequired()Allow constructor injection- Overrides:
- isNoArgConstructorRequiredin class- ObjectFactory
 
 
-