001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/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 17:22:25 +0100 (Do, 27 Dez 2007) $
068 */
069
070 public class DescribePlatformRequest extends AbstractOGCWebServiceRequest {
071
072 private static final NamespaceContext nsContext = CommonNamespaces.getNamespaceContext();
073
074 private static final ILogger LOG = LoggerFactory.getLogger( DescribePlatformRequest.class );
075
076 private String[] typeNames = null;
077
078 private String outputFormat = null;
079
080 /**
081 *
082 * creates a DescribePlatform Request from a KVP Map
083 *
084 * @param map
085 * @return
086 * @throws OGCWebServiceException
087 *
088 */
089 public static DescribePlatformRequest create( Map map )
090 throws OGCWebServiceException {
091
092 // added by deegree
093 String id = (String) map.get( "ID" );
094
095 // optional Parameter
096 String version = (String) map.get( "VERSION" );
097
098 // optional Parameter, fixed to "SOS"
099 String service = (String) map.get( "SERVICE" );
100 if ( ( service != null ) && ( !service.equals( "SOS" ) ) ) {
101 throw new OGCWebServiceException( "service must be 'SOS'" );
102 }
103
104 // optional Parameter, fixed to "SensorML"
105 String outputFormat = (String) map.get( "OUTPUTFORMAT" );
106 if ( ( outputFormat != null ) && ( !outputFormat.equals( "SensorML" ) ) ) {
107 throw new OGCWebServiceException( "outputFormat must be 'SensorML'" );
108 }
109
110 // optional and unbounded
111 String[] typeNames = null;
112 if ( map.get( "TYPENAMES" ) != null ) {
113 String tmp = (String) map.get( "TYPENAMES" );
114 typeNames = StringTools.toArray( tmp, ",", false );
115 }
116
117 return new DescribePlatformRequest( typeNames, "SensorML", version, id, null );
118
119 }
120
121 /**
122 * creates a DescribePlatform Request from a XML Document
123 *
124 * @param id
125 * @param doc
126 * @return
127 * @throws OGCWebServiceException
128 *
129 */
130 public static DescribePlatformRequest create( String id, Document doc )
131 throws OGCWebServiceException {
132
133 try {
134 // optional Parameter
135 String version = XMLTools.getNodeAsString( doc, "/sos:DescribePlatform/@version", nsContext, null );
136
137 // optional Parameter, fixed to "SCS"
138 String service = XMLTools.getNodeAsString( doc, "/sos:DescribePlatform/@service", nsContext, null );
139 if ( ( service != null ) && ( !service.equals( "SOS" ) ) ) {
140 throw new OGCWebServiceException( "service must be 'SOS'" );
141 }
142
143 // optional Parameter, fixed to "SensorML"
144 String outputFormat = XMLTools.getNodeAsString( doc, "/sos:DescribePlatform/@outputFormat", nsContext, null );
145 if ( ( outputFormat != null ) && ( !outputFormat.equals( "SensorML" ) ) ) {
146 throw new OGCWebServiceException( "outputFormat must be 'SensorML'" );
147 }
148
149 // optional and unbounded
150 ArrayList<String> al = new ArrayList<String>();
151 List nl = XMLTools.getNodes( doc, "/sos:DescribePlatform/sos:TypeName", nsContext );
152 for ( int i = 0; i < nl.size(); i++ ) {
153 al.add( XMLTools.getRequiredNodeAsString( (Node) nl.get( i ), "text()", nsContext ) );
154 }
155
156 String[] types = al.toArray( new String[al.size()] );
157
158 return new DescribePlatformRequest( types, "SensorML", version, id, null );
159
160 } catch ( Exception e ) {
161 e.printStackTrace();
162 throw new OGCWebServiceException( "scs webservice failure" );
163 }
164
165 }
166
167 /**
168 * @param id
169 * @param version
170 * @param outputFormat
171 * @param typeNames
172 *
173 */
174 public static void create( String id, String version, String outputFormat, String[] typeNames ) {
175 throw new UnsupportedOperationException();
176 }
177
178 /**
179 *
180 * @param typeNames
181 * @param outputFormat
182 * @param version
183 * @param id
184 * @param vendorSpecificParameter
185 * @throws InvalidParameterValueException
186 */
187 private DescribePlatformRequest( String[] typeNames, String outputFormat, String version, String id,
188 Map<String, String> vendorSpecificParameter ) {
189
190 super( version, id, vendorSpecificParameter );
191
192 this.typeNames = typeNames;
193 this.outputFormat = outputFormat;
194
195 StringBuffer sb = new StringBuffer( 200 );
196 sb.append( "create DescribePlatformRequest: service= SCS" );
197 sb.append( " version=" ).append( version ).append( " outputFormat=" );
198 sb.append( outputFormat ).append( " id=" ).append( id );
199 sb.append( " NumberOfTypeNames=" ).append( typeNames.length );
200 LOG.logDebug( sb.toString() );
201
202 }
203
204 /**
205 * fixed 'SOS'
206 *
207 * @return the String "SOS"
208 */
209 public String getServiceName() {
210 return "SOS";
211 }
212
213 /**
214 * @return typeNames
215 */
216 public String[] getTypeNames() {
217 return typeNames;
218 }
219
220 /**
221 * returns the desired output format name
222 *
223 * @return desired output format name
224 */
225 public String getOutputFormat() {
226 return outputFormat;
227 }
228
229 }