001    // $HeadURL:
002    // /cvsroot/deegree/src/org/deegree/ogcwebservices/OGCRequestFactory.java,v 1.12
003    // 2004/08/10 17:17:02 tf Exp $
004    /*----------------    FILE HEADER  ------------------------------------------
005    
006     This file is part of deegree.
007     Copyright (C) 2001-2008 by:
008     EXSE, Department of Geography, University of Bonn
009     http://www.giub.uni-bonn.de/deegree/
010     lat/lon GmbH
011     http://www.lat-lon.de
012    
013     This library is free software; you can redistribute it and/or
014     modify it under the terms of the GNU Lesser General Public
015     License as published by the Free Software Foundation; either
016     version 2.1 of the License, or (at your option) any later version.
017    
018     This library is distributed in the hope that it will be useful,
019     but WITHOUT ANY WARRANTY; without even the implied warranty of
020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
021     Lesser General Public License for more details.
022    
023     You should have received a copy of the GNU Lesser General Public
024     License along with this library; if not, write to the Free Software
025     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026    
027     Contact:
028    
029     Andreas Poth
030     lat/lon GmbH
031     Aennchenstr. 19
032     53177 Bonn
033     Germany
034     E-Mail: poth@lat-lon.de
035    
036     Prof. Dr. Klaus Greve
037     Department of Geography
038     University of Bonn
039     Meckenheimer Allee 166
040     53115 Bonn
041     Germany
042     E-Mail: greve@giub.uni-bonn.de
043    
044     
045     ---------------------------------------------------------------------------*/
046    package org.deegree.ogcwebservices;
047    
048    import java.io.BufferedReader;
049    import java.io.IOException;
050    import java.io.InputStreamReader;
051    import java.io.StringReader;
052    import java.io.UnsupportedEncodingException;
053    import java.net.MalformedURLException;
054    import java.net.URLDecoder;
055    import java.util.HashMap;
056    import java.util.Map;
057    
058    import javax.servlet.ServletRequest;
059    import javax.servlet.http.HttpServletRequest;
060    
061    import org.deegree.framework.log.ILogger;
062    import org.deegree.framework.log.LoggerFactory;
063    import org.deegree.framework.util.CharsetUtils;
064    import org.deegree.framework.util.IDGenerator;
065    import org.deegree.framework.util.StringTools;
066    import org.deegree.framework.xml.XMLFragment;
067    import org.deegree.framework.xml.XMLParsingException;
068    import org.deegree.framework.xml.XMLTools;
069    import org.deegree.ogcbase.CommonNamespaces;
070    import org.deegree.ogcbase.ExceptionCode;
071    import org.deegree.ogcwebservices.csw.capabilities.CatalogueGetCapabilities;
072    import org.deegree.ogcwebservices.csw.capabilities.CatalogueOperationsMetadata;
073    import org.deegree.ogcwebservices.csw.discovery.DescribeRecord;
074    import org.deegree.ogcwebservices.csw.discovery.GetRecordById;
075    import org.deegree.ogcwebservices.csw.discovery.GetRecords;
076    import org.deegree.ogcwebservices.csw.discovery.GetRepositoryItem;
077    import org.deegree.ogcwebservices.csw.manager.Harvest;
078    import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
079    import org.deegree.ogcwebservices.sos.capabilities.SOSGetCapabilities;
080    import org.deegree.ogcwebservices.sos.capabilities.SOSOperationsMetadata;
081    import org.deegree.ogcwebservices.sos.describeplatform.DescribePlatformRequest;
082    import org.deegree.ogcwebservices.sos.describesensor.DescribeSensorRequest;
083    import org.deegree.ogcwebservices.sos.getobservation.GetObservationRequest;
084    import org.deegree.ogcwebservices.wass.common.CloseSession;
085    import org.deegree.ogcwebservices.wass.common.GetSession;
086    import org.deegree.ogcwebservices.wass.was.operation.DescribeUser;
087    import org.deegree.ogcwebservices.wass.was.operation.WASGetCapabilities;
088    import org.deegree.ogcwebservices.wass.wss.operation.DoService;
089    import org.deegree.ogcwebservices.wass.wss.operation.WSSGetCapabilities;
090    import org.deegree.ogcwebservices.wcs.describecoverage.DescribeCoverage;
091    import org.deegree.ogcwebservices.wcs.getcapabilities.WCSGetCapabilities;
092    import org.deegree.ogcwebservices.wcs.getcoverage.GetCoverage;
093    import org.deegree.ogcwebservices.wfs.operation.DescribeFeatureType;
094    import org.deegree.ogcwebservices.wfs.operation.GetFeature;
095    import org.deegree.ogcwebservices.wfs.operation.GetFeatureWithLock;
096    import org.deegree.ogcwebservices.wfs.operation.LockFeature;
097    import org.deegree.ogcwebservices.wfs.operation.WFSGetCapabilities;
098    import org.deegree.ogcwebservices.wfs.operation.transaction.Transaction;
099    import org.deegree.ogcwebservices.wmps.operation.PrintMap;
100    import org.deegree.ogcwebservices.wmps.operation.WMPSGetCapabilities;
101    import org.deegree.ogcwebservices.wms.operation.DescribeLayer;
102    import org.deegree.ogcwebservices.wms.operation.GetFeatureInfo;
103    import org.deegree.ogcwebservices.wms.operation.GetLegendGraphic;
104    import org.deegree.ogcwebservices.wms.operation.GetMap;
105    import org.deegree.ogcwebservices.wms.operation.WMSGetCapabilities;
106    import org.deegree.ogcwebservices.wps.capabilities.WPSGetCapabilities;
107    import org.deegree.ogcwebservices.wps.describeprocess.DescribeProcessRequest;
108    import org.deegree.ogcwebservices.wps.execute.ExecuteRequest;
109    import org.deegree.ogcwebservices.wpvs.operation.Get3DFeatureInfo;
110    import org.deegree.ogcwebservices.wpvs.operation.GetView;
111    import org.deegree.ogcwebservices.wpvs.operation.WPVSGetCapabilities;
112    import org.w3c.dom.Document;
113    import org.w3c.dom.Element;
114    import org.xml.sax.SAXException;
115    
116    /**
117     * Factory for generating request objects for OGC Web Services.
118     * <p>
119     * Requests may be generated from KVP or DOM representations. Also contains methods that decide
120     * whether an incoming request representation is valid for a certain service.
121     * </p>
122     * Currently supported services are:
123     * <ul>
124     * <li>CSW</li>
125     * <li>WFS</li>
126     * <li>WCS</li>
127     * <li>WMS</li>
128     * <li>WFS-G</li>
129     * <li>SOS</li>
130     * <li>WMPS</li>
131     * <li>WSS</li>
132     * <li>WAS</li>
133     * <li>WPVS</li>
134     * </ul>
135     * 
136     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
137     * @author last edited by: $Author: hrubach $
138     * 
139     * @version $Revision: 11631 $, $Date: 2008-05-08 10:05:58 +0200 (Do, 08 Mai 2008) $
140     */
141    public class OGCRequestFactory {
142    
143        private static final ILogger LOG = LoggerFactory.getLogger( OGCRequestFactory.class );
144    
145        private static final String CSW_SERVICE_NAME = "CSW";
146    
147        /**
148         * The service name of a getRepositoryItem request, only valid for the csw/ebrim. Fixed value:
149         * "urn:x-ogc:specification:cswebrim:Service:OGC-CSW:ebRIM"
150         */
151        public static final String CSW_SERVICE_NAME_EBRIM = "urn:x-ogc:specification:cswebrim:Service:OGC-CSW:ebRIM";
152    
153        private static final String WFS_SERVICE_NAME = "WFS";
154    
155        private static final String WCS_SERVICE_NAME = "WCS";
156    
157        private static final String WMS_SERVICE_NAME = "WMS";
158    
159        private static final String SOS_SERVICE_NAME = "SOS";
160    
161        private static final String WPVS_SERVICE_NAME = "WPVS";
162    
163        private static final String WMPS_SERVICE_NAME = "WMPS";
164    
165        private static final String WPS_SERVICE_NAME = "WPS";
166    
167        private static final String WSS_SERVICE_NAME = "WSS";
168    
169        private static final String WAS_SERVICE_NAME = "WAS";
170    
171        /**
172         * Creates an <code>OGCWebServiceRequest</code> from the content contained within the passed
173         * request.
174         * 
175         * @param request
176         * @return the request object
177         * @throws OGCWebServiceException
178         */
179        public static OGCWebServiceRequest create( ServletRequest request )
180                                throws OGCWebServiceException {
181    
182            // according to javax.servlet.* documentation, the type is correct
183            Map<String, String[]> map = request.getParameterMap();
184            Map<String, String> result = new HashMap<String, String>();
185            for ( String key : map.keySet() ) {
186                String[] tmp = map.get( key );
187                for ( int i = 0; i < tmp.length; i++ ) {
188                    tmp[i] = tmp[i].trim();
189                }
190                result.put( key.toUpperCase(), StringTools.arrayToString( tmp, ',' ) );
191            }
192    
193            LOG.logDebug( "Request parameters: " + result );
194    
195            if ( map.size() != 0 ) {
196                return createFromKVP( result );
197            }
198    
199            XMLFragment fragment = null;
200            try {
201                if ( request.getContentType() != null ) {
202                    fragment = new XMLFragment( request.getReader(), XMLFragment.DEFAULT_URL );
203                } else {
204                    // DO NOT REMOVE THIS !!!!!
205                    // IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
206                    StringReader sr = new StringReader( getRequestContent( (HttpServletRequest) request ) );
207                    fragment = new XMLFragment( sr, XMLFragment.DEFAULT_URL );
208                }
209            } catch ( SAXException se ) {
210                throw new OGCWebServiceException(
211                                                  "OGCRequestFactory",
212                                                  "No key-value pairs were given and the request does not contain parsable xml",
213                                                  ExceptionCode.NOAPPLICABLECODE );
214            } catch ( Exception e ) {
215                LOG.logError( "Error parsing XML request: " + e.getMessage(), e );
216                throw new OGCWebServiceException( "OGCRequestFactory", "Error parsing XML request: " + e.getMessage() );
217            }
218            Document doc = fragment.getRootElement().getOwnerDocument();
219    
220            return createFromXML( doc );
221        }
222    
223        /**
224         * DO NOT REMOVE THIS !!!!! IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
225         * 
226         * @param request
227         * @return
228         * @throws IOException
229         */
230        private static String getRequestContent( HttpServletRequest request )
231                                throws IOException {
232            String method = request.getMethod();
233    
234            if ( method.equalsIgnoreCase( "POST" ) ) {
235                String charset = request.getCharacterEncoding();
236                LOG.logDebug( "posted character encoding: ", charset );
237                if ( charset == null ) {
238                    charset = "UTF-8";
239                }
240                StringBuffer req = readPost( request, charset );
241                if ( charset.equalsIgnoreCase( CharsetUtils.getSystemCharset() ) ) {
242                    return req.toString();
243                }
244                if ( charset.equalsIgnoreCase( "UTF-8" ) && !charset.equalsIgnoreCase( CharsetUtils.getSystemCharset() ) ) {
245                    String s = new String( req.toString().getBytes(), CharsetUtils.getSystemCharset() );
246                    return s;
247                }
248                if ( !charset.equalsIgnoreCase( "UTF-8" ) && !charset.equalsIgnoreCase( CharsetUtils.getSystemCharset() ) ) {
249                    String s = new String( req.toString().getBytes(), "UTF-8" );
250                    return s;
251                }
252                return req.toString();
253            }
254    
255            String req = request.getQueryString();
256            if ( req == null ) {
257                req = readPost( request, CharsetUtils.getSystemCharset() ).toString();
258            }
259            LOG.logDebug( "request string: ", req );
260    
261            return URLDecoder.decode( req, CharsetUtils.getSystemCharset() );
262    
263        }
264    
265        /**
266         * DO NOT REMOVE THIS !!!!! IT IS ABSOLUTLY NECESSARY TO ENSURE CORRECT CHARACTER ENCODING !!!
267         * 
268         * @param request
269         * @param charset
270         * @return
271         * @throws UnsupportedEncodingException
272         * @throws IOException
273         */
274        private static StringBuffer readPost( HttpServletRequest request, String charset )
275                                throws UnsupportedEncodingException, IOException {
276            java.io.Reader reader = new InputStreamReader( request.getInputStream(), charset );
277            BufferedReader br = new BufferedReader( reader );
278            StringBuffer req = new StringBuffer( 10000 );
279            for ( String line = null; ( line = br.readLine() ) != null; ) {
280                req.append( ( new StringBuilder( String.valueOf( line ) ) ).append( "\n" ).toString() );
281            }
282    
283            br.close();
284            return req;
285        }
286    
287        /**
288         * Creates an instance of an <code>AbstractOGCWebServiceRequest</code> from the passed DOM
289         * object. Supported OWS are 'WMS', 'WFS', 'WCS' and 'CSW'. If a request for another service is
290         * passed or a request that isn't supported by one of the listed services an exception will be
291         * thrown. <BR>
292         * Notice that not all listed services will support request processing by reading the request to
293         * be performed from a DOM object. In this case also an exception will be thrown even if the
294         * same request may can be performed if KVP is used.
295         * 
296         * @param doc
297         * @return the request object
298         * @throws OGCWebServiceException
299         */
300        public static OGCWebServiceRequest createFromXML( Document doc )
301                                throws OGCWebServiceException {
302    
303            if ( LOG.getLevel() == ILogger.LOG_DEBUG ) {
304                XMLFragment xml = new XMLFragment();
305                xml.setRootElement( doc.getDocumentElement() );
306                LOG.logDebug( "XML request (pretty printed): ", xml.getAsPrettyString() );
307            }
308    
309            String service = XMLTools.getAttrValue( doc.getDocumentElement(), null, "service", null );
310            String request = doc.getDocumentElement().getLocalName();
311            service = getTargetService( service, request, doc );
312            if ( "unknown".equals( service ) ) {
313                throw new OGCWebServiceException( "OGCRequestFactory", "Specified service '" + service
314                                                                       + "' is not a known OGC service type." );
315            }
316            OGCWebServiceRequest ogcRequest = null;
317            if ( request == null ) {
318                throw new OGCWebServiceException( "Request parameter must be set!" );
319            } else if ( WMS_SERVICE_NAME.equals( service ) ) {
320                ogcRequest = getWMSRequest( request, doc );
321            } else if ( WFS_SERVICE_NAME.equals( service ) ) {
322                ogcRequest = getWFSRequest( request, doc );
323            } else if ( WCS_SERVICE_NAME.equals( service ) ) {
324                ogcRequest = getWCSRequest( request, doc );
325            } else if ( CSW_SERVICE_NAME.equals( service ) ) {
326                ogcRequest = getCSWRequest( request, doc );
327            } else if ( SOS_SERVICE_NAME.equals( service ) ) {
328                ogcRequest = getSOSRequest( request, doc );
329            } else if ( WPVS_SERVICE_NAME.equals( service ) ) {
330                ogcRequest = getSOSRequest( request, doc );
331            } else if ( WMPS_SERVICE_NAME.equals( service ) ) {
332                ogcRequest = getWMPSRequest( request, doc );
333            } else if ( WPS_SERVICE_NAME.equals( service ) ) {
334                ogcRequest = getWPSRequest( request, doc );
335            } else if ( WSS_SERVICE_NAME.equals( service ) ) {
336                ogcRequest = getWSSRequest( request, doc );
337            } else if ( WAS_SERVICE_NAME.equals( service ) ) {
338                ogcRequest = getWASRequest( request, doc );
339            } else {
340                throw new OGCWebServiceException( "OGCRequestFactory", "No handler for service " + service
341                                                                       + " in OGCRequestFactory." );
342            }
343            return ogcRequest;
344        }
345    
346        /**
347         * Creates an instance of an <code>AbstractOGCWebServiceRequest</code> from the passed KVP
348         * encoded request. Supported OWS are 'WMS', 'WFS', 'WCS' and 'CSW'. If a request for another
349         * service is passed or a request that isn't supported by one of the listed services an
350         * exception will be thrown. <BR>
351         * Notice that not all listed services will support request processing by reading the request to
352         * be performed from KVPs. In this case also an exception will be thrown even if the same
353         * request may be performed if a DOM object is used.
354         * 
355         * @param map
356         * @return the request object
357         * @throws OGCWebServiceException
358         */
359        public static OGCWebServiceRequest createFromKVP( Map<String, String> map )
360                                throws OGCWebServiceException {
361    
362            LOG.logDebug( "KVP request: ", map );
363            // request parameter given?
364            String request = map.get( "REQUEST" );
365            if ( request == null ) {
366                LOG.logInfo( "parameter: ", map );
367                throw new InvalidParameterValueException( "OGCRequestFactory", "Request parameter must be set." );
368            }
369            // service parameter given?
370            String service = map.get( "SERVICE" );
371            if ( service == null ) {
372                // a profile of a service will be treated as a service
373                service = map.get( "PROFILE" );
374                if ( service == null ) {
375                    service = getTargetService( service, request, null );
376                }
377            }
378    
379            OGCWebServiceRequest ogcRequest = null;
380            if ( WMS_SERVICE_NAME.equals( service ) ) {
381                ogcRequest = getWMSRequest( request, map );
382            } else if ( WFS_SERVICE_NAME.equals( service ) ) {
383                ogcRequest = getWFSRequest( request, map );
384            } else if ( WCS_SERVICE_NAME.equals( service ) ) {
385                ogcRequest = getWCSRequest( request, map );
386            } else if ( CSW_SERVICE_NAME_EBRIM.equals( service ) || CSW_SERVICE_NAME.equals( service ) ) {
387                ogcRequest = getCSWRequest( request, map );
388            } else if ( SOS_SERVICE_NAME.equals( service ) ) {
389                ogcRequest = getSOSRequest( request, map );
390            } else if ( WPVS_SERVICE_NAME.equals( service ) ) {
391                ogcRequest = getWPVSRequest( request, map );
392            } else if ( WMPS_SERVICE_NAME.equals( service ) ) {
393                ogcRequest = getWMPSRequest( request, map );
394            } else if ( WPS_SERVICE_NAME.equals( service ) ) {
395                ogcRequest = getWPSRequest( request, map );
396            } else if ( WSS_SERVICE_NAME.equals( service ) ) {
397                ogcRequest = getWSSRequest( request, map );
398            } else if ( WAS_SERVICE_NAME.equals( service ) ) {
399                ogcRequest = getWASRequest( request, map );
400            } else {
401                throw new OGCWebServiceException( "OGCRequestFactory", "Specified service '" + map.get( "SERVICE" )
402                                                                       + "' is not a known OGC service type." );
403            }
404            return ogcRequest;
405        }
406    
407        /**
408         * Creates the corresponding WFS request object from the given parameters.
409         * 
410         * @param request
411         * @param map
412         * @return the corresponding WFS request object
413         * @throws OGCWebServiceException
414         */
415        private static OGCWebServiceRequest getWFSRequest( String request, Map<String, String> map )
416                                throws OGCWebServiceException {
417            OGCWebServiceRequest ogcRequest = null;
418            map.put( "ID", "" + IDGenerator.getInstance().generateUniqueID() );
419            if ( request.equals( "GetCapabilities" ) ) {
420                ogcRequest = WFSGetCapabilities.create( map );
421            } else if ( request.equals( "GetFeature" ) ) {
422                ogcRequest = GetFeature.create( map );
423            } else if ( request.equals( "GetFeatureWithLock" ) ) {
424                ogcRequest = GetFeatureWithLock.create( map );
425            } else if ( request.equals( "GetGmlObject" ) ) {
426                throw new OGCWebServiceException( "'GetGmlObject' operation is not implemented. " );
427            } else if ( request.equals( "LockFeature" ) ) {
428                ogcRequest = LockFeature.create( map );
429            } else if ( request.equals( "DescribeFeatureType" ) ) {
430                ogcRequest = DescribeFeatureType.create( map );
431            } else if ( request.equals( "Transaction" ) ) {
432                ogcRequest = Transaction.create( map );
433            } else {
434                throw new InvalidParameterValueException( "Unknown WFS request type: '" + request + "'." );
435            }
436            return ogcRequest;
437        }
438    
439        /**
440         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The
441         * returned request will be a WFS request. The type of request is determined by also submitted
442         * request name. Known requests are:
443         * <ul>
444         * <li>GetCapabilities</li>
445         * <li>GetFeature</li>
446         * <li>GetFeatureWithLock</li>
447         * <li>DescribeFeatureType</li>
448         * <li>Transaction</li>
449         * <li>LockFeature</li>
450         * </ul>
451         * <p>
452         * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be
453         * thrown.
454         * </p>
455         * 
456         * @param request
457         * @param doc
458         * @return created <code>OGCWebServiceRequest</code>
459         * @throws OGCWebServiceException
460         */
461        private static OGCWebServiceRequest getWFSRequest( String request, Document doc )
462                                throws OGCWebServiceException {
463            OGCWebServiceRequest ogcRequest = null;
464            String id = "" + IDGenerator.getInstance().generateUniqueID();
465            if ( request.equals( "GetCapabilities" ) ) {
466                ogcRequest = WFSGetCapabilities.create( id, doc.getDocumentElement() );
467            } else if ( request.equals( "GetFeature" ) ) {
468                ogcRequest = GetFeature.create( id, doc.getDocumentElement() );
469            } else if ( request.equals( "GetFeatureWithLock" ) ) {
470                ogcRequest = GetFeatureWithLock.create( id, doc.getDocumentElement() );
471            } else if ( request.equals( "DescribeFeatureType" ) ) {
472                ogcRequest = DescribeFeatureType.create( id, doc.getDocumentElement() );
473            } else if ( request.equals( "Transaction" ) ) {
474                ogcRequest = Transaction.create( id, doc.getDocumentElement() );
475            } else if ( request.equals( "LockFeature" ) ) {
476                ogcRequest = LockFeature.create( id, doc.getDocumentElement() );
477            } else {
478                throw new OGCWebServiceException( "Unknown / unimplemented WFS request type: '" + request + "'." );
479            }
480            return ogcRequest;
481        }
482    
483        /**
484         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The
485         * returned request will be a WSS request. The type of request is determined by also submitted
486         * request name. Known requests are:
487         * <ul>
488         * <li>GetCapabilities</li>
489         * <li>GetSession</li>
490         * <li>CloseSession</li>
491         * <li>DoService</li>
492         * </ul>
493         * <p>
494         * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be
495         * thrown.
496         * </p>
497         * 
498         * @param request
499         * @param doc
500         * @return created <code>OGCWebServiceRequest</code>
501         * @throws OGCWebServiceException
502         */
503        private static OGCWebServiceRequest getWSSRequest( String request, Document doc )
504                                throws OGCWebServiceException {
505            OGCWebServiceRequest ogcRequest = null;
506            String id = "" + IDGenerator.getInstance().generateUniqueID();
507            if ( ( "GetCapabilities" ).equals( request ) ) {
508                ogcRequest = WSSGetCapabilities.create( id, doc.getDocumentElement() );
509            } else if ( ( "GetSession" ).equals( request ) ) {
510                ogcRequest = GetSession.create( id, doc.getDocumentElement() );
511            } else if ( ( "CloseSession" ).equals( request ) ) {
512                ogcRequest = CloseSession.create( id, doc.getDocumentElement() );
513            } else if ( ( "DoService" ).equals( request ) ) {
514                ogcRequest = DoService.create( id, doc.getDocumentElement() );
515            } else {
516                throw new OGCWebServiceException( "Unknown / unimplemented WSS request type: '" + request + "'." );
517            }
518            return ogcRequest;
519        }
520    
521        /**
522         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>key value pair</code>.
523         * The returned request will be a WSS request. The type of request is determined by also
524         * submitted request name. Known requests are:
525         * <ul>
526         * <li>GetCapabilities</li>
527         * <li>GetSession</li>
528         * <li>CloseSession</li>
529         * <li>DoService</li>
530         * </ul>
531         * <p>
532         * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be
533         * thrown.
534         * </p>
535         * 
536         * @param request
537         * @param kvp
538         * @return created <code>OGCWebServiceRequest</code>
539         * @throws OGCWebServiceException
540         */
541        private static OGCWebServiceRequest getWSSRequest( String request, Map<String, String> kvp )
542                                throws OGCWebServiceException {
543            OGCWebServiceRequest ogcRequest = null;
544            String id = "" + IDGenerator.getInstance().generateUniqueID();
545            if ( ( "GetCapabilities" ).equals( request ) ) {
546                ogcRequest = WSSGetCapabilities.create( id, kvp );
547            } else if ( ( "GetSession" ).equals( request ) ) {
548                ogcRequest = GetSession.create( id, kvp );
549            } else if ( ( "CloseSession" ).equals( request ) ) {
550                ogcRequest = CloseSession.create( id, kvp );
551            } else if ( ( "DoService" ).equals( request ) ) {
552                ogcRequest = DoService.create( id, kvp );
553            } else {
554                throw new OGCWebServiceException( "Unknown / unimplemented WSS request type: '" + request + "'." );
555            }
556            return ogcRequest;
557        }
558    
559        /**
560         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The
561         * returned request will be a WAS request. The type of request is determined by also submitted
562         * request name. Known requests are:
563         * <ul>
564         * <li>GetCapabilities</li>
565         * <li>GetSession</li>
566         * <li>CloseSession</li>
567         * </ul>
568         * <p>
569         * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be
570         * thrown.
571         * </p>
572         * 
573         * @param request
574         * @param doc
575         * @return created <code>OGCWebServiceRequest</code>
576         * @throws OGCWebServiceException
577         */
578        private static OGCWebServiceRequest getWASRequest( String request, Document doc )
579                                throws OGCWebServiceException {
580            OGCWebServiceRequest ogcRequest = null;
581            String id = "" + IDGenerator.getInstance().generateUniqueID();
582            // note: DescribeUser is only supported through KVP
583            if ( ( "GetCapabilities" ).equals( request ) ) {
584                ogcRequest = WASGetCapabilities.create( id, doc.getDocumentElement() );
585            } else if ( ( "GetSession" ).equals( request ) ) {
586                ogcRequest = GetSession.create( id, doc.getDocumentElement() );
587            } else if ( ( "CloseSession" ).equals( request ) ) {
588                ogcRequest = CloseSession.create( id, doc.getDocumentElement() );
589            } else {
590                throw new OGCWebServiceException( "Unknown / unimplemented WAS request type: '" + request + "'." );
591            }
592            return ogcRequest;
593        }
594    
595        /**
596         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>key value pair</code>.
597         * The returned request will be a WAS request. The type of request is determined by also
598         * submitted request name. Known requests are:
599         * <ul>
600         * <li>GetCapabilities</li>
601         * <li>GetSession</li>
602         * <li>CloseSession</li>
603         * <li>DescribeUser</li>
604         * </ul>
605         * <p>
606         * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be
607         * thrown.
608         * </p>
609         * 
610         * @param request
611         * @param kvp
612         * @return created <code>OGCWebServiceRequest</code>
613         * @throws OGCWebServiceException
614         */
615        private static OGCWebServiceRequest getWASRequest( String request, Map<String, String> kvp )
616                                throws OGCWebServiceException {
617            OGCWebServiceRequest ogcRequest = null;
618            String id = "" + IDGenerator.getInstance().generateUniqueID();
619            if ( ( "GetCapabilities" ).equals( request ) ) {
620                ogcRequest = WASGetCapabilities.create( id, kvp );
621            } else if ( ( "GetSession" ).equals( request ) ) {
622                ogcRequest = GetSession.create( id, kvp );
623            } else if ( ( "CloseSession" ).equals( request ) ) {
624                ogcRequest = CloseSession.create( id, kvp );
625            } else if ( ( "DescribeUser" ).equals( request ) ) {
626                ogcRequest = new DescribeUser( id, kvp );
627            } else {
628                throw new OGCWebServiceException( "Unknown / unimplemented WAS request type: '" + request + "'." );
629            }
630            return ogcRequest;
631        }
632    
633        /**
634         * return the type of service the passed request targets
635         * 
636         * @param service
637         * @param request
638         * @param doc
639         * @return the type of service the passed request targets
640         */
641        public static String getTargetService( String service, String request, Document doc ) {
642    
643            if ( WMS_SERVICE_NAME.equals( service ) || isWMSRequest( request ) ) {
644                return WMS_SERVICE_NAME;
645            } else if ( WFS_SERVICE_NAME.equals( service ) || isWFSRequest( request, doc ) ) {
646                return WFS_SERVICE_NAME;
647            } else if ( WCS_SERVICE_NAME.equals( service ) || isWCSRequest( request ) ) {
648                return WCS_SERVICE_NAME;
649            } else if ( CSW_SERVICE_NAME_EBRIM.equals( service ) || CSW_SERVICE_NAME.equals( service )
650                        || isCSWRequest( request, doc ) ) {
651                return CSW_SERVICE_NAME;
652            } else if ( SOS_SERVICE_NAME.equals( service ) || isSOSRequest( request ) ) {
653                return SOS_SERVICE_NAME;
654            } else if ( WPVS_SERVICE_NAME.equals( service ) || isWPVSRequest( request ) ) {
655                return WPVS_SERVICE_NAME;
656            } else if ( WMPS_SERVICE_NAME.equals( service ) || isWMPSRequest( request ) ) {
657                return WMPS_SERVICE_NAME;
658            } else if ( WPS_SERVICE_NAME.equals( service ) || isWPSRequest( request ) ) {
659                return WPS_SERVICE_NAME;
660            } else if ( WAS_SERVICE_NAME.equals( service ) || isWASRequest( request ) ) {
661                return WAS_SERVICE_NAME;
662            } else if ( WSS_SERVICE_NAME.equals( service ) || isWSSRequest( request ) ) {
663                return WSS_SERVICE_NAME;
664            } else {
665                return "unknown";
666            }
667    
668        }
669    
670        /**
671         * returns true if the request is a WMPS request
672         * 
673         * @param request
674         *            name, e.g. 'GetCapabilities' name, e.g. 'PrintMap'
675         * @return true if the request is a WMPS request
676         */
677        private static boolean isWMPSRequest( String request ) {
678            if ( "GetCapabilities".equals( request ) || ( "PrintMap".equals( request ) ) ) {
679                return true;
680            }
681            return false;
682        }
683    
684        /**
685         * returns true if the request is a WMS request
686         * 
687         * @param request
688         * @return true if the request is a WMS request
689         */
690        private static boolean isWMSRequest( String request ) {
691            if ( "GetMap".equals( request ) || "map".equals( request ) || "GetFeatureInfo".equals( request )
692                 || "feature_info".equals( request ) || "GetLegendGraphic".equals( request )
693                 || "GetStyles".equals( request ) || "PutStyles".equals( request ) || "DescribeLayer".equals( request ) ) {
694                return true;
695            }
696            return false;
697        }
698    
699        /**
700         * returns true if the request is a WFS request
701         * 
702         * @param request
703         * @param doc
704         * @return true if the request is a WFS request
705         */
706        private static boolean isWFSRequest( String request, Document doc ) {
707            if ( doc != null ) {
708                String s = doc.getDocumentElement().getNamespaceURI();
709                if ( CommonNamespaces.WFSNS.toString().equals( s ) ) {
710                    return true;
711                }
712            } else {
713                if ( "DescribeFeatureType".equals( request ) || "GetFeature".equals( request )
714                     || "GetFeatureWithLock".equals( request ) || "GetGmlObject".equals( request )
715                     || "Lock".equals( request ) || "Transaction".equals( request ) ) {
716                    return true;
717                }
718            }
719            return false;
720        }
721    
722        /**
723         * returns true if the request is a WCS request
724         * 
725         * @param request
726         * @return true if the request is a WCS request
727         */
728        private static boolean isWCSRequest( String request ) {
729            if ( "GetCoverage".equals( request ) || "DescribeCoverage".equals( request ) ) {
730                return true;
731            }
732            return false;
733        }
734    
735        /**
736         * returns true if the request is a CSW request
737         * 
738         * @param request
739         * @return true if the request is a CSW request
740         */
741        private static boolean isCSWRequest( String request, Document doc ) {
742            if ( doc != null ) {
743                String s = doc.getDocumentElement().getNamespaceURI();
744                if ( CommonNamespaces.CSWNS.toString().equals( s ) || CommonNamespaces.CSW202NS.toString().equals( s ) ) {
745                    return true;
746                }
747            } else {
748                if ( CatalogueOperationsMetadata.GET_RECORDS_NAME.equals( request )
749                     || CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME.equals( request )
750                     || CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME.equals( request )
751                     || CatalogueOperationsMetadata.GET_DOMAIN_NAME.equals( request )
752                     || CatalogueOperationsMetadata.HARVEST_NAME.equals( request ) ) {
753                    return true;
754                }
755            }
756            return false;
757        }
758    
759        /**
760         * returns true if the request is a SOS request
761         * 
762         * @param request
763         * @return true if the request is a SOS request
764         */
765        private static boolean isSOSRequest( String request ) {
766            if ( "GetObservation".equals( request ) || "DescribeSensor".equals( request )
767                 || "DescribePlatform".equals( request ) ) {
768                return true;
769            }
770            return false;
771        }
772    
773        /**
774         * returns true if the request is a WPVS request
775         * 
776         * @param request
777         *            name, e.g. 'GetView'
778         * @return true if the request is a WPVS request
779         */
780        private static boolean isWPVSRequest( String request ) {
781            if ( "GetView".equals( request ) ) {
782                return true;
783            }
784            return false;
785        }
786    
787        /**
788         * returns true if the request is a WPS request
789         * 
790         * @param request
791         *            name, e.g. 'GetCapabilities' name, e.g. 'DescribeProcess', e.g. 'Exceute'
792         * @return true if the request is a WPS request
793         */
794        private static boolean isWPSRequest( String request ) {
795            if ( "DescribeProcess".equals( request ) || "Execute".equals( request ) ) {
796                return true;
797            }
798            return false;
799        }
800    
801        /**
802         * returns true if the request is a WAS request
803         * 
804         * @param request
805         *            name, e.g. 'GetSession' name, e.g. 'CloseSession', e.g. 'GetSAMLResponse'
806         * @return true if and only if the request contains one of the above Strings
807         */
808        private static boolean isWASRequest( String request ) {
809            if ( "GetSession".equals( request ) || "CloseSession".equals( request ) || "GetSAMLResponse".equals( request )
810                 || "DescribeUser".equals( request ) ) {
811                return true;
812            }
813            return false;
814        }
815    
816        /**
817         * returns true if the request is a WSS request
818         * 
819         * @param request
820         *            name, e.g. 'GetSession' name, e.g. 'CloseSession', e.g. 'GetSAMLResponse'
821         * @return true if and only if the request contains one of the above Strins
822         */
823        private static boolean isWSSRequest( String request ) {
824            if ( "GetSession".equals( request ) || "CloseSession".equals( request ) || "DoService".equals( request ) ) {
825                return true;
826            }
827            return false;
828        }
829    
830        /**
831         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Object</code>. the
832         * returned request will be a WCS request. The type of request is determind by the the also
833         * passed 'request' parameter. Possible requests are:
834         * <ul>
835         * <li>GetCapabilities
836         * <li>GetCoverage
837         * <li>DescribeCoverage
838         * </ul>
839         * <p>
840         * Any other request passed to the method causes an exception to be thrown.
841         * </p>
842         * 
843         * @param request
844         * @param req
845         * @return created <code>OGCWebServiceRequest</code>
846         * @throws OGCWebServiceException
847         */
848        private static OGCWebServiceRequest getWMSRequest( String request, Object req )
849                                throws OGCWebServiceException {
850            OGCWebServiceRequest ogcRequest = null;
851            String id = "" + IDGenerator.getInstance().generateUniqueID();
852            try {
853                Map<String, String> map = null;
854                if ( req instanceof Map ) {
855                    map = (Map) req;
856                    map.put( "ID", id );
857                }
858                if ( request.equals( "GetCapabilities" ) || "capabilities".equals( request ) ) {
859                    if ( map != null ) {
860                        // defaulting to 1.1.1 is not possible because of spec requirements
861                        // if( ( map.get( "VERSION" ) == null ) && ( map.get( "WMTVER" ) == null ) )
862                        // {
863                        // map.put( "VERSION", "1.3.0" );
864                        // }
865                        ogcRequest = WMSGetCapabilities.create( map );
866                    }
867                } else if ( request.equals( "GetMap" ) || request.equals( "map" ) ) {
868                    if ( map != null ) {
869                        ogcRequest = GetMap.create( map );
870                    } else {
871                        ogcRequest = GetMap.create( id, (Document) req );
872                    }
873                } else if ( request.equals( "GetFeatureInfo" ) || request.equals( "feature_info" ) ) {
874                    if ( map != null ) {
875                        ogcRequest = GetFeatureInfo.create( map );
876                    }
877                } else if ( request.equals( "GetLegendGraphic" ) ) {
878                    if ( map != null ) {
879                        ogcRequest = GetLegendGraphic.create( map );
880                    }
881                } else if ( request.equals( "DescribeLayer" ) ) {
882                    if ( map != null ) {
883                        ogcRequest = DescribeLayer.create( map );
884                    }
885                } else {
886                    throw new OGCWebServiceException( "Unknown WMS request type: '" + request + "'." );
887                }
888            } catch ( MalformedURLException e ) {
889                LOG.logError( e.getLocalizedMessage(), e );
890                throw new OGCWebServiceException( e.getMessage() );
891            } catch ( XMLParsingException e ) {
892                LOG.logError( e.getLocalizedMessage(), e );
893                throw new OGCWebServiceException( e.getMessage() );
894            }
895            return ogcRequest;
896        }
897    
898        /**
899         * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>.
900         * the returned request will be a WCS request. The type of request is determind by the the also
901         * passed 'request' parameter. Possible requests are:
902         * <ul>
903         * <li>GetCapabilities
904         * <li>GetCoverage
905         * <li>DescribeCoverage
906         * </ul>
907         * Any other request passed to the method causes an exception to be thrown.
908         * 
909         * @param request
910         *            a string describing the request type.
911         * @param req
912         *            the kvp-encoded request
913         * @return one of the above mentioned Requests.
914         * @throws OGCWebServiceException
915         *             if the requested operation is not one of the above mentioned, or something went
916         *             wrong while creating the request.
917         */
918        private static AbstractOGCWebServiceRequest getWCSRequest( String request, Map<String, String> req )
919                                throws OGCWebServiceException {
920            AbstractOGCWebServiceRequest ogcRequest = null;
921            String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
922            req.put( "ID", id );
923            if ( request.equals( "GetCapabilities" ) ) {
924                ogcRequest = WCSGetCapabilities.create( req );
925            } else if ( request.equals( "GetCoverage" ) ) {
926                ogcRequest = GetCoverage.create( req );
927            } else if ( request.equals( "DescribeCoverage" ) ) {
928                ogcRequest = DescribeCoverage.create( req );
929            } else {
930                throw new OGCWebServiceException( "Unknown WCS request type: '" + request + "'." );
931            }
932            return ogcRequest;
933        }
934    
935        /**
936         * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Docuement</code>.
937         * the returned request will be a WCS request. The type of request is determind by the the also
938         * passed 'request' parameter. Possible requests are:
939         * <ul>
940         * <li>GetCapabilities
941         * <li>GetCoverage
942         * <li>DescribeCoverage
943         * </ul>
944         * Any other request passed to the method causes an exception to be thrown.
945         * 
946         * @param request
947         *            a string describing the request type.
948         * @param req
949         *            the XML-encoded request
950         * @return one of the above mentioned Requests.
951         * @throws OGCWebServiceException
952         *             if the requested operation is not one of the above mentioned, or something went
953         *             wrong while creating the request.
954         */
955        private static AbstractOGCWebServiceRequest getWCSRequest( String request, Document req )
956                                throws OGCWebServiceException {
957            AbstractOGCWebServiceRequest ogcRequest = null;
958            String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
959            if ( request.equals( "GetCapabilities" ) ) {
960                ogcRequest = WCSGetCapabilities.create( id, req );
961            } else if ( request.equals( "GetCoverage" ) ) {
962                ogcRequest = GetCoverage.create( id, req );
963            } else if ( request.equals( "DescribeCoverage" ) ) {
964                ogcRequest = DescribeCoverage.create( id, req );
965            } else {
966                throw new OGCWebServiceException( "Unknown WCS request type: '" + request + "'." );
967            }
968            return ogcRequest;
969        }
970    
971        /**
972         * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>.
973         * The returned request will be a <code>CSW</code> request. The type of request is determined
974         * by the the also passed 'request' parameter. Allowed values for the request parameter are:
975         * <ul>
976         * <li>GetCapabilities</li>
977         * <li>GetRecords</li>
978         * <li>GetRecordsByID</li>
979         * <li>DescribeRecord</li>
980         * <li>GetDomain, will cause an exception to be thrown</li>
981         * <li>Transaction, will cause an exception to be thrown</li>
982         * <li>Harvest</li>
983         * </ul>
984         * 
985         * Any other request passed to the method causes an exception to be thrown.
986         * 
987         * @param request
988         *            a string describing the request type.
989         * @param req
990         *            the KVP-encoded request
991         * @return one of the above mentioned Requests.
992         * @throws OGCWebServiceException
993         *             if the requested operation is not one of the above mentioned, not supported or
994         *             something went wrong while creating the request.
995         */
996        private static AbstractOGCWebServiceRequest getCSWRequest( String request, Map<String, String> req )
997                                throws OGCWebServiceException {
998            AbstractOGCWebServiceRequest ogcRequest = null;
999            String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1000            LOG.logDebug( StringTools.concat( 200, "Creating CSW request '", request, "' with ID=", id, "/type:",
1001                                              req.getClass().getName() ) );
1002    
1003            if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( request ) ) {
1004                req.put( "ID", id );
1005                ogcRequest = CatalogueGetCapabilities.create( req );
1006            } else if ( CatalogueOperationsMetadata.GET_RECORDS_NAME.equals( request ) ) {
1007                req.put( "ID", id );
1008                ogcRequest = GetRecords.create( req );
1009            } else if ( CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME.equals( request ) ) {
1010                // req.put( "ID", id );
1011                ogcRequest = GetRecordById.create( id, req );
1012            } else if ( CatalogueOperationsMetadata.GET_REPOSITORY_ITEM.equals( request ) ) {
1013                req.put( "REQUESTID", id );
1014                ogcRequest = GetRepositoryItem.create( req );
1015            } else if ( CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME.equals( request ) ) {
1016                req.put( "ID", id );
1017                ogcRequest = DescribeRecord.create( req );
1018            } else if ( CatalogueOperationsMetadata.GET_DOMAIN_NAME.equals( request ) ) {
1019                // TODO
1020                throw new OGCWebServiceException( CatalogueOperationsMetadata.TRANSACTION_NAME + " is not supported." );
1021            } else if ( CatalogueOperationsMetadata.TRANSACTION_NAME.equals( request ) ) {
1022                throw new OGCWebServiceException( CatalogueOperationsMetadata.TRANSACTION_NAME
1023                                                  + " through HTTP Get is not supported." );
1024            } else if ( CatalogueOperationsMetadata.HARVEST_NAME.equals( request ) ) {
1025                req.put( "ID", id );
1026                ogcRequest = Harvest.create( req );
1027            } else {
1028                throw new OGCWebServiceException( "Unknown CSW request type: '" + request + "'." );
1029            }
1030            LOG.logDebug( "CSW request created: " + ogcRequest );
1031            return ogcRequest;
1032        }
1033    
1034        /**
1035         * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>.
1036         * The returned request will be a <code>CSW</code> request. The type of request is determined
1037         * by the the also passed 'request' parameter. Allowed values for the request parameter are:
1038         * <ul>
1039         * <li>GetCapabilities</li>
1040         * <li>GetRecords</li>
1041         * <li>GetRecordsByID</li>
1042         * <li>DescribeRecord</li>
1043         * <li>GetDomain, will cause an exception to be thrown</li>
1044         * <li>Transaction</li>
1045         * <li>Harvest, will cause an exception to be thrown</li>
1046         * </ul>
1047         * 
1048         * Any other request passed to the method causes an exception to be thrown.
1049         * 
1050         * @param request
1051         *            a string describing the request type.
1052         * @param req
1053         *            the XML-encoded request
1054         * @return one of the above mentioned Requests.
1055         * @throws OGCWebServiceException
1056         *             if the requested operation is not one of the above mentioned, or something went
1057         *             wrong while creating the request.
1058         */
1059        private static AbstractOGCWebServiceRequest getCSWRequest( String request, Document req )
1060                                throws OGCWebServiceException {
1061            AbstractOGCWebServiceRequest ogcRequest = null;
1062            String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1063            LOG.logDebug( StringTools.concat( 200, "Creating CSW request '", request, "' with ID=", id, "/type:",
1064                                              req.getClass().getName() ) );
1065            Element docElem = req.getDocumentElement();
1066            if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( request ) ) {
1067                ogcRequest = CatalogueGetCapabilities.create( id, docElem );
1068            } else if ( CatalogueOperationsMetadata.GET_RECORDS_NAME.equals( request ) ) {
1069                ogcRequest = GetRecords.create( id, docElem );
1070            } else if ( CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME.equals( request ) ) {
1071                ogcRequest = GetRecordById.create( id, docElem );
1072            } else if ( CatalogueOperationsMetadata.GET_REPOSITORY_ITEM.equals( request ) ) {
1073                throw new OGCWebServiceException( CatalogueOperationsMetadata.GET_REPOSITORY_ITEM + " is not supported." );
1074            } else if ( CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME.equals( request ) ) {
1075                ogcRequest = DescribeRecord.create( id, docElem );
1076            } else if ( CatalogueOperationsMetadata.GET_DOMAIN_NAME.equals( request ) ) {
1077                // TODO
1078                throw new OGCWebServiceException( CatalogueOperationsMetadata.TRANSACTION_NAME + " is not supported." );
1079            } else if ( CatalogueOperationsMetadata.TRANSACTION_NAME.equals( request ) ) {
1080                ogcRequest = org.deegree.ogcwebservices.csw.manager.Transaction.create( id, docElem );
1081            } else if ( CatalogueOperationsMetadata.HARVEST_NAME.equals( request ) ) {
1082                throw new OGCWebServiceException( CatalogueOperationsMetadata.HARVEST_NAME
1083                                                  + " through HTTP post is not supported." );
1084            } else {
1085                throw new OGCWebServiceException( "Unknown CSW request type: '" + request + "'." );
1086            }
1087            LOG.logDebug( "CSW request created: " + ogcRequest );
1088            return ogcRequest;
1089        }
1090    
1091        /**
1092         * 
1093         * @param request
1094         * @param req
1095         * @return created <code>OGCWebServiceRequest</code>
1096         * @throws OGCWebServiceException
1097         */
1098        private static AbstractOGCWebServiceRequest getSOSRequest( String request, Object req )
1099                                throws OGCWebServiceException {
1100    
1101            AbstractOGCWebServiceRequest ogcRequest = null;
1102    
1103            String id = "" + IDGenerator.getInstance().generateUniqueID();
1104    
1105            LOG.logDebug( "Creating SOS request '" + request + "' with ID=" + id + "/type:" + req.getClass().getName() );
1106    
1107            if ( req instanceof Map ) {
1108                ( (Map) req ).put( "ID", id );
1109            }
1110    
1111            if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( request ) ) {
1112                if ( req instanceof Map ) {
1113                    ogcRequest = SOSGetCapabilities.create( (Map) req );
1114                } else {
1115                    ogcRequest = SOSGetCapabilities.create( id, (Document) req );
1116                }
1117    
1118            } else if ( SOSOperationsMetadata.DESCRIBE_PLATFORM_NAME.equals( request ) ) {
1119                if ( req instanceof Map ) {
1120                    ogcRequest = DescribePlatformRequest.create( (Map) req );
1121                } else {
1122                    ogcRequest = DescribePlatformRequest.create( id, (Document) req );
1123                }
1124    
1125            } else if ( SOSOperationsMetadata.DESCRIBE_SENSOR_NAME.equals( request ) ) {
1126                if ( req instanceof Map ) {
1127                    ogcRequest = DescribeSensorRequest.create( (Map) req );
1128                } else {
1129                    ogcRequest = DescribeSensorRequest.create( id, (Document) req );
1130                }
1131            } else if ( SOSOperationsMetadata.GET_OBSERVATION_NAME.equals( request ) ) {
1132                if ( req instanceof Map ) {
1133                    ogcRequest = GetObservationRequest.create( (Map) req );
1134                } else {
1135                    ogcRequest = GetObservationRequest.create( id, (Document) req );
1136                }
1137            } else {
1138                throw new OGCWebServiceException( "Unknown SCS request type: '" + request + "'." );
1139            }
1140            LOG.logDebug( "SCS request created: " + ogcRequest );
1141            return ogcRequest;
1142        }
1143    
1144        /**
1145         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>XML-Document</code>.
1146         * the returned request will be a WPVS request. The type of request is determind by the the also
1147         * passed 'request' parameter. Possible requests are:
1148         * <ul>
1149         * <li>GetCapabilities
1150         * <li>GetView
1151         * </ul>
1152         * <p>
1153         * Any other request passed to the method causes an exception to be thrown.
1154         * </p>
1155         * 
1156         * @param requestName
1157         *            name of the request, one of GetCapabilities or GetView
1158         * @param request
1159         *            the request as an xml document
1160         * @return created <code>OGCWebServiceRequest</code>
1161         * @throws OGCWebServiceException
1162         */
1163        @SuppressWarnings("unused")
1164        private static OGCWebServiceRequest getWPVSRequest( String requestName, Document request )
1165                                throws OGCWebServiceException {
1166            OGCWebServiceRequest ogcRequest = null;
1167            String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1168    
1169            if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( requestName ) ) {
1170                // ogcRequest = WPVSGetCapabilities.create(id, (Document) req);
1171            } else if ( "GetView".equals( requestName ) ) {
1172                // ogcRequest = GetView.create( req );
1173            } else {
1174                throw new OGCWebServiceException( "Unknown WPVS request type: '" + requestName + "'." );
1175            }
1176            return ogcRequest;
1177        }
1178    
1179        /**
1180         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>KVP-Map</code>. the
1181         * returned request will be a WPVS request. The type of request is determind by the the also
1182         * passed 'request' parameter. Possible requests are:
1183         * <ul>
1184         * <li>GetCapabilities
1185         * <li>GetView
1186         * </ul>
1187         * <p>
1188         * Any other request passed to the method causes an exception to be thrown.
1189         * </p>
1190         * 
1191         * @param requestName
1192         *            name of the request, one of GetCapabilities or GetView
1193         * @param request
1194         *            the actual parameters of the request
1195         * @return created <code>OGCWebServiceRequest</code>
1196         * @throws OGCWebServiceException
1197         */
1198        private static OGCWebServiceRequest getWPVSRequest( String requestName, Map<String, String> request )
1199                                throws OGCWebServiceException {
1200            OGCWebServiceRequest ogcRequest = null;
1201            String id = Long.toString( IDGenerator.getInstance().generateUniqueID() );
1202    
1203            if ( OperationsMetadata.GET_CAPABILITIES_NAME.equals( requestName ) ) {
1204                request.put( "ID", id );
1205                ogcRequest = WPVSGetCapabilities.create( request );
1206            } else if ( "GetView".equals( requestName ) ) {
1207                ogcRequest = GetView.create( request );
1208            } else if ( "Get3DFeatureInfo".equals( requestName ) ) {
1209                ogcRequest = Get3DFeatureInfo.create( request );
1210            } else {
1211                throw new OGCWebServiceException( "Unknown WPVS request type: '" + requestName + "'." );
1212            }
1213            return ogcRequest;
1214        }
1215    
1216        /**
1217         * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>.
1218         * the returned request will be a WMPS request. The type of request is determind by the the also
1219         * passed 'request' parameter. Possible requests are:
1220         * <ul>
1221         * <li>GetCapabilities
1222         * </ul>
1223         * Any other request passed to the method causes an exception to be thrown.
1224         * 
1225         * @param request
1226         * @param doc
1227         * @param req
1228         * @return created <code>OGCWebServiceRequest</code>
1229         * @throws OGCWebServiceException
1230         * @throws OGCWebServiceException
1231         */
1232        private static OGCWebServiceRequest getWMPSRequest( String request, Document doc )
1233                                throws OGCWebServiceException {
1234            OGCWebServiceRequest ogcRequest = null;
1235    
1236            if ( request.equals( "PrintMap" ) ) {
1237                try {
1238                    ogcRequest = PrintMap.create( doc.getDocumentElement() );
1239                } catch ( Exception e ) {
1240                    throw new OGCWebServiceException( "Error creating a Print Map object for the request '" + request
1241                                                      + "'. " + e.getMessage() );
1242                }
1243            } else {
1244                throw new OGCWebServiceException( "Unknown / unimplemented WMPS request type: '" + request + "'." );
1245            }
1246            return ogcRequest;
1247        }
1248    
1249        /**
1250         * Creates an <code>AbstractOGCWebServiceRequest</code> from the passed <code>Object</code>.
1251         * the returned request will be a WMPS request. The type of request is determind by the the also
1252         * passed 'request' parameter. Possible requests are:
1253         * <ul>
1254         * <li>GetCapabilities
1255         * </ul>
1256         * Any other request passed to the method causes an exception to be thrown.
1257         * 
1258         * @param request
1259         * @param map
1260         * @param req
1261         * @return OGCWebServiceRequest
1262         * @throws InconsistentRequestException
1263         * @throws InvalidParameterValueException
1264         * @throws OGCWebServiceException
1265         */
1266        private static OGCWebServiceRequest getWMPSRequest( String request, Map<String, String> map )
1267                                throws InconsistentRequestException, InvalidParameterValueException {
1268            OGCWebServiceRequest ogcRequest = null;
1269            map.put( "ID", "" + IDGenerator.getInstance().generateUniqueID() );
1270            if ( request.equals( "GetCapabilities" ) ) {
1271                ogcRequest = WMPSGetCapabilities.create( map );
1272            } else if ( request.equals( "PrintMap" ) ) {
1273                ogcRequest = PrintMap.create( map );
1274            } else {
1275                throw new InvalidParameterValueException( "Unknown WMPS request type: '" + request + "'." );
1276            }
1277            return ogcRequest;
1278        }
1279    
1280        /**
1281         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Map</code>. The
1282         * returned request will be a WPS request. The type of request is determined by also submitted
1283         * request name. Known requests are:
1284         * <ul>
1285         * <li>GetCapabilities</li>
1286         * <li>DescribeProcess</li>
1287         * <li>Execute</li>
1288         * </ul>
1289         * <p>
1290         * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be
1291         * thrown.
1292         * </p>
1293         * 
1294         * @param request
1295         * @param map
1296         * @return created <code>OGCWebServiceRequest</code>
1297         * @throws OGCWebServiceException
1298         */
1299        private static OGCWebServiceRequest getWPSRequest( String request, Map<String, String> map )
1300                                throws OGCWebServiceException {
1301            OGCWebServiceRequest ogcRequest = null;
1302            map.put( "ID", "" + IDGenerator.getInstance().generateUniqueID() );
1303            if ( "GetCapabilities".equals( request ) ) {
1304                ogcRequest = WPSGetCapabilities.create( map );
1305            } else if ( "DescribeProcess".equals( request ) ) {
1306                ogcRequest = DescribeProcessRequest.create( map );
1307            } else if ( "Execute".equals( request ) ) {
1308                ogcRequest = ExecuteRequest.create( map );
1309            } else {
1310                throw new InvalidParameterValueException( "Unknown WPS request type: '" + request + "'." );
1311            }
1312            return ogcRequest;
1313        }
1314    
1315        /**
1316         * Creates an <code>OGCWebServiceRequest</code> from the passed <code>Document</code>. The
1317         * returned request will be a WPS request. The type of request is determined by also submitted
1318         * request name. Known requests are:
1319         * <ul>
1320         * <li>GetCapabilities</li>
1321         * <li>DescribeProcess</li>
1322         * <li>Execute</li>
1323         * </ul>
1324         * <p>
1325         * Any other request passed to the method causes an <code>OGCWebServiceException</code> to be
1326         * thrown.
1327         * </p>
1328         * 
1329         * @param request
1330         * @param doc
1331         * @return created <code>OGCWebServiceRequest</code>
1332         * @throws OGCWebServiceException
1333         */
1334        private static OGCWebServiceRequest getWPSRequest( String request, Document doc )
1335                                throws OGCWebServiceException {
1336            OGCWebServiceRequest ogcRequest = null;
1337            String id = "" + IDGenerator.getInstance().generateUniqueID();
1338            if ( "GetCapabilities".equals( request ) ) {
1339                ogcRequest = WPSGetCapabilities.create( id, doc.getDocumentElement() );
1340            } else if ( "DescribeProcess".equals( request ) ) {
1341                ogcRequest = DescribeProcessRequest.create( id, doc.getDocumentElement() );
1342    
1343            } else if ( "Execute".equals( request ) ) {
1344                ogcRequest = ExecuteRequest.create( id, doc.getDocumentElement() );
1345    
1346            } else {
1347                throw new OGCWebServiceException( "Unknown WPS request type: '" + request + "'." );
1348            }
1349            return ogcRequest;
1350        }
1351    
1352    }