Revision 15558 trunk/applications/appCatalogAndGazetteerClient/src/es/gva/cit/gazetteer/GazetteerClient.java

View differences:

GazetteerClient.java
1 1

  
2 2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42 42
package es.gva.cit.gazetteer;
43
import java.io.IOException;
44
import java.net.MalformedURLException;
45
import java.net.Socket;
46
import java.net.URL;
47
import java.net.UnknownHostException;
48
import java.util.Collection;
49

  
50
import com.iver.utiles.swing.jcomboServer.ServerData;
51
import es.gva.cit.gazetteer.adl.drivers.ADLGazetteerServiceDriver;
43
import es.gva.cit.catalog.DiscoveryServiceClient;
44
import es.gva.cit.gazetteer.drivers.GazetteerCapabilities;
52 45
import es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver;
53
import es.gva.cit.gazetteer.idec.drivers.IDECGazetteerServiceDriver;
54
import es.gva.cit.gazetteer.querys.Query;
55
import es.gva.cit.gazetteer.wfsg.drivers.WFSGazetteerServiceDriver;
46
import es.gva.cit.gazetteer.querys.Feature;
47
import es.gva.cit.gazetteer.querys.FeatureType;
48
import es.gva.cit.gazetteer.querys.FeatureTypeAttribute;
49
import es.gva.cit.gazetteer.querys.GazetteerQuery;
56 50

  
57 51
/**
58 52
 * This class represents a gazetteer client. It must be created to
59
 * use the gazetteer service
60
 * 
61
 * 
53
 * use the gazetteer service 
62 54
 * @author Jorge Piera Llodra (piera_jor@gva.es)
63 55
 */
64
public class GazetteerClient {
56
public class GazetteerClient extends DiscoveryServiceClient{
57
	
58
	public GazetteerClient(String uri, IGazetteerServiceDriver driver) {
59
		super(uri, driver);		
60
	}
65 61

  
66
/**
67
 * 
68
 * 
69
 */
70
    private URL url = null;
62
	/**
63
	 * @return the feature types
64
	 * @throws Exception 
65
	 */
66
	public FeatureType[] getFeatureTypes() throws Exception {
67
		return ((GazetteerCapabilities)getCapabilities()).getFeatureTypes();
68
	}
71 69

  
72
/**
73
 * 
74
 * 
75
 */
76
    private String sURL = null;
70
	/**
71
	 * This method makes the describeFeatureType
72
	 * operation
73
	 * @param featureName
74
	 * Feature name
75
	 * @return
76
	 * @throws Exception 
77
	 */
78
	public FeatureTypeAttribute[] describeFeatureType(String featureName) throws Exception{
79
		return ((IGazetteerServiceDriver)getDriver()).describeFeatureType(getUri(), featureName);
80
	}
81
	
82
	/**
83
	 * @return if the describeFeatureType operation is
84
	 * supported by the driver
85
	 */
86
	public boolean isDescribeFeatureTypeNeeded(){
87
		return ((IGazetteerServiceDriver)getDriver()).isDescribeFeatureTypeNeeded();
88
	}
77 89

  
78
/**
79
 * 
80
 * 
81
 */
82
    private String protocol = null;
83
/**
84
 * 
85
 * 
86
 */
87
    private IGazetteerServiceDriver lnkIGazetteerDriver;
90
	/**
91
	 * This method implements the getFeature operation
92
	 * @return 
93
	 * A result collection
94
	 * @param query 
95
	 * The results query
96
	 * @throws Exception 
97
	 */
98
	public Feature[] getFeature(GazetteerQuery query) throws Exception {        
99
		return ((IGazetteerServiceDriver)getDriver()).getFeature(getUri(), query);
100
	} 	
88 101

  
89
/**
90
 * 
91
 * 
92
 */
93
    private String serverStatus = null;
102
	/**
103
	 * This method is used to create a new Query
104
	 * @return 
105
	 */
106
	public GazetteerQuery createNewQuery() {        
107
		return new GazetteerQuery();   
108
	} 	
109
	
110
	/**
111
	 * @return the projection
112
	 */
113
	public String getProjection() {
114
		return ((IGazetteerServiceDriver)getDriver()).getProjection();
115
	}
94 116

  
95
/**
96
 * 
97
 * 
98
 * 
99
 * @param url 
100
 * @param protocol 
101
 */
102
    public  GazetteerClient(String url, String protocol) {        
103
    	 if (!(url.regionMatches(0, "http://", 0, 7))) {
104
             url = "http://" + url;
105
         }
106
    	 
107
    	setProtocol(protocol);
108
        setSURL(url);
109
        
110
        try {
111
            setUrl(new URL(url));
112
            
113
                      
114
            if (getUrl().getPort() == -1) {
115
                setUrl(new URL("http", getUrl().getHost(), 80, getUrl().getFile()));
116
            } else {
117
                setUrl(new URL("http", getUrl().getHost(), getUrl().getPort(),getUrl().getFile()));
118
            }
119
            
120
            
121
            
122
        } catch (MalformedURLException e) {
123
            // TODO Auto-generated catch block
124
            e.printStackTrace();
125
        }
126
     
127
        //Casting to the respective driver
128
        if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_WFSG)) ||
129
                protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_WFS))) {
130
            lnkIGazetteerDriver = new WFSGazetteerServiceDriver();
131
        }
132
        if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_ADL))) {
133
            lnkIGazetteerDriver = new ADLGazetteerServiceDriver();
134
        }
135
        
136
        if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_IDEC))) {
137
            lnkIGazetteerDriver = new IDECGazetteerServiceDriver();
138
        }
139
        
140
      
141
    } 
142

  
143
/**
144
 * 
145
 * 
146
 * 
147
 * @return 
148
 */
149
    public boolean getCapabilities() {        
150
           if (!serverReady()) {
151
               serverStatus = ("errorServerNotFound");
152
           } else if (!getLnkIGazetteerDriver().isProtocolSupported(getUrl())) {
153
               serverStatus = "errorNotSupportedProtocol";
154
           } else {
155
               //getCapabilities
156
               Collection nodesCapabilities = getLnkIGazetteerDriver()
157
                                                 .getCapabilities(getUrl());
158
               if (nodesCapabilities == null) {
159
                   serverStatus = "errorNotSupportedCapabilities";
160
               } else {
161
                   //Configure the client
162
                   if (!getLnkIGazetteerDriver().setParameters(nodesCapabilities)) {
163
                       if (!(getLnkIGazetteerDriver()
164
                                        .getServerAnswerReady().equals(""))) {
165
                           serverStatus = getLnkIGazetteerDriver().getServerAnswerReady();
166
                       } else {
167
                           serverStatus = "errorNotParsedReply";
168
                       }
169
                   } else {
170
                       serverStatus = getLnkIGazetteerDriver().getServerAnswerReady();
171
                       return true;
172
                   }
173
               }
174
           }
175
           
176
           return false;           
177
    } 
178

  
179
/**
180
 * This method implements the getFeature operation
181
 * 
182
 * 
183
 * @return 
184
 * @param url 
185
 * @param query 
186
 */
187
    public Collection getFeature(URL url, Query query) {        
188
            return lnkIGazetteerDriver.getFeature(url, query);
189
    } 
190

  
191
/**
192
 * 
193
 * 
194
 * 
195
 * @return Returns the lnkIGazetteerDriver.
196
 */
197
    public IGazetteerServiceDriver getLnkIGazetteerDriver() {        
198
        return lnkIGazetteerDriver;
199
    } 
200

  
201
/**
202
 * 
203
 * 
204
 * 
205
 * @param lnkIGazetteerDriver The lnkIGazetteerDriver to set.
206
 */
207
    public void setLnkICatalogServerDriver(IGazetteerServiceDriver lnkIGazetteerDriver) {        
208
        this.lnkIGazetteerDriver = lnkIGazetteerDriver;
209
    } 
210

  
211
/**
212
 * This method is used to create a new Query
213
 * 
214
 * 
215
 * @return 
216
 */
217
    public Query createNewQuery() {        
218
        return new Query();   
219
    } 
220

  
221
/**
222
 * 
223
 * 
224
 * 
225
 * @return 
226
 */
227
    public String getProtocol() {        
228
        return protocol;
229
    } 
230

  
231
/**
232
 * 
233
 * 
234
 * 
235
 * @param protocol The protocol to set.
236
 */
237
    public void setProtocol(String protocol) {        
238
        this.protocol = protocol;
239
    } 
240

  
241
/**
242
 * 
243
 * 
244
 * 
245
 * @return Returns the url.
246
 */
247
    public URL getUrl() {        
248
        return url;
249
    } 
250

  
251
/**
252
 * 
253
 * 
254
 * 
255
 * @param url The url to set.
256
 */
257
    public void setUrl(URL url) {        
258
        this.url = url;
259
    } 
260

  
261
/**
262
 * It tries if the server is ready
263
 * 
264
 * 
265
 * @return boolean
266
 * true --> server is ready
267
 * false --> server is not ready
268
 */
269
    public boolean serverReady() {        
270
        try {
271
            new Socket(this.getUrl().getHost(),
272
                    this.getUrl().getPort());
273
        } catch (UnknownHostException e) {
274
            // TODO Auto-generated catch block
275
            return false;
276
        } catch (IOException e) {
277
            // TODO Auto-generated catch block
278
            return false;
279
        }
280
        return true;
281
    } 
282

  
283
/**
284
 * 
285
 * 
286
 * 
287
 * @return Returns the sURL.
288
 */
289
    public String getSURL() {        
290
        return sURL;
291
    } 
292

  
293
/**
294
 * 
295
 * 
296
 * 
297
 * @param surl The sURL to set.
298
 */
299
    public void setSURL(String surl) {        
300
        sURL = surl;
301
    } 
302

  
303
/**
304
 * 
305
 * 
306
 * 
307
 * @return Returns the serverStatus.
308
 */
309
    public String getServerStatus() {        
310
            return serverStatus;
311
    } 
312
 }
117
	/**
118
	 * @param projection the projection to set
119
	 */
120
	public void setProjection(String projection) {
121
		((IGazetteerServiceDriver)getDriver()).setProjection(projection);
122
	} 
123
}

Also available in: Unified diff