svn-gvsig-desktop / tags / v1_1_Build_1015 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / ConnectionFactory.java @ 13679
History | View | Annotate | Download (3.89 KB)
1 | 11926 | caballero | |
---|---|---|---|
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 com.iver.utiles.extensionPoints.ExtensionPoint; |
||
46 | import com.iver.utiles.extensionPoints.ExtensionPoints; |
||
47 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
48 | |||
49 | import java.util.ArrayList; |
||
50 | import java.util.HashMap; |
||
51 | import java.util.Iterator; |
||
52 | |||
53 | |||
54 | /**
|
||
55 | * Connection Factory
|
||
56 | *
|
||
57 | * @author Vicente Caballero Navarro
|
||
58 | */
|
||
59 | public class ConnectionFactory { |
||
60 | private static ArrayList connections = new ArrayList(); |
||
61 | // private static HashMap lastConnections=new HashMap();
|
||
62 | /**
|
||
63 | * DOCUMENT ME!
|
||
64 | *
|
||
65 | * @param connectionStr DOCUMENT ME!
|
||
66 | * @param user DOCUMENT ME!
|
||
67 | * @param _pw DOCUMENT ME!
|
||
68 | *
|
||
69 | * @return DOCUMENT ME!
|
||
70 | *
|
||
71 | * @throws DBException DOCUMENT ME!
|
||
72 | */
|
||
73 | public static IConnection createConnection(String connectionStr, |
||
74 | String user, String _pw) throws DBException { |
||
75 | IConnection connection = null;
|
||
76 | |||
77 | if (connectionStr.startsWith("jdbc")) { |
||
78 | connection = new ConnectionJDBC();
|
||
79 | connection.setDataConnection(connectionStr, user, _pw); |
||
80 | return connection;
|
||
81 | } else {
|
||
82 | // if (lastConnections.containsKey(connectionStr))
|
||
83 | // return (IConnection)lastConnections.get(connectionStr);
|
||
84 | |||
85 | refreshExtensionPointsConnections(); |
||
86 | |||
87 | IConnection[] conns = (IConnection[]) connections.toArray(new IConnection[0]); |
||
88 | String type = connectionStr.substring(0,connectionStr.indexOf(":")); |
||
89 | |||
90 | for (int i = 0; i < conns.length; i++) { |
||
91 | if (conns[i].getTypeConnection().equals(type)) {
|
||
92 | connection=conns[i]; |
||
93 | connection.setDataConnection(connectionStr, user, _pw); |
||
94 | // lastConnections.put(connectionStr,connection);
|
||
95 | return connection;
|
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | |||
100 | return connection;
|
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * DOCUMENT ME!
|
||
105 | */
|
||
106 | private static void refreshExtensionPointsConnections() { |
||
107 | connections.clear(); |
||
108 | |||
109 | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
||
110 | ExtensionPoint extensionPoint = (ExtensionPoint) extensionPoints.get( |
||
111 | "databaseconnections");
|
||
112 | Iterator iterator = extensionPoint.keySet().iterator();
|
||
113 | |||
114 | while (iterator.hasNext()) {
|
||
115 | try {
|
||
116 | IConnection obj = (IConnection) extensionPoint.create((String) iterator.next());
|
||
117 | connections.add(obj); |
||
118 | } catch (InstantiationException e) { |
||
119 | e.printStackTrace(); |
||
120 | } catch (IllegalAccessException e) { |
||
121 | e.printStackTrace(); |
||
122 | } catch (ClassCastException e) { |
||
123 | e.printStackTrace(); |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | } |