root / branches / v10 / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 8822
History | View | Annotate | Download (18.9 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.io.IOException; |
5 |
import java.net.ConnectException; |
6 |
import java.net.MalformedURLException; |
7 |
import java.net.URL; |
8 |
import java.util.HashMap; |
9 |
import java.util.Map; |
10 |
import java.util.Vector; |
11 |
|
12 |
import javax.swing.ImageIcon; |
13 |
|
14 |
import org.gvsig.remoteClient.gml.schemas.IXMLType; |
15 |
import org.gvsig.remoteClient.gml.schemas.XMLComplexType; |
16 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
17 |
import org.gvsig.remoteClient.wfs.WFSStatus; |
18 |
import org.gvsig.remoteClient.wfs.filters.FilterEncoding; |
19 |
|
20 |
import com.iver.andami.PluginServices; |
21 |
import com.iver.cit.gvsig.fmap.DriverException; |
22 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
23 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
24 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
25 |
import com.iver.cit.gvsig.fmap.drivers.WFSException; |
26 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver; |
27 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory; |
28 |
import com.iver.cit.gvsig.fmap.drivers.wfs.filters.SQLExpressionFormat; |
29 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
30 |
import com.iver.utiles.StringUtilities; |
31 |
import com.iver.utiles.XMLEntity; |
32 |
|
33 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
34 |
*
|
35 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
36 |
*
|
37 |
* This program is free software; you can redistribute it and/or
|
38 |
* modify it under the terms of the GNU General Public License
|
39 |
* as published by the Free Software Foundation; either version 2
|
40 |
* of the License, or (at your option) any later version.
|
41 |
*
|
42 |
* This program is distributed in the hope that it will be useful,
|
43 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
44 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
45 |
* GNU General Public License for more details.
|
46 |
*
|
47 |
* You should have received a copy of the GNU General Public License
|
48 |
* along with this program; if not, write to the Free Software
|
49 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
50 |
*
|
51 |
* For more information, contact:
|
52 |
*
|
53 |
* Generalitat Valenciana
|
54 |
* Conselleria d'Infraestructures i Transport
|
55 |
* Av. Blasco Ib??ez, 50
|
56 |
* 46010 VALENCIA
|
57 |
* SPAIN
|
58 |
*
|
59 |
* +34 963862235
|
60 |
* gvsig@gva.es
|
61 |
* www.gvsig.gva.es
|
62 |
*
|
63 |
* or
|
64 |
*
|
65 |
* IVER T.I. S.A
|
66 |
* Salamanca 50
|
67 |
* 46005 Valencia
|
68 |
* Spain
|
69 |
*
|
70 |
* +34 963163400
|
71 |
* dac@iver.es
|
72 |
*/
|
73 |
/* CVS MESSAGES:
|
74 |
*
|
75 |
* $Id: FLyrWFS.java 8822 2006-11-16 15:38:51Z jorpiell $
|
76 |
* $Log$
|
77 |
* Revision 1.10.2.6 2006-11-16 15:38:51 jorpiell
|
78 |
* Se han modificado los metodos para guargar y crear un XML a partir de una capa WFS.
|
79 |
*
|
80 |
* Revision 1.10.2.5 2006/11/15 00:08:20 jjdelcerro
|
81 |
* *** empty log message ***
|
82 |
*
|
83 |
* Revision 1.18 2006/10/31 12:24:04 jorpiell
|
84 |
* Comprobado el caso en el que los atributos no tienen tipo
|
85 |
*
|
86 |
* Revision 1.17 2006/10/31 09:55:28 jorpiell
|
87 |
* Se ha modificado el constructor del WFS desde cat?logo
|
88 |
*
|
89 |
* Revision 1.16 2006/10/31 09:38:15 jorpiell
|
90 |
* Se ha creado una factoria para crear la capa. De ese modo no se repite c?digo desde le panel de propiedades y desde el panel de la capa
|
91 |
*
|
92 |
* Revision 1.15 2006/10/23 07:37:04 jorpiell
|
93 |
* Ya funciona el filterEncoding
|
94 |
*
|
95 |
* Revision 1.14 2006/10/10 12:55:06 jorpiell
|
96 |
* Se ha a?adido el soporte de features complejas
|
97 |
*
|
98 |
* Revision 1.13 2006/10/02 12:54:35 jorpiell
|
99 |
* No se pod?a crear un mapa que tubiera la opci?n enlace vivo habilitada
|
100 |
*
|
101 |
* Revision 1.12 2006/10/02 09:09:45 jorpiell
|
102 |
* Cambios del 10 copiados al head
|
103 |
*
|
104 |
* Revision 1.10.2.3 2006/09/29 14:12:53 luisw2
|
105 |
* CRSFactory.getCRS substitutes ProjectionPool.get
|
106 |
*
|
107 |
* Revision 1.10.2.2 2006/09/28 08:54:01 jorpiell
|
108 |
* Ya se puede reproyectar
|
109 |
*
|
110 |
* Revision 1.10.2.1 2006/09/26 07:36:24 jorpiell
|
111 |
* El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
|
112 |
*
|
113 |
* Revision 1.10 2006/09/05 15:41:52 jorpiell
|
114 |
* A?adida la funcionalidad de cargar WFS desde el cat?logo
|
115 |
*
|
116 |
* Revision 1.9 2006/07/05 12:05:41 jorpiell
|
117 |
* Se ha modificado para que avise si se han recuperado las mismas features que marca el campo buffer
|
118 |
*
|
119 |
* Revision 1.8 2006/06/21 12:52:10 jorpiell
|
120 |
* A?adido un icono para la capa WFS
|
121 |
*
|
122 |
* Revision 1.7 2006/06/21 12:35:45 jorpiell
|
123 |
* Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
|
124 |
*
|
125 |
* Revision 1.6 2006/06/15 11:17:06 jorpiell
|
126 |
* Se ha encontrado la forma de comprobar cuando se prodicia un error de parseo al hacer un hasnext (en la feature). Se atrapa y se lanza la excepci?n hacia arriba
|
127 |
*
|
128 |
* Revision 1.5 2006/06/14 07:57:19 jorpiell
|
129 |
* Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
|
130 |
*
|
131 |
* Revision 1.4 2006/06/05 16:49:31 caballero
|
132 |
* poder editar y exportar
|
133 |
*
|
134 |
* Revision 1.3 2006/05/25 10:31:55 jorpiell
|
135 |
* Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
|
136 |
*
|
137 |
* Revision 1.2 2006/05/23 13:21:59 jorpiell
|
138 |
* Si hay alg?n problema en la carga se muestra un mensaje de error
|
139 |
*
|
140 |
* Revision 1.1 2006/05/19 12:54:11 jorpiell
|
141 |
* Creada la capa WFS
|
142 |
*
|
143 |
*
|
144 |
*/
|
145 |
/**
|
146 |
* FMap's WFS Layer class.
|
147 |
*
|
148 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
149 |
*/
|
150 |
public class FLyrWFS extends FLyrVect{ |
151 |
private URL host = null; |
152 |
private String onlineResource = null; |
153 |
private String name = null; |
154 |
private String layerName = null; |
155 |
private String userName = null; |
156 |
private String password = null; |
157 |
private String AttributesQuery = null; |
158 |
private String CoordinatesQuery = null; |
159 |
private XMLElement[] fields = null; |
160 |
private int numfeatures = 100; |
161 |
private int timeout = 10000; |
162 |
private String srs = null; |
163 |
private FMapWFSDriver wfsDriver = null; |
164 |
private VectorialAdapter vectorialAdapter = null; |
165 |
private WFSLayerNode wfsLayerNode = null; |
166 |
|
167 |
/**
|
168 |
* Constructor
|
169 |
*/
|
170 |
public FLyrWFS(){
|
171 |
super();
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Constructor to load a new layer from a catalog
|
176 |
* search
|
177 |
* @param args
|
178 |
* Params to load a new layer
|
179 |
* @throws WFSException
|
180 |
* @throws IOException
|
181 |
* @throws MalformedURLException
|
182 |
* @throws ConnectException
|
183 |
* @throws DriverIOException
|
184 |
*/
|
185 |
public FLyrWFS(Map args) throws WFSException, ConnectException, MalformedURLException, IOException, DriverIOException{ |
186 |
String[] sLayer = (String[])args.get("layer"); |
187 |
String user = (String)args.get("user"); |
188 |
String pwd = (String)args.get("pwd"); |
189 |
String host = (String)args.get("host"); |
190 |
String projection = (String)args.get("projection"); |
191 |
|
192 |
FMapWFSDriver driver = FMapWFSDriverFactory.getFMapDriverForURL(new URL(host)); |
193 |
WFSLayerNode[] layers = driver.getLayerList();
|
194 |
WFSLayerNode layer = driver.getLayerInfo(sLayer[0]);
|
195 |
|
196 |
layer.setSelectedFields(layer.getFields()); |
197 |
|
198 |
Vector vAtts = new Vector(); |
199 |
if (layer.getFields().size() == 1){ |
200 |
XMLElement element = (XMLElement)layer.getFields().get(0);
|
201 |
if (element.getEntityType().getType() != IXMLType.COMPLEX){
|
202 |
vAtts.add(element); |
203 |
}else{
|
204 |
vAtts = ((XMLComplexType)element.getEntityType()).getAttributes(); |
205 |
} |
206 |
} |
207 |
for (int i=0 ; i<layer.getFields().size() ; i++){ |
208 |
XMLElement element = (XMLElement)layer.getFields().get(i); |
209 |
if (element.getEntityType().getType() != IXMLType.COMPLEX){
|
210 |
vAtts.add((XMLElement)layer.getFields().get(i)); |
211 |
}else{
|
212 |
|
213 |
} |
214 |
} |
215 |
|
216 |
XMLElement[] atts = new XMLElement[vAtts.size()]; |
217 |
for (int i=0 ; i<vAtts.size() ; i++){ |
218 |
atts[i] = (XMLElement)vAtts.get(i); |
219 |
} |
220 |
|
221 |
setHost(host); |
222 |
setName(sLayer[0]);
|
223 |
setLayerName(sLayer[0]);
|
224 |
setWfsLayerNode(layer); |
225 |
setFields(atts); |
226 |
setUserName(user); |
227 |
setPassword(pwd); |
228 |
setNumfeatures(10000);
|
229 |
setTimeout(10000);
|
230 |
setWfsDriver(driver); |
231 |
setProjection(CRSFactory.getCRS(projection)); |
232 |
|
233 |
load(); |
234 |
} |
235 |
|
236 |
|
237 |
/**
|
238 |
* Loads the features from the server
|
239 |
*/
|
240 |
public void load() throws DriverIOException{ |
241 |
WFSAdapter adapter = new WFSAdapter();
|
242 |
try {
|
243 |
wfsDriver.getFeature(getWFSStatus()); |
244 |
|
245 |
adapter.setDriver((VectorialDriver) wfsDriver); |
246 |
setSource(adapter); |
247 |
|
248 |
if (getLegend() == null){ |
249 |
setLegend(LegendFactory.createSingleSymbolLegend( |
250 |
getShapeType())); |
251 |
} |
252 |
} catch (Exception e){ |
253 |
e.printStackTrace(); |
254 |
throw new DriverIOException(e.getMessage()); |
255 |
} |
256 |
} |
257 |
|
258 |
/**
|
259 |
* Gets the WFS Status
|
260 |
* @return
|
261 |
*/
|
262 |
private WFSStatus getWFSStatus(){
|
263 |
WFSStatus status = new WFSStatus(getLayerName());
|
264 |
status.setUserName(getUserName()); |
265 |
status.setPassword(getPassword()); |
266 |
status.setBuffer(getNumfeatures()); |
267 |
status.setTimeout(getTimeout()); |
268 |
status.setFields(getFieldNames()); |
269 |
status.setOnlineResource(getOnlineResource()); |
270 |
status.setSrs(getSrs()); |
271 |
//Filter Encoding transformation
|
272 |
FilterEncoding fe = SQLExpressionFormat.createFilter(); |
273 |
fe.setQuery(getAttributesQuery()); |
274 |
status.setFilterQuery(fe.toString()); |
275 |
return status;
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* Adds the vectorial adapter to the layer
|
280 |
* @param vectorialAdapter
|
281 |
*/
|
282 |
public void setSource(VectorialAdapter vectorialAdapter) { |
283 |
this.vectorialAdapter = vectorialAdapter;
|
284 |
super.setSource(vectorialAdapter);
|
285 |
} |
286 |
|
287 |
/**
|
288 |
* @return Returns the layerName.
|
289 |
*/
|
290 |
public String getLayerName() { |
291 |
return layerName;
|
292 |
} |
293 |
/**
|
294 |
* @param layerName The layerName to set.
|
295 |
*/
|
296 |
public void setLayerName(String layerName) { |
297 |
this.layerName = layerName;
|
298 |
} |
299 |
/**
|
300 |
* @return Returns the numfeatures.
|
301 |
*/
|
302 |
public int getNumfeatures() { |
303 |
return numfeatures;
|
304 |
} |
305 |
/**
|
306 |
* @param numfeatures The numfeatures to set.
|
307 |
*/
|
308 |
public void setNumfeatures(int numfeatures) { |
309 |
this.numfeatures = numfeatures;
|
310 |
} |
311 |
|
312 |
/**
|
313 |
* @return Returns the pwd.
|
314 |
*/
|
315 |
public String getPassword() { |
316 |
return password;
|
317 |
} |
318 |
/**
|
319 |
* @param pwd The pwd to set.
|
320 |
*/
|
321 |
public void setPassword(String password) { |
322 |
this.password = password;
|
323 |
} |
324 |
/**
|
325 |
* @return Returns the timeout.
|
326 |
*/
|
327 |
public int getTimeout() { |
328 |
return timeout;
|
329 |
} |
330 |
/**
|
331 |
* @param timeout The timeout to set.
|
332 |
*/
|
333 |
public void setTimeout(int timeout) { |
334 |
this.timeout = timeout;
|
335 |
} |
336 |
/**
|
337 |
* @return Returns the user.
|
338 |
*/
|
339 |
public String getUserName() { |
340 |
return userName;
|
341 |
} |
342 |
/**
|
343 |
* @param user The user to set.
|
344 |
*/
|
345 |
public void setUserName(String userName) { |
346 |
this.userName = userName;
|
347 |
} |
348 |
/**
|
349 |
* @return Returns the fields.
|
350 |
*/
|
351 |
public XMLElement[] getFields() { |
352 |
if (fields == null){ |
353 |
return new XMLElement[0]; |
354 |
} |
355 |
return fields;
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Return the attributes name
|
360 |
* @return
|
361 |
*/
|
362 |
public String[] getFieldNames(){ |
363 |
Vector vAttributes = new Vector(); |
364 |
for (int i=0 ; i<getFields().length ; i++){ |
365 |
if ((getFields()[i].getEntityType() == null) || |
366 |
(getFields()[i].getEntityType().getType() != IXMLType.COMPLEX)){ |
367 |
vAttributes.add(getFields()[i].getName()); |
368 |
} |
369 |
} |
370 |
String[] attributes = new String[vAttributes.size()]; |
371 |
for (int i=0 ; i<vAttributes.size() ; i++){ |
372 |
attributes[i] = (String)vAttributes.get(i);
|
373 |
} |
374 |
return attributes;
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* @param fields The fields to set.
|
379 |
*/
|
380 |
public void setFields(XMLElement[] fields) { |
381 |
this.fields = fields;
|
382 |
} |
383 |
/**
|
384 |
* @return Returns the name.
|
385 |
*/
|
386 |
public String getName() { |
387 |
return name;
|
388 |
} |
389 |
/**
|
390 |
* @param name The name to set.
|
391 |
*/
|
392 |
public void setName(String name) { |
393 |
this.name = name;
|
394 |
} |
395 |
/**
|
396 |
* @return Returns the host.
|
397 |
*/
|
398 |
public URL getHost() { |
399 |
return host;
|
400 |
} |
401 |
/**
|
402 |
* @param host The host to set.
|
403 |
*/
|
404 |
public void setHost(URL host) { |
405 |
this.host = host;
|
406 |
} |
407 |
|
408 |
/**
|
409 |
* @return Returns the wfs.
|
410 |
*/
|
411 |
public FMapWFSDriver getWfsDriver() {
|
412 |
return wfsDriver;
|
413 |
} |
414 |
|
415 |
/**
|
416 |
* @param wfs The wfs to set.
|
417 |
*/
|
418 |
public void setWfsDriver(FMapWFSDriver wfs) { |
419 |
this.wfsDriver = wfs;
|
420 |
} |
421 |
|
422 |
|
423 |
/*
|
424 |
* (non-Javadoc)
|
425 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getStrategy()
|
426 |
*/
|
427 |
// public Strategy getStrategy() {
|
428 |
// if (wfsStrategy == null){
|
429 |
// wfsStrategy = new WFSStrategy(this);
|
430 |
// }
|
431 |
// return wfsStrategy;
|
432 |
// }
|
433 |
|
434 |
/*
|
435 |
* (non-Javadoc)
|
436 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
437 |
*/
|
438 |
public Rectangle2D getFullExtent() throws DriverException { |
439 |
try {
|
440 |
Rectangle2D extent = wfsDriver.getFullExtent();
|
441 |
if (getCoordTrans() != null){ |
442 |
return getCoordTrans().convert(extent);
|
443 |
} |
444 |
return extent;
|
445 |
} catch (IOException e) { |
446 |
throw new DriverException(e.toString()); |
447 |
} |
448 |
} |
449 |
|
450 |
/**
|
451 |
* @return Returns the onlineResource.
|
452 |
*/
|
453 |
public String getOnlineResource() { |
454 |
return onlineResource;
|
455 |
} |
456 |
|
457 |
/**
|
458 |
* @param onlineResource The onlineResource to set.
|
459 |
*/
|
460 |
public void setOnlineResource(String onlineResource) { |
461 |
this.onlineResource = onlineResource;
|
462 |
} |
463 |
|
464 |
public HashMap getProperties() { |
465 |
HashMap info = new HashMap(); |
466 |
info.put("name", getName());
|
467 |
info.put("layerName", getLayerName());
|
468 |
info.put("layerText", getLayerText());
|
469 |
info.put("attributes", getFields());
|
470 |
info.put("host", getHost());
|
471 |
info.put("wfsLayerNode", getWfsLayerNode());
|
472 |
WFSStatus status = new WFSStatus(getLayerName());
|
473 |
status.setBuffer(getNumfeatures()); |
474 |
status.setTimeout(getTimeout()); |
475 |
status.setUserName(getUserName()); |
476 |
status.setPassword(getPassword()); |
477 |
info.put("status",status);
|
478 |
return info;
|
479 |
|
480 |
} |
481 |
|
482 |
/**
|
483 |
* @return Returns the wfsLayerNode.
|
484 |
*/
|
485 |
public WFSLayerNode getWfsLayerNode() {
|
486 |
return wfsLayerNode;
|
487 |
} |
488 |
|
489 |
/**
|
490 |
* @param wfsLayerNode The wfsLayerNode to set.
|
491 |
*/
|
492 |
public void setWfsLayerNode(WFSLayerNode wfsLayerNode) { |
493 |
this.wfsLayerNode = wfsLayerNode;
|
494 |
} |
495 |
|
496 |
public void setHost(String host2) { |
497 |
try {
|
498 |
setHost(new URL(host2)); |
499 |
} catch (MalformedURLException e) { |
500 |
// TODO Auto-generated catch block
|
501 |
e.printStackTrace(); |
502 |
} |
503 |
} |
504 |
|
505 |
public ImageIcon getTocImageIcon() { |
506 |
return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wfs2").getClassLoader().getResource("images/icoLayer.png")); |
507 |
} |
508 |
|
509 |
/*
|
510 |
* (non-Javadoc)
|
511 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrVect#isPropertiesMenuVisible()
|
512 |
*/
|
513 |
public boolean isPropertiesMenuVisible(){ |
514 |
return false; |
515 |
} |
516 |
|
517 |
public String getSrs() { |
518 |
return srs;
|
519 |
} |
520 |
|
521 |
public void setSrs(String srs) { |
522 |
this.srs = srs;
|
523 |
} |
524 |
|
525 |
/**
|
526 |
* @return XMLEntity.
|
527 |
* @throws XMLException
|
528 |
*/
|
529 |
public XMLEntity getXMLEntity() throws XMLException { |
530 |
XMLEntity xml = super.getXMLEntity();
|
531 |
|
532 |
// Full extent
|
533 |
try {
|
534 |
xml.putProperty("fullExtent", StringUtilities.rect2String(getFullExtent()));
|
535 |
} catch (DriverException e) {
|
536 |
// TODO Auto-generated catch block
|
537 |
e.printStackTrace(); |
538 |
} |
539 |
|
540 |
// Host
|
541 |
xml.putProperty("host", host.toExternalForm());
|
542 |
|
543 |
// Layer name
|
544 |
xml.putProperty("layerName", getLayerName());
|
545 |
xml.putProperty("name", getName());
|
546 |
|
547 |
//Layer fields
|
548 |
XMLElement[] fields = getFields();
|
549 |
String strFields = ""; |
550 |
for (int i=0 ; i<fields.length ; i++){ |
551 |
//If is not the root node
|
552 |
if (fields[i].getParentElement() != null){ |
553 |
strFields = strFields + fields[i].getFullName(); |
554 |
if (i < fields.length - 1){ |
555 |
strFields = strFields + "~##SEP1##~";
|
556 |
} |
557 |
}else{
|
558 |
xml.putProperty("rootNode", true); |
559 |
} |
560 |
} |
561 |
xml.putProperty("fields", strFields);
|
562 |
|
563 |
// User name
|
564 |
xml.putProperty("user", getUserName());
|
565 |
|
566 |
// SRS
|
567 |
xml.putProperty("srs", getSrs());
|
568 |
|
569 |
// OnlineResources
|
570 |
xml.putProperty("onlineResource", getOnlineResource());
|
571 |
|
572 |
// TimeOut
|
573 |
xml.putProperty("timeout", getTimeout());
|
574 |
|
575 |
// Buffer
|
576 |
xml.putProperty("buffer", getNumfeatures());
|
577 |
|
578 |
//Projection
|
579 |
xml.putProperty("projection",getProjection().getAbrev());
|
580 |
|
581 |
return xml;
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* @param xml XMLEntity
|
586 |
*
|
587 |
* @throws XMLException
|
588 |
* @throws DriverException
|
589 |
* @throws DriverI OException
|
590 |
*/
|
591 |
public void setXMLEntity(XMLEntity xml)throws XMLException { |
592 |
|
593 |
// Host
|
594 |
try {
|
595 |
host = new URL(xml.getStringProperty("host")); |
596 |
} catch (MalformedURLException e) { |
597 |
throw new XMLException(e); |
598 |
} |
599 |
|
600 |
// Layer name
|
601 |
setLayerName(xml.getStringProperty("layerName"));
|
602 |
setName(xml.getStringProperty("name"));
|
603 |
|
604 |
// User name
|
605 |
if (xml.contains("user")){ |
606 |
setUserName(xml.getStringProperty("user"));
|
607 |
} |
608 |
|
609 |
// SRS
|
610 |
if (xml.contains("srs")){ |
611 |
setSrs(xml.getStringProperty("srs"));
|
612 |
} |
613 |
|
614 |
// OnlineResources
|
615 |
if (xml.contains("onlineResource")){ |
616 |
setOnlineResource(xml.getStringProperty("onlineResource"));
|
617 |
} |
618 |
|
619 |
// TimeOut
|
620 |
if (xml.contains("timeout")){ |
621 |
setTimeout(xml.getIntProperty("timeout"));
|
622 |
} |
623 |
|
624 |
// Buffer
|
625 |
if (xml.contains("buffer")){ |
626 |
setNumfeatures(xml.getIntProperty("buffer"));
|
627 |
} |
628 |
|
629 |
//Projection
|
630 |
if (xml.contains("projection")){ |
631 |
setProjection(CRSFactory.getCRS(xml.getStringProperty("projection")));
|
632 |
} |
633 |
|
634 |
// Layer fields
|
635 |
FMapWFSDriver driver; |
636 |
try {
|
637 |
driver = FMapWFSDriverFactory.getFMapDriverForURL(host); |
638 |
setWfsDriver(driver); |
639 |
WFSAdapter adapter = new WFSAdapter();
|
640 |
adapter.setDriver((VectorialDriver) wfsDriver); |
641 |
setSource(adapter); |
642 |
super.setXMLEntity(xml);
|
643 |
setLegend(LegendFactory.createFromXML(xml.getChild(0)));
|
644 |
} catch (Exception e) { |
645 |
throw new XMLException(e); |
646 |
} |
647 |
driver.getLayerList(); |
648 |
WFSLayerNode layer = driver.getLayerInfo(getLayerName()); |
649 |
XMLElement[] atts = null; |
650 |
|
651 |
// The root element always exists
|
652 |
XMLElement rootElement = (XMLElement)layer.getFields().get(0);
|
653 |
|
654 |
if (xml.contains("fields")) { |
655 |
String[] fields = xml.getStringProperty("fields").split("~##SEP1##~"); |
656 |
if ((fields.length == 1) && (fields[0].equals(""))){ |
657 |
fields = new String[0]; |
658 |
} |
659 |
//The root element always is a complex type
|
660 |
Vector allFields = ((XMLComplexType)rootElement.getEntityType()).getAttributes();
|
661 |
//If the root node has been selected
|
662 |
if (xml.contains("rootNode")){ |
663 |
if (xml.getBooleanProperty("rootNode")==true){ |
664 |
atts = new XMLElement[fields.length + 1]; |
665 |
atts[fields.length] = rootElement; |
666 |
}else{
|
667 |
atts = new XMLElement[fields.length];
|
668 |
} |
669 |
}else{
|
670 |
atts = new XMLElement[fields.length];
|
671 |
} |
672 |
//Adding the other fields
|
673 |
for (int i=0 ; i<fields.length ; i++){ |
674 |
for (int j=0 ; j<allFields.size() ; j++){ |
675 |
XMLElement attribute = (XMLElement)allFields.get(j); |
676 |
if (attribute != null){ |
677 |
XMLElement found = attribute.searchAttribute(fields[i]); |
678 |
if (found != null){ |
679 |
atts[i] = found; |
680 |
break;
|
681 |
} |
682 |
} |
683 |
} |
684 |
} |
685 |
}else{
|
686 |
if (xml.contains("rootNode")){ |
687 |
if (xml.getBooleanProperty("rootNode")==true){ |
688 |
atts = new XMLElement[1]; |
689 |
atts[0] = rootElement;
|
690 |
} |
691 |
} |
692 |
} |
693 |
layer.setSelectedFields(atts); |
694 |
setWfsLayerNode(layer); |
695 |
setFields(atts); |
696 |
setAvailable(true);
|
697 |
} |
698 |
|
699 |
/**
|
700 |
* @return Returns the attributesQuery.
|
701 |
*/
|
702 |
public String getAttributesQuery() { |
703 |
return AttributesQuery;
|
704 |
} |
705 |
|
706 |
/**
|
707 |
* @param attributesQuery The attributesQuery to set.
|
708 |
*/
|
709 |
public void setAttributesQuery(String attributesQuery) { |
710 |
AttributesQuery = attributesQuery; |
711 |
} |
712 |
|
713 |
/**
|
714 |
* @return Returns the coordinatesQuery.
|
715 |
*/
|
716 |
public String getCoordinatesQuery() { |
717 |
return CoordinatesQuery;
|
718 |
} |
719 |
|
720 |
/**
|
721 |
* @param coordinatesQuery The coordinatesQuery to set.
|
722 |
*/
|
723 |
public void setCoordinatesQuery(String coordinatesQuery) { |
724 |
CoordinatesQuery = coordinatesQuery; |
725 |
} |
726 |
} |