org.openadaptor.adaptor.value.action
Class MathsAction
java.lang.Object
org.openadaptor.adaptor.value.action.MathsAction
- All Implemented Interfaces:
- XFAction
public class MathsAction
- extends java.lang.Object
- implements XFAction
Perfoms a mathemetical operation on the specified Dataobject Attribute values.
Reads in the two source Attributes from the given Dataobject,
applies the operation specified, then puts the results in the
Attribute specified by Dest.
Intialisation in Adaptor Property file
prefix.Name = Maths
prefix.Operator = arithmetic operator: + - * /
prefix.Source1 = Attribute Name or constant value in braces e.g. {123}
prefix.Source2 = Attribute Name or constant value in braces
prefix.Destination = Attribute Name
For example, for DOType Sale this adds the values in sale1 and sale2 and puts
the result in total:
Adaptor.Totaliser.Sale.Action1.Name = Maths
Adaptor.Totaliser.Sale.Action1.Operator = +
Adaptor.Totaliser.Sale.Action1.Source1 = Sale1
Adaptor.Totaliser.Sale.Action1.Source2 = Sale2
Adaptor.Totaliser.Sale.Action1.Destination = total
This multiplies total by 10, putting the result back in total:
Adaptor.Totaliser.Sale.Action2.Name = Maths
Adaptor.Totaliser.Sale.Action2.Operator = *
Adaptor.Totaliser.Sale.Action2.Source1 = Total
Adaptor.Totaliser.Sale.Action2.Source2 = {10}
Adaptor.Totaliser.Sale.Action2.Destination = Total
Adaptor.Totaliser.Sale.Action2.Precision = 0
This example, with no Source or Operator properties, rounds cost to 2dp
Adaptor.GrassPipe.Type1.Action1.Name = Math
Adaptor.GrassPipe.Type1.Action1.Destination = cost
Adaptor.GrassPipe.Type1.Action1.Precision = 2
- Version:
- 1.01
- Author:
- Maili Buckingham
- See Also:
XFAction
Field Summary |
(package private) static org.apache.log4j.Logger |
log
|
Method Summary |
void |
init(java.lang.String name,
java.util.Properties props,
java.lang.String prefix)
Initialise from properties object. |
DataObject |
transform(DataObject dObject)
Performs the mathematical function on the attributes in the dataObject * |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
log
static org.apache.log4j.Logger log
MathsAction
public MathsAction()
init
public void init(java.lang.String name,
java.util.Properties props,
java.lang.String prefix)
throws ValueException
- Initialise from properties object. See class comment for property values
- Specified by:
init
in interface XFAction
- Parameters:
name
- props
- Properties objectprefix
- Prefix string to search for properties
- Throws:
ValueException
- Thrown if initialisation fails, mandatory properties are missing or properties cannot be parsed.
transform
public DataObject transform(DataObject dObject)
throws ValueException
- Performs the mathematical function on the attributes in the dataObject *
- Specified by:
transform
in interface XFAction
- Throws:
ValueException