org.springframework.batch.core.scope
Class StepScope

java.lang.Object
  extended by org.springframework.batch.core.scope.StepScope
All Implemented Interfaces:
BeanFactoryPostProcessor, Scope, Ordered

public class StepScope
extends Object
implements Scope, BeanFactoryPostProcessor, Ordered

Scope for step context. Objects in this scope use the Spring container as an object factory, so there is only one instance of such a bean per executing step. All objects in this scope are <aop:scoped-proxy/> (no need to decorate the bean definitions).

In addition, support is provided for late binding of references accessible from the StepContext using #{..} placeholders. Using this feature, bean properties can be pulled from the step or job execution context and the job parameters. E.g.

 <bean id="..." class="..." scope="step">
        <property name="parent" ref="#{stepExecutionContext[helper]}" />
 </bean>
 
 <bean id="..." class="..." scope="step">
        <property name="name" value="#{stepExecutionContext['input.name']}" />
 </bean>
 
 <bean id="..." class="..." scope="step">
        <property name="name" value="#{jobParameters[input]}" />
 </bean>
 
 <bean id="..." class="..." scope="step">
        <property name="name" value="#{jobExecutionContext['input.stem']}.txt" />
 </bean>
 
The StepContext is referenced using standard bean property paths (as per BeanWrapper). The examples above all show the use of the Map accessors provided as a convenience for step and job attributes.

Since:
2.0
Author:
Dave Syer

Field Summary
static String ID_KEY
          Context key for clients to use for conversation identifier.
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
StepScope()
           
 
Method Summary
 Object get(String name, ObjectFactory objectFactory)
           
 String getConversationId()
           
 int getOrder()
           
 void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
          Register this scope with the enclosing BeanFactory.
 void registerDestructionCallback(String name, Runnable callback)
           
 Object remove(String name)
           
 Object resolveContextualObject(String key)
           
 void setName(String name)
          Public setter for the name property.
 void setOrder(int order)
           
 void setProxyTargetClass(boolean proxyTargetClass)
          Flag to indicate that proxies should use dynamic subclassing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_KEY

public static final String ID_KEY
Context key for clients to use for conversation identifier.

See Also:
Constant Field Values
Constructor Detail

StepScope

public StepScope()
Method Detail

setOrder

public void setOrder(int order)
Parameters:
order - the order value to set priority of callback execution for the BeanFactoryPostProcessor part of this scope bean.

getOrder

public int getOrder()
Specified by:
getOrder in interface Ordered

setProxyTargetClass

public void setProxyTargetClass(boolean proxyTargetClass)
Flag to indicate that proxies should use dynamic subclassing. This allows classes with no interface to be proxied. Defaults to false.

Parameters:
proxyTargetClass - set to true to have proxies created using dynamic subclasses

resolveContextualObject

public Object resolveContextualObject(String key)

get

public Object get(String name,
                  ObjectFactory objectFactory)
Specified by:
get in interface Scope
See Also:
Scope.get(String, ObjectFactory)

getConversationId

public String getConversationId()
Specified by:
getConversationId in interface Scope
See Also:
Scope.getConversationId()

registerDestructionCallback

public void registerDestructionCallback(String name,
                                        Runnable callback)
Specified by:
registerDestructionCallback in interface Scope
See Also:
Scope.registerDestructionCallback(String, Runnable)

remove

public Object remove(String name)
Specified by:
remove in interface Scope
See Also:
Scope.remove(String)

postProcessBeanFactory

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
                            throws BeansException
Register this scope with the enclosing BeanFactory.

Specified by:
postProcessBeanFactory in interface BeanFactoryPostProcessor
Parameters:
beanFactory - the BeanFactory to register with
Throws:
BeansException - if there is a problem.
See Also:
BeanFactoryPostProcessor.postProcessBeanFactory(ConfigurableListableBeanFactory)

setName

public void setName(String name)
Public setter for the name property. This can then be used as a bean definition attribute, e.g. scope="step". Defaults to "step".

Parameters:
name - the name to set for this scope.


Copyright © 2009 SpringSource. All Rights Reserved.