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