KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > connection > JRXMLDataSourceConnection


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  * JRXMLDataSourceConnection.java
28  *
29  * Created on 4 giugno 2003, 18.15
30  *
31  */

32
33 package it.businesslogic.ireport.connection;
34 import it.businesslogic.ireport.*;
35 import it.businesslogic.ireport.util.*;
36 import java.sql.*;
37 import javax.swing.*;
38
39 import net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory;
40 import java.io.File JavaDoc;
41 import org.w3c.dom.Document JavaDoc;
42 import net.sf.jasperreports.engine.util.JRXmlUtils;
43 /**
44  *
45  * @author Administrator
46  */

47 public class JRXMLDataSourceConnection extends it.businesslogic.ireport.IReportConnection {
48     
49     private String JavaDoc name;
50     
51     private String JavaDoc filename;
52     
53     private String JavaDoc selectExpression;
54     
55     private boolean useConnection = false;
56     
57     /** Creates a new instance of JDBCConnection */
58     public JRXMLDataSourceConnection() {
59     }
60     
61     /** This method return an instanced connection to the database.
62      * If isJDBCConnection() return false => getConnection() return null
63      *
64      */

65     public java.sql.Connection JavaDoc getConnection() {
66             return null;
67     }
68     
69     public boolean isJDBCConnection() {
70         return false;
71     }
72     
73     public boolean isJRDataSource() {
74         return !isUseConnection();
75     }
76     
77     /*
78      * This method return all properties used by this connection
79      */

80     public java.util.HashMap JavaDoc getProperties()
81     {
82         java.util.HashMap JavaDoc map = new java.util.HashMap JavaDoc();
83         map.put("Filename", Misc.nvl(this.getFilename() ,"") );
84         map.put("SelectExpression", Misc.nvl(this.getSelectExpression() ,"") );
85         map.put("UseConnection", Misc.nvl(""+this.isUseConnection() ,"false") );
86         return map;
87     }
88     
89     public void loadProperties(java.util.HashMap JavaDoc map)
90     {
91         this.setFilename( (String JavaDoc)map.get("Filename"));
92         this.setSelectExpression( (String JavaDoc)map.get("SelectExpression"));
93         this.setUseConnection( Boolean.valueOf( Misc.nvl(map.get("UseConnection"),"false") ).booleanValue() );
94     }
95     
96     public String JavaDoc getDescription(){ return "JasperReports XML Datasource"; }
97     
98     /**
99      * Getter for property filename.
100      * @return Value of property filename.
101      */

102     public java.lang.String JavaDoc getFilename() {
103         return filename;
104     }
105    
106     /**
107      * Setter for property filename.
108      * @param filename New value of property filename.
109      */

110     public void setFilename(java.lang.String JavaDoc filename) {
111         this.filename = filename;
112     }
113     
114     /**
115      * Getter for property name.
116      * @return Value of property name.
117      */

118     public java.lang.String JavaDoc getName() {
119         return name;
120     }
121     
122     /**
123      * Setter for property name.
124      * @param name New value of property name.
125      */

126     public void setName(java.lang.String JavaDoc name) {
127         this.name = name;
128     }
129     
130     /**
131      * This method return an instanced JRDataDource to the database.
132      * If isJDBCConnection() return true => getJRDataSource() return false
133      */

134     public net.sf.jasperreports.engine.JRDataSource getJRDataSource() {
135         try {
136         return new net.sf.jasperreports.engine.data.JRXmlDataSource(filename, getSelectExpression() );
137         } catch (Exception JavaDoc ex){}
138         return null;
139     }
140
141     public String JavaDoc getSelectExpression() {
142         return selectExpression;
143     }
144
145     public void setSelectExpression(String JavaDoc selectExpression) {
146         this.selectExpression = selectExpression;
147     }
148
149     public boolean isUseConnection() {
150         return useConnection;
151     }
152
153     public void setUseConnection(boolean useConnection) {
154         this.useConnection = useConnection;
155     }
156
157     
158     /**
159      * This method is call before the datasource is used and permit to add special parameters to the map
160      *
161      */

162     public java.util.Map JavaDoc getSpecialParameters(java.util.Map JavaDoc map) throws net.sf.jasperreports.engine.JRException
163     {
164         if (isUseConnection())
165         {
166             Document JavaDoc document = JRXmlUtils.parse(new File JavaDoc( this.getFilename()));
167         map.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
168         }
169         return map;
170     }
171     
172     
173 }
174
175
Popular Tags