KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > servlets > reports > JRDataSourceAbstract


1 /*
2  * $Header:
3  * /cvsroot/jdbforms/dbforms/src/org/dbforms/servlets/reports/JRDataSourceRSV.java,v
4  * 1.15 2004/10/11 08:55:02 hkollmann Exp $ $Revision: 1.3 $ $Date: 2004/10/11
5  * 08:55:02 $
6  *
7  * DbForms - a Rapid Application Development Framework Copyright (C) 2001
8  * Joachim Peer <joepeer@excite.com>
9  *
10  * This library is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU Lesser General Public License as published by the Free
12  * Software Foundation; either version 2.1 of the License, or (at your option)
13  * any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation, Inc.,
22  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */

24
25 package org.dbforms.servlets.reports;
26
27 import net.sf.jasperreports.engine.JRException;
28 import net.sf.jasperreports.engine.JRField;
29 import net.sf.jasperreports.engine.JRDataSource;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 import java.util.Map JavaDoc;
35
36 public abstract class JRDataSourceAbstract implements JRDataSource {
37     private static Log logCat = LogFactory.getLog(JRDataSourceAbstract.class
38             .getName());
39     private Map JavaDoc attributes;
40     
41     JRDataSourceAbstract(Map JavaDoc attributes) {
42         this.attributes = attributes;
43     }
44     /**
45      * @see net.sf.jasperreports.engine.JRDataSource#next()
46      */

47     public abstract boolean next() throws JRException;
48
49     /**
50      * @see net.sf.jasperreports.engine.JRDataSource#getFieldValue(net.sf.jasperreports.engine.JRField)
51      * Philip Grunikiewicz 2004-01-13 Because I had fields defined
52      * (dbforms-config.xml) in mix case (ie: creditLimit) and in my XML
53      * file, my field was in uppercase (ie: CREDITLIMIT), my field could
54      * not be found. Added some logging to help out debugging this type of
55      * problem.
56      */

57     public Object JavaDoc getFieldValue(JRField field) throws JRException {
58         String JavaDoc search = field.getName();
59         logCat.debug("Trying to find data for field named: " + search);
60         Object JavaDoc o = getFieldValue(field.getName());
61         if (o == null) {
62             logCat
63                     .debug("Field not found in dbforms-config, trying field renamed to uppercase: "
64                             + search.toUpperCase());
65             o = getFieldValue(search.toUpperCase());
66         }
67         if (o == null) {
68             logCat
69                     .debug("Field not found in dbforms-config, trying field renamed to lowercase: "
70                             + search.toLowerCase());
71             o = getFieldValue(field.getName().toLowerCase());
72         }
73
74         /*
75          * // Try class conversation if the classes do not match! if ((o !=
76          * null) && (o.getClass() != field.getValueClass())) { try { Object[]
77          * constructorArgs = new Object[] { o.toString() }; Class[]
78          * constructorArgsTypes = new Class[] { String.class }; o =
79          * ReflectionUtil.newInstance(field.getValueClass(),
80          * constructorArgsTypes, constructorArgs); } catch (Exception e) { ; } }
81          */

82         return o;
83     }
84
85     public abstract Object JavaDoc getFieldValue(String JavaDoc fieldName);
86
87     /**
88      * @return Returns the attributes.
89      */

90     public Map JavaDoc getAttributes() {
91         return attributes;
92     }
93 }
94
Popular Tags