KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xeus > bottomline > util > JdbcUrl


1 /*
2  * JdbcUrl.java
3  * Created on Dec 23, 2006
4  */

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

32 package xeus.bottomline.util;
33
34 import java.util.Collections JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Map JavaDoc;
37
38 import xeus.bottomline.exception.BottomlineException;
39
40 /**
41  * @author Kamran Zafar
42  *
43  */

44 public class JdbcUrl {
45
46     private String JavaDoc absoluteUrl;
47     private Map JavaDoc queryMap;
48     private String JavaDoc url;
49
50     private JdbcUrl() {
51     }
52
53     /**
54      * @param absoluteUrl
55      * @return
56      * @throws BottomlineException
57      */

58     public static synchronized JdbcUrl parse(String JavaDoc absoluteUrl)
59             throws BottomlineException {
60         Map JavaDoc query = Collections.synchronizedMap(new HashMap JavaDoc());
61
62         String JavaDoc lquery;
63
64         String JavaDoc urlParts[] = absoluteUrl.split("\\?");
65
66         String JavaDoc url = urlParts[0];
67
68         if (urlParts.length > 1) {
69             
70             if (urlParts.length != 2)
71                 throw new BottomlineException("Malformed Connection URL");
72
73             lquery = urlParts[1];
74
75             String JavaDoc params[] = lquery.split("&");
76
77             for (int i = 0; i < params.length; i++) {
78                 String JavaDoc keyVal[] = params[i].split("=");
79
80                 if (keyVal.length == 2)
81                     query.put(keyVal[0], keyVal[1]);
82                 else
83                     query.put(keyVal[0], null);
84             }
85         }
86
87         JdbcUrl jurl = new JdbcUrl();
88         jurl.setAbsoluteUrl(absoluteUrl);
89         jurl.setQueryMap(query);
90         jurl.setUrl(url);
91
92         return jurl;
93     }
94
95     /**
96      * @return
97      */

98     public String JavaDoc getAbsoluteUrl() {
99         return absoluteUrl;
100     }
101
102     /**
103      * @param absoluteUrl
104      */

105     public void setAbsoluteUrl(String JavaDoc absoluteUrl) {
106         this.absoluteUrl = absoluteUrl;
107     }
108
109     /**
110      * @return
111      */

112     public Map JavaDoc getQueryMap() {
113         return queryMap;
114     }
115
116     /**
117      * @param queryMap
118      */

119     public void setQueryMap(Map JavaDoc queryMap) {
120         this.queryMap = queryMap;
121     }
122
123     /**
124      * @return
125      */

126     public String JavaDoc getUrl() {
127         return url;
128     }
129
130     /**
131      * @param url
132      */

133     public void setUrl(String JavaDoc url) {
134         this.url = url;
135     }
136 }
137
Popular Tags