Revision 144
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/ui/serverconnect/ServerConnectDialogPanel.java | ||
---|---|---|
44 | 44 |
import java.awt.Cursor; |
45 | 45 |
import java.awt.event.ActionEvent; |
46 | 46 |
import java.awt.event.ActionListener; |
47 |
import java.io.BufferedReader; |
|
48 |
import java.io.File; |
|
49 |
import java.io.FileNotFoundException; |
|
50 |
import java.io.FileReader; |
|
51 |
import java.net.URL; |
|
52 | 47 |
import java.util.Iterator; |
53 |
import java.util.TreeMap;
|
|
48 |
import java.util.Map; |
|
54 | 49 |
|
55 | 50 |
import javax.swing.Icon; |
56 | 51 |
import javax.swing.ImageIcon; |
57 | 52 |
import javax.swing.JFrame; |
58 |
import javax.swing.JOptionPane; |
|
59 | 53 |
import javax.swing.JPanel; |
60 | 54 |
|
61 | 55 |
import org.gvsig.catalog.CatalogClient; |
... | ... | |
72 | 66 |
import org.slf4j.LoggerFactory; |
73 | 67 |
|
74 | 68 |
/** |
75 |
*
|
|
76 |
*
|
|
77 |
*
|
|
69 |
* |
|
70 |
* |
|
71 |
* |
|
78 | 72 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
79 | 73 |
*/ |
80 | 74 |
public class ServerConnectDialogPanel extends JPanel implements ActionListener { |
81 | 75 |
private static final long serialVersionUID = 1224880378648403038L; |
82 | 76 |
private static Logger logger = |
83 | 77 |
LoggerFactory.getLogger(ServerConnectDialogPanel.class); |
84 |
|
|
78 |
|
|
85 | 79 |
private static final CatalogManager catalogManager = CatalogLocator.getCatalogManager(); |
86 |
private static TreeMap serverList = new TreeMap(); |
|
87 | 80 |
private ServerConnectPanel controlsPanel = null; |
88 | 81 |
private JFrame parent = null; |
89 | 82 |
protected CatalogClient client = null; |
90 |
protected String serversFile = "servers/CatalogServers.txt"; |
|
91 | 83 |
protected String currentServer = ""; |
92 | 84 |
private ConnectThread connectThread = null; |
93 |
|
|
85 |
|
|
94 | 86 |
/** |
95 | 87 |
* Constructor |
96 |
* @param parent
|
|
88 |
* @param parent |
|
97 | 89 |
*/ |
98 | 90 |
public ServerConnectDialogPanel(JFrame parent) { |
99 | 91 |
this.parent = parent; |
100 | 92 |
this.setLayout(new BorderLayout()); |
101 | 93 |
add(getControlsPanel(),BorderLayout.CENTER); |
102 | 94 |
//Loads the servers |
103 |
int n_servers = loadServerList(serversFile);
|
|
95 |
int n_servers = loadServerList(); |
|
104 | 96 |
|
105 | 97 |
//Load the protocols |
106 | 98 |
controlsPanel.loadDrivers( |
... | ... | |
110 | 102 |
if (n_servers == 0) { |
111 | 103 |
return; |
112 | 104 |
} |
113 |
|
|
114 |
//Load the first protocol
|
|
115 |
controlsPanel.setProtocol(controlsPanel.getServer().getServiceSubType());
|
|
105 |
|
|
106 |
//Load the selected server protocol
|
|
107 |
controlsPanel.updateProtocol();
|
|
116 | 108 |
enableServerPropertiesButton(); |
117 |
}
|
|
118 |
|
|
109 |
} |
|
110 |
|
|
119 | 111 |
protected Icon getPropertiesIcon(){ |
120 | 112 |
return new ImageIcon("./gvSIG/extensiones/org.gvsig.catalog/images/serverProperties.png"); |
121 | 113 |
} |
... | ... | |
123 | 115 |
/** |
124 | 116 |
* @return the main panel |
125 | 117 |
*/ |
126 |
public ServerConnectPanel getControlsPanel() {
|
|
118 |
public ServerConnectPanel getControlsPanel() { |
|
127 | 119 |
if (controlsPanel == null) { |
128 | 120 |
controlsPanel = new ServerConnectPanel(); |
129 | 121 |
controlsPanel.addActionListener(this); |
130 | 122 |
controlsPanel.enableSearchButton(false); |
131 | 123 |
} |
132 | 124 |
return controlsPanel; |
133 |
}
|
|
125 |
} |
|
134 | 126 |
|
135 | 127 |
/** |
136 |
* It adds a server in the TreeMap Object
|
|
137 |
* @param server
|
|
128 |
* Loads the list of used and default servers and returns its number
|
|
129 |
* @return
|
|
138 | 130 |
*/ |
139 |
protected static void addTreeMapServer(ServerData server) { |
|
140 |
if (ServerConnectDialogPanel.serverList == null) { |
|
141 |
ServerConnectDialogPanel.serverList = new TreeMap(); |
|
142 |
} |
|
143 |
serverList.put(server.getServerAddress(), server); |
|
144 |
} |
|
131 |
private int loadServerList(){ |
|
132 |
Map<String,ServerData> serversMap=catalogManager.getServersPersistence(); |
|
133 |
if (serversMap!=null){ |
|
134 |
Iterator<String> iter = serversMap.keySet().iterator(); |
|
135 |
while (iter.hasNext()) { |
|
136 |
String key=(String) iter.next(); |
|
137 |
ServerData server = (ServerData) serversMap.get(key); |
|
138 |
controlsPanel.addServer(server); |
|
139 |
} |
|
140 |
return serversMap.size(); |
|
141 |
} |
|
142 |
return 0; |
|
143 |
} |
|
145 | 144 |
|
146 |
/** |
|
147 |
* This method loads a server list in the combo |
|
148 |
* @param sfile |
|
149 |
*/ |
|
150 |
private int loadServerList(String sfile) { |
|
151 |
|
|
152 |
int n = loadServersFromFile(sfile); |
|
153 |
|
|
154 |
if (n == 0) { |
|
155 |
return 0; |
|
156 |
} |
|
157 |
|
|
158 |
Iterator iter = serverList.keySet().iterator(); |
|
159 |
while (iter.hasNext()) { |
|
160 |
ServerData server = (ServerData) serverList.get((String) iter.next()); |
|
161 |
controlsPanel.addServer(server); |
|
162 |
} |
|
163 |
|
|
164 |
return n; |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* It loads a server list from a text file |
|
169 |
* @param sfile |
|
170 |
* File that contains the rervers |
|
171 |
*/ |
|
172 |
private int loadServersFromFile(String sfile) { |
|
173 |
|
|
174 |
int servers_loaded = 0; |
|
175 |
|
|
176 |
File file = null; |
|
177 |
try { |
|
178 |
URL uf = getClass().getClassLoader().getResource(sfile); |
|
179 |
|
|
180 |
if (uf != null) { |
|
181 |
file = new File(uf.getFile()); |
|
182 |
if (!file.exists()) { |
|
183 |
throw new FileNotFoundException(file.getAbsolutePath()); |
|
184 |
} |
|
185 |
FileReader _fr = new FileReader(file); |
|
186 |
BufferedReader _br = new BufferedReader(_fr); |
|
187 |
String s; |
|
188 |
while ((s = _br.readLine()) != null) { |
|
189 |
addTreeMapServer(new ServerData(s,"","")); |
|
190 |
servers_loaded++; |
|
191 |
} |
|
192 |
_br.close(); |
|
193 |
_fr.close(); |
|
194 |
} else { |
|
195 |
throw new FileNotFoundException(sfile); |
|
196 |
} |
|
197 |
} catch (Exception e) { |
|
198 |
|
|
199 |
logger.info("Error while loading server list file: " + e.getMessage()); |
|
200 |
|
|
201 |
String tit = Messages.getText("_Loading_servers"); |
|
202 |
String msg = Messages.getText("_Unable_to_load_server_list_file") |
|
203 |
+ ": " + sfile; |
|
204 |
JOptionPane.showMessageDialog( |
|
205 |
this, |
|
206 |
msg, tit, JOptionPane.ERROR_MESSAGE); |
|
207 |
} |
|
208 |
|
|
209 |
return servers_loaded; |
|
210 |
} |
|
211 |
|
|
212 | 145 |
/* |
213 | 146 |
* (non-Javadoc) |
214 | 147 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) |
215 | 148 |
*/ |
216 |
public void actionPerformed(ActionEvent e) {
|
|
149 |
public void actionPerformed(ActionEvent e) { |
|
217 | 150 |
if (e.getActionCommand().compareTo(CatalogConstants.CONNECT_BUTTON_ACTION_COMMAND)==0) { |
218 | 151 |
connectButtonActionPerformed(); |
219 | 152 |
}else if (e.getActionCommand().compareTo(CatalogConstants.SEARCH_BUTTON_ACTION_COMMAND)==0) { |
... | ... | |
239 | 172 |
controlsPanel.enableServerPropertiesButton(true); |
240 | 173 |
} |
241 | 174 |
} |
242 |
|
|
175 |
|
|
243 | 176 |
/** |
244 | 177 |
* Action when the search button is clicked |
245 | 178 |
*/ |
246 |
protected void searchButtonActionPerformed() {
|
|
179 |
protected void searchButtonActionPerformed() { |
|
247 | 180 |
setEnabled(false); |
248 | 181 |
new SearchDialog(client,parent); |
249 |
}
|
|
182 |
} |
|
250 | 183 |
|
251 | 184 |
/** |
252 | 185 |
* It is thrown the the server properties button is clicked |
... | ... | |
262 | 195 |
/** |
263 | 196 |
* It is thrown the the connect button is clicked |
264 | 197 |
*/ |
265 |
protected void connectButtonActionPerformed() {
|
|
266 |
controlsPanel.enableSearchButton(false);
|
|
267 |
createClient();
|
|
198 |
protected void connectButtonActionPerformed() { |
|
199 |
controlsPanel.enableSearchButton(false); |
|
200 |
createClient(); |
|
268 | 201 |
if (connectThread != null){ |
269 | 202 |
connectThread.stop(); |
270 | 203 |
} |
271 | 204 |
connectThread = new ConnectThread(); |
272 | 205 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
273 |
}
|
|
206 |
} |
|
274 | 207 |
|
275 | 208 |
/** |
276 | 209 |
* Create the catalog client |
... | ... | |
285 | 218 |
(ICatalogServiceDriver)controlsPanel.getDriver()); |
286 | 219 |
client.setServerData(serverData); |
287 | 220 |
} |
288 |
|
|
221 |
|
|
289 | 222 |
/** |
290 | 223 |
* * It is thrown the the close button is clicked |
291 | 224 |
*/ |
292 |
protected void closeButtonActionPerformed() {
|
|
225 |
protected void closeButtonActionPerformed() { |
|
293 | 226 |
parent.setVisible(false); |
294 | 227 |
System.exit(0); |
295 |
}
|
|
228 |
} |
|
296 | 229 |
|
297 | 230 |
/** |
298 |
* @return Returns the serversFile. |
|
299 |
*/ |
|
300 |
public String getServersFile() { |
|
301 |
return serversFile; |
|
302 |
} |
|
303 |
|
|
304 |
/** |
|
305 |
* @param serversFile The serversFile to set. |
|
306 |
*/ |
|
307 |
public void setServersFile(String serversFile) { |
|
308 |
this.serversFile = serversFile; |
|
309 |
} |
|
310 |
|
|
311 |
/** |
|
312 | 231 |
* @return Returns the currentServer. |
313 | 232 |
*/ |
314 |
public String getCurrentServer() {
|
|
233 |
public String getCurrentServer() { |
|
315 | 234 |
return currentServer; |
316 |
}
|
|
235 |
} |
|
317 | 236 |
|
318 | 237 |
/** |
319 | 238 |
* @return Returns the client. |
320 | 239 |
*/ |
321 |
public CatalogClient getClient() {
|
|
240 |
public CatalogClient getClient() { |
|
322 | 241 |
return client; |
323 |
}
|
|
242 |
} |
|
324 | 243 |
|
325 | 244 |
/** |
326 | 245 |
* This class is used to manage the searches. |
327 | 246 |
* It contains method to start and to stop a thread. It is |
328 | 247 |
* necessary to create because "stop" method (for the Thread class) |
329 | 248 |
* is deprecated. |
330 |
*
|
|
331 |
*
|
|
249 |
* |
|
250 |
* |
|
332 | 251 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
333 | 252 |
*/ |
334 | 253 |
private class ConnectThread implements Runnable { |
335 | 254 |
volatile Thread myThread = null; |
336 | 255 |
|
337 |
public ConnectThread() {
|
|
256 |
public ConnectThread() { |
|
338 | 257 |
myThread = new Thread(this); |
339 | 258 |
myThread.start(); |
340 |
}
|
|
259 |
} |
|
341 | 260 |
|
342 | 261 |
public void stop(){ |
343 | 262 |
myThread.stop(); |
... | ... | |
346 | 265 |
* (non-Javadoc) |
347 | 266 |
* @see java.lang.Runnable#run() |
348 | 267 |
*/ |
349 |
public void run() {
|
|
268 |
public void run() { |
|
350 | 269 |
try { |
351 | 270 |
DiscoveryServiceCapabilities capabilities = client.getCapabilities(); |
352 | 271 |
if (capabilities.isAvailable()){ |
353 | 272 |
controlsPanel.enableSearchButton(true); |
354 | 273 |
currentServer = controlsPanel.getServerAddress(); |
355 |
searchButtonActionPerformed();
|
|
356 |
}
|
|
357 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
|
274 |
searchButtonActionPerformed(); |
|
275 |
} |
|
276 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
358 | 277 |
controlsPanel.setServerReply(capabilities.getServerMessage()); |
359 | 278 |
|
360 | 279 |
} catch (Exception e) { |
361 | 280 |
controlsPanel.setServerReply(Messages.getText(e.toString())); |
362 | 281 |
e.printStackTrace(); |
363 |
}
|
|
282 |
} |
|
364 | 283 |
} |
365 |
}
|
|
284 |
} |
|
366 | 285 |
} |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/CatalogManager.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Government (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
24 | 24 |
* AUTHORS (In addition to CIT): |
25 | 25 |
* 2009 {Iver T.I.} {Task} |
26 | 26 |
*/ |
27 |
|
|
27 |
|
|
28 | 28 |
package org.gvsig.catalog; |
29 | 29 |
|
30 | 30 |
import java.lang.reflect.InvocationTargetException; |
31 | 31 |
import java.net.URI; |
32 |
import java.util.Map; |
|
32 | 33 |
|
33 | 34 |
import org.gvsig.catalog.drivers.ICatalogServiceDriver; |
34 | 35 |
import org.gvsig.catalog.loaders.LayerLoader; |
35 | 36 |
import org.gvsig.catalog.metadataxml.XMLNode; |
36 | 37 |
import org.gvsig.catalog.schemas.Record; |
37 | 38 |
import org.gvsig.catalog.schemas.Resource; |
39 |
import org.gvsig.utils.swing.jcomboServer.ServerData; |
|
38 | 40 |
|
39 | 41 |
/** |
40 | 42 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
41 | 43 |
*/ |
42 | 44 |
public interface CatalogManager { |
43 | 45 |
/** |
44 |
* It is used to retrieve a driver that supports a concrete
|
|
46 |
* It is used to retrieve a driver that supports a concrete |
|
45 | 47 |
* protocol |
46 | 48 |
* @param protocol |
47 | 49 |
* Catalog protocol |
... | ... | |
49 | 51 |
* The concrete catalog service driver |
50 | 52 |
*/ |
51 | 53 |
public ICatalogServiceDriver getDriver(String protocol); |
52 |
|
|
54 |
|
|
53 | 55 |
/** |
54 | 56 |
* @return a list with all the catalog drivers |
55 | 57 |
*/ |
56 | 58 |
public ICatalogServiceDriver[] getDrivers(); |
57 |
|
|
59 |
|
|
58 | 60 |
/** |
59 |
* This method is used to register a new catalog driver
|
|
61 |
* This method is used to register a new catalog driver |
|
60 | 62 |
* that manage a concrete protocol |
61 | 63 |
* @param driver |
62 | 64 |
* Catalog driver to register |
63 | 65 |
*/ |
64 | 66 |
public void register(String name, Class driver); |
65 |
|
|
67 |
|
|
66 | 68 |
/** |
67 | 69 |
* Adds a new record |
68 | 70 |
* @param record |
69 | 71 |
* New record to add |
70 | 72 |
*/ |
71 |
public void addRecord(Record record);
|
|
73 |
public void addRecord(Record record); |
|
72 | 74 |
|
73 | 75 |
/** |
74 | 76 |
* Try to identify the XML format and return a record |
... | ... | |
79 | 81 |
* @return |
80 | 82 |
*/ |
81 | 83 |
public Record createRecord(URI uri, XMLNode node); |
82 |
|
|
84 |
|
|
83 | 85 |
public void addLayerLoader(String key, Class loader); |
84 |
|
|
86 |
|
|
85 | 87 |
public LayerLoader getLayerLoader(Resource resource) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
/** |
|
90 |
* gets Map object to persist servers list |
|
91 |
* @return Map<String,ServerData> |
|
92 |
*/ |
|
93 |
public Map<String,ServerData> getServersPersistence(); |
|
94 |
|
|
95 |
/** |
|
96 |
* sets Map object to persist servers list |
|
97 |
* @param serversPersistence |
|
98 |
*/ |
|
99 |
public void setServersPersistence(Map<String,ServerData> serversPersistence); |
|
88 | 100 |
} |
89 | 101 |
|
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/impl/DefaultCatalogManager.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Government (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
24 | 24 |
* AUTHORS (In addition to CIT): |
25 | 25 |
* 2009 {Iver T.I.} {Task} |
26 | 26 |
*/ |
27 |
|
|
27 |
|
|
28 | 28 |
package org.gvsig.catalog.impl; |
29 | 29 |
|
30 | 30 |
import java.lang.reflect.InvocationTargetException; |
31 | 31 |
import java.net.URI; |
32 | 32 |
import java.util.ArrayList; |
33 | 33 |
import java.util.Iterator; |
34 |
import java.util.Map; |
|
34 | 35 |
import java.util.TreeMap; |
35 | 36 |
|
36 | 37 |
import org.gvsig.catalog.CatalogManager; |
... | ... | |
43 | 44 |
import org.gvsig.tools.ToolsLocator; |
44 | 45 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
45 | 46 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
47 |
import org.gvsig.utils.swing.jcomboServer.ServerData; |
|
46 | 48 |
import org.slf4j.Logger; |
47 | 49 |
import org.slf4j.LoggerFactory; |
48 | 50 |
|
... | ... | |
52 | 54 |
public class DefaultCatalogManager implements CatalogManager { |
53 | 55 |
private static final Logger logger = LoggerFactory.getLogger(DefaultCatalogManager.class); |
54 | 56 |
private static final String DRIVER_REGISTER_NAME = "CatalogDrivers"; |
55 |
private ArrayList records = null;
|
|
57 |
private ArrayList records = null; |
|
56 | 58 |
private static TreeMap loadersPool = null; |
57 |
|
|
59 |
private Map<String,ServerData> serversPersistence =null; |
|
60 |
|
|
58 | 61 |
public DefaultCatalogManager() { |
59 | 62 |
super(); |
60 | 63 |
records = new ArrayList(); |
... | ... | |
68 | 71 |
ExtensionPointManager extensionPointManager = ToolsLocator |
69 | 72 |
.getExtensionPointManager(); |
70 | 73 |
ExtensionPoint extensionPoint = extensionPointManager.add(DRIVER_REGISTER_NAME); |
71 |
|
|
74 |
|
|
72 | 75 |
Iterator extensions = extensionPoint.iterator(); |
73 | 76 |
while (extensions.hasNext()){ |
74 | 77 |
ExtensionPoint.Extension extension = (ExtensionPoint.Extension)extensions.next(); |
... | ... | |
82 | 85 |
logger.error("Impossible to create a catalog driver", e); |
83 | 86 |
} catch (IllegalAccessException e) { |
84 | 87 |
logger.error("Impossible to create a catalog driver", e); |
85 |
}
|
|
88 |
} |
|
86 | 89 |
} |
87 | 90 |
return null; |
88 | 91 |
} |
... | ... | |
96 | 99 |
.getExtensionPointManager(); |
97 | 100 |
ExtensionPoint extensionPoint = extensionPointManager.add(DRIVER_REGISTER_NAME); |
98 | 101 |
drivers = new ICatalogServiceDriver[extensionPoint.getCount()]; |
99 |
Iterator extensions = extensionPoint.iterator();
|
|
100 |
int i = 0;
|
|
102 |
Iterator extensions = extensionPoint.iterator(); |
|
103 |
int i = 0; |
|
101 | 104 |
while (extensions.hasNext()){ |
102 | 105 |
ExtensionPoint.Extension extension = (ExtensionPoint.Extension)extensions.next(); |
103 | 106 |
ICatalogServiceDriver driver; |
104 | 107 |
try { |
105 | 108 |
driver = (ICatalogServiceDriver)extension.create(); |
106 |
drivers[i] = driver;
|
|
109 |
drivers[i] = driver; |
|
107 | 110 |
} catch (InstantiationException e) { |
108 | 111 |
logger.error("Impossible to create a catalog driver", e); |
109 | 112 |
} catch (IllegalAccessException e) { |
110 | 113 |
logger.error("Impossible to create a catalog driver", e); |
111 |
}
|
|
112 |
|
|
114 |
} |
|
115 |
|
|
113 | 116 |
i++; |
114 | 117 |
} |
115 | 118 |
return drivers; |
... | ... | |
129 | 132 |
* @see org.gvsig.catalog.CatalogManager#addRecord(org.gvsig.catalog.schemas.Record) |
130 | 133 |
*/ |
131 | 134 |
public void addRecord(Record record) { |
132 |
records.add(record);
|
|
135 |
records.add(record); |
|
133 | 136 |
} |
134 | 137 |
|
135 | 138 |
/* (non-Javadoc) |
... | ... | |
141 | 144 |
if (node != null){ |
142 | 145 |
if (record.accept(uri, node)){ |
143 | 146 |
Object[] values = {uri, node}; |
144 |
Class[] types = {URI.class, XMLNode.class};
|
|
147 |
Class[] types = {URI.class, XMLNode.class}; |
|
145 | 148 |
try { |
146 | 149 |
return (Record)record.getClass().getConstructor(types).newInstance(values); |
147 | 150 |
} catch (Exception e) { |
148 |
//It the instance can be created the
|
|
151 |
//It the instance can be created the |
|
149 | 152 |
//default record has to be returned |
150 |
}
|
|
151 |
}
|
|
153 |
} |
|
154 |
} |
|
152 | 155 |
} |
153 | 156 |
} |
154 |
return new UnknownRecord(uri,node);
|
|
157 |
return new UnknownRecord(uri,node); |
|
155 | 158 |
} |
156 | 159 |
|
157 | 160 |
/* (non-Javadoc) |
158 | 161 |
* @see org.gvsig.catalog.CatalogManager#addLayerLoader(java.lang.String, java.lang.Class) |
159 | 162 |
*/ |
160 | 163 |
public void addLayerLoader(String key, Class loader) { |
161 |
loadersPool.put(key, loader);
|
|
164 |
loadersPool.put(key, loader); |
|
162 | 165 |
} |
163 | 166 |
|
164 | 167 |
/* (non-Javadoc) |
... | ... | |
177 | 180 |
return null; |
178 | 181 |
} |
179 | 182 |
|
183 |
@Override |
|
184 |
public Map<String,ServerData> getServersPersistence() { |
|
185 |
return serversPersistence; |
|
186 |
} |
|
187 |
|
|
188 |
@Override |
|
189 |
public void setServersPersistence(Map<String,ServerData> serversPersistence) { |
|
190 |
this.serversPersistence=serversPersistence; |
|
191 |
} |
|
192 |
|
|
180 | 193 |
} |
181 | 194 |
|
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.extension/src/main/java/org/gvsig/catalog/gui/ConnectDialog.java | ||
---|---|---|
41 | 41 |
package org.gvsig.catalog.gui; |
42 | 42 |
|
43 | 43 |
import java.awt.Frame; |
44 |
import java.util.Map; |
|
44 | 45 |
|
45 | 46 |
import javax.swing.Icon; |
46 | 47 |
import javax.swing.JDialog; |
47 | 48 |
|
48 | 49 |
import org.gvsig.andami.IconThemeHelper; |
49 | 50 |
import org.gvsig.andami.PluginServices; |
50 |
import org.gvsig.andami.persistence.serverData.ServerDataPersistence; |
|
51 | 51 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
52 | 52 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
53 |
import org.gvsig.catalog.CatalogLocator; |
|
54 |
import org.gvsig.catalog.CatalogManager; |
|
53 | 55 |
import org.gvsig.catalog.drivers.ICatalogServiceDriver; |
54 | 56 |
import org.gvsig.catalog.ui.serverconnect.ServerConnectDialogPanel; |
55 | 57 |
import org.gvsig.catalog.utils.Frames; |
... | ... | |
64 | 66 |
*/ |
65 | 67 |
public class ConnectDialog extends ServerConnectDialogPanel implements IWindow { |
66 | 68 |
public WindowInfo m_windowInfo = null; |
69 |
private static final CatalogManager catalogManager = CatalogLocator.getCatalogManager(); |
|
67 | 70 |
|
68 | 71 |
/** |
69 | 72 |
* Constructor de la ventana de dialogo. |
... | ... | |
82 | 85 |
} |
83 | 86 |
|
84 | 87 |
/** |
85 |
* Add a server |
|
86 |
* |
|
87 |
* @param server |
|
88 |
*/ |
|
89 |
public static void addServer(ServerData server) { |
|
90 |
ServerConnectDialogPanel.addTreeMapServer(server); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 | 88 |
* Search Button action |
95 | 89 |
*/ |
96 | 90 |
protected void searchButtonActionPerformed() { |
... | ... | |
99 | 93 |
|
100 | 94 |
JDialog panel = new JDialog((Frame) PluginServices.getMainFrame(), false); |
101 | 95 |
Frames.centerFrame(panel,525,165); |
102 |
panel.setTitle(Messages.getText( "catalog_search"));
|
|
96 |
panel.setTitle(Messages.getText( "catalog_search")); |
|
103 | 97 |
SearchDialog dialog = new SearchDialog(getClient(),this); |
104 | 98 |
dialog.setCurrentServer(getCurrentServer()); |
105 | 99 |
dialog.setFrame(panel); |
106 | 100 |
panel.getContentPane().add(dialog); |
107 |
panel.setVisible(true);
|
|
101 |
panel.setVisible(true); |
|
108 | 102 |
} |
109 | 103 |
|
110 | 104 |
/** |
... | ... | |
113 | 107 |
*/ |
114 | 108 |
private void addCurrentHost() { |
115 | 109 |
String host = getClient().getSUri(); |
116 |
ServerDataPersistence persistence = new ServerDataPersistence(ServerData.SERVER_TYPE_CATALOG); |
|
117 | 110 |
ServerData newServerData = new ServerData(host, ServerData.SERVER_TYPE_CATALOG, getClient().getProtocol(),getControlsPanel().getDatabase()); |
118 | 111 |
if (client.getServerData() != null){ |
119 |
if ((client.getServerData() .getServerAddress().compareTo(newServerData.getServerAddress()) == 0) &&
|
|
112 |
if ((client.getServerData().getServerAddress().compareTo(newServerData.getServerAddress()) == 0) && |
|
120 | 113 |
(client.getServerData() .getServiceSubType().compareTo(newServerData.getServiceSubType()) == 0)){ |
121 | 114 |
newServerData.setProperies(client.getServerData().getProperies()); |
122 | 115 |
} |
123 | 116 |
} |
124 |
persistence.addServerData(newServerData);
|
|
125 |
// persistence..setPersistent();
|
|
117 |
Map serversMap = catalogManager.getServersPersistence();
|
|
118 |
serversMap.put(newServerData.getServerAddress(), newServerData);
|
|
126 | 119 |
} |
127 | 120 |
|
128 | 121 |
/* |
129 | 122 |
* (non-Javadoc) |
130 | 123 |
* @see es.gva.cit.catalog.ui.serverconnect.ServerConnectDialogPanel#closeButtonActionPerformed() |
131 | 124 |
*/ |
132 |
protected void closeButtonActionPerformed() {
|
|
125 |
protected void closeButtonActionPerformed() { |
|
133 | 126 |
closeJDialog(); |
134 | 127 |
} |
135 | 128 |
|
... | ... | |
171 | 164 |
|
172 | 165 |
/* (non-Javadoc) |
173 | 166 |
* @see org.gvsig.catalog.ui.serverconnect.ServerConnectDialogPanel#getPropertiesIcon() |
174 |
*/
|
|
167 |
*/ |
|
175 | 168 |
protected Icon getPropertiesIcon() { |
176 | 169 |
// catalog-move-down |
177 | 170 |
// catalog-move-up |
178 | 171 |
// catalog-server-properties |
179 | 172 |
return IconThemeHelper.getImageIcon("catalog-server-properties"); |
180 |
}
|
|
173 |
} |
|
181 | 174 |
} |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.extension/src/main/java/org/gvsig/catalog/CatalogClientExtension.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package org.gvsig.catalog; |
42 | 42 |
|
43 |
import java.util.Calendar; |
|
44 |
import java.util.Date; |
|
45 |
import java.util.GregorianCalendar; |
|
43 |
import java.io.File; |
|
44 |
import java.io.FileInputStream; |
|
45 |
import java.io.FileNotFoundException; |
|
46 |
import java.io.IOException; |
|
47 |
import java.util.HashMap; |
|
48 |
import java.util.Map; |
|
49 |
import java.util.Properties; |
|
46 | 50 |
|
47 |
import org.slf4j.Logger; |
|
48 |
import org.slf4j.LoggerFactory; |
|
49 |
|
|
51 |
import org.apache.commons.io.IOUtils; |
|
50 | 52 |
import org.gvsig.andami.IconThemeHelper; |
51 | 53 |
import org.gvsig.andami.PluginServices; |
52 |
import org.gvsig.andami.persistence.serverData.ServerDataPersistence;
|
|
54 |
import org.gvsig.andami.PluginsLocator;
|
|
53 | 55 |
import org.gvsig.andami.plugins.Extension; |
54 | 56 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
55 | 57 |
import org.gvsig.catalog.gui.ConnectDialog; |
... | ... | |
61 | 63 |
import org.gvsig.catalog.loaders.WMSLayerLoader; |
62 | 64 |
import org.gvsig.catalog.schemas.Resource; |
63 | 65 |
import org.gvsig.tools.ToolsLocator; |
66 |
import org.gvsig.tools.dynobject.DynObject; |
|
64 | 67 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
65 | 68 |
import org.gvsig.utils.swing.jcomboServer.ServerData; |
69 |
import org.slf4j.Logger; |
|
70 |
import org.slf4j.LoggerFactory; |
|
66 | 71 |
|
67 | 72 |
|
68 | 73 |
|
... | ... | |
75 | 80 |
public class CatalogClientExtension extends Extension { |
76 | 81 |
private static final Logger LOG = LoggerFactory.getLogger(CatalogClientExtension.class); |
77 | 82 |
private static final String CATALOGLAYERS = "CatalogLayers"; |
83 |
private static final String serversPropsFilename = "servers.properties"; |
|
78 | 84 |
|
79 | 85 |
public void initialize() { |
80 | 86 |
ExtensionPointManager extensionPointManager = ToolsLocator |
81 | 87 |
.getExtensionPointManager(); |
82 | 88 |
extensionPointManager.add(CATALOGLAYERS, "List of possible layers that can be loaded from a catalog"); |
83 | 89 |
registerIcons(); |
90 |
setPersistence(); |
|
84 | 91 |
} |
85 | 92 |
|
86 | 93 |
private void registerIcons(){ |
... | ... | |
112 | 119 |
*/ |
113 | 120 |
private void actionConnectDialogStart() { |
114 | 121 |
System.out.println("Bot?n Cliente de metadatos pulsado"); |
115 |
restoreServerList(); |
|
116 |
|
|
117 | 122 |
ConnectDialog connectDialog = new ConnectDialog(); |
118 | 123 |
PluginServices.getMDIManager().addWindow(connectDialog); |
119 | 124 |
} |
... | ... | |
122 | 127 |
* It restores a server list. If this list does't exist it create a server |
123 | 128 |
* list by default. |
124 | 129 |
*/ |
125 |
private void restoreServerList() { |
|
126 |
ServerDataPersistence persistence = |
|
127 |
new ServerDataPersistence(ServerData.SERVER_TYPE_CATALOG); |
|
130 |
private void setPersistence() { |
|
131 |
PluginServices plugin=PluginsLocator.getManager().getPlugin(this.getClass()); |
|
132 |
DynObject preferences = plugin.getPluginProperties(); |
|
133 |
Map serversMapPersistence = (Map) preferences.getDynValue("servers"); |
|
128 | 134 |
|
129 |
ServerData[] servers = persistence.getArrayOfServerData(); |
|
135 |
if (serversMapPersistence == null) { |
|
136 |
serversMapPersistence = new HashMap(); |
|
137 |
preferences.setDynValue("servers", serversMapPersistence); |
|
138 |
} |
|
139 |
addDefaultServers(serversMapPersistence); |
|
130 | 140 |
|
131 |
boolean found = false; |
|
132 |
for (int i=0 ; i<servers.length ; i++){ |
|
133 |
if (servers[i].getServiceType().equals(ServerData.SERVER_TYPE_CATALOG)){ |
|
134 |
found = true; |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
if (!found){ |
|
139 |
if (servers.length == 0){ |
|
140 |
servers = getDefaultServers(); |
|
141 |
}else{ |
|
142 |
ServerData[] newServers = new ServerData[servers.length + getDefaultServers().length ]; |
|
143 |
System.arraycopy(servers, 0, newServers, 0, servers.length); |
|
144 |
System.arraycopy(getDefaultServers(), 0, newServers, servers.length, getDefaultServers().length); |
|
145 |
servers = newServers; |
|
146 |
} |
|
147 |
persistence.setArrayOfServerData(servers); |
|
148 |
} |
|
149 |
|
|
150 |
|
|
151 |
for (int i = 0; i < servers.length; i++) { |
|
152 |
if (servers[i].getServiceType().equals(ServerData.SERVER_TYPE_CATALOG)){ |
|
153 |
ConnectDialog.addServer(servers[i]); |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
|
|
141 |
CatalogManager cm= CatalogLocator.getCatalogManager(); |
|
142 |
cm.setServersPersistence(serversMapPersistence); |
|
158 | 143 |
} |
159 | 144 |
|
160 | 145 |
/** |
161 |
* It creates a server list by default |
|
162 |
* |
|
163 |
* @return |
|
146 |
* Loads servers from a properties file |
|
147 |
* @param serversMapPersistence |
|
164 | 148 |
*/ |
165 |
private ServerData[] getDefaultServers() { |
|
166 |
ServerData[] servers = new ServerData[0]; |
|
167 |
Calendar cal = new GregorianCalendar(); |
|
168 |
Date date = cal.getTime(); |
|
169 |
|
|
170 |
//servers[0] = new ServerData("http://delta.icc.es/indicio/csw", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_CSW); |
|
171 |
//servers[1] = new ServerData("mapas.euitto.upm.es:2100", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_Z3950); |
|
172 |
//servers[2] = new ServerData("193.43.36.137:2100", date, date, ServerData.SERVER_TYPE_CATALOG, ServerData.SERVER_SUBTYPE_CATALOG_Z3950); |
|
173 |
//servers[3] = new ServerData("http://idee.unizar.es/SRW/servlet/search/ExplainSOAP",date,date,ServerData.SERVER_TYPE_CATALOG,ServerData.SERVER_SUBTYPE_CATALOG_SRW); |
|
174 |
return servers; |
|
149 |
private void addDefaultServers(Map serversMapPersistence) { |
|
150 |
PluginServices plugin=PluginsLocator.getManager().getPlugin(this.getClass()); |
|
151 |
//Lee los servidores del properties y los mezcla con los que hay en la persistencia |
|
152 |
Properties prop = new Properties(); |
|
153 |
File propFile = new File(plugin.getPluginDirectory(), serversPropsFilename); |
|
154 |
FileInputStream fis = null; |
|
155 |
try { |
|
156 |
fis = new FileInputStream(propFile); |
|
157 |
prop.load(fis); |
|
158 |
} catch (FileNotFoundException e) { |
|
159 |
LOG.info("Properties file '" + propFile.getAbsolutePath() + "' not found", e); |
|
160 |
} catch (IOException e) { |
|
161 |
LOG.info("Error reading properties file '" + propFile.getAbsolutePath() + "'.", e); |
|
162 |
} finally { |
|
163 |
IOUtils.closeQuietly(fis); |
|
164 |
} |
|
165 |
for (int i = 0; i < prop.size(); i++) { |
|
166 |
String serverKey="server[" + i + "]"; |
|
167 |
String subtypeKey="subtype[" + i + "]"; |
|
168 |
if (prop.containsKey(serverKey) && prop.containsKey(subtypeKey)){ |
|
169 |
Object value = prop.get(serverKey); |
|
170 |
String host=value.toString(); |
|
171 |
if (!serversMapPersistence.containsKey(host)){ |
|
172 |
Object subType=prop.get(subtypeKey); |
|
173 |
if (subType!=null){ |
|
174 |
ServerData server = new ServerData(host, ServerData.SERVER_TYPE_CATALOG, subType.toString()); |
|
175 |
serversMapPersistence.put(host, server); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
175 | 180 |
} |
176 | 181 |
|
177 | 182 |
public boolean isEnabled() { |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.extension/src/main/resources-plugin/plugin-persistence.def | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!-- |
|
3 |
Definitions of plugin persistence org.gvsig.editing. |
|
4 |
--> |
|
5 |
<definitions> |
|
6 |
<version>1.0.0</version> |
|
7 |
<classes> |
|
8 |
<class name="org.gvsig.catalog.extension"> |
|
9 |
<description>Persistence definition for the catalog plugin</description> |
|
10 |
<fields> |
|
11 |
<field name="servers" type="Map" classOfItems="org.gvsig.utils.swing.jcomboServer.ServerData" mandatory="false"> |
|
12 |
<description>Map of catalog servers</description> |
|
13 |
</field> |
|
14 |
</fields> |
|
15 |
</class> |
|
16 |
</classes> |
|
17 |
</definitions> |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.extension/src/main/resources-plugin/servers.properties | ||
---|---|---|
1 |
#You can add here servers loaded by default using this example: |
|
2 |
#server[i]=url |
|
3 |
#subtype[i]=subtype |
|
4 |
#i-> server number(0,1,2..) |
|
5 |
#url-> host url |
|
6 |
#subtype -> as found for CATALOG in org.gvsig.utils.swing.jcomboServer.ServerData (Z3950,SRW,CSW,WFS-G,ADL,IDEC,WFS) |
|
7 |
|
|
8 |
#server[0]=http://www.idee.es/IGN-WFS-SIGLIM/ogcwebservice? |
|
9 |
#subtype[0]=SRW |
org.gvsig.catalog/trunk/org.gvsig.catalog/pom.xml | ||
---|---|---|
14 | 14 |
<parent> |
15 | 15 |
<groupId>org.gvsig</groupId> |
16 | 16 |
<artifactId>org.gvsig.desktop</artifactId> |
17 |
<version>2.0.118</version>
|
|
17 |
<version>2.0.119</version>
|
|
18 | 18 |
</parent> |
19 | 19 |
|
20 | 20 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-catalog</url> |
... | ... | |
41 | 41 |
</repository> |
42 | 42 |
</repositories> |
43 | 43 |
<properties> |
44 |
<org.gvsig.raster.wcs.app.wcsclient.version>2.2.20</org.gvsig.raster.wcs.app.wcsclient.version>
|
|
45 |
<org.gvsig.raster.wcs.io.version>2.2.20</org.gvsig.raster.wcs.io.version>
|
|
46 |
</properties>
|
|
44 |
<org.gvsig.raster.wcs.app.wcsclient.version>2.2.22</org.gvsig.raster.wcs.app.wcsclient.version>
|
|
45 |
<org.gvsig.raster.wcs.io.version>2.2.22</org.gvsig.raster.wcs.io.version>
|
|
46 |
</properties> |
|
47 | 47 |
<dependencyManagement> |
48 | 48 |
<dependencies> |
49 | 49 |
<dependency> |
Also available in: Unified diff