001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wass/common/SessionOperationsDocument.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.common; 046 047 import org.deegree.framework.log.ILogger; 048 import org.deegree.framework.log.LoggerFactory; 049 import org.deegree.framework.xml.XMLParsingException; 050 import org.deegree.framework.xml.XMLTools; 051 import org.deegree.i18n.Messages; 052 import org.deegree.ogcbase.CommonNamespaces; 053 import org.deegree.ogcbase.OGCDocument; 054 import org.w3c.dom.Element; 055 import org.w3c.dom.Node; 056 057 /** 058 * Parser class that can parse all elements within the namespace. 059 * 060 * Namespace: http://www.gdi-nrw.de/session 061 * 062 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 063 * @author last edited by: $Author: apoth $ 064 * 065 * @version 2.0, $Revision: 9348 $, $Date: 2007-12-27 17:59:14 +0100 (Do, 27 Dez 2007) $ 066 * 067 * @since 2.0 068 */ 069 070 public class SessionOperationsDocument extends OGCDocument { 071 072 private static final long serialVersionUID = 7190634032990406558L; 073 074 private static final ILogger LOG = LoggerFactory.getLogger( SessionOperationsDocument.class ); 075 076 private static final String PSESSION = CommonNamespaces.WSSSESSION_PREFIX + ":"; 077 078 /** 079 * Parses a GetSession element. 080 * 081 * @param id 082 * the request id 083 * 084 * @param request 085 * the element 086 * @return an object with the parsed data 087 * @throws XMLParsingException 088 */ 089 public GetSession parseGetSession( String id, Element request ) 090 throws XMLParsingException { 091 092 093 String serviceName = parseService( request ); 094 String version = parseVersion( request ); 095 096 String pre = CommonNamespaces.GDINRW_AUTH_PREFIX + ":"; 097 Node data = XMLTools.getRequiredNode( request, pre + "AuthenticationData", nsContext ); 098 AuthenticationData authenticationData = new AuthenticationDocument().parseAuthenticationData( data ); 099 GetSession gs = new GetSession( id, serviceName, version, authenticationData ); 100 101 return gs; 102 } 103 104 /** 105 * Parses a CloseSession element. 106 * 107 * @param id 108 * the request id 109 * 110 * @param request 111 * the element 112 * @return an object with the data 113 * @throws XMLParsingException 114 */ 115 public CloseSession parseCloseSession( String id, Element request ) 116 throws XMLParsingException { 117 118 String serviceName = parseService( request ); 119 String version = parseVersion( request ); 120 String sessionID = XMLTools.getRequiredNodeAsString( request, PSESSION + "SessionID", 121 nsContext ); 122 CloseSession cs = new CloseSession( id, serviceName, version, sessionID ); 123 124 return cs; 125 } 126 127 /** 128 * Parses the service name. 129 * 130 * @param basicRequest 131 * the request element 132 * @return a String containing the service name 133 * @throws XMLParsingException 134 * if the service name was not WAS or WSS 135 */ 136 private String parseService( Element basicRequest ) 137 throws XMLParsingException { 138 139 String serviceName = XMLTools.getRequiredNodeAsString( basicRequest, "@service", nsContext ); 140 if ( !( serviceName.equals( "WAS" ) || serviceName.equals( "WSS" ) ) ) { 141 throw new XMLParsingException( 142 Messages.getMessage( "WASS_ERROR_NO_SERVICE_ATTRIBUTE" ) ); 143 } 144 145 return serviceName; 146 } 147 148 /** 149 * Parses the version attribute of a request element. 150 * 151 * @param basicRequest 152 * the element 153 * @return a string containing the version number (currently "1.0") 154 * @throws XMLParsingException 155 */ 156 private String parseVersion( Element basicRequest ) 157 throws XMLParsingException { 158 159 String version = XMLTools.getRequiredNodeAsString( basicRequest, "@version", nsContext ); 160 if ( !version.equals( "1.0" ) ) { 161 throw new XMLParsingException( 162 Messages.getMessage( "WASS_ERROR_NO_VERSION_ATTRIBUTE" ) ); 163 } 164 165 return version; 166 } 167 168 }