001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wass/wss/operation/DoServiceDocument.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2008 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/deegree/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     This library is free software; you can redistribute it and/or
012     modify it under the terms of the GNU Lesser General Public
013     License as published by the Free Software Foundation; either
014     version 2.1 of the License, or (at your option) any later version.
015    
016     This library is distributed in the hope that it will be useful,
017     but WITHOUT ANY WARRANTY; without even the implied warranty of
018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019     Lesser General Public License for more details.
020    
021     You should have received a copy of the GNU Lesser General Public
022     License along with this library; if not, write to the Free Software
023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024    
025     Contact:
026    
027     Andreas Poth
028     lat/lon GmbH
029     Aennchenstr. 19
030     53115 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: greve@giub.uni-bonn.de
041    
042     
043     ---------------------------------------------------------------------------*/
044    
045    package org.deegree.ogcwebservices.wass.wss.operation;
046    
047    import java.net.URI;
048    import java.util.ArrayList;
049    import java.util.List;
050    
051    import org.deegree.framework.xml.XMLFragment;
052    import org.deegree.framework.xml.XMLParsingException;
053    import org.deegree.framework.xml.XMLTools;
054    import org.deegree.i18n.Messages;
055    import org.deegree.ogcbase.CommonNamespaces;
056    import org.deegree.ogcwebservices.wass.common.AuthenticationData;
057    import org.deegree.ogcwebservices.wass.common.AuthenticationDocument;
058    import org.w3c.dom.Element;
059    import org.w3c.dom.Node;
060    
061    /**
062     * A parser for a xml DoService Request.
063     * 
064     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
065     * @author last edited by: $Author: apoth $
066     * 
067     * @version 2.0, $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $
068     * 
069     * @since 2.0
070     */
071    
072    public class DoServiceDocument extends XMLFragment {
073    
074        private static final long serialVersionUID = -8223141905965433189L;
075    
076        private static final String PRE = CommonNamespaces.GDINRWWSS_PREFIX + ":";
077    
078        /**
079         * @param id
080         *            the request id
081         * @param rootElement
082         * @return the encapsulated data
083         * @throws XMLParsingException
084         */
085        public DoService parseDoService( String id, Element rootElement )
086                                throws XMLParsingException {
087            
088    
089            String service = XMLTools.getRequiredNodeAsString( rootElement, "@service", nsContext );
090            if ( ! "WSS".equals( service  ) )
091                throw new XMLParsingException( Messages.getMessage( "WASS_ERROR_NOT_WSS" ) );
092    
093            String version = XMLTools.getRequiredNodeAsString( rootElement, "@version", nsContext );
094            if ( !version.equals( "1.0" ) )
095                throw new XMLParsingException(
096                                               Messages.getMessage( "WASS_ERROR_NO_VERSION_ATTRIBUTE" ) );
097    
098            String currentPre = CommonNamespaces.GDINRW_AUTH_PREFIX + ":";
099            Element authData = (Element) XMLTools.getRequiredNode( rootElement, currentPre
100                                                                                + "AuthenticationData",
101                                                                   nsContext );
102    
103            AuthenticationData authenticationData = new AuthenticationDocument().parseAuthenticationData( authData );
104    
105            Element serviceRequest = (Element) XMLTools.getRequiredNode( rootElement,
106                                                                         PRE + "ServiceRequest",
107                                                                         nsContext );
108    
109            String DCP = XMLTools.getRequiredNodeAsString( serviceRequest, "@DCP", nsContext );
110            if ( !( DCP.equals( "HTTP_GET" ) || DCP.equals( "HTTP_POST" ) ) )
111                throw new XMLParsingException(
112                                               Messages.getMessage(
113                                                                "WASS_ERROR_NOT_POST_OR_GET",
114                                                                "WSS" ) );
115    
116            ArrayList<RequestParameter> requestParameters = parseRequestParameters( serviceRequest );
117    
118            String payload = XMLTools.getRequiredNodeAsString( serviceRequest, PRE + "Payload",
119                                                               nsContext );
120    
121            URI facadeURL = XMLTools.getRequiredNodeAsURI( rootElement, PRE + "FacadeURL", nsContext );
122    
123            DoService theService = new DoService( id, service, version, authenticationData, DCP,
124                                                  requestParameters, payload, facadeURL );
125            
126            return theService;
127        }
128    
129        private ArrayList<RequestParameter> parseRequestParameters( Element serviceRequest )
130                                throws XMLParsingException {
131            
132            List<Node> requestParameter = XMLTools.getNodes( serviceRequest, PRE + "RequestParameter",
133                                                       nsContext );
134            if ( requestParameter == null ) {
135                
136                return null;
137            }
138            ArrayList<RequestParameter> serviceRequests = new ArrayList<RequestParameter>();
139            for ( Object element : requestParameter ) {
140                String id = XMLTools.getRequiredNodeAsString( (Element) element, "@id", nsContext );
141                String nodeValue = ( (Element) element ).getNodeValue();
142                RequestParameter param = new RequestParameter( nodeValue, id );
143                serviceRequests.add( param );
144            }
145            
146            return serviceRequests;
147        }
148    }