Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.spring
Class SpringObjectFactory

    java.lang.Object
      com.opensymphony.xwork2.ObjectFactory
          com.opensymphony.xwork2.spring.SpringObjectFactory

All Implemented Interfaces:
  Serializable

Direct Known Subclasses:
  SpringProxyableObjectFactory

    public class SpringObjectFactory

extends ObjectFactory

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.

Author:
  Simon Stewart (sms@lateral.net)
See Also:
  Serialized Form

Field Summary
`protected ApplicationContext` | `appContext`
`protected int` | `autowireStrategy`
`protected AutowireCapableBeanFactory` | `autoWiringFactory`
`private Map` | `classes`
`private static Log` | `log`
`private boolean` | `useClassCache`

Constructor Summary
`SpringObjectFactory()`

Method Summary
`Object` | `autoWireBean(Object bean)`
`Object` | `autoWireBean(Object bean, AutowireCapableBeanFactory autoWiringFactory)`
`Object` | `buildBean(Class clazz, Map extraContext)` Build a generic Java object of the given type.
`Object` | `buildBean(String beanName, Map 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()` This method sets the ObjectFactory used by XWork to this object.
`boolean` | `isNoArgConstructorRequired()` Allows for ObjectFactory implementations that support Actions without no-arg constructors.
`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, setObjectFactory`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    private static final Log log

### appContext

    protected ApplicationContext appContext

### autoWiringFactory

    protected AutowireCapableBeanFactory autoWiringFactory

### autowireStrategy

    protected int autowireStrategy

### classes

    private Map classes

### useClassCache

    private boolean useClassCache

Constructor Detail

### SpringObjectFactory

    public SpringObjectFactory()

Method Detail

### setApplicationContextPath

    public void setApplicationContextPath(String ctx)

### setApplicationContext

    public void setApplicationContext(ApplicationContext appContext)
                               throws BeansException

  Set the Spring ApplicationContext that should be used to look beans up with.

  Parameters:
    `appContext` - The Spring ApplicationContext that should be used to look beans up with.
  Throws:
    `BeansException`

### setAutowireStrategy

    public void setAutowireStrategy(int autowireStrategy)

  Sets the autowiring strategy

  Parameters:
    `autowireStrategy` -

### getAutowireStrategy

    public int getAutowireStrategy()

### findAutoWiringBeanFactory

    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.

  Parameters:
    `context` -

### buildBean

    public Object buildBean(String beanName,
                            Map extraContext,
                            boolean injectInternal)
                     throws Exception

  Looks up beans using Spring's application context before falling back to the method defined in the `ObjectFactory`.

  Overrides:
    `buildBean` in class `ObjectFactory`
  Parameters:
    `beanName` - The name of the bean to look up in the application context
    `extraContext` -
  Returns:
    A bean from Spring or the result of calling the overridden method.
  Throws:
    `Exception`

### buildBean

    public Object buildBean(Class clazz,
                            Map extraContext)
                     throws Exception

  Description copied from class: `ObjectFactory`
  Build a generic Java object of the given type.

  Overrides:
    `buildBean` in class `ObjectFactory`
  Parameters:
    `clazz` -
    `extraContext` -
  Throws:
    `Exception`

### autoWireBean

    public Object autoWireBean(Object bean)

### autoWireBean

    public Object autoWireBean(Object bean,
                               AutowireCapableBeanFactory autoWiringFactory)

  Parameters:
    `bean` -
    `autoWiringFactory` -

### getClassInstance

    public Class getClassInstance(String className)
                           throws ClassNotFoundException

  Description copied from class: `ObjectFactory`
  Utility method to obtain the class matched to className. Caches look ups so that subsequent lookups will be faster.

  Overrides:
    `getClassInstance` in class `ObjectFactory`
  Parameters:
    `className` - The fully qualified name of the class to return
  Returns:
    The class itself
  Throws:
    `ClassNotFoundException`

### initObjectFactory

    public void initObjectFactory()

  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)

### isNoArgConstructorRequired

    public boolean isNoArgConstructorRequired()

  Allows for ObjectFactory implementations that support Actions without no-arg constructors.

  Overrides:
    `isNoArgConstructorRequired` in class `ObjectFactory`
  Returns:
    false

### setUseClassCache

    public void setUseClassCache(boolean useClassCache)

  Enable / disable caching of classes loaded by Spring.

  Parameters:
    `useClassCache` -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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