com.opensymphony.xwork
Class ObjectFactory

java.lang.Object
  extended bycom.opensymphony.xwork.ObjectFactory

public class ObjectFactory
extends Object

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

Constructor Summary
protected ObjectFactory()
           
 
Method Summary
 Action buildAction(ActionConfig config)
          Build an Action of the given type
 Object buildBean(Class clazz)
          Build a generic Java object of the given type.
 Object buildBean(String className)
          Build a generic Java object of the given type.
 Interceptor buildInterceptor(InterceptorConfig interceptorConfig, Map interceptorRefParams)
          Builds an Interceptor from the InterceptorConfig and the Map of parameters from the interceptor reference.
 Result buildResult(ResultConfig resultConfig)
          Build a Result using the type in the ResultConfig and set the parameters in the ResultConfig.
 Validator buildValidator(String className, Map params)
          Build a Validator of the given type and set the parameters on it
 Class getClassInstance(String className)
          Utility method to obtain the class matched to className.
static ObjectFactory getObjectFactory()
           
 boolean isNoArgConstructorRequired()
          Allows for ObjectFactory implementations that support Actions without no-arg constructors.
static void setObjectFactory(ObjectFactory factory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectFactory

protected ObjectFactory()
Method Detail

setObjectFactory

public static void setObjectFactory(ObjectFactory factory)

getObjectFactory

public static ObjectFactory getObjectFactory()

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

public Class getClassInstance(String className)
                       throws ClassNotFoundException
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

buildAction

public Action buildAction(ActionConfig config)
                   throws Exception
Build an Action of the given type

Throws:
Exception

buildBean

public Object buildBean(Class clazz)
                 throws Exception
Build a generic Java object of the given type.

Parameters:
clazz - the type of Object to build
Throws:
Exception

buildBean

public Object buildBean(String className)
                 throws Exception
Build a generic Java object of the given type.

Parameters:
className - the type of Object to build
Throws:
Exception

buildInterceptor

public Interceptor buildInterceptor(InterceptorConfig interceptorConfig,
                                    Map interceptorRefParams)
                             throws ConfigurationException
Builds an Interceptor from the InterceptorConfig and the Map of parameters from the interceptor reference. Implementations of this method should ensure that the Interceptor is parameterized 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 configuration
interceptorRefParams - a Map of params provided in the Interceptor reference in the Action mapping or InterceptorStack definition
Throws:
ConfigurationException

buildResult

public Result buildResult(ResultConfig resultConfig)
                   throws Exception
Build a Result using the type in the ResultConfig and set the parameters in the ResultConfig.

Throws:
Exception

buildValidator

public Validator buildValidator(String className,
                                Map params)
                         throws Exception
Build a Validator of the given type and set the parameters on it

Parameters:
className - the type of Validator to build
params - property name -> value Map to set onto the Validator instance
Throws:
Exception

XWork Project Page