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: * ResourceFieldTemplate.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 java.util.MissingResourceException;
032:
033: import org.jfree.report.filter.DataRowDataSource;
034: import org.jfree.report.filter.ResourceFileFilter;
035: import org.jfree.report.filter.StringFilter;
036: import org.jfree.report.function.ExpressionRuntime;
037:
038: /**
039: * A resource field template, which reads a String value from a ResourceBundle.
040: *
041: * @author Thomas Morgner
042: */
043: public class ResourceFieldTemplate extends AbstractTemplate {
044: /**
045: * A data-row accessor.
046: */
047: private DataRowDataSource dataRowDataSource;
048:
049: /**
050: * A string filter.
051: */
052: private StringFilter stringFilter;
053:
054: /**
055: * A resource file filter.
056: */
057: private ResourceFileFilter resourceFilter;
058:
059: /**
060: * Creates a new template.
061: */
062: public ResourceFieldTemplate() {
063: dataRowDataSource = new DataRowDataSource();
064: resourceFilter = new ResourceFileFilter();
065: resourceFilter.setDataSource(dataRowDataSource);
066: stringFilter = new StringFilter();
067: stringFilter.setDataSource(resourceFilter);
068: }
069:
070: /**
071: * Returns the field name.
072: *
073: * @return The field name.
074: */
075: public String getField() {
076: return dataRowDataSource.getDataSourceColumnName();
077: }
078:
079: /**
080: * Sets the field name.
081: *
082: * @param field the field name.
083: */
084: public void setField(final String field) {
085: dataRowDataSource.setDataSourceColumnName(field);
086: }
087:
088: /**
089: * Returns the formula used to compute the value of the data source.
090: *
091: * @return the formula.
092: */
093: public String getFormula() {
094: return dataRowDataSource.getFormula();
095: }
096:
097: /**
098: * Defines the formula used to compute the value of this data source.
099: *
100: * @param formula the formula for the data source.
101: */
102: public void setFormula(final String formula) {
103: dataRowDataSource.setFormula(formula);
104: }
105:
106: /**
107: * Returns the resource class name.
108: *
109: * @return The resource class name.
110: */
111: public String getResourceIdentifier() {
112: return resourceFilter.getResourceIdentifier();
113: }
114:
115: /**
116: * Sets the resource class name.
117: *
118: * @param resourceClassName the resource class name.
119: * @throws MissingResourceException if the resource is missing.
120: */
121: public void setResourceIdentifier(final String resourceClassName)
122: throws MissingResourceException {
123: resourceFilter.setResourceIdentifier(resourceClassName);
124: }
125:
126: /**
127: * Returns the string that represents a <code>null</code> value.
128: *
129: * @return The string that represents a <code>null</code> value.
130: */
131: public String getNullValue() {
132: return stringFilter.getNullValue();
133: }
134:
135: /**
136: * Sets the string that represents a <code>null</code> value.
137: *
138: * @param nullValue the string that represents a <code>null</code> value.
139: */
140: public void setNullValue(final String nullValue) {
141: stringFilter.setNullValue(nullValue);
142: }
143:
144: /**
145: * Returns the current value for the data source.
146: *
147: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
148: * this filter.
149: * @return the value.
150: */
151: public Object getValue(final ExpressionRuntime runtime) {
152: return stringFilter.getValue(runtime);
153: }
154:
155: /**
156: * Clones the template.
157: *
158: * @return the clone.
159: *
160: * @throws CloneNotSupportedException this should never happen.
161: */
162: public Object clone() throws CloneNotSupportedException {
163: final ResourceFieldTemplate template = (ResourceFieldTemplate) super
164: .clone();
165: template.stringFilter = (StringFilter) stringFilter.clone();
166: template.resourceFilter = (ResourceFileFilter) template.stringFilter
167: .getDataSource();
168: template.dataRowDataSource = (DataRowDataSource) template.resourceFilter
169: .getDataSource();
170: return template;
171: }
172:
173: /**
174: * Returns the datarow data source used in this template.
175: *
176: * @return the datarow data source.
177: */
178: protected DataRowDataSource getDataRowDataSource() {
179: return dataRowDataSource;
180: }
181: }
|