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

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.filter.StringFilter
All Implemented Interfaces:
Serializable, Cloneable, DataFilter, DataSource, DataTarget, RawDataSource

public class StringFilter
extends Object
implements DataFilter, RawDataSource

A filter that returns the value from a data source as a String. The value is converted to an String using String.valueOf () which uses Object.toString() to convert the object into the string.

You can specify a default string to return when the value from the data source is null. Initially the string 'null' is used.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
StringFilter()
          Default constructor.
 
Method Summary
 Object clone()
          Clones the filter.
 DataSource getDataSource()
          Returns the data source for this filter.
 FormatSpecification getFormatString(ExpressionRuntime runtime, Element element, FormatSpecification formatSpecification)
          Returns information about the formatstring that was used to transform a raw-value into a formatted text.
 String getNullValue()
          Returns the string used to represent a null value.
 Object getRawValue(ExpressionRuntime runtime, Element element)
          Returns the unformated raw value.
 Object getValue(ExpressionRuntime runtime, Element element)
          Returns the value obtained from the data source.
 void setDataSource(DataSource ds)
          Sets the data source for this filter.
 void setNullValue(String nullvalue)
          Sets the string used to represent a null value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringFilter

public StringFilter()
Default constructor.

Method Detail

setNullValue

public void setNullValue(String nullvalue)
Sets the string used to represent a null value.

Parameters:
nullvalue - the null value.

getNullValue

public String getNullValue()
Returns the string used to represent a null value.

Returns:
the string.

getValue

public Object getValue(ExpressionRuntime runtime,
                       Element element)
Returns the value obtained from the data source.

The filter ensures that the returned value is a String, even though the return type is Object (as required by the DataSource interface).

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 string.

getDataSource

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

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

setDataSource

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

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

clone

public Object clone()
             throws CloneNotSupportedException
Clones the filter.

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.

getRawValue

public Object getRawValue(ExpressionRuntime runtime,
                          Element element)
Description copied from interface: RawDataSource
Returns the unformated raw value. Whether that raw value is useable for the export is beyond the scope of this API definition, but providing access to Number or Date objects is a good idea.

Specified by:
getRawValue in interface RawDataSource
Parameters:
runtime - the expression runtime that is used to evaluate formulas and expressions when computing the value of this filter.
Returns:
the raw data.

getFormatString

public FormatSpecification getFormatString(ExpressionRuntime runtime,
                                           Element element,
                                           FormatSpecification formatSpecification)
Description copied from interface: RawDataSource
Returns information about the formatstring that was used to transform a raw-value into a formatted text. Not all elements will make use of a format-string. These elements will return FormatSpecification.TYPE_UNDEFINED in that case.

Specified by:
getFormatString in interface RawDataSource
Parameters:
runtime - the Expression runtime used to possibly compute the raw-value.
element - the element to which this datasource is added.
formatSpecification - the format specification (can be null). @return a filled format specififcation. If the formatSpecification parameter was not null, this given instance is reused.