Class FormatParser
- java.lang.Object
-
- 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
Constructors Constructor Description FormatParser()
DefaultConstructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FormatParser
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, ReportElement element)
Returns the parsed object.protected boolean
isValidOutput(Object o)
Checks whether the given value is already a valid result.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.
-
-
-
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, ReportElement 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 interfaceDataSource
- 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.
-
isValidOutput
protected boolean isValidOutput(Object o)
Checks whether the given value is already a valid result. IF the datasource already returned a valid value, and no parsing is required, a parser can skip the parsing process by returning true in this function.- Parameters:
o
- the object to parse.- Returns:
- false as this class does not know anything about the format of input or result objects.
-
getDataSource
public DataSource getDataSource()
Returns the data source for the filter.- Specified by:
getDataSource
in interfaceDataTarget
- Returns:
- The data source.
-
setDataSource
public void setDataSource(DataSource ds)
Sets the data source.- Specified by:
setDataSource
in interfaceDataTarget
- 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 FormatParser clone() throws CloneNotSupportedException
Clones the parser.- Specified by:
clone
in interfaceDataSource
- Specified by:
clone
in interfaceDataTarget
- Overrides:
clone
in classObject
- Returns:
- a clone.
- Throws:
CloneNotSupportedException
- this should never happen.
-
-