Class ScriptItemProcessor<I,O>

All Implemented Interfaces:
ItemProcessor<I,O>, org.springframework.beans.factory.InitializingBean

public class ScriptItemProcessor<I,O> extends 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.

Chris Schaefer
  • Field Details

  • Constructor Details

    • ScriptItemProcessor

      public ScriptItemProcessor()
  • Method Details

    • process

      @Nullable public O process(I item) throws 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.

      A null item will never reach this method because the only possible sources are:

      • an ItemReader (which indicates no more items)
      • a previous ItemProcessor in a composite processor (which indicates a filtered item)
      Specified by:
      process in interface ItemProcessor<I,O>
      item - to be processed, never null.
      potentially modified or new item for continued processing, null if processing of the provided item should not continue.
      Exception - thrown if exception occurs during processing.
    • setScript

      public void setScript( 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.
    • setScriptSource

      public void setScriptSource(String scriptSource, 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.
    • setItemBindingVariableName

      public void setItemBindingVariableName(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 name
    • setScriptEvaluator

      public void setScriptEvaluator(org.springframework.scripting.ScriptEvaluator scriptEvaluator)

      Provides the ability to set a custom ScriptEvaluator implementation. If not set, a StandardScriptEvaluator will be used by default.

      scriptEvaluator - the ScriptEvaluator to use
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean