org.jdto.mergers
Class MultiGroovyMerger

java.lang.Object
  extended by org.jdto.mergers.AbstractGroovyMerger
      extended by org.jdto.mergers.MultiGroovyMerger
All Implemented Interfaces:
Serializable, MultiPropertyValueMerger<Object>, PropertyValueMerger

public class MultiGroovyMerger
extends AbstractGroovyMerger
implements MultiPropertyValueMerger<Object>

Merge the source values by evaluating a Groovy Expression.
This merger uses the embedded Groovy engine to provide convenience and simplicity to specify complex transformations.
In order to access the input of this merger, a scoped variable called sourceValues has been introduced.
For convenience, the following packages have been imported:

Finally, a scoped variable called logger has been introduced to help with logging. Here are some examples:
 "sourceValues.toString()" //convert to string.
 "sourceValues[1] //return the second value.
 "sourceValues[0].getName() + sourceValues[1].toString()" //concatenate the first and second value.
 "logger.error('Values are: ' + sourceValues); return sourceValues;" //log the values and return them.
 

Author:
Juan Alberto López Cavallotti
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jdto.mergers.AbstractGroovyMerger
currentConfiguration, logger, LOGGER_VARIABLE_NAME
 
Constructor Summary
MultiGroovyMerger()
           
 
Method Summary
 Object mergeObjects(List<Object> values, String[] extraParam)
          Merge a list of source values by aplying the groovy expression sent as the first merger parameter.
 
Methods inherited from class org.jdto.mergers.AbstractGroovyMerger
evaluateGroovyScript, getExpression, isRestoreSupported, restoreObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiGroovyMerger

public MultiGroovyMerger()
Method Detail

mergeObjects

public Object mergeObjects(List<Object> values,
                           String[] extraParam)
Merge a list of source values by aplying the groovy expression sent as the first merger parameter.

Specified by:
mergeObjects in interface MultiPropertyValueMerger<Object>
Parameters:
values - the list of values in the order defined by the mapping.
extraParam - the first param is the the groovy expression to evaluate.
Returns:
the result of evaluating the expression.


Copyright © 2013. All Rights Reserved.