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