001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * IReportConnection.java
028: *
029: * Created on 28 maggio 2003, 0.11
030: *
031: */
032:
033: package it.businesslogic.ireport;
034:
035: import it.businesslogic.ireport.connection.gui.BasicIReportConnectionEditor;
036: import it.businesslogic.ireport.gui.MainFrame;
037: import it.businesslogic.ireport.util.I18n;
038: import java.util.Map;
039: import javax.swing.JOptionPane;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public abstract class IReportConnection {
046:
047: private String name = "";
048:
049: /*
050: * Return true if this connection is a "Connection" to a database
051: * I.E. you can see JDBCConnection
052: */
053: public boolean isJDBCConnection() {
054: return false;
055: }
056:
057: /*
058: * Return true if this ireport connection can be used using getJRDataSource
059: * I.E. you can see JDBCConnection
060: */
061: public boolean isJRDataSource() {
062: return true;
063: }
064:
065: /**
066: * This method provides the name of the connection type. I.e.: JDBC connection
067: */
068: public abstract String getDescription();
069:
070: /**
071: * This method return an instanced connection to the database.
072: * If isJDBCConnection() return false => getConnection() return null
073: */
074: public java.sql.Connection getConnection() {
075: return null;
076: }
077:
078: /**
079: * This method return an instanced JRDataDource to the database.
080: * If isJDBCConnection() return true => getJRDataSource() return false
081: */
082: public net.sf.jasperreports.engine.JRDataSource getJRDataSource() {
083: return new net.sf.jasperreports.engine.JREmptyDataSource();
084: }
085:
086: /** Getter for property name.
087: * @return Value of property name.
088: *
089: */
090: public java.lang.String getName() {
091: return name;
092: }
093:
094: /** Setter for property name.
095: * @param name New value of property name.
096: *
097: */
098: public void setName(java.lang.String name) {
099: this .name = name;
100: }
101:
102: /** All properties of an IReportConnection are stored in a XML file as Pair key/value
103: * This HashMap must contain all the properties that the IReportConnection must save in the
104: * XML.
105: * IReport will store the content of this HashMap in the XML. Please note that all the values
106: * and keys will be casted to String!
107: */
108: public java.util.HashMap getProperties() {
109: return new java.util.HashMap();
110: }
111:
112: /** All properties of a IReportConnection are stored in a XML file as Pair key/value
113: * This HashMap contains all the properties found for this IReportConnection in the
114: * XML. You must use this hashMap to initialize all attributes of your IReprotConnection
115: */
116: public void loadProperties(java.util.HashMap map) {
117: }
118:
119: /** Redefine this method is not useful (and not raccomended)
120: * It just write a portion of XML for save properties a IReportConnection name
121: */
122: public void save(java.io.PrintWriter pw) {
123: java.util.HashMap hm = this .getProperties();
124: pw.println("\t<iReportConnection name=\"" + this .getName()
125: + "\" connectionClass=\"" + this .getClass().getName()
126: + "\">");
127: java.util.Iterator iterator = hm.keySet().iterator();
128:
129: while (iterator.hasNext()) {
130: String key = (String) iterator.next();
131: pw.println("\t\t<connectionParameter name=\"" + key
132: + "\"><![CDATA[" + hm.get(key)
133: + "]]></connectionParameter>");
134: }
135: pw.println("\t</iReportConnection>");
136: }
137:
138: public String toString() {
139: return getName();
140: }
141:
142: /**
143: * This method is call before the datasource is used and permit to add special parameters to the map
144: *
145: */
146: public Map getSpecialParameters(Map map)
147: throws net.sf.jasperreports.engine.JRException {
148: return map;
149: }
150:
151: /**
152: * This method is call after the datasource is used to dispose special parameters
153: * (i.e. closing an Hibernate session create as parameter with a getSpecialParameters...
154: *
155: */
156: public Map disposeSpecialParameters(Map map) {
157: return map;
158: }
159:
160: /**
161: * This method is used to test the configuration. To throw an exception if the test fails is not mandatory
162: * and anyway the exception will be ignored.
163: * The method is responsible to show error messages it the test has success or fails!!
164: *
165: */
166: public void test() throws Exception {
167: JOptionPane
168: .showMessageDialog(
169: MainFrame.getMainInstance(),
170: I18n
171: .getString(
172: "messages.connectionDialog.connectionTestSuccessful",
173: "Connection test successful!"),
174: "", JOptionPane.INFORMATION_MESSAGE);
175: return;
176: }
177:
178: /**
179: * This method is used to provide to the datasources window the GUI to configure this kind of component.
180: *
181: *
182: */
183: public IReportConnectionEditor getIReportConnectionEditor() {
184: return new BasicIReportConnectionEditor();
185: }
186: }
|