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: * StaticDataSource.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.filter;
030:
031: import java.io.IOException;
032: import java.io.ObjectOutputStream;
033:
034: import org.jfree.report.function.ExpressionRuntime;
035: import org.jfree.serializer.SerializerHelper;
036:
037: /**
038: * A data source that returns a constant value. An example is a label on a report.
039: *
040: * @author Thomas Morgner
041: */
042: public class StaticDataSource implements DataSource {
043: /**
044: * The value.
045: */
046: private transient Object value;
047:
048: /**
049: * Default constructor.
050: */
051: public StaticDataSource() {
052: }
053:
054: /**
055: * Constructs a new static data source.
056: *
057: * @param o The value.
058: */
059: public StaticDataSource(final Object o) {
060: setValue(o);
061: }
062:
063: /**
064: * Sets the value of the data source.
065: *
066: * @param o The value.
067: */
068: public void setValue(final Object o) {
069: this .value = o;
070: }
071:
072: /**
073: * Returns the value set in this datasource. This method exists to make the value-property beanified.
074: *
075: * @return the value.
076: */
077: public Object getValue() {
078: return value;
079: }
080:
081: /**
082: * Returns the value of the data source.
083: *
084: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
085: * this filter.
086: * @return The value.
087: */
088: public Object getValue(final ExpressionRuntime runtime) {
089: return value;
090: }
091:
092: /**
093: * Clones the data source, although the enclosed 'static' value is not cloned.
094: *
095: * @return a clone.
096: *
097: * @throws CloneNotSupportedException this should never happen.
098: */
099: public Object clone() throws CloneNotSupportedException {
100: return super .clone();
101: }
102:
103: /**
104: * Helper method for serialization.
105: *
106: * @param out the output stream where to write the object.
107: * @throws IOException if errors occur while writing the stream.
108: */
109: private void writeObject(final ObjectOutputStream out)
110: throws IOException {
111: out.defaultWriteObject();
112: SerializerHelper.getInstance().writeObject(value, out);
113: }
114:
115: /**
116: * Helper method for serialization.
117: *
118: * @param in the input stream from where to read the serialized object.
119: * @throws IOException when reading the stream fails.
120: * @throws ClassNotFoundException if a class definition for a serialized object could
121: * not be found.
122: */
123: private void readObject(final java.io.ObjectInputStream in)
124: throws IOException, ClassNotFoundException {
125: in.defaultReadObject();
126: value = SerializerHelper.getInstance().readObject(in);
127: }
128: }
|