KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xeus > bottomline > BottomlineDriver


1
2 /**
3  * Bottomline
4  * A JDBC Bridge API to load multiple database drivers from JAR files
5  *
6  * Copyright (C) 2006 Technology N
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * @author Kamran Zafar
23  *
24  * Contact Info:
25  * Email: kamran@technology-n.com
26  * xeus.man@gmail.com
27  */

28
29
30 /*
31  * BottomlineDriver.java
32  * Created on Sep 9, 2006
33  */

34
35 package xeus.bottomline;
36
37 import java.sql.Connection JavaDoc;
38 import java.sql.Driver JavaDoc;
39 import java.sql.DriverManager JavaDoc;
40 import java.sql.DriverPropertyInfo JavaDoc;
41 import java.sql.SQLException JavaDoc;
42 import java.util.Properties JavaDoc;
43
44 import org.apache.log4j.Logger;
45
46 import xeus.bottomline.util.JdbcUrl;
47
48 /**
49  * @author Kamran Zafar
50  *
51  */

52 public class BottomlineDriver implements Driver JavaDoc {
53
54     private static final int MAJOR_VERSION = 1;
55     private static final int MINOR_VERSION = 0;
56     public static final String JavaDoc USER_PREFIX = "jdbc:bottomline:";
57     static Logger logger=Logger.getLogger(BottomlineDriver.class);
58
59     static {
60         try {
61             DriverManager.registerDriver(new BottomlineDriver());
62         } catch (SQLException JavaDoc e) {
63             e.printStackTrace();
64         }
65     }
66
67     /* (non-Javadoc)
68      * @see java.sql.Driver#connect(java.lang.String, java.util.Properties)
69      */

70     public Connection JavaDoc connect(String JavaDoc url, Properties JavaDoc props) throws SQLException JavaDoc {
71         logger.debug(">>>>>>>>>>> In connect");
72
73         if (!url.startsWith(USER_PREFIX))
74             return null;
75
76         BottomlineConnection conn;
77         try {
78             JdbcUrl jurl=JdbcUrl.parse(url);
79             
80             url=jurl.getUrl();
81             props.putAll(jurl.getQueryMap());
82             
83             conn = new BottomlineConnection(url, props);
84         } catch (Exception JavaDoc e) {
85             SQLException JavaDoc sqle= new SQLException JavaDoc(e.getMessage());
86             sqle.setStackTrace(e.getStackTrace());
87             
88             throw sqle;
89         }
90
91         return conn;
92     }
93     
94     /* (non-Javadoc)
95      * @see java.sql.Driver#acceptsURL(java.lang.String)
96      */

97     public boolean acceptsURL(String JavaDoc url) throws SQLException JavaDoc {
98         logger.debug(">>>>>>>>>>>> In accept");
99         return url.startsWith(USER_PREFIX);
100     }
101     
102     /* (non-Javadoc)
103      * @see java.sql.Driver#getPropertyInfo(java.lang.String, java.util.Properties)
104      */

105     public DriverPropertyInfo JavaDoc[] getPropertyInfo(String JavaDoc url, Properties JavaDoc info)
106             throws SQLException JavaDoc {
107         logger.debug(">>>>>>>>>>> In prop Info");
108
109         DriverPropertyInfo JavaDoc pinfo[] = new DriverPropertyInfo JavaDoc[2];
110         DriverPropertyInfo JavaDoc p;
111
112         p = new DriverPropertyInfo JavaDoc(BottomlineConstants.USER, null);
113         p.value = info.getProperty(BottomlineConstants.USER);
114         p.required = true;
115         pinfo[0] = p;
116         p = new DriverPropertyInfo JavaDoc(BottomlineConstants.PASSWORD, null);
117         p.value = info.getProperty(BottomlineConstants.PASSWORD);
118         p.required = true;
119         pinfo[1] = p;
120
121         return pinfo;
122     }
123     
124     /* (non-Javadoc)
125      * @see java.sql.Driver#getMajorVersion()
126      */

127     public int getMajorVersion() {
128         return MAJOR_VERSION;
129     }
130     
131     /* (non-Javadoc)
132      * @see java.sql.Driver#getMinorVersion()
133      */

134     public int getMinorVersion() {
135         return MINOR_VERSION;
136     }
137     
138     /* (non-Javadoc)
139      * @see java.sql.Driver#jdbcCompliant()
140      */

141     public boolean jdbcCompliant() {
142         logger.debug(">>>>>>>>>>> In compliance");
143         return true;
144     }
145 }
146
Popular Tags