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 org.jdom.Element;
027: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSBoundingBox;
028:
029: /**
030: * @author ETj
031: */
032: public class WMSBoundingBoxImpl implements WMSBoundingBox {
033: private String _srs = null;
034: private float _minx = Float.NaN;
035: private float _miny = Float.NaN;
036: private float _maxx = Float.NaN;
037: private float _maxy = Float.NaN;
038: private float _resx = Float.NaN; // opt
039: private float _resy = Float.NaN; // opt
040:
041: private WMSBoundingBoxImpl() {
042: }
043:
044: public static WMSBoundingBox newInstance() {
045: return new WMSBoundingBoxImpl();
046: }
047:
048: public static WMSBoundingBox parse(Element ebb) {
049: WMSBoundingBoxImpl bb = new WMSBoundingBoxImpl();
050:
051: bb.setSRS(ebb.getAttributeValue("srs"));
052: bb.setMinx(Float.parseFloat(ebb.getAttributeValue("minx")));
053: bb.setMiny(Float.parseFloat(ebb.getAttributeValue("miny")));
054: bb.setMaxx(Float.parseFloat(ebb.getAttributeValue("maxx")));
055: bb.setMaxy(Float.parseFloat(ebb.getAttributeValue("maxy")));
056:
057: String sresx = ebb.getAttributeValue("resx");
058: if (sresx != null)
059: bb.setResx(Float.parseFloat(sresx));
060:
061: String sresy = ebb.getAttributeValue("resy");
062: if (sresy != null)
063: bb.setResy(Float.parseFloat(sresy));
064:
065: return bb;
066: }
067:
068: /**
069: * Sets Srs
070: */
071: public void setSRS(String srs) {
072: _srs = srs;
073: }
074:
075: /**
076: * Returns Srs
077: */
078: public String getSRS() {
079: return _srs;
080: }
081:
082: /**
083: * Sets Minx
084: */
085: public void setMinx(float minx) {
086: _minx = minx;
087: }
088:
089: /**
090: * Returns Minx
091: */
092: public float getMinx() {
093: return _minx;
094: }
095:
096: /**
097: * Sets Miny
098: */
099: public void setMiny(float miny) {
100: _miny = miny;
101: }
102:
103: /**
104: * Returns Miny
105: */
106: public float getMiny() {
107: return _miny;
108: }
109:
110: /**
111: * Sets Maxx
112: */
113: public void setMaxx(float maxx) {
114: _maxx = maxx;
115: }
116:
117: /**
118: * Returns Maxx
119: */
120: public float getMaxx() {
121: return _maxx;
122: }
123:
124: /**
125: * Sets Maxy
126: */
127: public void setMaxy(float maxy) {
128: _maxy = maxy;
129: }
130:
131: /**
132: * Returns Maxy
133: */
134: public float getMaxy() {
135: return _maxy;
136: }
137:
138: /**
139: * Sets Resx
140: */
141: public void setResx(float resx) {
142: _resx = resx;
143: }
144:
145: /**
146: * Returns Resx
147: */
148: public float getResx() {
149: return _resx;
150: }
151:
152: /**
153: * Sets Resy
154: */
155: public void setResy(float resy) {
156: _resy = resy;
157: }
158:
159: /**
160: * Returns Resy
161: */
162: public float getResy() {
163: return _resy;
164: }
165:
166: /**
167: * Method toElement
168: */
169: public Element toElement(String name) {
170: if (_srs == null)
171: throw new IllegalStateException(name + "/SRS is missing");
172: if (_minx == Float.NaN)
173: throw new IllegalStateException(name + "/minx is missing");
174: if (_miny == Float.NaN)
175: throw new IllegalStateException(name + "/miny is missing");
176: if (_maxx == Float.NaN)
177: throw new IllegalStateException(name + "/maxx is missing");
178: if (_maxy == Float.NaN)
179: throw new IllegalStateException(name + "/maxy is missing");
180:
181: Element ret = new Element(name).setAttribute("SRS", _srs)
182: .setAttribute("minx", "" + _minx).setAttribute("miny",
183: "" + _miny).setAttribute("maxx", "" + _maxx)
184: .setAttribute("maxy", "" + _maxy);
185:
186: if (_resx != Float.NaN)
187: ret.setAttribute("resx", "" + _resx);
188: if (_resy != Float.NaN)
189: ret.setAttribute("resy", "" + _resy);
190:
191: return ret;
192: }
193:
194: }
|