svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / drivers / wfs / FMapWFSDriver.java @ 4911
History | View | Annotate | Download (6.91 KB)
1 |
package com.iver.cit.gvsig.fmap.drivers.wfs; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.net.ConnectException; |
5 |
import java.net.URL; |
6 |
import java.util.Hashtable; |
7 |
import java.util.Iterator; |
8 |
import java.util.Set; |
9 |
import java.util.Vector; |
10 |
|
11 |
import org.gvsig.remoteClient.wfs.WFSClient; |
12 |
import org.gvsig.remoteClient.wfs.WFSFeature; |
13 |
import org.gvsig.remoteClient.wfs.WFSProtocolHandler.ServiceInformation; |
14 |
|
15 |
import com.iver.cit.gvsig.fmap.DriverException; |
16 |
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
17 |
import com.iver.cit.gvsig.fmap.drivers.WFSDriver; |
18 |
import com.iver.cit.gvsig.fmap.drivers.WFSException; |
19 |
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode; |
20 |
|
21 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
22 |
*
|
23 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
24 |
*
|
25 |
* This program is free software; you can redistribute it and/or
|
26 |
* modify it under the terms of the GNU General Public License
|
27 |
* as published by the Free Software Foundation; either version 2
|
28 |
* of the License, or (at your option) any later version.
|
29 |
*
|
30 |
* This program is distributed in the hope that it will be useful,
|
31 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
32 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
33 |
* GNU General Public License for more details.
|
34 |
*
|
35 |
* You should have received a copy of the GNU General Public License
|
36 |
* along with this program; if not, write to the Free Software
|
37 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
38 |
*
|
39 |
* For more information, contact:
|
40 |
*
|
41 |
* Generalitat Valenciana
|
42 |
* Conselleria d'Infraestructures i Transport
|
43 |
* Av. Blasco Ib??ez, 50
|
44 |
* 46010 VALENCIA
|
45 |
* SPAIN
|
46 |
*
|
47 |
* +34 963862235
|
48 |
* gvsig@gva.es
|
49 |
* www.gvsig.gva.es
|
50 |
*
|
51 |
* or
|
52 |
*
|
53 |
* IVER T.I. S.A
|
54 |
* Salamanca 50
|
55 |
* 46005 Valencia
|
56 |
* Spain
|
57 |
*
|
58 |
* +34 963163400
|
59 |
* dac@iver.es
|
60 |
*/
|
61 |
/* CVS MESSAGES:
|
62 |
*
|
63 |
* $Id: FMapWFSDriver.java 4911 2006-04-20 16:38:24Z jorpiell $
|
64 |
* $Log$
|
65 |
* Revision 1.2 2006-04-20 16:38:24 jorpiell
|
66 |
* Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
|
67 |
*
|
68 |
* Revision 1.1 2006/04/19 12:50:16 jorpiell
|
69 |
* Primer commit de la aplicaci?n. Se puede hacer un getCapabilities y ver el mensaje de vienvenida del servidor
|
70 |
*
|
71 |
*
|
72 |
*/
|
73 |
/**
|
74 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
75 |
*/
|
76 |
public class FMapWFSDriver implements WFSDriver{ |
77 |
private WFSClient client;
|
78 |
private WFSLayerNode[] featuresList; |
79 |
private Hashtable features; |
80 |
|
81 |
/*
|
82 |
* (non-Javadoc)
|
83 |
* @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getCapabilities(java.net.URL)
|
84 |
*/
|
85 |
public void getCapabilities(URL server) |
86 |
throws WFSException {
|
87 |
try {
|
88 |
getClient(server).connect(); |
89 |
} catch (Exception e) { |
90 |
throw new WFSException(e); |
91 |
} |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Devuelve WFSClient a partir de su URL.
|
96 |
*
|
97 |
* @param url URL.
|
98 |
*
|
99 |
* @return WMSClient.
|
100 |
* @throws IOException
|
101 |
* @throws ConnectException
|
102 |
*
|
103 |
* @throws UnsupportedVersionException
|
104 |
* @throws IOException
|
105 |
*/
|
106 |
public WFSClient getClient(URL url) throws ConnectException, IOException { |
107 |
if (client == null) { |
108 |
client = new WFSClient(url.toString());
|
109 |
} |
110 |
return client;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Creates a new instance of a WFSClient.
|
115 |
* @param
|
116 |
* host
|
117 |
* @throws IOException
|
118 |
* @throws ConnectException
|
119 |
*/
|
120 |
public void createClient(URL host) throws ConnectException, IOException { |
121 |
client = new WFSClient(host.toString());
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Establishes the connection to the WfS server. Connecting to a WFS is
|
126 |
* an abstraction.<br>
|
127 |
* <p>
|
128 |
* Actually, it sends a GetCapabilities request to read the necessary
|
129 |
* data for building further DescribeFeatureType requests.
|
130 |
* </p>
|
131 |
* @throws IOException, DriverException.
|
132 |
*/
|
133 |
public boolean connect() throws IOException, DriverException { |
134 |
return client.connect();
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Returns an array of WFSLayerNode's with the descriptors of
|
139 |
* all features (retrieved using the getCapabilities operation)
|
140 |
* @return WFSLayerNode[]
|
141 |
*/
|
142 |
public WFSLayerNode[] getLayerList(){ |
143 |
if (features == null) { |
144 |
features = new Hashtable(); |
145 |
Hashtable wfsFeatures = client.getFeatures();
|
146 |
|
147 |
Iterator keys = wfsFeatures.keySet().iterator();
|
148 |
featuresList = new WFSLayerNode[wfsFeatures.size()];
|
149 |
|
150 |
for (int i=0 ; i<wfsFeatures.size() ; i++){ |
151 |
WFSLayerNode lyr = new WFSLayerNode();
|
152 |
WFSFeature feature = (WFSFeature)wfsFeatures.get(keys.next()); |
153 |
|
154 |
lyr.setName(feature.getName()); |
155 |
lyr.setTitle(feature.getTitle()); |
156 |
lyr.setAbstract(feature.getAbstract()); |
157 |
lyr.setFields(feature.getFields()); |
158 |
|
159 |
featuresList[i] = lyr; |
160 |
features.put(lyr.getName(), lyr); |
161 |
} |
162 |
} |
163 |
return featuresList;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* Returns all the feature information retrieved using a
|
168 |
* describeFeatureTypeOpearion
|
169 |
* @param layerName
|
170 |
* Feature name
|
171 |
* @return
|
172 |
*/
|
173 |
public WFSLayerNode getLayerInfo(String layerName){ |
174 |
WFSLayerNode lyr = (WFSLayerNode)features.get(layerName); |
175 |
if (lyr.getFields().size() == 0){ |
176 |
try {
|
177 |
describeFeatureType(layerName); |
178 |
WFSFeature feature = (WFSFeature) client.getFeatures().get(layerName); |
179 |
lyr.setFields(feature.getFields()); |
180 |
} catch (WFSException e) {
|
181 |
// The feature doesn't has fields
|
182 |
e.printStackTrace(); |
183 |
} |
184 |
} |
185 |
return lyr;
|
186 |
} |
187 |
|
188 |
|
189 |
/**
|
190 |
* @return The title of the service offered by the WMS server.
|
191 |
*/
|
192 |
public String getServiceTitle() { |
193 |
return client.getServiceInformation().title;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @return The abstract of the service offered by the WMS server.
|
198 |
*/
|
199 |
public String getServiceAbstract() { |
200 |
return client.getServiceInformation().abstr;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* Returns a Hash table containing the values for each online resource.
|
205 |
* Using as key a String with name of the WMS request and the value returned
|
206 |
* by the hash is another string containing the corresponding Url
|
207 |
* @return HashTable
|
208 |
*/
|
209 |
public Hashtable getOnlineResources() { |
210 |
Hashtable onlineResources = new Hashtable(); |
211 |
ServiceInformation si = client.getServiceInformation(); |
212 |
Iterator it = si.operations.keySet().iterator();
|
213 |
while (it.hasNext()) {
|
214 |
String key = (String) it.next(); |
215 |
String val = (String) si.operations.get(key); |
216 |
if (val==null && (si.online_resource!=null || si.online_resource!= "")) |
217 |
val = si.online_resource; |
218 |
if (val!=null) { |
219 |
onlineResources.put(key, val); |
220 |
} |
221 |
} |
222 |
return onlineResources;
|
223 |
} |
224 |
|
225 |
/**
|
226 |
*
|
227 |
* @return the host
|
228 |
*/
|
229 |
public String getHost(){ |
230 |
return client.getHost();
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* @return the version of this client.
|
235 |
*/
|
236 |
public String getVersion() { |
237 |
return client.getVersion();
|
238 |
} |
239 |
|
240 |
/*
|
241 |
* (non-Javadoc)
|
242 |
* @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#describeFeatureType(java.lang.String)
|
243 |
*/
|
244 |
public void describeFeatureType(String featureType) throws WFSException { |
245 |
client.describeFeatureType(null,featureType);
|
246 |
} |
247 |
|
248 |
|
249 |
} |