org.jfree.report.function
Class AbstractFunction

java.lang.Object
  extended byorg.jfree.report.function.AbstractFunction
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, Expression, Function, ReportListener, java.io.Serializable
Direct Known Subclasses:
CountDistinctFunction, CSVWriter, ElementColorFunction, ElementVisibilitySwitchFunction, EventMonitorFunction, FontChangeFunction, GroupCountFunction, HideArticleDetailsFunction, ImageRenderFunction, ItemAvgFunction, ItemCountFunction, ItemHideFunction, ItemMaxFunction, ItemMinFunction, ItemPercentageFunction, ItemSumFunction, NettoProfitFunction, PageFunction, PageLayouter, PaintComponentFunction, PaintDynamicComponentFunction, SelectCardFunction, TableWriter, TotalCalculationFunction, TotalGroupSumFunction, TotalGroupSumQuotientFunction, TotalGroupSumQuotientPercentFunction, TotalItemCountFunction, TriggerNestedGroupFunction, TriggerTypeFunction, XMLWriter

public abstract class AbstractFunction
extends java.lang.Object
implements Function, java.io.Serializable

Base class for implementing new report functions. Provides empty implementations of all the methods in the Function interface.

The function is initialized when it gets added to the report. The method initialize gets called to perform the required initializations. At this point, all function properties must have been set to a valid state and the function must be named. If the initialisation fails, a FunctionInitializeException is thrown and the function get not added to the report.

Author:
Thomas Morgner
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.jfree.report.function.Expression
AUTOACTIVATE_PROPERTY
 
Constructor Summary
protected AbstractFunction()
          Creates an unnamed function.
protected AbstractFunction(java.lang.String name)
          Creates an named function.
 
Method Summary
 java.lang.Object clone()
          Clones the function.
 DataRow getDataRow()
          returns the datarow for this function.
 int getDependencyLevel()
          Returns the dependency level for the functions (controls evaluation order for expressions and functions).
 Expression getInstance()
          Return a completly separated copy of this function.
 java.lang.String getName()
          Returns the function name.
 java.util.Properties getProperties()
          Gets a copy of the properties used in this function.
 java.lang.String getProperty(java.lang.String name)
          Returns the value of a property, or null if no such property is defined.
 java.lang.String getProperty(java.lang.String name, java.lang.String defaultVal)
          Returns the value of a property, or defaultVal if no such property is defined.
 void groupFinished(ReportEvent event)
          Receives notification that a group has finished.
 void groupStarted(ReportEvent event)
          Receives notification that a group has started.
 void initialize()
          Checks that the function has been correctly initialized.
 boolean isActive()
          Returns true if this expression contains autoactive content and should be called by the system, regardless whether this expression is referenced in the datarow.
 void itemsAdvanced(ReportEvent event)
          Receives notification that a row of data is being processed.
 void itemsFinished(ReportEvent event)
          Receives notification that a group of item bands has been completed.
 void itemsStarted(ReportEvent event)
          Receives notification that a group of item bands is about to be processed.
 void reportDone(ReportEvent event)
          Receives notification that report generation has completed, the report footer was printed, no more output is done.
 void reportFinished(ReportEvent event)
          Receives notification that the report has finished.
 void reportInitialized(ReportEvent event)
          Receives notification that report generation initializes the current run.
 void reportStarted(ReportEvent event)
          Receives notification that the report has started.
 void setDataRow(DataRow dataRow)
          Defines the datarow for this function.
 void setDependencyLevel(int level)
          Sets the dependency level for the function.
 void setName(java.lang.String name)
          Sets the name of the function.
 void setProperties(java.util.Properties p)
          Adds a property collection to the properties for this function (overwriting existing properties with the same name).
 void setProperty(java.lang.String name, java.lang.String value)
          Sets a property for the function.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jfree.report.function.Expression
getValue
 

Constructor Detail

AbstractFunction

protected AbstractFunction()
Creates an unnamed function. Make sure the name of the function is set using setName(java.lang.String) before the function is added to the report's function collection.


AbstractFunction

protected AbstractFunction(java.lang.String name)
Creates an named function.

Parameters:
name - the name of the function.
Method Detail

getName

public java.lang.String getName()
Returns the function name.

Specified by:
getName in interface Expression
Returns:
the function name.

setName

public void setName(java.lang.String name)
Sets the name of the function.

The name should be unique among:

This allows the expression to be referenced by name from any report element.

You should not change the name of an expression once it has been added to the report's expression collection.

Specified by:
setName in interface Expression
Parameters:
name - the name (null not permitted).

getProperty

public java.lang.String getProperty(java.lang.String name)
Returns the value of a property, or null if no such property is defined.

Parameters:
name - the property name.
Returns:
the property value.

getProperty

public java.lang.String getProperty(java.lang.String name,
                                    java.lang.String defaultVal)
Returns the value of a property, or defaultVal if no such property is defined.

Parameters:
name - the property name.
defaultVal - the default value.
Returns:
the property value.

isActive

public boolean isActive()
Returns true if this expression contains autoactive content and should be called by the system, regardless whether this expression is referenced in the datarow.

Specified by:
isActive in interface Expression
Returns:
true, if the expression is activated automaticly, false otherwise.

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Sets a property for the function. If the property value is null, the property will be removed from the property collection.

Parameters:
name - the property name (null not permitted).
value - the property value.

getProperties

public java.util.Properties getProperties()
Gets a copy of the properties used in this function. Modifying the returned properties has no effect on the function.

Specified by:
getProperties in interface Expression
Returns:
a copy of the properties defined for this function.

setProperties

public void setProperties(java.util.Properties p)
Adds a property collection to the properties for this function (overwriting existing properties with the same name).

Function parameters are recorded as properties. The required parameters (if any) will be specified in the documentation for the class that implements the function.

Specified by:
setProperties in interface Expression
Parameters:
p - the properties.

getDependencyLevel

public int getDependencyLevel()
Returns the dependency level for the functions (controls evaluation order for expressions and functions).

Specified by:
getDependencyLevel in interface Expression
Returns:
the level.

setDependencyLevel

public void setDependencyLevel(int level)
Sets the dependency level for the function.

The dependency level controls the order of evaluation for expressions and functions. Higher level expressions are evaluated before lower level expressions. Any level in the range 0 to Integer.MAX_VALUE is allowed. Negative values are reserved for system functions (printing and layouting).

Specified by:
setDependencyLevel in interface Expression
Parameters:
level - the level (must be greater than or equal to 0).

getDataRow

public DataRow getDataRow()
returns the datarow for this function. A datarow is used to query the values of functions, expressions and datasource fields in an uniform way.

Specified by:
getDataRow in interface Expression
Returns:
the assigned datarow for this expression.

setDataRow

public void setDataRow(DataRow dataRow)
Defines the datarow for this function. A datarow is used to query the values of functions, expressions and datasource fields in an uniform way.

Specified by:
setDataRow in interface Expression
Parameters:
dataRow - assigns the datarow for this expression.

initialize

public void initialize()
                throws FunctionInitializeException
Checks that the function has been correctly initialized.

The only check performed at present is to make sure the name is not null.

Specified by:
initialize in interface Expression
Throws:
FunctionInitializeException - in case the function is not initialized properly.

reportInitialized

public void reportInitialized(ReportEvent event)
Receives notification that report generation initializes the current run.

The event carries a ReportState.Started state. Use this to initialize the report.

Specified by:
reportInitialized in interface ReportListener
Parameters:
event - The event.

reportStarted

public void reportStarted(ReportEvent event)
Receives notification that the report has started.

Specified by:
reportStarted in interface ReportListener
Parameters:
event - the event.

reportFinished

public void reportFinished(ReportEvent event)
Receives notification that the report has finished.

Specified by:
reportFinished in interface ReportListener
Parameters:
event - the event.

groupStarted

public void groupStarted(ReportEvent event)
Receives notification that a group has started.

Specified by:
groupStarted in interface ReportListener
Parameters:
event - the event.

groupFinished

public void groupFinished(ReportEvent event)
Receives notification that a group has finished.

Specified by:
groupFinished in interface ReportListener
Parameters:
event - the event.

itemsAdvanced

public void itemsAdvanced(ReportEvent event)
Receives notification that a row of data is being processed.

Specified by:
itemsAdvanced in interface ReportListener
Parameters:
event - the event.

itemsStarted

public void itemsStarted(ReportEvent event)
Receives notification that a group of item bands is about to be processed.

The next events will be itemsAdvanced events until the itemsFinished event is raised.

Specified by:
itemsStarted in interface ReportListener
Parameters:
event - The event.

itemsFinished

public void itemsFinished(ReportEvent event)
Receives notification that a group of item bands has been completed.

The itemBand is finished, the report starts to close open groups.

Specified by:
itemsFinished in interface ReportListener
Parameters:
event - The event.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the function.

Be aware, this does not create a deep copy. If you have complex strucures contained in objects, you have to override this function.

Specified by:
clone in interface Function
Returns:
a clone of this function.
Throws:
java.lang.CloneNotSupportedException - this should never happen.

getInstance

public Expression getInstance()
Return a completly separated copy of this function. The copy does no longer share any changeable objects with the original function.

Specified by:
getInstance in interface Expression
Returns:
a copy of this function.

reportDone

public void reportDone(ReportEvent event)
Receives notification that report generation has completed, the report footer was printed, no more output is done. This is a helper event to shut down the output service.

Specified by:
reportDone in interface ReportListener
Parameters:
event - The event.