KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > IReportConnection


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * IReportConnection.java
28  *
29  * Created on 28 maggio 2003, 0.11
30  *
31  */

32
33 package it.businesslogic.ireport;
34
35 import java.util.Map JavaDoc;
36
37 /**
38  *
39  * @author Administrator
40  */

41 public abstract class IReportConnection {
42     
43   private String JavaDoc name="";
44   /*
45    * Return true if this connection is a "Connection" to a database
46    * I.E. you can see JDBCConnection
47    */

48   public boolean isJDBCConnection(){ return false; }
49   
50   
51   /*
52    * Return true if this ireport connection can be used using getJRDataSource
53    * I.E. you can see JDBCConnection
54    */

55   public boolean isJRDataSource() { return true; }
56    
57   
58   public String JavaDoc getDescription(){ return ""; }
59     /**
60      * This method return an instanced connection to the database.
61      * If isJDBCConnection() return false => getConnection() return null
62      */

63     public java.sql.Connection JavaDoc getConnection(){ return null; }
64     
65     /**
66      * This method return an instanced JRDataDource to the database.
67      * If isJDBCConnection() return true => getJRDataSource() return false
68      */

69     public net.sf.jasperreports.engine.JRDataSource getJRDataSource() { return new net.sf.jasperreports.engine.JREmptyDataSource(); }
70     
71     /** Getter for property name.
72      * @return Value of property name.
73      *
74      */

75     public java.lang.String JavaDoc getName() {
76         return name;
77     }
78     
79     /** Setter for property name.
80      * @param name New value of property name.
81      *
82      */

83     public void setName(java.lang.String JavaDoc name) {
84         this.name = name;
85     }
86     
87     public java.util.HashMap JavaDoc getProperties()
88     {
89         return new java.util.HashMap JavaDoc();
90     }
91     
92     /** All properties of a IReportConnection are stored in a XML file as Pair key/value
93      * This HashMap contains alla properties found for this IReportConnection in the
94      * XML. You must use this hashMap to initialize all attributes of your IReprotConnection
95      */

96     public void loadProperties(java.util.HashMap JavaDoc map)
97     {
98     }
99     
100     /** Redefine this method is not useful (and not raccomended)
101      * It just write a portion of XML for save properties a IReportConnection name
102      */

103     public void save(java.io.PrintWriter JavaDoc pw)
104     {
105         java.util.HashMap JavaDoc hm = this.getProperties();
106         pw.println("\t<iReportConnection name=\""+ this.getName() +"\" connectionClass=\"" + this.getClass().getName() +"\">");
107         java.util.Iterator JavaDoc iterator = hm.keySet().iterator();
108         
109         while (iterator.hasNext())
110         {
111             String JavaDoc key = (String JavaDoc)iterator.next();
112             pw.println("\t\t<connectionParameter name=\"" + key + "\"><![CDATA[" + hm.get(key) + "]]></connectionParameter>");
113         }
114         pw.println("\t</iReportConnection>");
115     }
116     
117     public String JavaDoc toString()
118     {
119         return getName();
120     }
121     
122     /**
123      * This method is call before the datasource is used and permit to add special parameters to the map
124      *
125      */

126     public Map JavaDoc getSpecialParameters(Map JavaDoc map) throws net.sf.jasperreports.engine.JRException
127     {
128         return map;
129     }
130     
131     /**
132      * This method is call after the datasource is used to dispose special parameters
133      * (i.e. closing an Hibernate session create as parameter with a getSpecialParameters...
134      *
135      */

136     public Map JavaDoc disposeSpecialParameters(Map JavaDoc map)
137     {
138         return map;
139     }
140     
141     
142     /**
143      * This method is used to test the configuration. Throw an exception if the test fails.
144      *
145      */

146     public void test() throws Exception JavaDoc {}
147 }
148
Popular Tags