Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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

    java.lang.Object
      org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
          org.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 :

- 20% VAT calculation : eval="(amount / 100) * 20"
- 100$ volume discount : eval="If(amount > 1000,100,0)" (read: if amount is greater than 1000 then the result will be 100, otherwise 0)
- Number of boxes needed to carry that number of items : eval="Ceiling(items / boxsize)"
- Number of items you can add before another box is needed : eval="Reminder(items,boxside)"

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.java 587759 2007-10-24 03:00:37Z vgritsenko $

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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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