org.springframework.batch.core.resource
Class StepExecutionResourceProxy

java.lang.Object
  extended by org.springframework.batch.core.listener.StepExecutionListenerSupport
      extended by org.springframework.batch.core.resource.StepExecutionResourceProxy
All Implemented Interfaces:
StepExecutionListener, StepListener, ResourceLoaderAware, InputStreamSource, Resource

public class StepExecutionResourceProxy
extends StepExecutionListenerSupport
implements Resource, ResourceLoaderAware, StepExecutionListener

Strategy for locating different resources on the file system. For each unique step execution, the same file handle will be returned. A unique step is defined as having the same job instance and step name. An external file mover (such as an EAI solution) should rename and move any input files to conform to the pattern defined here.
If no pattern is passed in, then following default is used:

 data/%JOB_NAME%/%STEP_NAME%.txt
 
The %% variables are replaced with the corresponding bean property at run time, when the factory method is executed. To insert JobParameters use a pattern with the parameter key surrounded by %%, e.g.
 //home/jobs/data/%JOB_NAME%/%STEP_NAME%-%schedule.date%.txt
 
Note that the default pattern does not start with a separator. Because of the implementation of the Spring Core Resource abstractions, it would need to start with a double forward slash "//" to resolve to an absolute directory (or else use a full URL with the file: prefix).
To use this resource it must be initialised with a StepExecution. The best way to do that is to register it as a listener in the step that is going to need it. For this reason the resource implements StepExecutionListener.

Author:
Tomas Slanina, Lucas Ward, Dave Syer
See Also:
Resource

Constructor Summary
StepExecutionResourceProxy()
           
 
Method Summary
 void beforeStep(StepExecution execution)
          Collect the properties of the enclosing StepExecution that will be needed to create a file name.
 Resource createRelative(String relativePath)
           
 boolean exists()
           
 String getDescription()
           
 File getFile()
           
 String getFilename()
           
 InputStream getInputStream()
           
 URI getURI()
           
 URL getURL()
           
 boolean isOpen()
           
 boolean isReadable()
           
 boolean isSingleton()
          Always false because we are expecting to be step scoped.
 void setFilePattern(String filePattern)
           
 void setJobParametersFactory(JobParametersConverter jobParametersConverter)
          Public setter for the JobParametersConverter used to translate JobParameters into Properties.
 void setResourceLoader(ResourceLoader resourceLoader)
           
 String toString()
          Delegates to the proxied Resource if set, otherwise returns the value of setFilePattern(String).
 
Methods inherited from class org.springframework.batch.core.listener.StepExecutionListenerSupport
afterStep, onErrorInStep
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.batch.core.StepExecutionListener
afterStep, onErrorInStep
 

Constructor Detail

StepExecutionResourceProxy

public StepExecutionResourceProxy()
Method Detail

createRelative

public Resource createRelative(String relativePath)
                        throws IOException
Specified by:
createRelative in interface Resource
Parameters:
relativePath -
Throws:
IOException
See Also:
Resource.createRelative(java.lang.String)

exists

public boolean exists()
Specified by:
exists in interface Resource
See Also:
Resource.exists()

getDescription

public String getDescription()
Specified by:
getDescription in interface Resource
See Also:
Resource.getDescription()

getFile

public File getFile()
             throws IOException
Specified by:
getFile in interface Resource
Throws:
IOException
See Also:
Resource.getFile()

getFilename

public String getFilename()
Specified by:
getFilename in interface Resource
See Also:
Resource.getFilename()

getInputStream

public InputStream getInputStream()
                           throws IOException
Specified by:
getInputStream in interface InputStreamSource
Throws:
IOException
See Also:
InputStreamSource.getInputStream()

getURI

public URI getURI()
           throws IOException
Specified by:
getURI in interface Resource
Throws:
IOException
See Also:
Resource.getURI()

getURL

public URL getURL()
           throws IOException
Specified by:
getURL in interface Resource
Throws:
IOException
See Also:
Resource.getURL()

isOpen

public boolean isOpen()
Specified by:
isOpen in interface Resource
See Also:
Resource.isOpen()

isReadable

public boolean isReadable()
Specified by:
isReadable in interface Resource
See Also:
Resource.isReadable()

setJobParametersFactory

public void setJobParametersFactory(JobParametersConverter jobParametersConverter)
Public setter for the JobParametersConverter used to translate JobParameters into Properties. Defaults to a DefaultJobParametersConverter.

Parameters:
jobParametersConverter - the JobParametersConverter to set

isSingleton

public boolean isSingleton()
Always false because we are expecting to be step scoped.

See Also:
AbstractFactoryBean.isSingleton()

setResourceLoader

public void setResourceLoader(ResourceLoader resourceLoader)
Specified by:
setResourceLoader in interface ResourceLoaderAware

setFilePattern

public void setFilePattern(String filePattern)

beforeStep

public void beforeStep(StepExecution execution)
Collect the properties of the enclosing StepExecution that will be needed to create a file name.

Specified by:
beforeStep in interface StepExecutionListener
Overrides:
beforeStep in class StepExecutionListenerSupport
See Also:
StepExecutionListener.beforeStep(org.springframework.batch.core.StepExecution)

toString

public String toString()
Delegates to the proxied Resource if set, otherwise returns the value of setFilePattern(String).

Overrides:
toString in class Object


Copyright © 2008 SpringSource. All Rights Reserved.