001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wass/wss/operation/DoServiceDocument.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2006 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/exse/
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     Aennchenstraße 19
030     53177 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Jens Fitzke
035     lat/lon GmbH
036     Aennchenstraße 19
037     53177 Bonn
038     Germany
039     E-Mail: jens.fitzke@uni-bonn.de
040    
041     ---------------------------------------------------------------------------*/
042    
043    package org.deegree.ogcwebservices.wass.wss.operation;
044    
045    import java.net.URI;
046    import java.util.ArrayList;
047    import java.util.List;
048    
049    import org.deegree.framework.xml.XMLFragment;
050    import org.deegree.framework.xml.XMLParsingException;
051    import org.deegree.framework.xml.XMLTools;
052    import org.deegree.i18n.Messages;
053    import org.deegree.ogcbase.CommonNamespaces;
054    import org.deegree.ogcwebservices.wass.common.AuthenticationData;
055    import org.deegree.ogcwebservices.wass.common.AuthenticationDocument;
056    import org.w3c.dom.Element;
057    import org.w3c.dom.Node;
058    
059    /**
060     * A parser for a xml DoService Request.
061     * 
062     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
063     * @author last edited by: $Author: rbezema $
064     * 
065     * @version 2.0, $Revision: 7398 $, $Date: 2007-05-31 18:21:45 +0200 (Do, 31 Mai 2007) $
066     * 
067     * @since 2.0
068     */
069    
070    public class DoServiceDocument extends XMLFragment {
071    
072        private static final long serialVersionUID = -8223141905965433189L;
073    
074        private static final String PRE = CommonNamespaces.GDINRWWSS_PREFIX + ":";
075    
076        /**
077         * @param id
078         *            the request id
079         * @param rootElement
080         * @return the encapsulated data
081         * @throws XMLParsingException
082         */
083        public DoService parseDoService( String id, Element rootElement )
084                                throws XMLParsingException {
085            
086    
087            String service = XMLTools.getRequiredNodeAsString( rootElement, "@service", nsContext );
088            if ( ! "WSS".equals( service  ) )
089                throw new XMLParsingException( Messages.getMessage( "WASS_ERROR_NOT_WSS" ) );
090    
091            String version = XMLTools.getRequiredNodeAsString( rootElement, "@version", nsContext );
092            if ( !version.equals( "1.0" ) )
093                throw new XMLParsingException(
094                                               Messages.getMessage( "WASS_ERROR_NO_VERSION_ATTRIBUTE" ) );
095    
096            String currentPre = CommonNamespaces.GDINRW_AUTH_PREFIX + ":";
097            Element authData = (Element) XMLTools.getRequiredNode( rootElement, currentPre
098                                                                                + "AuthenticationData",
099                                                                   nsContext );
100    
101            AuthenticationData authenticationData = new AuthenticationDocument().parseAuthenticationData( authData );
102    
103            Element serviceRequest = (Element) XMLTools.getRequiredNode( rootElement,
104                                                                         PRE + "ServiceRequest",
105                                                                         nsContext );
106    
107            String DCP = XMLTools.getRequiredNodeAsString( serviceRequest, "@DCP", nsContext );
108            if ( !( DCP.equals( "HTTP_GET" ) || DCP.equals( "HTTP_POST" ) ) )
109                throw new XMLParsingException(
110                                               Messages.getMessage(
111                                                                "WASS_ERROR_NOT_POST_OR_GET",
112                                                                "WSS" ) );
113    
114            ArrayList<RequestParameter> requestParameters = parseRequestParameters( serviceRequest );
115    
116            String payload = XMLTools.getRequiredNodeAsString( serviceRequest, PRE + "Payload",
117                                                               nsContext );
118    
119            URI facadeURL = XMLTools.getRequiredNodeAsURI( rootElement, PRE + "FacadeURL", nsContext );
120    
121            DoService theService = new DoService( id, service, version, authenticationData, DCP,
122                                                  requestParameters, payload, facadeURL );
123            
124            return theService;
125        }
126    
127        private ArrayList<RequestParameter> parseRequestParameters( Element serviceRequest )
128                                throws XMLParsingException {
129            
130            List<Node> requestParameter = XMLTools.getNodes( serviceRequest, PRE + "RequestParameter",
131                                                       nsContext );
132            if ( requestParameter == null ) {
133                
134                return null;
135            }
136            ArrayList<RequestParameter> serviceRequests = new ArrayList<RequestParameter>();
137            for ( Object element : requestParameter ) {
138                String id = XMLTools.getRequiredNodeAsString( (Element) element, "@id", nsContext );
139                String nodeValue = ( (Element) element ).getNodeValue();
140                RequestParameter param = new RequestParameter( nodeValue, id );
141                serviceRequests.add( param );
142            }
143            
144            return serviceRequests;
145        }
146    }