01: //The Salmon Open Framework for Internet Applications (SOFIA)
02: //Copyright (C) 1999 - 2002, Salmon LLC
03: //
04: //This program is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU General Public License version 2
06: //as published by the Free Software Foundation;
07: //
08: //This program is distributed in the hope that it will be useful,
09: //but WITHOUT ANY WARRANTY; without even the implied warranty of
10: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: //GNU General Public License for more details.
12: //
13: //You should have received a copy of the GNU General Public License
14: //along with this program; if not, write to the Free Software
15: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: //
17: //For more information please visit http://www.salmonllc.com
18: package com.salmonllc.jasperReports;
19:
20: import com.salmonllc.sql.DataStoreException;
21: import com.salmonllc.sql.DataStoreInterface;
22:
23: import dori.jasper.engine.JRDataSource;
24: import dori.jasper.engine.JRException;
25: import dori.jasper.engine.JRField;
26:
27: /**
28: * Serves as a link between a Jasper Report and a SOFIA DataStore
29: */
30: public class SJasperDataSource implements JRDataSource {
31:
32: DataStoreInterface _ds;
33: boolean _doNext = false;
34:
35: /**
36: * Creates a new SJasperDataSource from the DataStoreBuffer
37: */
38: public SJasperDataSource(DataStoreInterface ds) {
39: _ds = ds;
40: }
41:
42: /**
43: * Returns the value of a DataStoreField to the Jasper engine
44: */
45: public Object getFieldValue(JRField jrField) throws JRException {
46: try {
47: return _ds.getAny(jrField.getName());
48: } catch (DataStoreException ex) {
49: throw new JRException(ex.getMessage(), ex);
50: }
51: }
52:
53: /**
54: * Jumps to the next row in the DataStore
55: */
56: public boolean next() throws JRException {
57: if (_doNext)
58: return _ds.gotoNext();
59: else {
60: if (_ds.getRow() == -1)
61: _ds.gotoFirst();
62: _doNext = true;
63: return _ds.getRowCount() > 0;
64: }
65:
66: }
67:
68: /**
69: * Resets the DataSource so it can be used to fill another report
70: */
71: public void reset() {
72: _doNext = false;
73: _ds.gotoFirst();
74: }
75:
76: }
|