001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/csw/discovery/DescribeRecord.java $
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 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.framework.xml.NamespaceContext;
053: import org.deegree.framework.xml.XMLParsingException;
054: import org.deegree.framework.xml.XMLTools;
055: import org.deegree.ogcbase.CommonNamespaces;
056: import org.deegree.ogcwebservices.InvalidParameterValueException;
057: import org.deegree.ogcwebservices.MissingParameterValueException;
058: import org.deegree.ogcwebservices.OGCWebServiceException;
059: import org.deegree.ogcwebservices.csw.AbstractCSWRequest;
060: import org.deegree.ogcwebservices.csw.CSWPropertiesAccess;
061: import org.w3c.dom.Element;
062:
063: /**
064: * The mandatory DescribeRecord operation allows a client to discover elements of the information
065: * model supported by the target catalogue service. The operation allows some or all of the
066: * information model to be described.
067: *
068: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
069: * @author <a href="mailto:tfr@users.sourceforge.net">Torsten Friebe </a>
070: * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
071: *
072: * @author last edited by: $Author: apoth $
073: *
074: * @version $Revision: 9348 $, $Date: 2007-12-27 08:59:14 -0800 (Thu, 27 Dec 2007) $
075: */
076: public class DescribeRecord extends AbstractCSWRequest {
077:
078: private static final long serialVersionUID = 6554937884331546780L;
079:
080: private static final ILogger LOG = LoggerFactory
081: .getLogger(DescribeRecord.class);
082:
083: private static NamespaceContext nsContext = CommonNamespaces
084: .getNamespaceContext();
085:
086: private Map namespaceMappings;
087:
088: private String[] typeNames;
089:
090: private String outputFormat;
091:
092: private URI schemaLanguage;
093:
094: /**
095: * creates a GetRecords request from the XML fragment passed. The passed element must be valid
096: * against the OGC CSW 2.0 GetRecords schema.
097: *
098: * @param id
099: * unique ID of the request
100: * @param root
101: * root element of the GetRecors request
102: * @return
103: */
104: public static DescribeRecord create(String id, Element root)
105: throws MissingParameterValueException,
106: InvalidParameterValueException, OGCWebServiceException {
107:
108: String version = null;
109: try {
110: // first try to read verdsion attribute which is optional for CSW 2.0.0 and 2.0.1
111: version = XMLTools.getNodeAsString(root, "./@version",
112: nsContext, null);
113: } catch (XMLParsingException e) {
114:
115: }
116: if (version == null) {
117: // if no version attribute has been set try mapping namespace URI to a version;
118: // this is not well defined for 2.0.0 and 2.0.1 which uses the same namespace.
119: // in this case 2.0.0 will be returned!
120: version = CSWPropertiesAccess.getString(root
121: .getNamespaceURI());
122: }
123:
124: // read class for version depenging parsing of DescribeRecord request from properties
125: String className = CSWPropertiesAccess
126: .getString("DescribeRecord" + version);
127: Class clzz = null;
128: try {
129: clzz = Class.forName(className);
130: } catch (ClassNotFoundException e) {
131: LOG.logError(e.getMessage(), e);
132: throw new InvalidParameterValueException(e.getMessage(), e);
133: }
134: DescribeRecordDocument document = null;
135: try {
136: document = (DescribeRecordDocument) clzz.newInstance();
137: } catch (InstantiationException e) {
138: LOG.logError(e.getMessage(), e);
139: throw new InvalidParameterValueException(e.getMessage(), e);
140: } catch (IllegalAccessException e) {
141: LOG.logError(e.getMessage(), e);
142: throw new InvalidParameterValueException(e.getMessage(), e);
143: }
144:
145: document.setRootElement(root);
146: return document.parse(id);
147:
148: }
149:
150: /**
151: * Creates a new <code>DecribeRecord</code> instance from the values stored in the submitted
152: * Map. Keys (parameter names) in the Map must be uppercase.
153: *
154: * @TODO evaluate vendorSpecificParameter
155: *
156: * @param kvp
157: * Map containing the parameters
158: * @exception InvalidParameterValueException
159: * @throws MissingParameterValueException
160: */
161: public static DescribeRecord create(Map<String, String> kvp)
162: throws InvalidParameterValueException,
163: MissingParameterValueException {
164:
165: String id;
166: String version;
167: Map<String, String> vendorSpecificParameter = new HashMap<String, String>();
168: Map namespaceMappings;
169: String[] typeNames = new String[0];
170: String outputFormat;
171: URI schemaLanguage;
172:
173: // 'ID'-attribute (optional)
174: id = getParam("ID", kvp, "");
175:
176: // 'VERSION'-attribute (mandatory)
177: version = getRequiredParam("VERSION", kvp);
178:
179: // 'NAMESPACE'-attribute (optional)
180: namespaceMappings = getNSMappings(getParam("NAMESPACE", kvp,
181: null));
182:
183: // 'TYPENAME'-attribute (optional)
184: String typeNamesString = getParam("TYPENAME", kvp, null);
185: if (typeNamesString != null) {
186: typeNames = typeNamesString.split(",");
187: }
188:
189: // 'OUTPUTFORMAT'-attribute (optional)
190: if ("2.0.2".equals(version)) {
191: outputFormat = getParam("OUTPUTFORMAT", kvp,
192: "application/xml");
193: } else {
194: outputFormat = getParam("OUTPUTFORMAT", kvp, "text/xml");
195: }
196:
197: // 'SCHEMALANGUAGE'-attribute (optional)
198: String schemaLanguageString = getParam("SCHEMALANGUAGE", kvp,
199: "XMLSCHEMA");
200: try {
201: schemaLanguage = new URI(schemaLanguageString);
202: } catch (URISyntaxException e) {
203: String msg = "Value '"
204: + schemaLanguageString
205: + "' for parameter 'SCHEMALANGUAGE' is invalid. Must denote a valid URI.";
206: throw new InvalidParameterValueException(msg);
207: }
208:
209: return new DescribeRecord(id, version, vendorSpecificParameter,
210: namespaceMappings, typeNames, outputFormat,
211: schemaLanguage);
212: }
213:
214: /**
215: * Creates a new <code>DescribeRecord</code> instance.
216: *
217: * @param id
218: * @param version
219: * @param vendorSpecificParameter
220: */
221: DescribeRecord(String id, String version,
222: Map<String, String> vendorSpecificParameter) {
223: super (version, id, vendorSpecificParameter);
224: }
225:
226: /**
227: * Creates a new <code>DescribeRecord</code> instance.
228: *
229: * @param id
230: * @param version
231: * @param vendorSpecificParameter
232: * @param namespaceMappings
233: * @param typeNames
234: * @param outputFormat
235: * @param schemaLanguage
236: */
237: DescribeRecord(String id, String version,
238: Map<String, String> vendorSpecificParameter,
239: Map namespaceMappings, String[] typeNames,
240: String outputFormat, URI schemaLanguage) {
241: this (id, version, vendorSpecificParameter);
242: this .namespaceMappings = namespaceMappings;
243: this .typeNames = typeNames;
244: this .outputFormat = outputFormat;
245: this .schemaLanguage = schemaLanguage;
246: }
247:
248: /**
249: * Used to specify namespace(s) and their prefix(es). Format is [prefix:]uri. If prefix is not
250: * specified, then this is the default namespace.
251: * <p>
252: * Zero or one (Optional). Include value for each namespace used by a TypeName. If not included,
253: * all qualified names are in the default namespace
254: */
255: public Map getNamespaces() {
256: return this .namespaceMappings;
257: }
258:
259: /**
260: * One or more qualified type names to be described.
261: * <p>
262: * Zero or one (Optional). Default action is to describe all types known to server.
263: *
264: */
265: public String[] getTypeNames() {
266: return this .typeNames;
267: }
268:
269: /**
270: * A MIME type indicating the format that the output document should have.
271: * <p>
272: * Zero or one (Optional). Default value is text/xml
273: *
274: */
275: public String getOutputFormat() {
276: return this .outputFormat;
277: }
278:
279: /**
280: * Default value is 'XMLSCHEMA'.
281: *
282: */
283: public URI getSchemaLanguage() {
284: return this.schemaLanguage;
285: }
286: }
|