svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wfs / WFSClient.java @ 40559
History | View | Annotate | Download (11.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.remoteclient.wfs; |
25 |
|
26 |
import java.io.File; |
27 |
import java.io.IOException; |
28 |
import java.net.ConnectException; |
29 |
import java.util.ArrayList; |
30 |
import java.util.Hashtable; |
31 |
import java.util.Iterator; |
32 |
|
33 |
import org.gvsig.compat.net.ICancellable; |
34 |
import org.gvsig.remoteclient.RemoteClient; |
35 |
import org.gvsig.remoteclient.wfs.exceptions.WFSException; |
36 |
|
37 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
38 |
*
|
39 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
40 |
*
|
41 |
* This program is free software; you can redistribute it and/or
|
42 |
* modify it under the terms of the GNU General Public License
|
43 |
* as published by the Free Software Foundation; either version 2
|
44 |
* of the License, or (at your option) any later version.
|
45 |
*
|
46 |
* This program is distributed in the hope that it will be useful,
|
47 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
48 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
49 |
* GNU General Public License for more details.
|
50 |
*
|
51 |
* You should have received a copy of the GNU General Public License
|
52 |
* along with this program; if not, write to the Free Software
|
53 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
54 |
*
|
55 |
* For more information, contact:
|
56 |
*
|
57 |
* Generalitat Valenciana
|
58 |
* Conselleria d'Infraestructures i Transport
|
59 |
* Av. Blasco Ib??ez, 50
|
60 |
* 46010 VALENCIA
|
61 |
* SPAIN
|
62 |
*
|
63 |
* +34 963862235
|
64 |
* gvsig@gva.es
|
65 |
* www.gvsig.gva.es
|
66 |
*
|
67 |
* or
|
68 |
*
|
69 |
* IVER T.I. S.A
|
70 |
* Salamanca 50
|
71 |
* 46005 Valencia
|
72 |
* Spain
|
73 |
*
|
74 |
* +34 963163400
|
75 |
* dac@iver.es
|
76 |
*/
|
77 |
/* CVS MESSAGES:
|
78 |
*
|
79 |
* $Id: WFSClient.java 39768 2013-02-20 14:16:29Z jldominguez $
|
80 |
* $Log$
|
81 |
* Revision 1.10 2007-09-20 09:30:12 jaume
|
82 |
* removed unnecessary imports
|
83 |
*
|
84 |
* Revision 1.9 2007/02/09 14:11:01 jorpiell
|
85 |
* Primer piloto del soporte para WFS 1.1 y para WFS-T
|
86 |
*
|
87 |
* Revision 1.8 2006/06/14 08:46:07 jorpiell
|
88 |
* Se tiene en cuanta la opcion para refrescar las capabilities
|
89 |
*
|
90 |
* Revision 1.7 2006/05/25 10:28:25 jorpiell
|
91 |
* Se ha a?adido un atributo al m?todo connect
|
92 |
*
|
93 |
* Revision 1.6 2006/05/23 13:23:22 jorpiell
|
94 |
* Se ha cambiado el final del bucle de parseado y se tiene en cuenta el online resource
|
95 |
*
|
96 |
* Revision 1.4 2006/04/20 16:39:16 jorpiell
|
97 |
* A?adida la operacion de describeFeatureType y el parser correspondiente.
|
98 |
*
|
99 |
* Revision 1.3 2006/04/19 12:51:35 jorpiell
|
100 |
* A?adidas algunas de las clases del servicio WFS
|
101 |
*
|
102 |
*
|
103 |
*/
|
104 |
/**
|
105 |
* Represents the class the with the necessary logic to connect to a
|
106 |
* OGCWFS and interpretate the data
|
107 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
108 |
*/
|
109 |
public class WFSClient extends RemoteClient{ |
110 |
|
111 |
private WFSProtocolHandler handler;
|
112 |
|
113 |
//private Logger LOG = LoggerFactory.getLogger(WFSClient.class);
|
114 |
|
115 |
/**
|
116 |
* Constructor.
|
117 |
* the parameter host, indicates the WFS host to connect.
|
118 |
* @throws ConnectException,IOException
|
119 |
*
|
120 |
*/
|
121 |
public WFSClient(String host) throws ConnectException,IOException { |
122 |
setHost(host); |
123 |
|
124 |
handler = WFSProtocolHandlerFactory.negotiate(host); |
125 |
handler.setHost(host); |
126 |
} |
127 |
|
128 |
public WFSClient(String host, String version) throws IOException { |
129 |
|
130 |
setHost(host); |
131 |
|
132 |
if (version == null) { |
133 |
try {
|
134 |
handler = WFSProtocolHandlerFactory.negotiate(host); |
135 |
} catch(ConnectException conE) { |
136 |
conE.printStackTrace(); |
137 |
throw conE;
|
138 |
} catch(IOException ioE) { |
139 |
ioE.printStackTrace(); |
140 |
throw ioE;
|
141 |
} catch(Exception e) { |
142 |
e.printStackTrace(); |
143 |
} |
144 |
}else{
|
145 |
handler = WFSProtocolHandlerFactory.createVersionDriver(version); |
146 |
} |
147 |
|
148 |
if (handler == null){ |
149 |
throw new UnsupportedOperationException("Unsupported version"); |
150 |
} |
151 |
handler.setHost(host); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* Every OGC Web Service (OWS), including a Web Feature Service,
|
156 |
* must have the ability to describe its capabilities by returning
|
157 |
* service metadata in response to a GetCapabilities request.
|
158 |
* @param status
|
159 |
* WFS client status. Contains all the information to create
|
160 |
* the query
|
161 |
*/
|
162 |
public void getCapabilities(WFSStatus status, boolean override, ICancellable cancel)throws WFSException { |
163 |
handler.getCapabilities(status,override,cancel); |
164 |
} |
165 |
|
166 |
/**
|
167 |
* The function of the DescribeFeatureType operation is to
|
168 |
* generate a schema description of feature types serviced
|
169 |
* by a WFS implementation. The schema descriptions define
|
170 |
* how a WFS implementation expects feature instances to
|
171 |
* be encoded on input (via Insert and Update requests)
|
172 |
* and how feature instances will be generated on output
|
173 |
* (in response to GetFeature and GetGmlObject requests).
|
174 |
* @param status
|
175 |
* WFS client status. Contains all the information to create
|
176 |
* the query
|
177 |
*/
|
178 |
public File describeFeatureType(WFSStatus status, boolean override, ICancellable cancel)throws WFSException { |
179 |
return handler.describeFeatureType(status,override,cancel);
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* The GetFeature operation allows retrieval of features from a
|
184 |
* web feature service. A GetFeature request is processed by
|
185 |
* a WFS and when the value of the outputFormat attribute is
|
186 |
* set to text/gml a GML instance document, containing the
|
187 |
* result set, is returned to the client.
|
188 |
* @param status
|
189 |
* WFS client status. Contains all the information to create
|
190 |
* the query
|
191 |
* @return File
|
192 |
* GML File
|
193 |
*/
|
194 |
public File getFeature(WFSStatus status, boolean override, ICancellable cancel) throws WFSException{ |
195 |
if ((status.getNamespaceLocation() != null) && (status.getNamespacePrefix() == null)){ |
196 |
String namespacePrefix = getServiceInformation().getNamespacePrefix(status.getNamespaceLocation());
|
197 |
if (namespacePrefix != null){ |
198 |
status.setNamespacePrefix(namespacePrefix); |
199 |
} |
200 |
} |
201 |
return handler.getFeature(status,override,cancel);
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* The Transaction operation is used to describe data transformation
|
206 |
* operations that are to be applied to web accessible feature
|
207 |
* instances. A web feature service may process a Transaction
|
208 |
* operation directly or possibly translate it into the language
|
209 |
* of a target datastore to which it is connected and then have the
|
210 |
* datastore execute the transaction. When the transaction has been
|
211 |
* completed, a web feature service will generate an XML response
|
212 |
* document indicating the completion status of the transaction.
|
213 |
* @param status
|
214 |
* WFS client status. Contains all the information to create
|
215 |
* the query
|
216 |
*/
|
217 |
public void transaction(WFSStatus status, boolean override, ICancellable cancel) throws WFSException{ |
218 |
handler.transaction(status,override,cancel); |
219 |
} |
220 |
|
221 |
/**
|
222 |
* Web connections are inherently stateless. As a consequence
|
223 |
* of this, the semantics of serializable transactions are not
|
224 |
* preserved. To understand the issue, consider an update operation.
|
225 |
* The client fetches a feature instance. The feature is then
|
226 |
* modified on the client side, and submitted back to the database
|
227 |
* via a Transaction request for update. Serializability is lost
|
228 |
* since there is nothing to guarantee that while the feature was
|
229 |
* being modified on the client side, another client did not come
|
230 |
* along and update that same feature in the database.
|
231 |
* One way to ensure serializability is to require that access to
|
232 |
* data be done in a mutually exclusive manner; that is while one
|
233 |
* transaction accesses a data item, no other transaction can modify
|
234 |
* the same data item. This can be accomplished by using locks that
|
235 |
* control access to the data.
|
236 |
* The purpose of the LockFeature operation is to expose a long
|
237 |
* term feature locking mechanism to ensure consistency. The lock
|
238 |
* is considered long term because network latency would make
|
239 |
* feature locks last relatively longer than native commercial
|
240 |
* database locks.
|
241 |
* The LockFeature operation is optional and does not need to be
|
242 |
* implemented for a WFS implementation to conform to this
|
243 |
* specification. If a WFS implements the LockFeature operation,
|
244 |
* this fact must be advertised in the capabilities document
|
245 |
* @param status
|
246 |
*/
|
247 |
public void lockFeature(WFSStatus status, boolean override, ICancellable cancel)throws WFSException { |
248 |
handler.lockFeature(status,override,cancel); |
249 |
} |
250 |
|
251 |
|
252 |
/**
|
253 |
* <p>Checks the connection to de remote WFS and requests its
|
254 |
* capabilities.</p>
|
255 |
*
|
256 |
*/
|
257 |
public boolean connect(boolean override, ICancellable cancel) |
258 |
{ |
259 |
try {
|
260 |
if (handler == null) { |
261 |
if (getHost().trim().length() > 0) { |
262 |
handler = WFSProtocolHandlerFactory.negotiate(getHost()); |
263 |
handler.setHost(getHost()); |
264 |
} else {
|
265 |
// must to specify host first!!!!
|
266 |
return false; |
267 |
} |
268 |
} |
269 |
getCapabilities(null,override,cancel);
|
270 |
|
271 |
return true; |
272 |
|
273 |
} catch (Exception e) { |
274 |
e.printStackTrace(); |
275 |
return false; |
276 |
} |
277 |
} |
278 |
|
279 |
/*
|
280 |
* (non-Javadoc)
|
281 |
* @see org.gvsig.remoteClient.RemoteClient#connect(org.gvsig.remoteClient.wms.ICancellable)
|
282 |
*/
|
283 |
public boolean connect(ICancellable cancel) { |
284 |
return connect(false, cancel); |
285 |
} |
286 |
|
287 |
/*
|
288 |
* (non-Javadoc)
|
289 |
* @see org.gvsig.remoteClient.RemoteClient#close()
|
290 |
*/
|
291 |
public void close() { |
292 |
// TODO Auto-generated method stub
|
293 |
|
294 |
} |
295 |
|
296 |
public String getVersion() |
297 |
{ |
298 |
return handler.getVersion();
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* Gets the Service information included in the Capabilities
|
303 |
*/
|
304 |
|
305 |
public WFSServiceInformation getServiceInformation(){
|
306 |
return (WFSServiceInformation)handler.getServiceInformation();
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* Returns the features list
|
311 |
* @return
|
312 |
*/
|
313 |
public Hashtable getFeatures() |
314 |
{ |
315 |
return handler.getFeatures();
|
316 |
} |
317 |
|
318 |
public WFSFeature getFeature(String nameSpace, String localName){ |
319 |
Iterator it = handler.getFeatures().keySet().iterator();
|
320 |
String fullName = localName;
|
321 |
String prefix = getServiceInformation().getNamespacePrefix(nameSpace);
|
322 |
if (prefix != null){ |
323 |
fullName = prefix + ":" + localName;
|
324 |
} |
325 |
while (it.hasNext()){
|
326 |
String featureName = (String)it.next(); |
327 |
if (localName.equals(featureName)){
|
328 |
return (WFSFeature)handler.getFeatures().get(localName);
|
329 |
} |
330 |
if (fullName.equals(featureName)){
|
331 |
return (WFSFeature)handler.getFeatures().get(fullName);
|
332 |
} |
333 |
} |
334 |
return null; |
335 |
} |
336 |
|
337 |
/**
|
338 |
* @return the lastWfsRequestInformation
|
339 |
*/
|
340 |
public WFSRequestInformation getLastWfsRequestInformation() {
|
341 |
return handler.getLastWfsRequestInformation();
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* @return the number requests
|
346 |
*/
|
347 |
public int getWFSRequestInformationCount(){ |
348 |
return handler.getWfsRequestInformations().size();
|
349 |
} |
350 |
|
351 |
/**
|
352 |
* Return the information of a request
|
353 |
* @param index
|
354 |
* The position of the request
|
355 |
* @return
|
356 |
*/
|
357 |
public WFSRequestInformation getWFSRequestInformationAt(int index){ |
358 |
ArrayList wfsRequestInformations = handler.getWfsRequestInformations();
|
359 |
if (index < wfsRequestInformations.size()){
|
360 |
return (WFSRequestInformation)wfsRequestInformations.get(index);
|
361 |
} |
362 |
return null; |
363 |
} |
364 |
|
365 |
} |