root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / wfs / WFSServerExplorer.java @ 416
History | View | Annotate | Download (10 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.serverexplorer.wfs; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.FileNotFoundException; |
32 |
import java.io.IOException; |
33 |
import java.net.ConnectException; |
34 |
import java.util.ArrayList; |
35 |
import java.util.Hashtable; |
36 |
import java.util.Iterator; |
37 |
import java.util.List; |
38 |
|
39 |
import org.gvsig.fmap.dal.DALLocator; |
40 |
import org.gvsig.fmap.dal.DataManager; |
41 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
42 |
import org.gvsig.fmap.dal.DataStoreParameters; |
43 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
44 |
import org.gvsig.fmap.dal.exception.DataException; |
45 |
import org.gvsig.fmap.dal.exception.InitializeException; |
46 |
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer; |
47 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
48 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
49 |
import org.gvsig.fmap.dal.store.wfs.WFSFeatureFiller; |
50 |
import org.gvsig.fmap.dal.store.wfs.WFSOpenStoreParameters; |
51 |
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider; |
52 |
import org.gvsig.remoteclient.wfs.WFSClient; |
53 |
import org.gvsig.remoteclient.wfs.WFSFeature; |
54 |
import org.gvsig.remoteclient.wfs.WFSStatus; |
55 |
import org.gvsig.remoteclient.wfs.exceptions.WFSException; |
56 |
import org.gvsig.tools.exception.BaseException; |
57 |
import org.gvsig.xmlschema.lib.api.exceptions.SchemaCreationException; |
58 |
|
59 |
/**
|
60 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
61 |
*/
|
62 |
public class WFSServerExplorer extends AbstractDataServerExplorer implements |
63 |
DataServerExplorerProvider { |
64 |
public static final String NAME = "WFSServerExplorer"; |
65 |
// private WFSServerExplorerParameters parameters = null;
|
66 |
private DataManager dataManager = DALLocator.getDataManager();
|
67 |
private String url = null; |
68 |
|
69 |
//WFS Parameters
|
70 |
private WFSStatus status = null; |
71 |
private WFSClient wfsClient = null; |
72 |
|
73 |
/**
|
74 |
* @param parameters
|
75 |
*/
|
76 |
public WFSServerExplorer(WFSServerExplorerParameters parameters, DataServerExplorerProviderServices services) throws InitializeException{ |
77 |
super(parameters, services);
|
78 |
// this.parameters = parameters;
|
79 |
this.url = parameters.getUrl();
|
80 |
if (wfsClient == null){ |
81 |
try {
|
82 |
wfsClient = new WFSClient(url, parameters.getIgnoreChace());
|
83 |
if (status == null){ |
84 |
status = new WFSStatus(null); |
85 |
} |
86 |
|
87 |
wfsClient.getCapabilities(status, parameters.getIgnoreChace(), null);
|
88 |
} catch (ConnectException e) { |
89 |
throw new InitializeException("Not possible to connect with " + url, e); |
90 |
} catch (IOException e) { |
91 |
throw new InitializeException("Not possible to connect with " + url, e); |
92 |
} catch (WFSException e) {
|
93 |
throw new InitializeException("Not possible to connect with " + url, e); |
94 |
} |
95 |
} |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Returns all the feature information retrieved using a
|
100 |
* describeFeatureTypeOpearion
|
101 |
* @param nameSpace
|
102 |
* @param layerName
|
103 |
* Feature name
|
104 |
* @return
|
105 |
* @throws WFSException
|
106 |
*/
|
107 |
public WFSFeature getFeatureInfo(String nameSpace, String layerName) throws WFSException{ |
108 |
status = new WFSStatus(layerName, nameSpace);
|
109 |
WFSFeature feature = (WFSFeature) wfsClient.getFeature(nameSpace, layerName); |
110 |
if (!feature.isCompleted()){
|
111 |
File describeFeatureTypeFile = wfsClient.describeFeatureType(status, getParameters().getIgnoreChace(), null); |
112 |
|
113 |
WFSFeatureFiller featureFiller = new WFSFeatureFiller(feature);
|
114 |
try {
|
115 |
featureFiller.fill(describeFeatureTypeFile); |
116 |
} catch (SchemaCreationException e) {
|
117 |
throw new WFSException(e); |
118 |
} catch (FileNotFoundException e) { |
119 |
throw new WFSException(e); |
120 |
} |
121 |
} |
122 |
|
123 |
return feature;
|
124 |
} |
125 |
|
126 |
|
127 |
|
128 |
/**
|
129 |
* Returns an array of WFSLayerNode's with the descriptors of
|
130 |
* all features (retrieved using the getCapabilities operation)
|
131 |
* @return WFSLayerNode[]
|
132 |
*/
|
133 |
public Hashtable getFeatures(){ |
134 |
return wfsClient.getFeatures();
|
135 |
} |
136 |
|
137 |
/* (non-Javadoc)
|
138 |
* @see org.gvsig.fmap.dal.DataServerExplorer#add(org.gvsig.fmap.dal.NewDataStoreParameters, boolean)
|
139 |
*/
|
140 |
public boolean add(String providerName, NewDataStoreParameters parameters, boolean overwrite) |
141 |
throws DataException {
|
142 |
// TODO Auto-generated method stub
|
143 |
return false; |
144 |
} |
145 |
|
146 |
/* (non-Javadoc)
|
147 |
* @see org.gvsig.fmap.dal.DataServerExplorer#canAdd()
|
148 |
*/
|
149 |
public boolean canAdd() { |
150 |
// TODO Auto-generated method stub
|
151 |
return false; |
152 |
} |
153 |
|
154 |
/* (non-Javadoc)
|
155 |
* @see org.gvsig.fmap.dal.DataServerExplorer#canAdd(java.lang.String)
|
156 |
*/
|
157 |
public boolean canAdd(String storeName) throws DataException { |
158 |
// TODO Auto-generated method stub
|
159 |
return false; |
160 |
} |
161 |
|
162 |
@Override
|
163 |
protected void doDispose() throws BaseException { |
164 |
// Nothing to do
|
165 |
} |
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see org.gvsig.fmap.dal.DataServerExplorer#getAddParameters(java.lang.String)
|
169 |
*/
|
170 |
public NewDataStoreParameters getAddParameters(String storeName) |
171 |
throws DataException {
|
172 |
// TODO Auto-generated method stub
|
173 |
return null; |
174 |
} |
175 |
|
176 |
/* (non-Javadoc)
|
177 |
* @see org.gvsig.fmap.dal.DataServerExplorer#getName()
|
178 |
*/
|
179 |
public String getProviderName() { |
180 |
return NAME;
|
181 |
} |
182 |
|
183 |
/* (non-Javadoc)
|
184 |
* @see org.gvsig.fmap.dal.DataServerExplorer#getParameters()
|
185 |
*/
|
186 |
@Override
|
187 |
public WFSServerExplorerParameters getParameters() {
|
188 |
return (WFSServerExplorerParameters) super.getParameters(); |
189 |
} |
190 |
|
191 |
/* (non-Javadoc)
|
192 |
* @see org.gvsig.fmap.dal.DataServerExplorer#list()
|
193 |
*/
|
194 |
public List list() throws DataException { |
195 |
ArrayList list = new ArrayList(); |
196 |
Hashtable features = wfsClient.getFeatures();
|
197 |
Iterator it = features.keySet().iterator();
|
198 |
DataStoreParameters dsp = null;
|
199 |
while (it.hasNext()){
|
200 |
String key = (String)it.next(); |
201 |
WFSFeature feature = (WFSFeature)features.get(key); |
202 |
list.add(getParametersFor(feature)); |
203 |
} |
204 |
return list;
|
205 |
} |
206 |
|
207 |
public DataStoreParameters getParametersFor(WFSFeature feature)
|
208 |
throws DataException {
|
209 |
WFSOpenStoreParameters params = (WFSOpenStoreParameters)dataManager |
210 |
.createStoreParameters(WFSStoreProvider.NAME); |
211 |
params.setUrl(url); |
212 |
params.setFeatureType(feature.getNamespace().getPrefix(), |
213 |
feature.getNamespace().getLocation(), |
214 |
feature.getName()); |
215 |
return params;
|
216 |
} |
217 |
|
218 |
/* (non-Javadoc)
|
219 |
* @see org.gvsig.fmap.dal.DataServerExplorer#list(int)
|
220 |
*/
|
221 |
public List list(int mode) throws DataException { |
222 |
return list();
|
223 |
} |
224 |
|
225 |
/* (non-Javadoc)
|
226 |
* @see org.gvsig.fmap.dal.DataServerExplorer#remove(org.gvsig.fmap.dal.DataStoreParameters)
|
227 |
*/
|
228 |
public void remove(DataStoreParameters parameters) throws DataException { |
229 |
// TODO Auto-generated method stub
|
230 |
|
231 |
} |
232 |
|
233 |
/* (non-Javadoc)
|
234 |
* @see org.gvsig.fmap.dal.spi.DataServerExplorerProvider#getServerExplorerProviderServices()
|
235 |
*/
|
236 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() {
|
237 |
// TODO Auto-generated method stub
|
238 |
return null; |
239 |
} |
240 |
|
241 |
/* (non-Javadoc)
|
242 |
* @see org.gvsig.fmap.dal.spi.DataServerExplorerProvider#initialize(org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices)
|
243 |
*/
|
244 |
public void initialize( |
245 |
DataServerExplorerProviderServices dataServerExplorerProviderServices) { |
246 |
// TODO Auto-generated method stub
|
247 |
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* @return
|
252 |
*/
|
253 |
public String getTitle() { |
254 |
String title = wfsClient.getServiceInformation().title;
|
255 |
if (title == null){ |
256 |
return "None"; |
257 |
} |
258 |
return title;
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* @return
|
263 |
*/
|
264 |
public String getAbstract() { |
265 |
String _abstract = wfsClient.getServiceInformation().abstr;
|
266 |
if (_abstract == null){ |
267 |
return "None"; |
268 |
} |
269 |
return _abstract;
|
270 |
} |
271 |
|
272 |
/**
|
273 |
* @return
|
274 |
*/
|
275 |
public String getServerType() { |
276 |
String serverVersion = wfsClient.getVersion();
|
277 |
if (serverVersion == null) { |
278 |
return "WFS"; |
279 |
} |
280 |
return "WFS "+ serverVersion; |
281 |
} |
282 |
|
283 |
/**
|
284 |
* @return
|
285 |
*/
|
286 |
public String getUrl() { |
287 |
return wfsClient.getHost();
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* @return
|
292 |
*/
|
293 |
public int getMaxFeatures() { |
294 |
return status.getMaxFeatures();
|
295 |
} |
296 |
|
297 |
/**
|
298 |
* @return
|
299 |
*/
|
300 |
public int getTimeOut() { |
301 |
return status.getTimeout();
|
302 |
} |
303 |
|
304 |
/**
|
305 |
* @param userName
|
306 |
*/
|
307 |
public void setUserName(String userName) { |
308 |
status.setUserName(userName); |
309 |
} |
310 |
|
311 |
/**
|
312 |
* @param buffer
|
313 |
*/
|
314 |
public void setMaxFeatures(int buffer) { |
315 |
status.setMaxFeatures(buffer); |
316 |
} |
317 |
|
318 |
/**
|
319 |
* @param timeout
|
320 |
*/
|
321 |
public void setTimeOut(int timeout) { |
322 |
status.setTimeout(timeout); |
323 |
} |
324 |
|
325 |
/**
|
326 |
* @return
|
327 |
*/
|
328 |
public String getVersion() { |
329 |
return wfsClient.getVersion();
|
330 |
} |
331 |
|
332 |
public List getDataStoreProviderNames() { |
333 |
List x = new ArrayList(); |
334 |
x.add(WFSStoreProvider.NAME); |
335 |
return x;
|
336 |
} |
337 |
} |