root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / ConnectionFactory.java @ 13881
History | View | Annotate | Download (3.86 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* 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, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
|
43 |
package com.iver.cit.gvsig.fmap.drivers; |
44 |
|
45 |
import java.util.ArrayList; |
46 |
import java.util.Iterator; |
47 |
|
48 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
49 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
50 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
51 |
|
52 |
|
53 |
/**
|
54 |
* Connection Factory
|
55 |
*
|
56 |
* @author Vicente Caballero Navarro
|
57 |
*/
|
58 |
public class ConnectionFactory { |
59 |
private static ArrayList connections = new ArrayList(); |
60 |
// private static HashMap lastConnections=new HashMap();
|
61 |
/**
|
62 |
* DOCUMENT ME!
|
63 |
*
|
64 |
* @param connectionStr DOCUMENT ME!
|
65 |
* @param user DOCUMENT ME!
|
66 |
* @param _pw DOCUMENT ME!
|
67 |
*
|
68 |
* @return DOCUMENT ME!
|
69 |
*
|
70 |
* @throws DBException DOCUMENT ME!
|
71 |
*/
|
72 |
public static IConnection createConnection(String connectionStr, |
73 |
String user, String _pw) throws DBException { |
74 |
IConnection connection = null;
|
75 |
|
76 |
if (connectionStr.startsWith("jdbc")) { |
77 |
connection = new ConnectionJDBC();
|
78 |
connection.setDataConnection(connectionStr, user, _pw); |
79 |
return connection;
|
80 |
} else {
|
81 |
// if (lastConnections.containsKey(connectionStr))
|
82 |
// return (IConnection)lastConnections.get(connectionStr);
|
83 |
|
84 |
refreshExtensionPointsConnections(); |
85 |
|
86 |
IConnection[] conns = (IConnection[]) connections.toArray(new IConnection[0]); |
87 |
String type = connectionStr.substring(0,connectionStr.indexOf(":")); |
88 |
|
89 |
for (int i = 0; i < conns.length; i++) { |
90 |
if (conns[i].getTypeConnection().equals(type)) {
|
91 |
connection=conns[i]; |
92 |
connection.setDataConnection(connectionStr, user, _pw); |
93 |
// lastConnections.put(connectionStr,connection);
|
94 |
return connection;
|
95 |
} |
96 |
} |
97 |
} |
98 |
|
99 |
return connection;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*/
|
105 |
private static void refreshExtensionPointsConnections() { |
106 |
connections.clear(); |
107 |
|
108 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
109 |
ExtensionPoint extensionPoint = (ExtensionPoint) extensionPoints.get( |
110 |
"databaseconnections");
|
111 |
Iterator iterator = extensionPoint.keySet().iterator();
|
112 |
|
113 |
while (iterator.hasNext()) {
|
114 |
try {
|
115 |
IConnection obj = (IConnection) extensionPoint.create((String) iterator.next());
|
116 |
connections.add(obj); |
117 |
} catch (InstantiationException e) { |
118 |
e.printStackTrace(); |
119 |
} catch (IllegalAccessException e) { |
120 |
e.printStackTrace(); |
121 |
} catch (ClassCastException e) { |
122 |
e.printStackTrace(); |
123 |
} |
124 |
} |
125 |
} |
126 |
} |