001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/sos/describeplatform/DescribePlatformRequest.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.describeplatform;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import java.util.Map;
047:
048: import org.deegree.framework.log.ILogger;
049: import org.deegree.framework.log.LoggerFactory;
050: import org.deegree.framework.util.StringTools;
051: import org.deegree.framework.xml.NamespaceContext;
052: import org.deegree.framework.xml.XMLTools;
053: import org.deegree.ogcbase.CommonNamespaces;
054: import org.deegree.ogcwebservices.AbstractOGCWebServiceRequest;
055: import org.deegree.ogcwebservices.InvalidParameterValueException;
056: import org.deegree.ogcwebservices.OGCWebServiceException;
057: import org.w3c.dom.Document;
058: import org.w3c.dom.Node;
059:
060: /**
061: *
062: * represent a DescribePlatformRequest
063: *
064: * @author <a href="mailto:mkulbe@lat-lon.de">Matthias Kulbe </a>
065: * @author last edited by: $Author: apoth $
066: *
067: * @version $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
068: */
069:
070: public class DescribePlatformRequest extends
071: AbstractOGCWebServiceRequest {
072:
073: private static final NamespaceContext nsContext = CommonNamespaces
074: .getNamespaceContext();
075:
076: private static final ILogger LOG = LoggerFactory
077: .getLogger(DescribePlatformRequest.class);
078:
079: private String[] typeNames = null;
080:
081: private String outputFormat = null;
082:
083: /**
084: *
085: * creates a DescribePlatform Request from a KVP Map
086: *
087: * @param map
088: * @return
089: * @throws OGCWebServiceException
090: *
091: */
092: public static DescribePlatformRequest create(Map map)
093: throws OGCWebServiceException {
094:
095: // added by deegree
096: String id = (String) map.get("ID");
097:
098: // optional Parameter
099: String version = (String) map.get("VERSION");
100:
101: // optional Parameter, fixed to "SOS"
102: String service = (String) map.get("SERVICE");
103: if ((service != null) && (!service.equals("SOS"))) {
104: throw new OGCWebServiceException("service must be 'SOS'");
105: }
106:
107: // optional Parameter, fixed to "SensorML"
108: String outputFormat = (String) map.get("OUTPUTFORMAT");
109: if ((outputFormat != null)
110: && (!outputFormat.equals("SensorML"))) {
111: throw new OGCWebServiceException(
112: "outputFormat must be 'SensorML'");
113: }
114:
115: // optional and unbounded
116: String[] typeNames = null;
117: if (map.get("TYPENAMES") != null) {
118: String tmp = (String) map.get("TYPENAMES");
119: typeNames = StringTools.toArray(tmp, ",", false);
120: }
121:
122: return new DescribePlatformRequest(typeNames, "SensorML",
123: version, id, null);
124:
125: }
126:
127: /**
128: * creates a DescribePlatform Request from a XML Document
129: *
130: * @param id
131: * @param doc
132: * @return
133: * @throws OGCWebServiceException
134: *
135: */
136: public static DescribePlatformRequest create(String id, Document doc)
137: throws OGCWebServiceException {
138:
139: try {
140: // optional Parameter
141: String version = XMLTools.getNodeAsString(doc,
142: "/sos:DescribePlatform/@version", nsContext, null);
143:
144: // optional Parameter, fixed to "SCS"
145: String service = XMLTools.getNodeAsString(doc,
146: "/sos:DescribePlatform/@service", nsContext, null);
147: if ((service != null) && (!service.equals("SOS"))) {
148: throw new OGCWebServiceException(
149: "service must be 'SOS'");
150: }
151:
152: // optional Parameter, fixed to "SensorML"
153: String outputFormat = XMLTools.getNodeAsString(doc,
154: "/sos:DescribePlatform/@outputFormat", nsContext,
155: null);
156: if ((outputFormat != null)
157: && (!outputFormat.equals("SensorML"))) {
158: throw new OGCWebServiceException(
159: "outputFormat must be 'SensorML'");
160: }
161:
162: // optional and unbounded
163: ArrayList<String> al = new ArrayList<String>();
164: List nl = XMLTools.getNodes(doc,
165: "/sos:DescribePlatform/sos:TypeName", nsContext);
166: for (int i = 0; i < nl.size(); i++) {
167: al.add(XMLTools.getRequiredNodeAsString((Node) nl
168: .get(i), "text()", nsContext));
169: }
170:
171: String[] types = al.toArray(new String[al.size()]);
172:
173: return new DescribePlatformRequest(types, "SensorML",
174: version, id, null);
175:
176: } catch (Exception e) {
177: e.printStackTrace();
178: throw new OGCWebServiceException("scs webservice failure");
179: }
180:
181: }
182:
183: /**
184: * @param id
185: * @param version
186: * @param outputFormat
187: * @param typeNames
188: *
189: */
190: public static void create(String id, String version,
191: String outputFormat, String[] typeNames) {
192: throw new UnsupportedOperationException();
193: }
194:
195: /**
196: *
197: * @param typeNames
198: * @param outputFormat
199: * @param version
200: * @param id
201: * @param vendorSpecificParameter
202: * @throws InvalidParameterValueException
203: */
204: private DescribePlatformRequest(String[] typeNames,
205: String outputFormat, String version, String id,
206: Map<String, String> vendorSpecificParameter) {
207:
208: super (version, id, vendorSpecificParameter);
209:
210: this .typeNames = typeNames;
211: this .outputFormat = outputFormat;
212:
213: StringBuffer sb = new StringBuffer(200);
214: sb.append("create DescribePlatformRequest: service= SCS");
215: sb.append(" version=").append(version).append(" outputFormat=");
216: sb.append(outputFormat).append(" id=").append(id);
217: sb.append(" NumberOfTypeNames=").append(typeNames.length);
218: LOG.logDebug(sb.toString());
219:
220: }
221:
222: /**
223: * fixed 'SOS'
224: *
225: * @return the String "SOS"
226: */
227: public String getServiceName() {
228: return "SOS";
229: }
230:
231: /**
232: * @return typeNames
233: */
234: public String[] getTypeNames() {
235: return typeNames;
236: }
237:
238: /**
239: * returns the desired output format name
240: *
241: * @return desired output format name
242: */
243: public String getOutputFormat() {
244: return outputFormat;
245: }
246:
247: }
|