001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.impl;
025:
026: import java.util.ArrayList;
027: import java.util.Iterator;
028: import java.util.List;
029: import org.jdom.Element;
030: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSLegendURL;
031: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSStyle;
032: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSStyleSheetURL;
033: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSStyleURL;
034:
035: /**
036: * @author ETj
037: */
038: public class WMSStyleImpl implements WMSStyle {
039: private String _name; // 1..1
040: private String _title; // 1..1
041: private String _abstract; // 0..1
042: private List<WMSLegendURL> _legendUrlList = new ArrayList<WMSLegendURL>(); // 0..n
043: private WMSStyleSheetURL _styleSheetURL = null; // 0..1
044: private WMSStyleURL _styleURL = null; // 0..1
045:
046: private WMSStyleImpl() {
047: }
048:
049: public static WMSStyle newInstance() {
050: return new WMSStyleImpl();
051: }
052:
053: public static WMSStyle parse(Element eStyle) {
054: WMSStyleImpl style = new WMSStyleImpl();
055:
056: style.setTitle(eStyle.getChildText("Title"));
057: style.setName(eStyle.getChildText("Name"));
058: style.setAbstract(eStyle.getChildText("Abstract"));
059: for (Element eLegendUrl : (List<Element>) eStyle
060: .getChildren("LegendURL"))
061: style.addLegendURL(WMSFactory.parseLegendURL(eLegendUrl));
062:
063: Element essu = eStyle.getChild("StyleSheetURL");
064: if (essu != null)
065: style.setStyleSheetURL(WMSStyleSheetURLImpl.parse(essu)); // fixme use factory
066: Element esu = eStyle.getChild("StyleURL");
067: if (esu != null)
068: style.setStyleURL(WMSStyleURLImpl.parse(esu)); // fixme use factory
069:
070: return style;
071: }
072:
073: /**
074: * Sets Name
075: */
076: public void setName(String name) {
077: _name = name;
078: }
079:
080: /**
081: * Returns Name
082: */
083: public String getName() {
084: return _name;
085: }
086:
087: /**
088: * Sets Title
089: */
090: public void setTitle(String title) {
091: _title = title;
092: }
093:
094: /**
095: * Returns Title
096: */
097: public String getTitle() {
098: return _title;
099: }
100:
101: /**
102: * Sets Abstract
103: */
104: public void setAbstract(String abs) {
105: _abstract = abs;
106: }
107:
108: /**
109: * Returns Abstract
110: */
111: public String getAbstract() {
112: return _abstract;
113: }
114:
115: public void addLegendURL(WMSLegendURL legendUrl) {
116: _legendUrlList.add(legendUrl);
117: }
118:
119: public WMSLegendURL getLegendURL(int index) {
120: if (index < 0 || _legendUrlList.size() - 1 < index)
121: return null;
122: else
123: return _legendUrlList.get(0);
124: }
125:
126: public Iterable<WMSLegendURL> getLegendURLIterator() {
127: return new Iterable<WMSLegendURL>() {
128: public Iterator<WMSLegendURL> iterator() {
129: return _legendUrlList.iterator();
130: }
131: };
132: }
133:
134: /**
135: * Sets StyleSheetURL
136: */
137: public void setStyleSheetURL(WMSStyleSheetURL styleSheetURL) {
138: _styleSheetURL = styleSheetURL;
139: }
140:
141: /**
142: * Returns StyleSheetURL
143: */
144: public WMSStyleSheetURL getStyleSheetURL() {
145: return _styleSheetURL;
146: }
147:
148: /**
149: * Sets StyleURL
150: */
151: public void setStyleURL(WMSStyleURL styleURL) {
152: _styleURL = styleURL;
153: }
154:
155: /**
156: * Returns StyleURL
157: */
158: public WMSStyleURL getStyleURL() {
159: return _styleURL;
160: }
161:
162: }
|