|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.opensymphony.xwork2.ObjectFactory com.opensymphony.xwork2.spring.SpringObjectFactory
public class SpringObjectFactory
Simple implementation of the ObjectFactory that makes use of Spring's application context if one has been configured, before falling back on the default mechanism of instantiating a new class using the class name.
In order to use this class in your application, you will need to instantiate a copy of this class and set it as XWork's ObjectFactory before the xwork.xml file is parsed. In a servlet environment, this could be done using a ServletContextListener.
Field Summary | |
---|---|
protected ApplicationContext |
appContext
|
protected int |
autowireStrategy
|
protected AutowireCapableBeanFactory |
autoWiringFactory
|
Fields inherited from class com.opensymphony.xwork2.ObjectFactory |
---|
reflectionProvider |
Constructor Summary | |
---|---|
SpringObjectFactory()
|
Method Summary | |
---|---|
Object |
autoWireBean(Object bean)
|
Object |
autoWireBean(Object bean,
AutowireCapableBeanFactory autoWiringFactory)
|
Object |
buildBean(Class clazz,
Map<String,Object> extraContext)
Build a generic Java object of the given type. |
Object |
buildBean(String beanName,
Map<String,Object> extraContext,
boolean injectInternal)
Looks up beans using Spring's application context before falling back to the method defined in the ObjectFactory . |
protected AutowireCapableBeanFactory |
findAutoWiringBeanFactory(ApplicationContext context)
If the given context is assignable to AutowireCapbleBeanFactory or contains a parent or a factory that is, then set the autoWiringFactory appropriately. |
int |
getAutowireStrategy()
|
Class |
getClassInstance(String className)
Utility method to obtain the class matched to className. |
void |
initObjectFactory()
Deprecated. Since 2.1 as it isn't necessary |
boolean |
isNoArgConstructorRequired()
Allows for ObjectFactory implementations that support Actions without no-arg constructors. |
void |
setAlwaysRespectAutowireStrategy(boolean alwaysRespectAutowireStrategy)
Determines if the autowire strategy is always followed when creating beans |
void |
setApplicationContext(ApplicationContext appContext)
Set the Spring ApplicationContext that should be used to look beans up with. |
void |
setApplicationContextPath(String ctx)
|
void |
setAutowireStrategy(int autowireStrategy)
Sets the autowiring strategy |
void |
setUseClassCache(boolean useClassCache)
Enable / disable caching of classes loaded by Spring. |
Methods inherited from class com.opensymphony.xwork2.ObjectFactory |
---|
buildAction, buildBean, buildInterceptor, buildResult, buildValidator, getObjectFactory, injectInternalBeans, setClassLoader, setContainer, setReflectionProvider |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ApplicationContext appContext
protected AutowireCapableBeanFactory autoWiringFactory
protected int autowireStrategy
Constructor Detail |
---|
public SpringObjectFactory()
Method Detail |
---|
public void setApplicationContextPath(String ctx)
public void setApplicationContext(ApplicationContext appContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
appContext
- The Spring ApplicationContext that should be used to look beans up with.
BeansException
public void setAutowireStrategy(int autowireStrategy)
autowireStrategy
- public int getAutowireStrategy()
protected AutowireCapableBeanFactory findAutoWiringBeanFactory(ApplicationContext context)
context
- public Object buildBean(String beanName, Map<String,Object> extraContext, boolean injectInternal) throws Exception
ObjectFactory
.
buildBean
in class ObjectFactory
beanName
- The name of the bean to look up in the application contextextraContext
-
Exception
public Object buildBean(Class clazz, Map<String,Object> extraContext) throws Exception
ObjectFactory
buildBean
in class ObjectFactory
clazz
- extraContext
-
Exception
public Object autoWireBean(Object bean)
public Object autoWireBean(Object bean, AutowireCapableBeanFactory autoWiringFactory)
bean
- autoWiringFactory
- public Class getClassInstance(String className) throws ClassNotFoundException
ObjectFactory
getClassInstance
in class ObjectFactory
className
- The fully qualified name of the class to return
ClassNotFoundException
@Deprecated public void initObjectFactory()
public boolean isNoArgConstructorRequired()
isNoArgConstructorRequired
in class ObjectFactory
public void setUseClassCache(boolean useClassCache)
useClassCache
- public void setAlwaysRespectAutowireStrategy(boolean alwaysRespectAutowireStrategy)
alwaysRespectAutowireStrategy
- True if the strategy is always used
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |