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