Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Extending LibFormula is as simple as implementing two Java interfaces, and creating a couple of .properties files that tells it tell LibFormula about your new function. Here are the two Java interfaces you'll be implementing:

...

org.pentaho.reporting.libraries.formula.function.Function

...


org.pentaho.reporting.libraries.formula.function.FunctionDescription

...

To see a simple example that uses these classes, open up the LibFormula source in your IDE and go to the org.pentaho.reporting.libraries.formula.function.math package. Then open up the classes AbsFunction and AbsFunctionDescription, and the file Abs-Function.properties.

...

Code Block
org.pentaho.reporting.libraries.formula.functions.math.GreatestCommonDenom.class=com.acme.libformula.GreatestCommonDenomFunction
org.pentaho.reporting.libraries.formula.functions.math.GreatestCommonDenom.description=com.acme.libformula.GreatestCommonDenomFunctionDescription

Sample Code

Attached is PEOpen:a sample Java project that implements a simple LibFormula function called sleep (SLEEP). The SLEEP function takes a numeric parameter, and calls the Thread.sleep method which causes the current thread to cease execution for the specified number of milliseconds.

To build the source code, you'll need Apache Ant. You need to run the target resolve, followed by the target jar.

Summary

The Pentaho LibFormula library was designed from the very beginning to allow extensions in many different ways; adding your own formula is only one of many possible extension points. We hope that the extensibility of LibFormula encourages community contributions like financial libraries, algebraic expressions, and other useful operations.