Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Custom Functions

  1. #1
    Join Date
    Mar 2003

    Default Custom Functions

    I'm looking for an example or details on how to write and implement custom functions for JFreeReport. I've looked at the javaDoc on the AbstractFunction class, but I'm still lost. If I create a class that extends AbstractFunction for a given report, do I have to recompile the JFree jar to include this new class, or can the new class exist by itself in a new jar.

    As an example for this function, it would have running totals for salaries. Each datarow would be evaluated for employee type, and values for FTSalary or PTSalary would be incremented. Then in the group footer, counts and salary summaries would be displayed.

    Much Thanks,

  2. #2
    Join Date
    Mar 2003


    I have created new functions - like std dev, and other statistical ones.

    Have a look at the source code in the functions package, and adapt their code to your purpose. Its pretty straigtforward as there are lots of examples.

    Then all you do is add the function to a functioncollection and add that to your report when creating it, and use it the same way as any other function.


  3. #3
    Join Date
    Mar 2003



    you don't have to include your functions in the report package. Just write your function in any package you like, and make sure it either extends AbstractFunction or implements the Function interface.

    The function implementation is loaded via its default constructor by the report parser, all function implementations which should be used from within the xml-definitions must define a public default constructor. The functions implementation is defined by specifiying the "class" attribute of the "function" tag and is loaded by using the default class loader. Your function implementation must be in the classloaders classpath.

    As with every function, a single function can return one value, something mathematicans express like y = f(x)
    where x is the data from your report processing.

    A function is called several times, for every state change (whenever the report advances) one of the ReportListener methods are called (reportStarted, groupStarted etc).

    The functions value is returned by the "getValue()" function. You can return any Object, but make sure, that this object does not get modified anymore after it was returned to the caller. (A simple way to obey to this rule is to create a new object whenever the computed object changes).

    Functions may reuse results from other functions by using and querying the DataRow object supplied in the report state or the function.

    The order of the functions and the order for receiving events is undefined for functions of the same dependency level. So if you define a function which reads values from an other function, it is wise to define the dependencies for these functions.

    Defining dependencies is easy: A function with an higher dependency is called before any function with a lower dependency. By default all user functions have the dependency of "0", the lowest possible level. The dependency is defined by specifying the "deplevel" attribute of the function or expression tag.

    When using the API, the dependency level is read by "getDependencyLevel()" and can be set with "setDependencyLevel(int)".

    For the example above, the caller function would have the dependency level of '0' and the called function the level of '1' or higher.

    If you want to see, which and when events are fired during the report processing, you may want to include the EventMonitorFunction into your report. This function does not return any values, but prints a lot of log messages whenever an event is sent to that function.

    A last note: if your computation is not state-full, that means that it is only based on the current report state, then you may have a look at the expressions. They perform all computations when "getValue()" is called, maintain no state, and are much easier to be implemented.

    Another try to supply some documentation can be found in that thread:

    Have more fun,
    said Thomas

  4. #4
    Join Date
    Mar 2003

    Default thanks

    Just wanted to say thanks. It just took a little trial and error to get my userdefined class running.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.