Class ScriptItemProcessor<I,O>
- java.lang.Object
- org.springframework.batch.item.support.ScriptItemProcessor<I,O>
- All Implemented Interfaces:
ItemProcessor<I,O>
,org.springframework.beans.factory.InitializingBean
public class ScriptItemProcessor<I,O> extends java.lang.Object implements ItemProcessor<I,O>, org.springframework.beans.factory.InitializingBean
ItemProcessor
implementation that passes the current item to process to the provided script. Exposes the current item for processing via theITEM_BINDING_VARIABLE_NAME
key name ("item"). A custom key name can be set by invoking:setItemBindingVariableName(java.lang.String)
with the desired key name. The thread safety of thisItemProcessor
depends on the implementation of theScriptEvaluator
used.- Since:
- 3.0
- Author:
- Chris Schaefer
Constructor Summary
Constructors Constructor Description ScriptItemProcessor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
O
process(I item)
Process the provided item, returning a potentially modified or new item for continued processing.void
setItemBindingVariableName(java.lang.String itemBindingVariableName)
Provides the ability to change the key name that scripts use to obtain the current item to process if the variable represented by:ITEM_BINDING_VARIABLE_NAME
is not suitable ("item").void
setScript(org.springframework.core.io.Resource resource)
Sets theResource
location of the script to use.void
setScriptEvaluator(org.springframework.scripting.ScriptEvaluator scriptEvaluator)
Provides the ability to set a customScriptEvaluator
implementation.void
setScriptSource(java.lang.String scriptSource, java.lang.String language)
Sets the providedString
as the script source code to use.
Method Detail
process
public O process(I item) throws java.lang.Exception
Description copied from interface:ItemProcessor
Process the provided item, returning a potentially modified or new item for continued processing. If the returned result is null, it is assumed that processing of the item should not continue.- Specified by:
process
in interfaceItemProcessor<I,O>
- Parameters:
item
- to be processed- Returns:
- potentially modified or new item for continued processing,
null
if processing of the provided item should not continue. - Throws:
java.lang.Exception
- thrown if exception occurs during processing.
setScript
public void setScript(org.springframework.core.io.Resource resource)
Sets the
Resource
location of the script to use. The script language will be deduced from the filename extension.- Parameters:
resource
- theResource
location of the script to use.
setScriptSource
public void setScriptSource(java.lang.String scriptSource, java.lang.String language)
Sets the provided
String
as the script source code to use.- Parameters:
scriptSource
- theString
form of the script source code to use.language
- the language of the script.
setItemBindingVariableName
public void setItemBindingVariableName(java.lang.String itemBindingVariableName)
Provides the ability to change the key name that scripts use to obtain the current item to process if the variable represented by:
ITEM_BINDING_VARIABLE_NAME
is not suitable ("item").- Parameters:
itemBindingVariableName
- the desired binding variable name
setScriptEvaluator
public void setScriptEvaluator(org.springframework.scripting.ScriptEvaluator scriptEvaluator)
Provides the ability to set a custom
ScriptEvaluator
implementation. If not set, aStandardScriptEvaluator
will be used by default.- Parameters:
scriptEvaluator
- theScriptEvaluator
to use
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception