001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wcs/describecoverage/DescribeCoverage.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 package org.deegree.ogcwebservices.wcs.describecoverage; 045 046 import java.util.Map; 047 048 import org.deegree.framework.util.KVP2Map; 049 import org.deegree.framework.util.StringTools; 050 import org.deegree.framework.xml.ElementList; 051 import org.deegree.framework.xml.XMLParsingException; 052 import org.deegree.framework.xml.XMLTools; 053 import org.deegree.ogcbase.CommonNamespaces; 054 import org.deegree.ogcbase.ExceptionCode; 055 import org.deegree.ogcwebservices.InvalidParameterValueException; 056 import org.deegree.ogcwebservices.MissingParameterValueException; 057 import org.deegree.ogcwebservices.OGCWebServiceException; 058 import org.deegree.ogcwebservices.wcs.WCSException; 059 import org.deegree.ogcwebservices.wcs.WCSExceptionCode; 060 import org.deegree.ogcwebservices.wcs.WCSRequestBase; 061 import org.w3c.dom.Document; 062 import org.w3c.dom.Element; 063 064 /** 065 * A DescribeCoverage request lists the coverages to be described, identified by the Coverage 066 * parameter. A request that lists no coverages shall be interpreted as requesting descriptions of 067 * all coverages that a WCS can serve. 068 * 069 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 070 * @author last edited by: $Author: apoth $ 071 * 072 * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $ 073 */ 074 public class DescribeCoverage extends WCSRequestBase { 075 076 private String[] coverages = null; 077 078 /** 079 * creates a DescribeCoverage request from its KVP representation 080 * 081 * @param map 082 * request 083 * @return created <tt>DescribeCoverage</tt> 084 * @throws OGCWebServiceException 085 * will be thrown if something general is wrong 086 * @throws MissingParameterValueException 087 * @throws InvalidParameterValueException 088 * @throws WCSException 089 * will be thrown if a WCS/DescribeCoverage specific part of the request is 090 * erroreous 091 */ 092 public static DescribeCoverage create( Map map ) 093 throws OGCWebServiceException, MissingParameterValueException, 094 InvalidParameterValueException { 095 096 String version = (String) map.get( "VERSION" ); 097 if ( version == null ) { 098 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 099 throw new MissingParameterValueException( "DescribeCoverage", "'version' is missing", code ); 100 } 101 if ( !version.equals( "1.0.0" ) ) { 102 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 103 throw new InvalidParameterValueException( "DescribeCoverage", "'version' <> 1.0.0", code ); 104 } 105 String service = (String) map.get( "SERVICE" ); 106 if ( service == null ) { 107 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 108 throw new MissingParameterValueException( "DescribeCoverage", "'service' is missing", code ); 109 } 110 if ( !"WCS".equalsIgnoreCase( service ) ) { 111 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 112 throw new InvalidParameterValueException( "DescribeCoverage", "'service' <> WCS", code ); 113 } 114 115 String[] coverages = new String[0]; 116 if ( map.get( "COVERAGE" ) != null ) { 117 String s = (String) map.get( "COVERAGE" ); 118 coverages = StringTools.toArray( s, ",", true ); 119 } 120 121 String id = (String) map.get( "ID" ); 122 123 return new DescribeCoverage( id, version, coverages ); 124 } 125 126 /** 127 * creates a DescribeCoverage request from its KVP representation 128 * 129 * @param id 130 * unique ID of the request 131 * @param kvp 132 * request 133 * @return created <tt>DescribeCoverage</tt> 134 * @throws OGCWebServiceException 135 * will be thrown if something general is wrong 136 * @throws MissingParameterValueException 137 * @throws InvalidParameterValueException 138 * @throws WCSException 139 * will be thrown if a WCS/DescribeCoverage specific part of the request is 140 * erroreous 141 */ 142 public static DescribeCoverage createDescribeCoverage( String id, String kvp ) 143 throws OGCWebServiceException, MissingParameterValueException, 144 InvalidParameterValueException { 145 Map<String,String> map = KVP2Map.toMap( kvp ); 146 map.put( "ID", id ); 147 return create( map ); 148 } 149 150 /** 151 * creates a DescribeCoverage request from its XML representation 152 * 153 * @param id 154 * unique ID of the request 155 * @param doc 156 * XML representation of the request 157 * @return created <tt>DescribeCoverage</tt> 158 * @throws OGCWebServiceException 159 * will be thrown if something general is wrong 160 * @throws MissingParameterValueException 161 * @throws InvalidParameterValueException 162 * @throws WCSException 163 * will be thrown if a WCS/DescribeCoverage specific part of the request is 164 * erroreous 165 */ 166 public static DescribeCoverage create( String id, Document doc ) 167 throws OGCWebServiceException, MissingParameterValueException, 168 InvalidParameterValueException { 169 170 String[] coverages = null; 171 String version = null; 172 try { 173 Element root = XMLTools.getRequiredChildElement( "DescribeCoverage", CommonNamespaces.WCSNS, doc ); 174 175 version = XMLTools.getAttrValue( root, null, "version", null ); 176 if ( version == null ) { 177 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 178 throw new MissingParameterValueException( "DescribeCoverage", "'version' is missing", code ); 179 } 180 if ( !version.equals( "1.0.0" ) ) { 181 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 182 throw new InvalidParameterValueException( "DescribeCoverage", "'version' <> 1.0.0", code ); 183 } 184 185 String service = XMLTools.getAttrValue( root, null, "service", null ); 186 if ( service == null ) { 187 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 188 throw new MissingParameterValueException( "DescribeCoverage", "'service' is missing", code ); 189 } 190 if ( !"WCS".equalsIgnoreCase( service ) ) { 191 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 192 throw new InvalidParameterValueException( "DescribeCoverage", "'service' <> WCS", code ); 193 } 194 195 ElementList el = XMLTools.getChildElements( "Coverage", CommonNamespaces.WCSNS, root ); 196 coverages = new String[el.getLength()]; 197 for ( int i = 0; i < coverages.length; i++ ) { 198 coverages[i] = XMLTools.getStringValue( el.item( i ) ); 199 } 200 } catch ( XMLParsingException e ) { 201 ExceptionCode code = WCSExceptionCode.INVALID_FORMAT; 202 throw new WCSException( "DescribeCoverage", e.toString(), code ); 203 } 204 205 return new DescribeCoverage( id, version, coverages ); 206 } 207 208 /** 209 * @param id 210 * unique ID of the request 211 * @param version 212 * Request protocol version 213 * @param coverages 214 * list of coverages to describe (identified by their name values in the Capabilities 215 * response). If <tt>null</tt> or length == 0 all coverages of the service 216 * instances will be described 217 */ 218 public DescribeCoverage( String id, String version, String[] coverages ) { 219 super( id, version ); 220 this.coverages = coverages; 221 } 222 223 /** 224 * @return Returns the coverages. 225 * 226 */ 227 public String[] getCoverages() { 228 return coverages; 229 } 230 231 }