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 the
ITEM_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 this ItemProcessor
depends on the implementation of the ScriptEvaluator used.
| Constructor and Description |
|---|
ScriptItemProcessor() |
| Modifier and Type | Method and 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 the
Resource location of the script to use. |
void |
setScriptSource(java.lang.String scriptSource,
java.lang.String language)
Sets the provided
String as the script source code to use. |
public O process(I item) throws java.lang.Exception
ItemProcessorprocess in interface ItemProcessor<I,O>item - to be processedjava.lang.Exceptionpublic 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.
resource - the Resource location of the script to use.public void setScriptSource(java.lang.String scriptSource,
java.lang.String language)
Sets the provided String as the script source code to use.
scriptSource - the String form of the script source code to use.language - the language of the script as returned by the javax.script.ScriptEngineFactorypublic 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").
itemBindingVariableName - the desired binding variable namepublic void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exception