org.apache.cocoon.forms.formmodel.algorithms
Class SimpleFormula

java.lang.Object
  extended byorg.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
      extended byorg.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
All Implemented Interfaces:
CalculatedFieldAlgorithm
Direct Known Subclasses:
RepeatedFormula

public class SimpleFormula
extends AbstractBaseAlgorithm

An xreported expression based algorithm.

This algorithm can be used to write simple formulas, examples are :

Note: please take care that xreporter expressions are not that accurate when it comes to decimals. The default divide operator rounds the result, see http://issues.cocoondev.org/browse/XRP-115. Also consider that the available set of functions can be expanded implementing and using new ones. Please see http://outerthought.net/wqm/xreporter/en/expressions.html for an overview of xreportes expressions and IsNullFunction or StringFunction for examples of custom xreporter functions.

Version:
$Id: SimpleFormula.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  org.outerj.expression.Expression formula
           
 
Fields inherited from class org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
triggers
 
Constructor Summary
SimpleFormula()
           
 
Method Summary
 Object calculate(Form form, Widget parent, Datatype datatype)
          Performs the actual calculation.
 org.outerj.expression.Expression getFormula()
           
 boolean isSuitableFor(Datatype dataType)
          Checks wether this algorithm is able to return the given datatype.
 void setFormula(org.outerj.expression.Expression formula)
           
 
Methods inherited from class org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
addTrigger, clearTriggers, getTriggerWidgets
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

formula

protected org.outerj.expression.Expression formula
Constructor Detail

SimpleFormula

public SimpleFormula()
Method Detail

isSuitableFor

public boolean isSuitableFor(Datatype dataType)
Description copied from interface: CalculatedFieldAlgorithm
Checks wether this algorithm is able to return the given datatype. For example, an arithmetic algorithm like sum should check that the given datatype is a number.

Parameters:
dataType - The target datatype.
Returns:
true if this algorithm can return a compatible value, false otherwise.

calculate

public Object calculate(Form form,
                        Widget parent,
                        Datatype datatype)
Description copied from interface: CalculatedFieldAlgorithm
Performs the actual calculation.

Parameters:
form - The form.
parent - The parent widget of the CalculatedField widget (may be the same as form)
datatype - The target datatype.
Returns:
the calculated value for the CalculatedField.

getFormula

public org.outerj.expression.Expression getFormula()
Returns:
Returns the formula.

setFormula

public void setFormula(org.outerj.expression.Expression formula)
Parameters:
formula - The formula to set.


Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.