KickJava   Java API By Example, From Geeks To Geeks.

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


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  * JRCustomDataSourceConnection.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  *
40  * @author Administrator
41  */

42 public class JRCustomDataSourceConnection extends it.businesslogic.ireport.IReportConnection {
43     
44     private String JavaDoc name;
45     
46     private String JavaDoc factoryClass;
47     
48     private String JavaDoc methodToCall;
49     
50     /** Creates a new instance of JDBCConnection */
51     
52     
53     public JRCustomDataSourceConnection() {
54     }
55     
56     /** This method return an instanced connection to the database.
57      * If isJDBCConnection() return false => getConnection() return null
58      *
59      */

60     public java.sql.Connection JavaDoc getConnection() {
61             return null;
62     }
63     
64     public boolean isJDBCConnection() {
65         return false;
66     }
67     
68     /*
69      * This method return all properties used by this connection
70      */

71     public java.util.HashMap JavaDoc getProperties()
72     {
73         java.util.HashMap JavaDoc map = new java.util.HashMap JavaDoc();
74         map.put("FactoryClass", Misc.nvl(this.getFactoryClass() ,"") );
75         map.put("MethodToCall", Misc.nvl(this.getMethodToCall(),""));
76        
77         return map;
78     }
79     
80     public void loadProperties(java.util.HashMap JavaDoc map)
81     {
82         this.setFactoryClass( (String JavaDoc)map.get("FactoryClass"));
83         this.setMethodToCall( (String JavaDoc)map.get("MethodToCall"));
84     }
85     
86     public String JavaDoc getDescription(){ return "Custom datasource"; }
87     
88     /** Getter for property methodToCall.
89      * @return Value of property methodToCall.
90      *
91      */

92     public java.lang.String JavaDoc getMethodToCall() {
93         return methodToCall;
94     }
95     
96     /** Setter for property methodToCall.
97      * @param methodToCall New value of property methodToCall.
98      *
99      */

100     public void setMethodToCall(java.lang.String JavaDoc methodToCall) {
101         this.methodToCall = methodToCall;
102     }
103     
104     /** Getter for property factoryClass.
105      * @return Value of property factoryClass.
106      *
107      */

108     public java.lang.String JavaDoc getFactoryClass() {
109         return factoryClass;
110     }
111     
112     /** Setter for property factoryClass.
113      * @param factoryClass New value of property factoryClass.
114      *
115      */

116     public void setFactoryClass(java.lang.String JavaDoc factoryClass) {
117         this.factoryClass = factoryClass;
118     }
119     
120     /**
121      * This method return an instanced JRDataDource to the database.
122      * If isJDBCConnection() return true => getJRDataSource() return false
123      */

124     public net.sf.jasperreports.engine.JRDataSource getJRDataSource()
125     {
126         try {
127         Object JavaDoc obj = Class.forName( factoryClass ).newInstance();
128         return (net.sf.jasperreports.engine.JRDataSource) obj.getClass().getMethod( methodToCall, new Class JavaDoc[0]).invoke(obj,new Object JavaDoc[0]);
129         } catch (Exception JavaDoc ex)
130         {
131             return super.getJRDataSource();
132         }
133     }
134 }
135
Popular Tags