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