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

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

public class DateFormatParser
extends FormatParser

Parses a String into a java.util.Date. The string is read from the given datasource and then parsed by the dateformat contained in this FormatParser.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
DateFormatParser()
          Creates a new 'date format parser'.
 
Method Summary
 DateFormat getDateFormat()
          Returns the format for this filter.
 Object getValue(ExpressionRuntime runtime, Element element)
          Returns the parsed object.
 void setDateFormat(DateFormat format)
          Sets the format for the filter.
 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 org.pentaho.reporting.engine.classic.core.filter.FormatParser
clone, getDataSource, getFormatter, getNullValue, setDataSource
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateFormatParser

public DateFormatParser()
Creates a new 'date format parser'.

Method Detail

getDateFormat

public DateFormat getDateFormat()
Returns the format for this filter. The format object is returned as DateFormat.

Returns:
the formatter.
Throws:
NullPointerException - if the given format is null

setDateFormat

public void setDateFormat(DateFormat format)
Sets the format for the filter.

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

setFormatter

public void setFormatter(Format format)
Sets the format for the filter. The formater is required to be of type DateFormat.

Overrides:
setFormatter in class FormatParser
Parameters:
format - The format.
Throws:
NullPointerException - if the given format is null
ClassCastException - if an invalid formater is set.

getValue

public Object getValue(ExpressionRuntime runtime,
                       Element element)
Description copied from class: FormatParser
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
Overrides:
getValue in class FormatParser
Parameters:
runtime - the expression runtime that is used to evaluate formulas and expressions when computing the value of this filter.
element - the element for which the data is computed.
Returns:
The formatted value.

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.

The null value for date format parsers is required to be either null or a java.util.Date.

Overrides:
setNullValue in class FormatParser
Parameters:
nullvalue - the nullvalue returned when parsing failed.
Throws:
ClassCastException - if the value is no date or not null.