org.pentaho.reporting.engine.classic.core.filter
Class FormatParser

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.filter.FormatParser
All Implemented Interfaces:
Serializable, Cloneable, DataFilter, DataSource, DataTarget
Direct Known Subclasses:
DateFormatParser, NumberFormatParser

public class FormatParser
extends Object
implements DataFilter

A format parser tries to parse a string into an object. If the value returned by the datasource is no string, a string is formed using String.valueOf (Object). This string is fed into the java.text.Format of this FormatParser and the parsed object is returned.

What class of object is returned, is determined by the given format. If parsing failed, the defined NullValue is returned.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
FormatParser()
          DefaultConstructor.
 
Method Summary
 Object clone()
          Clones the parser.
 DataSource getDataSource()
          Returns the data source for the filter.
 Format getFormatter()
          Returns the format for the filter.
 Object getNullValue()
          Returns the object representing a null value from the data source.
 Object getValue(ExpressionRuntime runtime, Element element)
          Returns the parsed object.
 void setDataSource(DataSource ds)
          Sets the data source.
 void setFormatter(Format format)
          Sets the format for the filter.
 void setNullValue(Object nullvalue)
          Sets the value that will be displayed if the data source supplies a null value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatParser

public FormatParser()
DefaultConstructor.

Method Detail

setFormatter

public void setFormatter(Format format)
Sets the format for the filter.

Parameters:
format - The format.
Throws:
NullPointerException - if the given format is null

getFormatter

public Format getFormatter()
Returns the format for the filter.

Returns:
The format.

getValue

public Object getValue(ExpressionRuntime runtime,
                       Element element)
Returns the parsed object. The value is read using the data source given and parsed using the formatter of this object. The parsing is guaranteed to completly form the target object or to return the defined NullValue.

If the given datasource does not return a string, the returned object is transformed into a string using String.valueOf (Object) and then parsed.

If format, datasource or object are null, the NullValue is returned.

Specified by:
getValue in interface DataSource
Parameters:
runtime - the expression runtime that is used to evaluate formulas and expressions when computing the value of this filter.
element -
Returns:
The formatted value.

getDataSource

public DataSource getDataSource()
Returns the data source for the filter.

Specified by:
getDataSource in interface DataTarget
Returns:
The data source.

setDataSource

public void setDataSource(DataSource ds)
Sets the data source.

Specified by:
setDataSource in interface DataTarget
Parameters:
ds - The data source.

setNullValue

public void setNullValue(Object nullvalue)
Sets the value that will be displayed if the data source supplies a null value. The nullValue itself can be null to cover the case when no reasonable default value can be defined.

Parameters:
nullvalue - The value returned when the parsing failed.

getNullValue

public Object getNullValue()
Returns the object representing a null value from the data source. This value will also be returned when parsing failed or no parser or datasource is set at all.

Returns:
The value returned when the parsing failed.

clone

public Object clone()
             throws CloneNotSupportedException
Clones the parser.

Specified by:
clone in interface DataSource
Specified by:
clone in interface DataTarget
Overrides:
clone in class Object
Returns:
a clone.
Throws:
CloneNotSupportedException - this should never happen.