Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteClient / wfs / WFSClient.java @ 28430

History | View | Annotate | Download (9.1 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.Hashtable;
7

    
8
import org.gvsig.remoteClient.RemoteClient;
9
import org.gvsig.remoteClient.wfs.exceptions.WFSException;
10
import org.gvsig.remoteClient.wms.ICancellable;
11

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