svn-gvsig-desktop / branches / CatalogYNomenclator_v1_1_0_1005 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / GazetteerClient.java @ 12750
History | View | Annotate | Download (5.34 KB)
1 |
|
---|---|
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 |
*/
|
42 |
package es.gva.cit.gazetteer; |
43 |
import java.io.IOException; |
44 |
import java.net.Socket; |
45 |
import java.net.URI; |
46 |
import java.net.URISyntaxException; |
47 |
import java.net.UnknownHostException; |
48 |
|
49 |
import es.gva.cit.catalogClient.exceptions.ServerIsNotReadyException; |
50 |
import es.gva.cit.catalogClient.utils.URIUtils; |
51 |
import es.gva.cit.gazetteer.drivers.GazetteerCapabilities; |
52 |
import es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver; |
53 |
import es.gva.cit.gazetteer.querys.Feature; |
54 |
import es.gva.cit.gazetteer.querys.FeatureType; |
55 |
import es.gva.cit.gazetteer.querys.FeatureTypeAttribute; |
56 |
import es.gva.cit.gazetteer.querys.Query; |
57 |
import es.gva.cit.gazetteer.utils.GazetteerClientRegister; |
58 |
|
59 |
/**
|
60 |
* This class represents a gazetteer client. It must be created to
|
61 |
* use the gazetteer service
|
62 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
63 |
*/
|
64 |
public class GazetteerClient { |
65 |
/**
|
66 |
* The server URI
|
67 |
*/
|
68 |
private URI uri = null; |
69 |
/**
|
70 |
* The driver to make the querys
|
71 |
*/
|
72 |
private IGazetteerServiceDriver gazetteerDriver;
|
73 |
|
74 |
/**
|
75 |
* The server status message
|
76 |
*/
|
77 |
private String serverStatus = null; |
78 |
|
79 |
/**
|
80 |
* Server capabilities
|
81 |
*/
|
82 |
private GazetteerCapabilities capabilities = null; |
83 |
|
84 |
/**
|
85 |
* @return the feature types
|
86 |
*/
|
87 |
public FeatureType[] getFeatureTypes() { |
88 |
return capabilities.getFeatureTypes();
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* Main constructor
|
93 |
* @param sUri
|
94 |
* Server URI
|
95 |
* @param protocol
|
96 |
* Server protocol
|
97 |
* @throws URISyntaxException
|
98 |
*/
|
99 |
public GazetteerClient(String sUri, IGazetteerServiceDriver driver) { |
100 |
GazetteerClientRegister gazzRegister = GazetteerClientRegister.getInstance(); |
101 |
gazetteerDriver = driver; |
102 |
if (gazetteerDriver == null){ |
103 |
serverStatus = "errorServerNotFound";
|
104 |
}else{
|
105 |
try {
|
106 |
this.uri = URIUtils.createUri(sUri, gazetteerDriver.getDefaultSchema(), gazetteerDriver.getDefaultPort());
|
107 |
} catch (URISyntaxException e) { |
108 |
serverStatus = "errorServerNotFound";
|
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
/**
|
114 |
* @return the server capabilities
|
115 |
* @throws Exception
|
116 |
*/
|
117 |
public GazetteerCapabilities getCapabilities() throws Exception { |
118 |
if (serverIsReady()){
|
119 |
if (getDriver().isProtocolSupported(getUri())) {
|
120 |
capabilities = getDriver().getCapabilities(getUri()); |
121 |
return capabilities;
|
122 |
} |
123 |
} |
124 |
return null; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* This method makes the describeFeatureType
|
129 |
* operation
|
130 |
* @param featureName
|
131 |
* Feature name
|
132 |
* @return
|
133 |
* @throws Exception
|
134 |
*/
|
135 |
public FeatureTypeAttribute[] describeFeatureType(String featureName) throws Exception{ |
136 |
return gazetteerDriver.describeFeatureType(uri, featureName);
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* @return if the describeFeatureType operation is
|
141 |
* supported by the driver
|
142 |
*/
|
143 |
public boolean isDescribeFeatureTypeNeeded(){ |
144 |
return gazetteerDriver.isDescribeFeatureTypeNeeded();
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* This method implements the getFeature operation
|
149 |
* @return
|
150 |
* A result collection
|
151 |
* @param query
|
152 |
* The results query
|
153 |
* @throws Exception
|
154 |
*/
|
155 |
public Feature[] getFeature(Query query) throws Exception { |
156 |
return gazetteerDriver.getFeature(uri, query);
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* @return Returns the lnkIGazetteerDriver.
|
161 |
*/
|
162 |
public IGazetteerServiceDriver getDriver() {
|
163 |
return gazetteerDriver;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* This method is used to create a new Query
|
168 |
* @return
|
169 |
*/
|
170 |
public Query createNewQuery() { |
171 |
return new Query(); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* @return the server protocol
|
176 |
*/
|
177 |
public String getProtocol() { |
178 |
return gazetteerDriver.getServiceName();
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* It tries if the server is ready
|
183 |
* @return boolean
|
184 |
* true --> server is ready
|
185 |
* false --> server is not ready
|
186 |
*/
|
187 |
public boolean serverIsReady() throws ServerIsNotReadyException { |
188 |
Socket sock = null; |
189 |
try {
|
190 |
sock = new Socket(getUri().getHost(), |
191 |
getUri().getPort()); |
192 |
} catch (UnknownHostException e) { |
193 |
throw new ServerIsNotReadyException(e); |
194 |
} catch (IOException e) { |
195 |
throw new ServerIsNotReadyException(e); |
196 |
} |
197 |
return (sock != null); |
198 |
} |
199 |
|
200 |
/**
|
201 |
* @return Returns the serverStatus.
|
202 |
*/
|
203 |
public String getServerStatus() { |
204 |
return serverStatus;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* @return the server URI
|
209 |
*/
|
210 |
private URI getUri() { |
211 |
return uri;
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* @return Return the server URI like a String
|
216 |
*/
|
217 |
public String getSUri() { |
218 |
return uri.toString();
|
219 |
} |
220 |
} |