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