001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * StringFieldTemplate.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.filter.templates;
030:
031: import org.jfree.report.filter.DataRowDataSource;
032: import org.jfree.report.filter.RawDataSource;
033: import org.jfree.report.filter.StringFilter;
034: import org.jfree.report.filter.FormatSpecification;
035: import org.jfree.report.function.ExpressionRuntime;
036:
037: /**
038: * A string field template.
039: *
040: * @author Thomas Morgner
041: */
042: public class StringFieldTemplate extends AbstractTemplate implements
043: RawDataSource {
044: /**
045: * The data-row data source.
046: */
047: private DataRowDataSource dataRowDataSource;
048:
049: /**
050: * A string filter.
051: */
052: private StringFilter stringFilter;
053:
054: /**
055: * Creates a new string field template.
056: */
057: public StringFieldTemplate() {
058: dataRowDataSource = new DataRowDataSource();
059: stringFilter = new StringFilter();
060: stringFilter.setDataSource(dataRowDataSource);
061: }
062:
063: /**
064: * Returns the field name.
065: *
066: * @return The field name.
067: */
068: public String getField() {
069: return dataRowDataSource.getDataSourceColumnName();
070: }
071:
072: /**
073: * Sets the field name.
074: *
075: * @param field the field name.
076: */
077: public void setField(final String field) {
078: dataRowDataSource.setDataSourceColumnName(field);
079: }
080:
081: /**
082: * Returns the formula used to compute the value of the data source.
083: *
084: * @return the formula.
085: */
086: public String getFormula() {
087: return dataRowDataSource.getFormula();
088: }
089:
090: /**
091: * Defines the formula used to compute the value of this data source.
092: *
093: * @param formula the formula for the data source.
094: */
095: public void setFormula(final String formula) {
096: dataRowDataSource.setFormula(formula);
097: }
098:
099: /**
100: * Returns the value displayed by the field when the data source value is
101: * <code>null</code>.
102: *
103: * @return A value to represent <code>null</code>.
104: */
105: public String getNullValue() {
106: return stringFilter.getNullValue();
107: }
108:
109: /**
110: * Sets the value displayed by the field when the data source value is
111: * <code>null</code>.
112: *
113: * @param nullValue the value that represents <code>null</code>.
114: */
115: public void setNullValue(final String nullValue) {
116: stringFilter.setNullValue(nullValue);
117: }
118:
119: /**
120: * Returns the current value for the data source.
121: *
122: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
123: * this filter.
124: * @return the value.
125: */
126: public Object getValue(final ExpressionRuntime runtime) {
127: return stringFilter.getValue(runtime);
128: }
129:
130: /**
131: * Clones the template.
132: *
133: * @return the clone.
134: *
135: * @throws CloneNotSupportedException this should never happen.
136: */
137: public Object clone() throws CloneNotSupportedException {
138: final StringFieldTemplate template = (StringFieldTemplate) super
139: .clone();
140: template.stringFilter = (StringFilter) stringFilter.clone();
141: template.dataRowDataSource = (DataRowDataSource) template.stringFilter
142: .getDataSource();
143: return template;
144: }
145:
146: /**
147: * Returns the datarow data source used in this template.
148: *
149: * @return the datarow data source.
150: */
151: protected DataRowDataSource getDataRowDataSource() {
152: return dataRowDataSource;
153: }
154:
155: public Object getRawValue(final ExpressionRuntime runtime) {
156: return stringFilter.getRawValue(runtime);
157: }
158:
159: public FormatSpecification getFormatString(
160: final ExpressionRuntime runtime,
161: FormatSpecification formatSpecification) {
162: if (formatSpecification == null) {
163: formatSpecification = new FormatSpecification();
164: }
165: formatSpecification.redefine(
166: FormatSpecification.TYPE_UNDEFINED, null);
167: return formatSpecification;
168: }
169: }
|