| Method from com.opensymphony.xwork2.ObjectFactory Detail: |
public Object buildAction(String actionName,
String namespace,
ActionConfig config,
Map extraContext) throws Exception {
return buildBean(config.getClassName(), extraContext);
}
Build an instance of the action class to handle a particular request (eg. web request) |
public Object buildBean(Class clazz,
Map extraContext) throws Exception {
return clazz.newInstance();
}
Build a generic Java object of the given type. |
public Object buildBean(String className,
Map extraContext) throws Exception {
return buildBean(className, extraContext, true);
}
Build a generic Java object of the given type. |
public Object buildBean(String className,
Map extraContext,
boolean injectInternal) throws Exception {
Class clazz = getClassInstance(className);
Object obj = buildBean(clazz, extraContext);
if (injectInternal) {
injectInternalBeans(obj);
}
return obj;
}
Build a generic Java object of the given type. |
public Interceptor buildInterceptor(InterceptorConfig interceptorConfig,
Map interceptorRefParams) throws ConfigurationException {
String interceptorClassName = interceptorConfig.getClassName();
Map thisInterceptorClassParams = interceptorConfig.getParams();
Map params = (thisInterceptorClassParams == null) ? new HashMap() : new HashMap(thisInterceptorClassParams);
params.putAll(interceptorRefParams);
String message;
Throwable cause;
try {
// interceptor instances are long-lived and used across user sessions, so don't try to pass in any extra context
Interceptor interceptor = (Interceptor) buildBean(interceptorClassName, null);
reflectionProvider.setProperties(params, interceptor);
interceptor.init();
return interceptor;
} catch (InstantiationException e) {
cause = e;
message = "Unable to instantiate an instance of Interceptor class [" + interceptorClassName + "].";
} catch (IllegalAccessException e) {
cause = e;
message = "IllegalAccessException while attempting to instantiate an instance of Interceptor class [" + interceptorClassName + "].";
} catch (ClassCastException e) {
cause = e;
message = "Class [" + interceptorClassName + "] does not implement com.opensymphony.xwork2.interceptor.Interceptor";
} catch (Exception e) {
cause = e;
message = "Caught Exception while registering Interceptor class " + interceptorClassName;
} catch (NoClassDefFoundError e) {
cause = e;
message = "Could not load class " + interceptorClassName + ". Perhaps it exists but certain dependencies are not available?";
}
throw new ConfigurationException(message, cause, interceptorConfig);
}
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. |
public Result buildResult(ResultConfig resultConfig,
Map extraContext) throws Exception {
String resultClassName = resultConfig.getClassName();
Result result = null;
if (resultClassName != null) {
result = (Result) buildBean(resultClassName, extraContext);
reflectionProvider.setProperties(resultConfig.getParams(), result, extraContext, true);
}
return result;
}
Build a Result using the type in the ResultConfig and set the parameters in the ResultConfig. |
public Validator buildValidator(String className,
Map params,
Map extraContext) throws Exception {
Validator validator = (Validator) buildBean(className, null);
reflectionProvider.setProperties(params, validator);
return validator;
}
Build a Validator of the given type and set the parameters on it |
public Class getClassInstance(String className) throws ClassNotFoundException {
if (ccl != null) {
return ccl.loadClass(className);
}
return ClassLoaderUtil.loadClass(className, this.getClass());
}
Utility method to obtain the class matched to className. Caches look ups so that subsequent
lookups will be faster. |
public static ObjectFactory getObjectFactory() {
return ActionContext.getContext().getContainer().getInstance(ObjectFactory.class);
} Deprecated! Since - 2.1
|
protected Object injectInternalBeans(Object obj) {
if (obj != null && container != null) {
container.inject(obj);
}
return obj;
}
|
public boolean isNoArgConstructorRequired() {
return true;
}
Allows for ObjectFactory implementations that support
Actions without no-arg constructors. |
public void setClassLoader(ClassLoader cl) {
this.ccl = cl;
}
|
public void setContainer(Container container) {
this.container = container;
}
|
public void setReflectionProvider(ReflectionProvider prov) {
this.reflectionProvider = prov;
}
|