001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/sos/describesensor/DescribeSensorRequest.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstraße 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: lat/lon GmbH
036: Aennchenstraße 19
037: 53177 Bonn
038: Germany
039: E-Mail: greve@giub.uni-bonn.de
040:
041: ---------------------------------------------------------------------------*/
042: package org.deegree.ogcwebservices.sos.describesensor;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import java.util.Map;
047:
048: import org.deegree.framework.util.StringTools;
049: import org.deegree.framework.xml.NamespaceContext;
050: import org.deegree.framework.xml.XMLTools;
051: import org.deegree.ogcbase.CommonNamespaces;
052: import org.deegree.ogcwebservices.AbstractOGCWebServiceRequest;
053: import org.deegree.ogcwebservices.OGCWebServiceException;
054: import org.w3c.dom.Document;
055: import org.w3c.dom.Node;
056:
057: /**
058: *
059: * represents a DescribeSensor Request
060: *
061: * @author <a href="mailto:mkulbe@lat-lon.de">Matthias Kulbe </a>
062: * @author last edited by: $Author: apoth $
063: *
064: * @version $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
065: */
066: public class DescribeSensorRequest extends AbstractOGCWebServiceRequest {
067:
068: private static final NamespaceContext nsContext = CommonNamespaces
069: .getNamespaceContext();
070:
071: private String[] typeNames = null;
072:
073: private String outputFormat = null;
074:
075: /**
076: *
077: * creates the Request by using a KVP Map
078: *
079: * @param map
080: * @return
081: * @throws OGCWebServiceException
082: */
083: public static DescribeSensorRequest create(Map map)
084: throws OGCWebServiceException {
085:
086: // id was set by deegree
087: String id = (String) map.get("ID");
088:
089: // optional Parameter
090: String version = (String) map.get("VERSION");
091:
092: // optional Parameter, is fixed to "SOS"
093: String service = (String) map.get("SERVICE");
094: if ((service != null) && (!service.equals("SOS"))) {
095: throw new OGCWebServiceException("service must be 'SOS'");
096: }
097:
098: // optional Parameter, is fixed to "SensorML"
099: String outputFormat = (String) map.get("OUTPUTFORMAT");
100: if ((outputFormat != null)
101: && (!outputFormat.equals("SensorML"))) {
102: throw new OGCWebServiceException(
103: "outputFormat must be 'SensorML'");
104: }
105:
106: // optional and unbounded
107: String[] typeNames = null;
108: if (map.get("TYPENAMES") != null) {
109: String tmp = (String) map.get("TYPENAMES");
110: typeNames = StringTools.toArray(tmp, ",", false);
111: }
112:
113: return new DescribeSensorRequest(typeNames, "SensorML",
114: version, id, null);
115:
116: }
117:
118: /**
119: * creates the Request by using a XML Document
120: *
121: * @param id
122: * @param doc
123: * @return
124: * @throws OGCWebServiceException
125: *
126: */
127: public static DescribeSensorRequest create(String id, Document doc)
128: throws OGCWebServiceException {
129:
130: try {
131: // optional Prameter
132: String version = XMLTools.getNodeAsString(doc,
133: "/sos:DescribeSensor/@version", nsContext, null);
134:
135: // optional Parameter, is fixed to "SCS"
136: String service = XMLTools.getNodeAsString(doc,
137: "/sos:DescribeSensor/@service", nsContext, null);
138: if ((service != null) && (!service.equals("SOS"))) {
139: throw new OGCWebServiceException(
140: "service must be 'SOS'");
141: }
142:
143: // optional Parameter, is fixed to "SensorML"
144: String outputFormat = XMLTools.getNodeAsString(doc,
145: "/sos:DescribeSensor/@outputFormat", nsContext,
146: null);
147: if ((outputFormat != null)
148: && (!outputFormat.equals("SensorML"))) {
149: throw new OGCWebServiceException(
150: "outputFormat must be 'SensorML'");
151: }
152:
153: // optional and unbounded
154: List nl = XMLTools.getNodes(doc,
155: "/sos:DescribeSensor/sos:TypeName", nsContext);
156: ArrayList<String> al = new ArrayList<String>(nl.size());
157: for (int i = 0; i < nl.size(); i++) {
158: al.add(XMLTools.getRequiredNodeAsString((Node) nl
159: .get(i), "text()", nsContext));
160: }
161:
162: return new DescribeSensorRequest(al.toArray(new String[al
163: .size()]), "SensorML", version, id, null);
164:
165: } catch (Exception e) {
166: e.printStackTrace();
167: throw new OGCWebServiceException("scs webservice failure");
168: }
169:
170: }
171:
172: /**
173: * @param id
174: * @param version
175: * @param outputFormat
176: * @param typeNames
177: *
178: */
179: public static void create(String id, String version,
180: String outputFormat, String[] typeNames) {
181: throw new UnsupportedOperationException(
182: "create( String , String , String , String[] ) not implemented");
183: }
184:
185: /**
186: * @param typeNames
187: * @param outputFormat
188: * @param version
189: * @param id
190: *
191: */
192: private DescribeSensorRequest(String[] typeNames,
193: String outputFormat, String version, String id,
194: Map<String, String> vendorSpecificParameter) {
195:
196: super (version, id, vendorSpecificParameter);
197:
198: this .typeNames = typeNames;
199: this .outputFormat = outputFormat;
200:
201: }
202:
203: /**
204: * fixed 'SOS'
205: *
206: * @return the String "SOS".
207: */
208: public String getServiceName() {
209: return "SOS";
210: }
211:
212: /**
213: *
214: * @return typeNames
215: */
216: public String[] getTypeNames() {
217: return typeNames;
218: }
219:
220: /**
221: *
222: * @return outputFormat
223: */
224: public String getOutputFormat() {
225: return outputFormat;
226: }
227:
228: }
|