org.jdto.mergers
Class GroovyMerger

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

public class GroovyMerger
extends AbstractGroovyMerger
implements SinglePropertyValueMerger<Object,Object>

Merge the source value 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 sourceValue 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:
 "sourceValue.toString()" //convert to string.
 "sourceValue == null ? 'isNull' : 'isNotNull'" //check for nulls
 "StringUtils.reverse(sourceValue)" //Access the StringUtils class from commons.
 "logger.error('Value is: ' + sourceValue); return sourceValue;" //log the value and return it.
 

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
GroovyMerger()
           
 
Method Summary
 Object mergeObjects(Object value, String[] extraParam)
          Merge the source value by applying 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
 
Methods inherited from interface org.jdto.SinglePropertyValueMerger
isRestoreSupported, restoreObject
 

Constructor Detail

GroovyMerger

public GroovyMerger()
Method Detail

mergeObjects

public Object mergeObjects(Object value,
                           String[] extraParam)
Merge the source value by applying the groovy expression sent as the first merger parameter.

Specified by:
mergeObjects in interface SinglePropertyValueMerger<Object,Object>
Parameters:
value - the object to be merged.
extraParam - the first element is the groovy expression to evaluate.
Returns:
the result of evaluating the expression.


Copyright © 2012. All Rights Reserved.