com.opensymphony.xwork2
Class ObjectFactory

java.lang.Object
  extended by com.opensymphony.xwork2.ObjectFactory
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
SpringObjectFactory

public class ObjectFactory
extends java.lang.Object
implements java.io.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:
Serialized Form

Field Summary
protected  ReflectionProvider reflectionProvider
           
 
Constructor Summary
ObjectFactory()
           
ObjectFactory(ReflectionProvider prov)
           
 
Method Summary
 java.lang.Object buildAction(java.lang.String actionName, java.lang.String namespace, ActionConfig config, java.util.Map<java.lang.String,java.lang.Object> extraContext)
          Build an instance of the action class to handle a particular request (eg.
 java.lang.Object buildBean(java.lang.Class clazz, java.util.Map<java.lang.String,java.lang.Object> extraContext)
          Build a generic Java object of the given type.
 java.lang.Object buildBean(java.lang.String className, java.util.Map<java.lang.String,java.lang.Object> extraContext)
          Build a generic Java object of the given type.
 java.lang.Object buildBean(java.lang.String className, java.util.Map<java.lang.String,java.lang.Object> extraContext, boolean injectInternal)
          Build a generic Java object of the given type.
 Interceptor buildInterceptor(InterceptorConfig interceptorConfig, java.util.Map<java.lang.String,java.lang.String> interceptorRefParams)
          Builds an Interceptor from the InterceptorConfig and the Map of parameters from the interceptor reference.
 Result buildResult(ResultConfig resultConfig, java.util.Map<java.lang.String,java.lang.Object> extraContext)
          Build a Result using the type in the ResultConfig and set the parameters in the ResultConfig.
 Validator buildValidator(java.lang.String className, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.Object> extraContext)
          Build a Validator of the given type and set the parameters on it
 java.lang.Class getClassInstance(java.lang.String className)
          Utility method to obtain the class matched to className.
static ObjectFactory getObjectFactory()
          Deprecated. Since 2.1
protected  java.lang.Object injectInternalBeans(java.lang.Object obj)
           
 boolean isNoArgConstructorRequired()
          Allows for ObjectFactory implementations that support Actions without no-arg constructors.
 void setClassLoader(java.lang.ClassLoader cl)
           
 void setContainer(Container container)
           
 void setReflectionProvider(ReflectionProvider prov)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reflectionProvider

protected ReflectionProvider reflectionProvider
Constructor Detail

ObjectFactory

public ObjectFactory()

ObjectFactory

public ObjectFactory(ReflectionProvider prov)
Method Detail

setClassLoader

public void setClassLoader(java.lang.ClassLoader cl)

setReflectionProvider

public void setReflectionProvider(ReflectionProvider prov)

setContainer

public void setContainer(Container container)

getObjectFactory

@Deprecated
public static ObjectFactory getObjectFactory()
Deprecated. Since 2.1


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 java.lang.Class getClassInstance(java.lang.String className)
                                 throws java.lang.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:
java.lang.ClassNotFoundException

buildAction

public java.lang.Object buildAction(java.lang.String actionName,
                                    java.lang.String namespace,
                                    ActionConfig config,
                                    java.util.Map<java.lang.String,java.lang.Object> extraContext)
                             throws java.lang.Exception
Build 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 configuration
namespace - the namespace the action is configured in
config - the action configuration found in the config for the actionName / namespace
extraContext - a Map of extra context which uses the same keys as the ActionContext
Returns:
instance of the action class to handle a web request
Throws:
java.lang.Exception

buildBean

public java.lang.Object buildBean(java.lang.Class clazz,
                                  java.util.Map<java.lang.String,java.lang.Object> extraContext)
                           throws java.lang.Exception
Build a generic Java object of the given type.

Parameters:
clazz - the type of Object to build
extraContext - a Map of extra context which uses the same keys as the ActionContext
Throws:
java.lang.Exception

injectInternalBeans

protected java.lang.Object injectInternalBeans(java.lang.Object obj)
Parameters:
obj -

buildBean

public java.lang.Object buildBean(java.lang.String className,
                                  java.util.Map<java.lang.String,java.lang.Object> extraContext)
                           throws java.lang.Exception
Build a generic Java object of the given type.

Parameters:
className - the type of Object to build
extraContext - a Map of extra context which uses the same keys as the ActionContext
Throws:
java.lang.Exception

buildBean

public java.lang.Object buildBean(java.lang.String className,
                                  java.util.Map<java.lang.String,java.lang.Object> extraContext,
                                  boolean injectInternal)
                           throws java.lang.Exception
Build a generic Java object of the given type.

Parameters:
className - the type of Object to build
extraContext - a Map of extra context which uses the same keys as the ActionContext
Throws:
java.lang.Exception

buildInterceptor

public Interceptor buildInterceptor(InterceptorConfig interceptorConfig,
                                    java.util.Map<java.lang.String,java.lang.String> 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,
                          java.util.Map<java.lang.String,java.lang.Object> extraContext)
                   throws java.lang.Exception
Build 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 returned
extraContext - a Map of extra context which uses the same keys as the ActionContext
Throws:
java.lang.Exception

buildValidator

public Validator buildValidator(java.lang.String className,
                                java.util.Map<java.lang.String,java.lang.String> params,
                                java.util.Map<java.lang.String,java.lang.Object> extraContext)
                         throws java.lang.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
extraContext - a Map of extra context which uses the same keys as the ActionContext
Throws:
java.lang.Exception


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.