svn-gvsig-desktop / branches / MULTITHREADING_DEVELOPMENT / libraries / libRemoteServices / src / org / gvsig / remoteClient / wms / WMSLayer.java @ 5292
History | View | Annotate | Download (14 KB)
1 | 3323 | ldiaz | package org.gvsig.remoteClient.wms; |
---|---|---|---|
2 | |||
3 | import java.io.IOException; |
||
4 | 3377 | ldiaz | import java.util.ArrayList; |
5 | 3341 | ldiaz | import java.util.Hashtable; |
6 | 3457 | ldiaz | import java.util.TreeMap; |
7 | 3323 | ldiaz | import java.util.Vector; |
8 | |||
9 | 3341 | ldiaz | import org.gvsig.remoteClient.utils.BoundaryBox; |
10 | 3755 | ldiaz | import org.gvsig.remoteClient.utils.CapabilitiesTags; |
11 | 3323 | ldiaz | import org.kxml2.io.KXmlParser; |
12 | import org.xmlpull.v1.XmlPullParserException; |
||
13 | |||
14 | /**
|
||
15 | * <p>Abstract class that defines an WMSLayer.</p>
|
||
16 | *
|
||
17 | */
|
||
18 | public abstract class WMSLayer implements org.gvsig.remoteClient.ILayer { |
||
19 | 3483 | jaume | |
20 | protected ArrayList children; |
||
21 | 3523 | jaume | protected WMSLayer parent;
|
22 | 3483 | jaume | |
23 | /**
|
||
24 | * <p>Layer Abstract field in the capabilities document </p>
|
||
25 | */
|
||
26 | 3323 | ldiaz | private String layerAbstract; |
27 | 3483 | jaume | |
28 | /**
|
||
29 | * <p>Themes provided by the WMS for the layer</p>
|
||
30 | */
|
||
31 | 3520 | jaume | public ArrayList styles = new ArrayList(); |
32 | 3323 | ldiaz | |
33 | 3483 | jaume | /**
|
34 | * <p>Layer name</p>
|
||
35 | */
|
||
36 | 3323 | ldiaz | private String name; |
37 | 3483 | jaume | |
38 | /**
|
||
39 | * <p>Layer title</p>
|
||
40 | */
|
||
41 | 3323 | ldiaz | private String title; |
42 | 3483 | jaume | |
43 | 3750 | ldiaz | private ArrayList keywordList = new ArrayList(); |
44 | 3483 | jaume | /**
|
45 | * <p>Layer srs.</p>
|
||
46 | */
|
||
47 | 4222 | jaume | protected Vector srs = new Vector(); |
48 | 3483 | jaume | |
49 | /**
|
||
50 | * <p>extents for each srs the layer can be reproyected to</p>
|
||
51 | */
|
||
52 | 3523 | jaume | private Hashtable bBoxes = new Hashtable(); |
53 | 3341 | ldiaz | |
54 | 3483 | jaume | /**
|
55 | * <p>extents that defines the bbox for the LatLon projection
|
||
56 | * It can be included in the bBoxes vector as well, because it is the most used, we keep it separeted too, according
|
||
57 | * with the OGC WMSCapabilities specifications...
|
||
58 | */
|
||
59 | 3341 | ldiaz | private org.gvsig.remoteClient.utils.BoundaryBox latLonBbox;
|
60 | 3483 | jaume | |
61 | /**
|
||
62 | * <p>min scale for the layer to be visible</p>
|
||
63 | */
|
||
64 | 3323 | ldiaz | private double scaleMin; |
65 | 3483 | jaume | |
66 | /**
|
||
67 | * <p>max scale for the layer to be visible</p>
|
||
68 | */
|
||
69 | 3323 | ldiaz | private double scaleMax; |
70 | 3483 | jaume | |
71 | /**
|
||
72 | * <p>Dimensions defined for the layer in the capabilities doc</p>
|
||
73 | */
|
||
74 | 4314 | ldiaz | protected java.util.ArrayList dimensions = new ArrayList(); |
75 | |||
76 | 3483 | jaume | /**
|
77 | * Tells if this layer accepts getFeatureInfo requests.
|
||
78 | */
|
||
79 | 4301 | ldiaz | private boolean queryable = false; |
80 | 3750 | ldiaz | |
81 | 3505 | jaume | /**
|
82 | 3750 | ldiaz | * Tells if this layer is opaque.
|
83 | */
|
||
84 | private boolean opaque = false; |
||
85 | /**
|
||
86 | * when set to true, noSubsets indicates that the server is not able to make a map
|
||
87 | * of a geographic area other than the layer's bounding box.
|
||
88 | */
|
||
89 | private boolean m_noSubSets = false; |
||
90 | |||
91 | /**
|
||
92 | * when present and non-zero fixedWidth and fixedHeight indicate that the server is not
|
||
93 | * able to produce a map of the layer at a width and height different from the fixed sizes indicated.
|
||
94 | */
|
||
95 | 4222 | jaume | private int fixedWidth = 0; |
96 | private int fixedHeight = 0; |
||
97 | 3750 | ldiaz | |
98 | /**
|
||
99 | 3505 | jaume | * Tells if this layer can be served with transparency.
|
100 | */
|
||
101 | private boolean transparency; |
||
102 | 3341 | ldiaz | |
103 | 3323 | ldiaz | /**
|
104 | * <p>Parses the LAYER tag in the WMS capabilities, filling the WMSLayer object
|
||
105 | * loading the data in memory to be easily accesed</p>
|
||
106 | *
|
||
107 | */
|
||
108 | 3483 | jaume | public abstract void parse(KXmlParser parser, TreeMap layerTreeMap) |
109 | throws IOException, XmlPullParserException; |
||
110 | |||
111 | 4314 | ldiaz | //public abstract ArrayList getAllDimensions();
|
112 | 3483 | jaume | |
113 | 3755 | ldiaz | /**
|
114 | * add a new keyword to the keywordList.
|
||
115 | * @param key
|
||
116 | */
|
||
117 | 3750 | ldiaz | protected void addkeyword(String key) |
118 | { |
||
119 | keywordList.add(key); |
||
120 | } |
||
121 | public ArrayList getKeywords() |
||
122 | { |
||
123 | return keywordList;
|
||
124 | } |
||
125 | 3483 | jaume | /**
|
126 | * <p>Adds a style to the styles vector</p>
|
||
127 | * @param _style
|
||
128 | */
|
||
129 | 3323 | ldiaz | public void addStyle(org.gvsig.remoteClient.wms.WMSStyle _style) { |
130 | 3520 | jaume | styles.add( _style ); } |
131 | 3483 | jaume | |
132 | 3520 | jaume | /**
|
133 | 3483 | jaume | * <p>Gets the style vector</p>
|
134 | * @return
|
||
135 | */
|
||
136 | 3779 | ldiaz | public ArrayList getStyles() { |
137 | 3780 | ldiaz | ArrayList list = new ArrayList(); |
138 | if (styles != null) |
||
139 | list.addAll(styles); |
||
140 | 3779 | ldiaz | if (this.getParent()!= null) |
141 | { |
||
142 | 3780 | ldiaz | //return getAllStyles(this);
|
143 | if(this.getParent().getStyles() != null) |
||
144 | list.addAll(this.getParent().getStyles());
|
||
145 | 3779 | ldiaz | } |
146 | 3780 | ldiaz | return list;
|
147 | 3323 | ldiaz | } |
148 | 3483 | jaume | |
149 | 3779 | ldiaz | public ArrayList getAllStyles(WMSLayer layer) |
150 | { |
||
151 | if (layer.getParent()!= null) |
||
152 | { |
||
153 | ArrayList list = getAllStyles(layer.getParent());
|
||
154 | for(int i = 0; i < this.styles.size(); i++) |
||
155 | { |
||
156 | 3780 | ldiaz | list.add(styles.get(i)); |
157 | 3779 | ldiaz | } |
158 | return list;
|
||
159 | } |
||
160 | else
|
||
161 | { |
||
162 | return styles;
|
||
163 | } |
||
164 | } |
||
165 | 3341 | ldiaz | /**
|
166 | * <p>Adds a bbox to the Bboxes vector</p>
|
||
167 | * @param bbox
|
||
168 | */
|
||
169 | 3523 | jaume | public void addBBox(BoundaryBox bbox) { |
170 | 3483 | jaume | bBoxes.put(bbox.getSrs(), bbox); |
171 | } |
||
172 | |||
173 | 3341 | ldiaz | /**
|
174 | * <p>returns the bbox with that id in the Bboxes vector</p>
|
||
175 | * @param id
|
||
176 | */
|
||
177 | 3523 | jaume | public BoundaryBox getBbox(String id) { |
178 | 3824 | ldiaz | if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0) |
179 | ||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0))
|
||
180 | { |
||
181 | if (latLonBbox != null) |
||
182 | return (BoundaryBox)latLonBbox;
|
||
183 | } |
||
184 | 3523 | jaume | BoundaryBox b = (BoundaryBox) bBoxes.get(id); |
185 | if (b == null && parent!=null) |
||
186 | return parent.getBbox(id);
|
||
187 | 3483 | jaume | return (BoundaryBox)bBoxes.get(id);
|
188 | } |
||
189 | |||
190 | 3341 | ldiaz | /**
|
191 | * <p>Gets the bBoxes vector</p>
|
||
192 | * @return
|
||
193 | */
|
||
194 | 3523 | jaume | public Hashtable getBboxes() { |
195 | 3483 | jaume | return bBoxes;
|
196 | } |
||
197 | 3341 | ldiaz | |
198 | 3483 | jaume | |
199 | 3341 | ldiaz | //Methods to manipulate the box that defines the layer extent in LatLon SRS.
|
200 | 3483 | jaume | public BoundaryBox getLatLonBox()
|
201 | { |
||
202 | return latLonBbox;
|
||
203 | } |
||
204 | public void setLatLonBox(BoundaryBox box) |
||
205 | { |
||
206 | latLonBbox = box; |
||
207 | } |
||
208 | 3341 | ldiaz | /**
|
209 | * <p>adds a new srs to the srs vector</p>
|
||
210 | */
|
||
211 | public void addSrs(String srs) |
||
212 | { |
||
213 | 4222 | jaume | if (!this.srs.contains(srs)) |
214 | this.srs.add(srs);
|
||
215 | 3341 | ldiaz | } |
216 | |||
217 | public Vector getAllSrs() |
||
218 | 3655 | jaume | { |
219 | Vector mySRSs = (Vector) this.srs.clone(); |
||
220 | if (parent!=null) |
||
221 | mySRSs.addAll(parent.getAllSrs()); |
||
222 | return mySRSs;
|
||
223 | 4222 | jaume | |
224 | // if (this.getParent()!= null)
|
||
225 | // {
|
||
226 | // Vector list = this.getParent().getAllSrs();
|
||
227 | // for(int i = 0; i < this.srs.size(); i++)
|
||
228 | // {
|
||
229 | // list.add(srs.get(i));
|
||
230 | // }
|
||
231 | // return list;
|
||
232 | // }
|
||
233 | // else
|
||
234 | // {
|
||
235 | // return srs;
|
||
236 | // }
|
||
237 | |||
238 | 3341 | ldiaz | } |
239 | 3483 | jaume | /**
|
240 | * <p>gets the maximum scale for this layer</p>
|
||
241 | * @return
|
||
242 | */
|
||
243 | 3323 | ldiaz | public double getScaleMax() { |
244 | return scaleMax;
|
||
245 | } |
||
246 | 3483 | jaume | |
247 | /**
|
||
248 | * <p>gets the minimum scale for this layer</p>
|
||
249 | * @return
|
||
250 | */
|
||
251 | 3323 | ldiaz | public double getScaleMin() { |
252 | return scaleMin;
|
||
253 | } |
||
254 | 3483 | jaume | |
255 | /**
|
||
256 | * <p>sets the minimum scale for this layer to be visible.</p>
|
||
257 | *
|
||
258 | * @param scale
|
||
259 | */
|
||
260 | 3323 | ldiaz | public void setScaleMin(double scale) { |
261 | scaleMin = scale; |
||
262 | } |
||
263 | 3483 | jaume | |
264 | /**
|
||
265 | * <p>sets the maximum scale for this layer to be visible</p>
|
||
266 | * @param scale
|
||
267 | */
|
||
268 | 3323 | ldiaz | public void setScaleMax(double scale) { |
269 | scaleMax = scale; |
||
270 | } |
||
271 | 4314 | ldiaz | |
272 | 3483 | jaume | /**
|
273 | * <p> gets the dimension vector defined in this layer</p>
|
||
274 | * @return
|
||
275 | */
|
||
276 | 4314 | ldiaz | public abstract ArrayList getDimensions(); |
277 | // public ArrayList getDimensions() {
|
||
278 | // return dimensions;
|
||
279 | // }
|
||
280 | 3483 | jaume | |
281 | 4314 | ldiaz | public WMSDimension getDimension(String name) |
282 | { |
||
283 | for(int i = 0; i < dimensions.size(); i++ ){ |
||
284 | if(((WMSDimension)dimensions.get(i)).getName().compareTo(name)==0) |
||
285 | { |
||
286 | return (WMSDimension)dimensions.get(i);
|
||
287 | } |
||
288 | } |
||
289 | return null; |
||
290 | } |
||
291 | |||
292 | 3537 | jaume | // /**
|
293 | // * <p>Sets the dimension vector defined for this layer</p>
|
||
294 | // * @param v
|
||
295 | // */
|
||
296 | // public void setDimensions(ArrayList v) {
|
||
297 | // dimensions = (ArrayList)v.clone();
|
||
298 | // }
|
||
299 | 3483 | jaume | |
300 | /**
|
||
301 | * <p>Adds a dimension to the dimension vector </p>
|
||
302 | * @param dimension
|
||
303 | */
|
||
304 | 3520 | jaume | public void addDimension(org.gvsig.remoteClient.wms.WMSDimension dimension) { |
305 | 3535 | jaume | dimensions.add(dimension); |
306 | 3323 | ldiaz | } |
307 | 4314 | ldiaz | |
308 | 3483 | jaume | /**
|
309 | * <p>Gets layer name</p>
|
||
310 | * @return
|
||
311 | */
|
||
312 | 3323 | ldiaz | public String getName() { |
313 | 3341 | ldiaz | return this.name; |
314 | 3323 | ldiaz | } |
315 | 3483 | jaume | |
316 | /**
|
||
317 | * <p>Sets layer name</p>
|
||
318 | * @param _name
|
||
319 | */
|
||
320 | 3341 | ldiaz | public void setName(String name) { |
321 | this.name = name;
|
||
322 | 3323 | ldiaz | } |
323 | 3483 | jaume | |
324 | /**
|
||
325 | * <p>Gets layer title</p>
|
||
326 | * @return
|
||
327 | */
|
||
328 | 3323 | ldiaz | public String getTitle() { |
329 | return title;
|
||
330 | } |
||
331 | 3483 | jaume | |
332 | /**
|
||
333 | * <p>Sets the layer title</p>
|
||
334 | * @param _title
|
||
335 | */
|
||
336 | 3341 | ldiaz | public void setTitle(String title) { |
337 | this.title = title;
|
||
338 | 3323 | ldiaz | } |
339 | 3483 | jaume | |
340 | /**
|
||
341 | * <p>Gets the layer abstract</p>
|
||
342 | * @return
|
||
343 | */
|
||
344 | 3323 | ldiaz | public String getAbstract() { |
345 | return layerAbstract;
|
||
346 | } |
||
347 | 3483 | jaume | |
348 | /**
|
||
349 | * <p>Sets the layer abstract</p>
|
||
350 | * @param m_abstract
|
||
351 | */
|
||
352 | 3323 | ldiaz | public void setAbstract(String _abstract) { |
353 | layerAbstract = _abstract; |
||
354 | 3377 | ldiaz | } |
355 | 3403 | jaume | |
356 | |||
357 | public ArrayList getChildren() { |
||
358 | 3483 | jaume | return children;
|
359 | 3403 | jaume | } |
360 | |||
361 | |||
362 | public void setChildren(ArrayList children) { |
||
363 | 3483 | jaume | this.children = children;
|
364 | 3403 | jaume | } |
365 | |||
366 | |||
367 | 3523 | jaume | public WMSLayer getParent() {
|
368 | 3483 | jaume | return parent;
|
369 | 3403 | jaume | } |
370 | |||
371 | |||
372 | 3660 | ldiaz | public void setParent(WMSLayer parent) { |
373 | 3483 | jaume | this.parent = parent;
|
374 | 3403 | jaume | } |
375 | |||
376 | public String toString(){ |
||
377 | 3483 | jaume | return this.getTitle(); |
378 | 3403 | jaume | } |
379 | 3520 | jaume | |
380 | 3483 | jaume | |
381 | /**
|
||
382 | * Tells if this layer accepts getFeatureInfo requests.
|
||
383 | */
|
||
384 | public boolean isQueryable() { |
||
385 | return queryable;
|
||
386 | } |
||
387 | |||
388 | |||
389 | /**
|
||
390 | * @param queryable The queryable to set.
|
||
391 | */
|
||
392 | public void setQueryable(boolean queryable) { |
||
393 | this.queryable = queryable;
|
||
394 | } |
||
395 | 3505 | jaume | |
396 | /**
|
||
397 | 3750 | ldiaz | * Tells if this layer is opaque.
|
398 | */
|
||
399 | public boolean isOpaque() { |
||
400 | return opaque;
|
||
401 | } |
||
402 | /**
|
||
403 | * @param opaque.
|
||
404 | */
|
||
405 | public void setOpaque(boolean opaque) { |
||
406 | this.opaque = opaque;
|
||
407 | } |
||
408 | |||
409 | /**
|
||
410 | * Tells if this layer is subsettable
|
||
411 | */
|
||
412 | public boolean noSubSets() { |
||
413 | return this.m_noSubSets; |
||
414 | } |
||
415 | /**
|
||
416 | * @param set layer nosubsets attribute.
|
||
417 | */
|
||
418 | public void setNoSubSets(boolean _noSubSets) { |
||
419 | m_noSubSets = _noSubSets; |
||
420 | } |
||
421 | |||
422 | 4222 | jaume | public void setfixedWidth(int w) { |
423 | 3750 | ldiaz | fixedWidth = w; |
424 | } |
||
425 | |||
426 | 4222 | jaume | public int getfixedWidth() { |
427 | 3750 | ldiaz | return fixedWidth;
|
428 | } |
||
429 | |||
430 | 4222 | jaume | public void setfixedHeight(int h) { |
431 | 3750 | ldiaz | fixedHeight = h; |
432 | } |
||
433 | |||
434 | 4222 | jaume | public int getfixedHeight() { |
435 | 3750 | ldiaz | return fixedHeight;
|
436 | } |
||
437 | |||
438 | /**
|
||
439 | 3505 | jaume | * @return <b>true</b> if this layer can be served with transparency, otherwise <b>false</b>
|
440 | */
|
||
441 | public boolean hasTransparency() { |
||
442 | return transparency;
|
||
443 | } |
||
444 | 3750 | ldiaz | |
445 | 3755 | ldiaz | //Methods to parse tags that are common to several versions of WMS.
|
446 | //In case there is a version which has different implemantation of one of this tags
|
||
447 | // the subclass can overwrite this method
|
||
448 | |||
449 | 3750 | ldiaz | /**
|
450 | 3755 | ldiaz | * Parses the keywordlist from the capabilities and fills this list in the WMSLayer.
|
451 | * @param parser
|
||
452 | */
|
||
453 | protected void parseKeywordList(KXmlParser parser) throws IOException, XmlPullParserException |
||
454 | { |
||
455 | int currentTag;
|
||
456 | boolean end = false; |
||
457 | String value;
|
||
458 | |||
459 | parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
|
||
460 | currentTag = parser.nextTag(); |
||
461 | |||
462 | while (!end)
|
||
463 | { |
||
464 | switch(currentTag)
|
||
465 | { |
||
466 | case KXmlParser.START_TAG:
|
||
467 | if (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0) |
||
468 | { |
||
469 | value = parser.nextText(); |
||
470 | if ((value != null) && (value.length() > 0 )) |
||
471 | addkeyword(value); |
||
472 | } |
||
473 | break;
|
||
474 | case KXmlParser.END_TAG:
|
||
475 | if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0) |
||
476 | end = true;
|
||
477 | break;
|
||
478 | case KXmlParser.TEXT:
|
||
479 | break;
|
||
480 | } |
||
481 | if (!end)
|
||
482 | { |
||
483 | currentTag = parser.next(); |
||
484 | } |
||
485 | } |
||
486 | parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.KEYWORDLIST);
|
||
487 | } |
||
488 | |||
489 | /**
|
||
490 | * Reads and parses the layer attributes
|
||
491 | * Maybe this method should be moved to the WMSLayer. Until now the attributes are teh same for all versions.
|
||
492 | * @param parser
|
||
493 | */
|
||
494 | protected void readLayerAttributes(KXmlParser parser) |
||
495 | { |
||
496 | String value = new String(); |
||
497 | |||
498 | //First of all set whether the layer is Queryable reading the attribute.
|
||
499 | value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
|
||
500 | if (value != null) |
||
501 | { |
||
502 | if (value.compareTo("0")==0) |
||
503 | setQueryable(false);
|
||
504 | else
|
||
505 | setQueryable(true);
|
||
506 | } |
||
507 | value = parser.getAttributeValue("", CapabilitiesTags.OPAQUE);
|
||
508 | if (value != null) |
||
509 | { |
||
510 | if (value.compareTo("0")==0) |
||
511 | setOpaque(false);
|
||
512 | else
|
||
513 | setOpaque(true);
|
||
514 | } |
||
515 | value = parser.getAttributeValue("", CapabilitiesTags.NOSUBSETS);
|
||
516 | if (value != null) |
||
517 | { |
||
518 | if (value.compareTo("0")==0) |
||
519 | setNoSubSets(false);
|
||
520 | else
|
||
521 | setNoSubSets(true);
|
||
522 | } |
||
523 | value = parser.getAttributeValue("", CapabilitiesTags.FIXEDWIDTH);
|
||
524 | if (value != null) |
||
525 | { |
||
526 | 4222 | jaume | setfixedWidth(Integer.parseInt(value));
|
527 | 3755 | ldiaz | } |
528 | value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
|
||
529 | if (value != null) |
||
530 | { |
||
531 | 4222 | jaume | setfixedHeight(Integer.parseInt(value));
|
532 | 3755 | ldiaz | } |
533 | } |
||
534 | |||
535 | |||
536 | /**
|
||
537 | 3750 | ldiaz | * <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
|
538 | *
|
||
539 | */
|
||
540 | protected class MetadataURL |
||
541 | { |
||
542 | public MetadataURL()
|
||
543 | { |
||
544 | type = new String(); |
||
545 | format = new String(); |
||
546 | onlineResource_xlink = new String(); |
||
547 | onlineResource_type = new String(); |
||
548 | onlineResource_href = new String(); |
||
549 | } |
||
550 | public String type; |
||
551 | public String format; |
||
552 | public String onlineResource_xlink; |
||
553 | public String onlineResource_type; |
||
554 | public String onlineResource_href; |
||
555 | } |
||
556 | |||
557 | /**
|
||
558 | * <p>Inner class describing the DataURL tag in OGC specifications in WMS</p>
|
||
559 | *
|
||
560 | */
|
||
561 | protected class DataURL |
||
562 | { |
||
563 | public DataURL()
|
||
564 | { |
||
565 | type = new String(); |
||
566 | format = new String(); |
||
567 | onlineResource_xlink = new String(); |
||
568 | onlineResource_type = new String(); |
||
569 | onlineResource_href = new String(); |
||
570 | } |
||
571 | public String type; |
||
572 | public String format; |
||
573 | public String onlineResource_xlink; |
||
574 | public String onlineResource_type; |
||
575 | public String onlineResource_href; |
||
576 | } |
||
577 | 3377 | ldiaz | } |