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: * DataRowConnector.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.states;
030:
031: import org.jfree.report.DataRow;
032: import org.jfree.report.filter.DataSource;
033: import org.jfree.report.filter.DataTarget;
034:
035: /**
036: * This is the connection-proxy to the various data sources contained in the elements.
037: * During report processing the report states get cloned while the elements remain
038: * uncloned. The DataRowConnector connects the DataRowBackend (which contains the data)
039: * with the stateless elements.
040: *
041: * @author Thomas Morgner
042: */
043: public class DataRowConnector implements DataRow {
044: /**
045: * The data row backend.
046: */
047: private DataRow dataRow;
048:
049: /**
050: * Default constructor.
051: */
052: public DataRowConnector() {
053: }
054:
055: /**
056: * Returns the assigned data row backend.
057: *
058: * @return the currently assigned DataRowBackend for this DataRowConnector.
059: */
060: public DataRow getDataRowBackend() {
061: return dataRow;
062: }
063:
064: /**
065: * Sets the data row backend for this DataRowConnector. The backend actually contains
066: * the data which will be queried, while this DataRowConnector is simply a proxy
067: * forwarding all requests to the backend.
068: *
069: * @param dataRow the data row backend
070: */
071: public void setDataRowBackend(final DataRow dataRow) {
072: this .dataRow = dataRow;
073: }
074:
075: /**
076: * Return the value of the function, expression or column in the tablemodel using the
077: * column number.
078: *
079: * @param col the column, function or expression index.
080: * @return the column, function or expression value.
081: *
082: * @throws java.lang.IllegalStateException
083: * if there is no backend connected.
084: */
085: public Object get(final int col) {
086: if (dataRow == null) {
087: throw new IllegalStateException("Not connected");
088: }
089: return dataRow.get(col);
090: }
091:
092: /**
093: * Returns the value of the column, function or expression using its name.
094: *
095: * @param col the column, function or expression index.
096: * @return The column, function or expression value.
097: *
098: * @throws java.lang.IllegalStateException
099: * if there is no backend connected
100: */
101: public Object get(final String col) {
102: if (dataRow == null) {
103: throw new IllegalStateException("Not connected");
104: }
105: return dataRow.get(col);
106: }
107:
108: /**
109: * Returns the name of the column, function or expression.
110: *
111: * @param col the column, function or expression index.
112: * @return the column, function or expression name.
113: *
114: * @throws java.lang.IllegalStateException
115: * if there is no backend connected.
116: */
117: public String getColumnName(final int col) {
118: if (dataRow == null) {
119: throw new IllegalStateException("Not connected");
120: }
121: return dataRow.getColumnName(col);
122: }
123:
124: /**
125: * Looks up the position of the column with the name <code>name</code>. returns the
126: * position of the column or -1 if no columns could be retrieved.
127: *
128: * @param name the column, function or expression name.
129: * @return the column position of the column, expression or function with the given name
130: * or -1 if the given name does not exist in this DataRow.
131: *
132: * @throws java.lang.IllegalStateException
133: * if there is no backend connected.
134: */
135: public int findColumn(final String name) {
136: if (dataRow == null) {
137: throw new IllegalStateException("Not connected");
138: }
139: return getDataRowBackend().findColumn(name);
140: }
141:
142: /**
143: * Returns the count of columns in this datarow. The columncount is the sum of all
144: * DataSource columns, all functions and all expressions.
145: *
146: * @return the number of accessible columns in this datarow.
147: *
148: * @throws java.lang.IllegalStateException
149: * if there is no backend connected.
150: */
151: public int getColumnCount() {
152: if (dataRow == null) {
153: throw new IllegalStateException("Not connected");
154: }
155: return getDataRowBackend().getColumnCount();
156: }
157:
158: /**
159: * Queries the last datasource in the chain of targets and filters.
160: * <p/>
161: * The last datasource is used to feed data into the data processing chain. The result
162: * of this computation is retrieved by the element using the registered datasource to
163: * query the queue.
164: *
165: * @param e the data target.
166: * @return The last DataSource in the chain.
167: * @deprecated no longer used.
168: */
169: public static DataSource getLastDatasource(final DataTarget e) {
170: if (e == null) {
171: throw new NullPointerException();
172: }
173: DataSource s = e.getDataSource();
174: while (s instanceof DataTarget) {
175: final DataTarget tgt = (DataTarget) s;
176: s = tgt.getDataSource();
177: }
178: return s;
179: }
180:
181: /**
182: * Returns a string describing the object.
183: *
184: * @return The string.
185: */
186: public String toString() {
187: if (dataRow == null) {
188: return "org.jfree.report.states.DataRowConnector=Not Connected";
189: }
190: return "org.jfree.report.states.DataRowConnector=Connected:"
191: + dataRow;
192:
193: }
194:
195: public boolean isChanged(final String name) {
196: return dataRow.isChanged(name);
197: }
198:
199: public boolean isChanged(final int index) {
200: return dataRow.isChanged(index);
201: }
202: }
|