001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/wass/common/SessionOperationsDocument.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    
037    package org.deegree.ogcwebservices.wass.common;
038    
039    import org.deegree.framework.xml.XMLParsingException;
040    import org.deegree.framework.xml.XMLTools;
041    import org.deegree.i18n.Messages;
042    import org.deegree.ogcbase.CommonNamespaces;
043    import org.deegree.ogcbase.OGCDocument;
044    import org.w3c.dom.Element;
045    import org.w3c.dom.Node;
046    
047    /**
048     * Parser class that can parse all elements within the namespace.
049     *
050     * Namespace: http://www.gdi-nrw.de/session
051     *
052     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
053     * @author last edited by: $Author: mschneider $
054     *
055     * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
056     *
057     * @since 2.0
058     */
059    
060    public class SessionOperationsDocument extends OGCDocument {
061    
062        private static final long serialVersionUID = 7190634032990406558L;
063    
064        private static final String PSESSION = CommonNamespaces.WSSSESSION_PREFIX + ":";
065    
066        /**
067         * Parses a GetSession element.
068         *
069         * @param id
070         *            the request id
071         *
072         * @param request
073         *            the element
074         * @return an object with the parsed data
075         * @throws XMLParsingException
076         */
077        public GetSession parseGetSession( String id, Element request )
078                                throws XMLParsingException {
079    
080    
081            String serviceName = parseService( request );
082            String version = parseVersion( request );
083    
084            String pre = CommonNamespaces.GDINRW_AUTH_PREFIX + ":";
085            Node data = XMLTools.getRequiredNode( request, pre + "AuthenticationData", nsContext );
086            AuthenticationData authenticationData = new AuthenticationDocument().parseAuthenticationData( data );
087            GetSession gs = new GetSession( id, serviceName, version, authenticationData );
088    
089            return gs;
090        }
091    
092        /**
093         * Parses a CloseSession element.
094         *
095         * @param id
096         *            the request id
097         *
098         * @param request
099         *            the element
100         * @return an object with the data
101         * @throws XMLParsingException
102         */
103        public CloseSession parseCloseSession( String id, Element request )
104                                throws XMLParsingException {
105    
106            String serviceName = parseService( request );
107            String version = parseVersion( request );
108            String sessionID = XMLTools.getRequiredNodeAsString( request, PSESSION + "SessionID",
109                                                                 nsContext );
110            CloseSession cs = new CloseSession( id, serviceName, version, sessionID );
111    
112            return cs;
113        }
114    
115        /**
116         * Parses the service name.
117         *
118         * @param basicRequest
119         *            the request element
120         * @return a String containing the service name
121         * @throws XMLParsingException
122         *             if the service name was not WAS or WSS
123         */
124        private String parseService( Element basicRequest )
125                                throws XMLParsingException {
126    
127            String serviceName = XMLTools.getRequiredNodeAsString( basicRequest, "@service", nsContext );
128            if ( !( serviceName.equals( "WAS" ) || serviceName.equals( "WSS" ) ) ) {
129                throw new XMLParsingException(
130                                               Messages.getMessage( "WASS_ERROR_NO_SERVICE_ATTRIBUTE" ) );
131            }
132    
133            return serviceName;
134        }
135    
136        /**
137         * Parses the version attribute of a request element.
138         *
139         * @param basicRequest
140         *            the element
141         * @return a string containing the version number (currently "1.0")
142         * @throws XMLParsingException
143         */
144        private String parseVersion( Element basicRequest )
145                                throws XMLParsingException {
146    
147            String version = XMLTools.getRequiredNodeAsString( basicRequest, "@version", nsContext );
148            if ( !version.equals( "1.0" ) ) {
149                throw new XMLParsingException(
150                                               Messages.getMessage( "WASS_ERROR_NO_VERSION_ATTRIBUTE" ) );
151            }
152    
153            return version;
154        }
155    
156    }