org.jfree.report.function
Class AbstractExpression

java.lang.Object
  extended byorg.jfree.report.function.AbstractExpression
All Implemented Interfaces:
java.lang.Cloneable, Expression, java.io.Serializable
Direct Known Subclasses:
BSHExpression, ItemColumnQuotientExpression, TextFormatExpression

public abstract class AbstractExpression
extends java.lang.Object
implements Expression, java.io.Serializable

An abstract base class for implementing new report expressions.

Expressions are stateless functions which have access to the report's DataRow. All expressions are named and the defined names have to be unique within the report's expressions, functions and fields of the datasource. Expressions are configured using properties.

todo: define a property query interface similar to the JDBC-Property interface

Author:
Thomas Morgner
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.jfree.report.function.Expression
AUTOACTIVATE_PROPERTY
 
Constructor Summary
protected AbstractExpression()
          Creates an unnamed expression.
 
Method Summary
 java.lang.Object clone()
          Clones the expression.
 DataRow getDataRow()
          Returns the current DataRow.
 int getDependencyLevel()
          Returns the dependency level for the expression (controls evaluation order for expressions and functions).
 Expression getInstance()
          Return a completly separated copy of this function.
 java.lang.String getName()
          Returns the name of the expression.
 java.util.Properties getProperties()
          Returns a copy of the properties for this expression.
 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 initialize()
          Checks that the expression has been correctly initialized.
 boolean isActive()
          Returns true if this expression contains "auto-active" content and should be called by the system regardless of whether this expression is referenced in the DataRow.
 void setDataRow(DataRow row)
          Sets the current DataRow for the expression.
 void setDependencyLevel(int level)
          Sets the dependency level for the expression.
 void setName(java.lang.String name)
          Sets the name of the expression.
 void setProperties(java.util.Properties p)
          Adds a property collection to the properties for this expression (overwriting existing properties with the same name).
 void setProperty(java.lang.String name, java.lang.String value)
          Sets a property for the expression.
 
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

AbstractExpression

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

Method Detail

getName

public java.lang.String getName()
Returns the name of the expression.

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

setName

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

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 "auto-active" content and should be called by the system regardless of 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 final void setProperty(java.lang.String name,
                              java.lang.String value)
Sets a property for the expression. 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()
Returns a copy of the properties for this expression.

Specified by:
getProperties in interface Expression
Returns:
the properties.

setProperties

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

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

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

getDependencyLevel

public int getDependencyLevel()
Returns the dependency level for the expression (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 expression.

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 current DataRow.

Specified by:
getDataRow in interface Expression
Returns:
the data row.

setDataRow

public void setDataRow(DataRow row)
Sets the current DataRow for the expression. The data row is set when the report processing starts and can be used to access the values of other expressions, functions, and the report's TableModel.

This method is used by the report processing engine, you shouldn't need to call it yourself.

Specified by:
setDataRow in interface Expression
Parameters:
row - the data row.

initialize

public void initialize()
                throws FunctionInitializeException
Checks that the expression 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 expression is not initialized properly.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the expression. The expression should be reinitialized after the cloning.

Expressions maintain no state, cloning is done at the beginning of the report processing to disconnect the expression from any other object space.

Specified by:
clone in interface Expression
Returns:
a clone of this expression.
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. Only the datarow may be shared.

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