Package org.apache.struts2
Class ObjectFactory
java.lang.Object
org.apache.struts2.ObjectFactory
- All Implemented Interfaces:
Serializable
ObjectFactory is responsible for building the core framework objects. Users may register their
own implementation of the ObjectFactory to control instantiation of these Objects.
This default implementation uses the buildBean
method to create all classes (interceptors, actions, results, etc).
- Author:
- Jason Carreira
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildAction
(String actionName, String namespace, ActionConfig config, Map<String, Object> extraContext) Build an instance of the action class to handle a particular request (eg.Build a generic Java object of the given type.Build a generic Java object of the given type.Build a generic Java object of the given type.buildConverter
(Class<? extends TypeConverter> converterClass, Map<String, Object> extraContext) Build converter of given typebuildInterceptor
(InterceptorConfig interceptorConfig, Map<String, String> interceptorRefParams) Builds an Interceptor from the InterceptorConfig and the Map of parameters from the interceptor reference.buildResult
(ResultConfig resultConfig, Map<String, Object> extraContext) Build a Result using the type in the ResultConfig and set the parameters in the ResultConfig.buildUnknownHandler
(String unknownHandlerName, Map<String, Object> extraContext) Builds unknown handlerBuild a Validator of the given type and set the parameters on itgetClassInstance
(String className) Utility method to obtain the class matched to className.protected Object
boolean
Allows for ObjectFactory implementations that support Actions without no-arg constructors.void
setActionFactory
(ActionFactory actionFactory) void
void
setContainer
(Container container) void
setConverterFactory
(ConverterFactory converterFactory) void
setInterceptorFactory
(InterceptorFactory interceptorFactory) void
setResultFactory
(ResultFactory resultFactory) void
setUnknownHandlerFactory
(UnknownHandlerFactory unknownHandlerFactory) void
setValidatorFactory
(ValidatorFactory validatorFactory)
-
Constructor Details
-
ObjectFactory
public ObjectFactory()
-
-
Method Details
-
setContainer
-
setClassLoader
-
setActionFactory
-
setResultFactory
-
setInterceptorFactory
-
setValidatorFactory
-
setConverterFactory
-
setUnknownHandlerFactory
-
isNoArgConstructorRequired
public boolean isNoArgConstructorRequired()Allows for ObjectFactory implementations that support Actions without no-arg constructors.- Returns:
- true if no-arg constructor is required, false otherwise
-
getClassInstance
Utility method to obtain the class matched to className. Caches look ups so that subsequent lookups will be faster.- Parameters:
className
- The fully qualified name of the class to return- Returns:
- The class itself
- Throws:
ClassNotFoundException
- if class not found in classpath
-
buildAction
public Object buildAction(String actionName, String namespace, ActionConfig config, Map<String, Object> extraContext) throws ExceptionBuild an instance of the action class to handle a particular request (eg. web request)- Parameters:
actionName
- the name the action configuration is set up with in the configurationnamespace
- the namespace the action is configured inconfig
- the action configuration found in the config for the actionName / namespaceextraContext
- a Map of extra context which uses the same keys as theActionContext
- Returns:
- instance of the action class to handle a web request
- Throws:
Exception
- in case of any error
-
buildBean
Build a generic Java object of the given type.- Parameters:
clazz
- the type of Object to buildextraContext
- a Map of extra context which uses the same keys as theActionContext
- Returns:
- object for the given type
- Throws:
Exception
- in case of any error
-
injectInternalBeans
- Parameters:
obj
- object to inject internal- Returns:
- the object
-
buildBean
Build a generic Java object of the given type.- Parameters:
className
- the type of Object to buildextraContext
- a Map of extra context which uses the same keys as theActionContext
- Returns:
- object for the given type
- Throws:
Exception
- in case of any error
-
buildBean
public Object buildBean(String className, Map<String, Object> extraContext, boolean injectInternal) throws ExceptionBuild a generic Java object of the given type.- Parameters:
className
- the type of Object to buildextraContext
- a Map of extra context which uses the same keys as theActionContext
injectInternal
- true if inject internal beans- Returns:
- object for the given type
- Throws:
Exception
- in case of any error
-
buildInterceptor
public Interceptor buildInterceptor(InterceptorConfig interceptorConfig, Map<String, String> interceptorRefParams) throws ConfigurationExceptionBuilds an Interceptor from the InterceptorConfig and the Map of parameters from the interceptor reference. Implementations of this method should ensure that the Interceptor is parametrized with both the parameters from the Interceptor config and the interceptor ref Map (the interceptor ref params take precedence), and that the Interceptor.init() method is called on the Interceptor instance before it is returned.- Parameters:
interceptorConfig
- the InterceptorConfig from the configurationinterceptorRefParams
- a Map of params provided in the Interceptor reference in the Action mapping or InterceptorStack definition- Returns:
- interceptor
- Throws:
ConfigurationException
-
buildResult
public Result buildResult(ResultConfig resultConfig, Map<String, Object> extraContext) throws ExceptionBuild a Result using the type in the ResultConfig and set the parameters in the ResultConfig.- Parameters:
resultConfig
- the ResultConfig found for the action with the result code returnedextraContext
- a Map of extra context which uses the same keys as theActionContext
- Returns:
- result
- Throws:
Exception
- in case of any error
-
buildValidator
public Validator buildValidator(String className, Map<String, Object> params, Map<String, throws ExceptionObject> extraContext) Build a Validator of the given type and set the parameters on it- Parameters:
className
- the type of Validator to buildparams
- property name -> value Map to set onto the Validator instanceextraContext
- a Map of extra context which uses the same keys as theActionContext
- Returns:
- validator of the given type
- Throws:
Exception
- in case of any error
-
buildConverter
public TypeConverter buildConverter(Class<? extends TypeConverter> converterClass, Map<String, Object> extraContext) throws ExceptionBuild converter of given type- Parameters:
converterClass
- to instantiateextraContext
- a Map of extra context which uses the same keys as theActionContext
- Returns:
- instance of converterClass with inject dependencies
- Throws:
Exception
- in case of any error
-
buildUnknownHandler
public UnknownHandler buildUnknownHandler(String unknownHandlerName, Map<String, Object> extraContext) throws ExceptionBuilds unknown handler- Parameters:
unknownHandlerName
- the unknown handler nameextraContext
- extra context- Returns:
- a unknown handler
- Throws:
Exception
- in case of any error
-