Class ScriptItemProcessor<I,O>
- All Implemented Interfaces:
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.
- Since:
- 3.0
- Author:
- Chris Schaefer
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidProcess the provided item, returning a potentially modified or new item for continued processing.voidsetItemBindingVariableName(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_NAMEis not suitable ("item").voidsetScript(org.springframework.core.io.Resource resource) Sets theResourcelocation of the script to use.voidsetScriptEvaluator(org.springframework.scripting.ScriptEvaluator scriptEvaluator) Provides the ability to set a customScriptEvaluatorimplementation.voidsetScriptSource(String scriptSource, String language) Sets the providedStringas the script source code to use.
-
Field Details
-
ITEM_BINDING_VARIABLE_NAME
- See Also:
-
-
Constructor Details
-
ScriptItemProcessor
public ScriptItemProcessor()
-
-
Method Details
-
process
Description copied from interface:ItemProcessorProcess the provided item, returning a potentially modified or new item for continued processing. If the returned result isnull, it is assumed that processing of the item should not continue.A
nullitem will never reach this method because the only possible sources are:- an
ItemReader(which indicates no more items) - a previous
ItemProcessorin a composite processor (which indicates a filtered item)
- Specified by:
processin interfaceItemProcessor<I,O> - Parameters:
item- to be processed, nevernull.- Returns:
- potentially modified or new item for continued processing,
nullif processing of the provided item should not continue. - Throws:
Exception- thrown if exception occurs during processing.
- an
-
setScript
public void setScript(org.springframework.core.io.Resource resource) Sets the
Resourcelocation of the script to use. The script language will be deduced from the filename extension.- Parameters:
resource- theResourcelocation of the script to use.
-
setScriptSource
Sets the provided
Stringas the script source code to use.- Parameters:
scriptSource- theStringform of the script source code to use.language- the language of the script.
-
setItemBindingVariableName
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_NAMEis 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
ScriptEvaluatorimplementation. If not set, aStandardScriptEvaluatorwill be used by default.- Parameters:
scriptEvaluator- theScriptEvaluatorto use
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-