com.jrefinery.report.filter
Class FormatParser

java.lang.Object
  extended bycom.jrefinery.report.filter.FormatParser
All Implemented Interfaces:
java.lang.Cloneable, DataFilter, DataSource, DataTarget, java.io.Serializable
Direct Known Subclasses:
DateFormatParser, NumberFormatParser

public class FormatParser
extends java.lang.Object
implements DataFilter, java.io.Serializable

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
 java.lang.Object clone()
          Clones the parser.
 DataSource getDataSource()
          Returns the data source for the filter.
 java.text.Format getFormatter()
          Returns the format for the filter.
 java.lang.Object getNullValue()
          Returns the object representing a null value from the data source.
 java.lang.Object getValue()
          Returns the parsed object.
protected  boolean isValidOutput(java.lang.Object o)
          Checks whether the given value is already a valid result.
 void setDataSource(DataSource ds)
          Sets the data source.
 void setFormatter(java.text.Format format)
          Sets the format for the filter.
 void setNullValue(java.lang.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, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatParser

public FormatParser()
DefaultConstructor.

Method Detail

setFormatter

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

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

getFormatter

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

Returns:
The format.

getValue

public java.lang.Object getValue()
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
Returns:
The formatted value.

isValidOutput

protected boolean isValidOutput(java.lang.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 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(java.lang.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 java.lang.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 java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the parser.

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