| Method from com.opensymphony.xwork2.spring.SpringObjectFactory Detail: |
public Object autoWireBean(Object bean) {
return autoWireBean(bean, autoWiringFactory);
}
|
public Object autoWireBean(Object bean,
AutowireCapableBeanFactory autoWiringFactory) {
if (autoWiringFactory != null) {
autoWiringFactory.autowireBeanProperties(bean,
autowireStrategy, false);
}
if (bean instanceof ApplicationContextAware) {
((ApplicationContextAware) bean).setApplicationContext(appContext);
}
injectInternalBeans(bean);
return bean;
}
|
public Object buildBean(Class clazz,
Map extraContext) throws Exception {
Object bean;
try {
bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
} catch (UnsatisfiedDependencyException e) {
// Fall back
bean = super.buildBean(clazz, extraContext);
}
bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean, bean.getClass().getName());
// We don't need to call the init-method since one won't be registered.
bean = autoWiringFactory.applyBeanPostProcessorsAfterInitialization(bean, bean.getClass().getName());
return autoWireBean(bean, autoWiringFactory);
}
|
public Object buildBean(String beanName,
Map extraContext,
boolean injectInternal) throws Exception {
Object o = null;
try {
o = appContext.getBean(beanName);
} catch (NoSuchBeanDefinitionException e) {
Class beanClazz = getClassInstance(beanName);
o = buildBean(beanClazz, extraContext);
}
if (injectInternal) {
injectInternalBeans(o);
}
return o;
}
Looks up beans using Spring's application context before falling back to the method defined in the ObjectFactory . |
protected AutowireCapableBeanFactory findAutoWiringBeanFactory(ApplicationContext context) {
if (context instanceof AutowireCapableBeanFactory) {
// Check the context
return (AutowireCapableBeanFactory) context;
} else if (context instanceof ConfigurableApplicationContext) {
// Try and grab the beanFactory
return ((ConfigurableApplicationContext) context).getBeanFactory();
} else if (context.getParent() != null) {
// And if all else fails, try again with the parent context
return findAutoWiringBeanFactory(context.getParent());
}
return null;
}
If the given context is assignable to AutowireCapbleBeanFactory or contains a parent or a factory that is, then
set the autoWiringFactory appropriately. |
public int getAutowireStrategy() {
return autowireStrategy;
}
|
public Class getClassInstance(String className) throws ClassNotFoundException {
Class clazz = null;
if (useClassCache) {
synchronized(classes) {
// this cache of classes is needed because Spring sucks at dealing with situations where the
// class instance changes
clazz = (Class) classes.get(className);
}
}
if (clazz == null) {
if (appContext.containsBean(className)) {
clazz = appContext.getBean(className).getClass();
} else {
clazz = super.getClassInstance(className);
}
if (useClassCache) {
synchronized(classes) {
classes.put(className, clazz);
}
}
}
return clazz;
}
|
public void initObjectFactory() {
// not necessary anymore
} Deprecated! Since - 2.1 as it isn't necessary
This method sets the ObjectFactory used by XWork to this object. It's best used as the "init-method" of a Spring
bean definition in order to hook Spring and XWork together properly (as an alternative to the
org.apache.struts2.spring.lifecycle.SpringObjectFactoryListener) |
public boolean isNoArgConstructorRequired() {
return false;
}
Allows for ObjectFactory implementations that support
Actions without no-arg constructors. |
public void setApplicationContext(ApplicationContext appContext) throws BeansException {
this.appContext = appContext;
autoWiringFactory = findAutoWiringBeanFactory(this.appContext);
}
Set the Spring ApplicationContext that should be used to look beans up with. |
public void setApplicationContextPath(String ctx) {
if (ctx != null) {
setApplicationContext(new ClassPathXmlApplicationContext(ctx));
}
}
|
public void setAutowireStrategy(int autowireStrategy) {
switch (autowireStrategy) {
case AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT:
LOG.info("Setting autowire strategy to autodetect");
this.autowireStrategy = autowireStrategy;
break;
case AutowireCapableBeanFactory.AUTOWIRE_BY_NAME:
LOG.info("Setting autowire strategy to name");
this.autowireStrategy = autowireStrategy;
break;
case AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE:
LOG.info("Setting autowire strategy to type");
this.autowireStrategy = autowireStrategy;
break;
case AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR:
LOG.info("Setting autowire strategy to constructor");
this.autowireStrategy = autowireStrategy;
break;
default:
throw new IllegalStateException("Invalid autowire type set");
}
}
Sets the autowiring strategy |
public void setUseClassCache(boolean useClassCache) {
this.useClassCache = useClassCache;
}
Enable / disable caching of classes loaded by Spring. |