001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/AbstractOGCWebServiceRequest.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/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; 046 047 import java.io.Serializable; 048 import java.util.HashMap; 049 import java.util.Map; 050 051 /** 052 * This is the abstract base class for all requests to OGC Web Services (OWS). 053 * <p> 054 * Contains utility methods to ease the extraction of values from KVP parameter maps. 055 * 056 * @author <a href="mailto:k.lupp@web.de">Katharina Lupp </a> 057 * @author last edited by: $Author: bezema $ 058 * 059 * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $ 060 */ 061 public abstract class AbstractOGCWebServiceRequest implements OGCWebServiceRequest, Serializable { 062 063 private Map<String, String> vendorSpecificParameter; 064 065 private String id; 066 067 private String version; 068 069 /** 070 * returns the ID of a request 071 */ 072 public String getId() { 073 return id; 074 } 075 076 /** 077 * returns the requested service version 078 */ 079 public String getVersion() { 080 return version; 081 } 082 083 /** 084 * Creates a new instance of <code>AbstractOGCWebServiceRequest</code>. 085 * 086 * @param version 087 * @param id 088 * @param vendorSpecificParameter 089 */ 090 protected AbstractOGCWebServiceRequest( String version, String id, Map<String, String> vendorSpecificParameter ) { 091 this.id = id; 092 if ( vendorSpecificParameter != null ) { 093 this.vendorSpecificParameter = vendorSpecificParameter; 094 } else { 095 this.vendorSpecificParameter = new HashMap<String, String>(); 096 } 097 this.version = version; 098 } 099 100 /** 101 * Finally, the requests allow for optional vendor-specific parameters (VSPs) that will enhance 102 * the results of a request. Typically, these are used for private testing of non-standard 103 * functionality prior to possible standardization. A generic client is not required or expected 104 * to make use of these VSPs. 105 */ 106 public Map<String, String> getVendorSpecificParameters() { 107 return vendorSpecificParameter; 108 } 109 110 /** 111 * Finally, the requests allow for optional vendor-specific parameters (VSPs) that will enhance 112 * the results of a request. Typically, these are used for private testing of non-standard 113 * functionality prior to possible standardization. A generic client is not required or expected 114 * to make use of these VSPs. 115 */ 116 public String getVendorSpecificParameter( String name ) { 117 return vendorSpecificParameter.get( name ); 118 } 119 120 /** 121 * returns the URI of a HTTP GET request. If the request doesn't support HTTP GET a 122 * <tt>WebServiceException</tt> will be thrown 123 * 124 */ 125 public String getRequestParameter() throws OGCWebServiceException { 126 throw new OGCWebServiceException( "HTTP GET isn't supported" ); 127 } 128 129 /** 130 * Extracts a <code>String</code> parameter value from the given parameter map. If the given 131 * parameter does not exist, the also submitted default value is returned. 132 * 133 * @param name 134 * name of the parameter to be looked up 135 * @param kvp 136 * must contain Strings as keys and Strings as values 137 * @param defaultValue 138 * default value to be used if parameter is missing 139 * @return parameter value 140 */ 141 protected static String getParam( String name, Map<String, String> kvp, String defaultValue ) { 142 String value = kvp.remove( name ); 143 if ( value == null ) { 144 value = defaultValue; 145 } 146 return value; 147 } 148 149 /** 150 * Extracts a <code>String</code> list from the given parameter map. The single values 151 * are separated by commas. If the given parameter does not exist, the also submitted 152 * default value is returned. 153 * 154 * @param name 155 * name of the parameter to be looked up 156 * @param kvp 157 * must contain Strings as keys and Strings as values 158 * @param defaultValue 159 * default value to be used if parameter is missing 160 * @return parameter value 161 */ 162 protected static String [] getParamValues( String name, Map<String, String> kvp, String defaultValue ) { 163 String value = kvp.get( name ); 164 if ( value == null ) { 165 value = defaultValue; 166 } 167 return value.split(","); 168 } 169 170 /** 171 * Extracts a <code>String</code> parameter value from the given parameter map. Generates 172 * exceptions with descriptive messages, if the parameter does not exist in the <code>Map</code>. 173 * 174 * @param name 175 * name of the parameter to be looked up 176 * @param kvp 177 * must contain Strings as keys and Strings as values 178 * @return parameter value 179 * @throws MissingParameterValueException 180 */ 181 protected static String getRequiredParam( String name, Map<String, String> kvp ) 182 throws MissingParameterValueException { 183 String value = kvp.remove( name ); 184 if ( value == null ) { 185 throw new MissingParameterValueException ( 186 "Cannot create OGC web service request. Required parameter '" 187 + name + "' is missing.", name ); 188 } 189 return value; 190 } 191 192 /** 193 * Extracts an <code>int</code> parameter value from the given parameter map. If the given 194 * parameter does not exist, the also submitted default value is returned. 195 * 196 * @param name 197 * name of the parameter to be looked up 198 * @param kvp 199 * must contain Strings as keys and Strings as values 200 * @param defaultValue 201 * default value to be used if parameter is missing 202 * @return parameter value 203 * @throws InvalidParameterValueException 204 */ 205 protected static int getParamAsInt( String name, Map<String, String> kvp, int defaultValue ) 206 throws InvalidParameterValueException { 207 int value = defaultValue; 208 String paramValue = kvp.get( name ); 209 if ( paramValue != null ) { 210 try { 211 value = Integer.parseInt( paramValue ); 212 } catch (NumberFormatException e) { 213 throw new InvalidParameterValueException( "Value '" 214 + paramValue + "' for parameter '" + name 215 + "' is invalid. Must be of type integer." ); 216 } 217 } 218 return value; 219 } 220 221 @Override 222 public String toString() { 223 String ret = "vendorSpecificParameter = " 224 + vendorSpecificParameter + "\n" ; 225 ret += ( "id = " 226 + id + "\n" ); 227 ret += ( "version = " 228 + version); 229 return ret; 230 } 231 } 232 233 /* ******************************************************************** 234 Changes to this class. What the people have been up to: 235 $Log$ 236 Revision 1.19 2006/11/29 16:01:01 bezema 237 fixed toString 238 239 Revision 1.18 2006/11/28 16:29:20 bezema 240 Fixed a null pointer bug in the tostring method 241 242 Revision 1.17 2006/11/07 11:09:54 mschneider 243 Fixed footer formatting. 244 245 Revision 1.16 2006/10/27 13:25:26 poth 246 chaged getParam and getRequiredParam methods to remove the parameters read from the Map 247 248 Revision 1.15 2006/08/28 12:52:04 bezema 249 little javadoc corrections 250 251 Revision 1.14 2006/08/28 07:52:16 bezema 252 added typesafety (<String, String>) for the map, and fixed documentation, no more warnings found 253 254 Revision 1.13 2006/07/21 14:07:09 mschneider 255 Improved javadoc. 256 257 Revision 1.12 2006/07/12 14:46:16 poth 258 comment footer added 259 260 ********************************************************************** */