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