001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/csw/discovery/DescribeRecord.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 This file is part of deegree. 004 Copyright (C) 2001-2007 by: 005 Department of Geography, University of Bonn 006 http://www.giub.uni-bonn.de/deegree/ 007 lat/lon GmbH 008 http://www.lat-lon.de 009 010 This library is free software; you can redistribute it and/or 011 modify it under the terms of the GNU Lesser General Public 012 License as published by the Free Software Foundation; either 013 version 2.1 of the License, or (at your option) any later version. 014 015 This library is distributed in the hope that it will be useful, 016 but WITHOUT ANY WARRANTY; without even the implied warranty of 017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 018 Lesser General Public License for more details. 019 020 You should have received a copy of the GNU Lesser General Public 021 License along with this library; if not, write to the Free Software 022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 023 024 Contact: 025 026 Andreas Poth 027 lat/lon GmbH 028 Aennchenstraße 19 029 53177 Bonn 030 Germany 031 E-Mail: poth@lat-lon.de 032 033 Prof. Dr. Klaus Greve 034 Department of Geography 035 University of Bonn 036 Meckenheimer Allee 166 037 53115 Bonn 038 Germany 039 E-Mail: greve@giub.uni-bonn.de 040 041 ---------------------------------------------------------------------------*/ 042 043 package org.deegree.ogcwebservices.csw.discovery; 044 045 import java.net.URI; 046 import java.net.URISyntaxException; 047 import java.util.HashMap; 048 import java.util.Map; 049 050 import org.deegree.framework.log.ILogger; 051 import org.deegree.framework.log.LoggerFactory; 052 import org.deegree.ogcwebservices.InvalidParameterValueException; 053 import org.deegree.ogcwebservices.MissingParameterValueException; 054 import org.deegree.ogcwebservices.OGCWebServiceException; 055 import org.deegree.ogcwebservices.csw.AbstractCSWRequest; 056 import org.w3c.dom.Element; 057 058 /** 059 * The mandatory DescribeRecord operation allows a client to discover elements of the information 060 * model supported by the target catalogue service. The operation allows some or all of the 061 * information model to be described. 062 * 063 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a> 064 * @author <a href="mailto:tfr@users.sourceforge.net">Torsten Friebe </a> 065 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a> 066 * 067 * @author last edited by: $Author: apoth $ 068 * 069 * @version $Revision: 6705 $, $Date: 2007-04-26 21:55:39 +0200 (Do, 26 Apr 2007) $ 070 */ 071 public class DescribeRecord extends AbstractCSWRequest { 072 073 private static final long serialVersionUID = 6554937884331546780L; 074 075 private static final ILogger LOG = LoggerFactory.getLogger( DescribeRecord.class ); 076 077 private Map namespaceMappings; 078 079 private String[] typeNames; 080 081 private String outputFormat; 082 083 private URI schemaLanguage; 084 085 /** 086 * creates a GetRecords request from the XML fragment passed. The passed element must be valid 087 * against the OGC CSW 2.0 GetRecords schema. 088 * 089 * @param id 090 * unique ID of the request 091 * @param root 092 * root element of the GetRecors request 093 * @return 094 */ 095 public static DescribeRecord create( String id, Element root ) 096 throws MissingParameterValueException, InvalidParameterValueException, 097 OGCWebServiceException { 098 099 DescribeRecordDocument document = new DescribeRecordDocument(); 100 document.setRootElement( root ); 101 DescribeRecord ogcRequest = document.parse( id ); 102 103 return ogcRequest; 104 } 105 106 /** 107 * Creates a new <code>DecribeRecord</code> instance from the values stored in the submitted 108 * Map. Keys (parameter names) in the Map must be uppercase. 109 * 110 * @TODO evaluate vendorSpecificParameter 111 * 112 * @param kvp 113 * Map containing the parameters 114 * @exception InvalidParameterValueException 115 * @throws MissingParameterValueException 116 */ 117 public static DescribeRecord create( Map<String,String> kvp ) 118 throws InvalidParameterValueException, MissingParameterValueException { 119 LOG.entering(); 120 121 String id; 122 String version; 123 Map<String, String> vendorSpecificParameter = new HashMap<String, String>(); 124 Map namespaceMappings; 125 String[] typeNames = new String[0]; 126 String outputFormat; 127 URI schemaLanguage; 128 129 // 'ID'-attribute (optional) 130 id = getParam( "ID", kvp, "" ); 131 132 // 'VERSION'-attribute (mandatory) 133 version = getRequiredParam( "VERSION", kvp ); 134 135 // 'NAMESPACE'-attribute (optional) 136 namespaceMappings = getNSMappings( getParam( "NAMESPACE", kvp, null ) ); 137 138 // 'TYPENAME'-attribute (optional) 139 String typeNamesString = getParam( "TYPENAME", kvp, null ); 140 if ( typeNamesString != null ) { 141 typeNames = typeNamesString.split( "," ); 142 } 143 144 // 'OUTPUTFORMAT'-attribute (optional) 145 outputFormat = getParam( "OUTPUTFORMAT", kvp, "text/xml" ); 146 147 // 'SCHEMALANGUAGE'-attribute (optional) 148 String schemaLanguageString = getParam( "SCHEMALANGUAGE", kvp, "XMLSCHEMA" ); 149 try { 150 schemaLanguage = new URI( schemaLanguageString ); 151 } catch ( URISyntaxException e ) { 152 String msg = "Value '" + schemaLanguageString + "' for parameter 'SCHEMALANGUAGE' is invalid. Must " 153 + "denote a valid URI."; 154 throw new InvalidParameterValueException( msg ); 155 } 156 157 LOG.exiting(); 158 return new DescribeRecord( id, version, vendorSpecificParameter, namespaceMappings, typeNames, outputFormat, 159 schemaLanguage ); 160 } 161 162 /** 163 * Creates a new <code>DescribeRecord</code> instance. 164 * 165 * @param id 166 * @param version 167 * @param vendorSpecificParameter 168 */ 169 DescribeRecord( String id, String version, Map<String, String> vendorSpecificParameter ) { 170 super( version, id, vendorSpecificParameter ); 171 } 172 173 /** 174 * Creates a new <code>DescribeRecord</code> instance. 175 * 176 * @param id 177 * @param version 178 * @param vendorSpecificParameter 179 * @param namespaceMappings 180 * @param typeNames 181 * @param outputFormat 182 * @param schemaLanguage 183 */ 184 DescribeRecord( String id, String version, Map<String, String> vendorSpecificParameter, Map namespaceMappings, String[] typeNames, 185 String outputFormat, URI schemaLanguage ) { 186 this( id, version, vendorSpecificParameter ); 187 this.namespaceMappings = namespaceMappings; 188 this.typeNames = typeNames; 189 this.outputFormat = outputFormat; 190 this.schemaLanguage = schemaLanguage; 191 } 192 193 /** 194 * Used to specify namespace(s) and their prefix(es). Format is [prefix:]uri. If prefix is not 195 * specified, then this is the default namespace. 196 * <p> 197 * Zero or one (Optional). Include value for each namespace used by a TypeName. If not included, 198 * all qualified names are in the default namespace 199 */ 200 public Map getNamespaces() { 201 return this.namespaceMappings; 202 } 203 204 /** 205 * One or more qualified type names to be described. 206 * <p> 207 * Zero or one (Optional). Default action is to describe all types known to server. 208 * 209 */ 210 public String[] getTypeNames() { 211 return this.typeNames; 212 } 213 214 /** 215 * A MIME type indicating the format that the output document should have. 216 * <p> 217 * Zero or one (Optional). Default value is text/xml 218 * 219 */ 220 public String getOutputFormat() { 221 return this.outputFormat; 222 } 223 224 /** 225 * Default value is 'XMLSCHEMA'. 226 * 227 */ 228 public URI getSchemaLanguage() { 229 return this.schemaLanguage; 230 } 231 }