001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/csw/discovery/GetRecordById.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: package org.deegree.ogcwebservices.csw.discovery;
044:
045: import java.util.Map;
046:
047: import org.deegree.framework.log.ILogger;
048: import org.deegree.framework.log.LoggerFactory;
049: import org.deegree.framework.util.IDGenerator;
050: import org.deegree.framework.util.StringTools;
051: import org.deegree.framework.xml.NamespaceContext;
052: import org.deegree.framework.xml.XMLParsingException;
053: import org.deegree.framework.xml.XMLTools;
054: import org.deegree.ogcbase.CommonNamespaces;
055: import org.deegree.ogcwebservices.InvalidParameterValueException;
056: import org.deegree.ogcwebservices.MissingParameterValueException;
057: import org.deegree.ogcwebservices.OGCWebServiceException;
058: import org.deegree.ogcwebservices.csw.AbstractCSWRequest;
059: import org.deegree.ogcwebservices.csw.CSWPropertiesAccess;
060: import org.deegree.ogcwebservices.csw.NonexistentCollectionException;
061: import org.deegree.ogcwebservices.csw.NonexistentTypeException;
062: import org.w3c.dom.Element;
063:
064: /**
065: * The mandatory GetRecordById request retrieves the default representation of catalogue records
066: * using their identifier. The GetRecordById operation is an implementation of the Present operation
067: * from the general model. This operation presumes that a previous query has been performed in order
068: * to obtain the identifiers that may be used with this operation. For example, records returned by
069: * a GetRecords operation may contain references to other records in the catalogue that may be
070: * retrieved using the GetRecordById operation. This operation is also a subset of the GetRecords
071: * operation, and is included as a convenient short form for retrieving and linking to records in a
072: * catalogue.
073: *
074: * @version $Revision: 9345 $
075: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
076: * @author last edited by: $Author: apoth $
077: *
078: * @version 1.0. $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
079: *
080: * @since 2.0
081: */
082: public class GetRecordById extends AbstractCSWRequest {
083:
084: private static final long serialVersionUID = -3602776884510160189L;
085:
086: private static final ILogger LOG = LoggerFactory
087: .getLogger(GetRecordById.class);
088:
089: private static NamespaceContext nsContext = CommonNamespaces
090: .getNamespaceContext();
091:
092: private String[] ids = null;
093:
094: private String elementSetName = null;
095:
096: /**
097: * creates a <code>GetRecordById</code> request from the XML fragment passed. The passed
098: * element must be valid against the OGC CSW 2.0 GetRecordById schema.
099: *
100: * @param id
101: * unique ID of the request
102: * @param root
103: * root element of the GetRecors request
104: * @return a GetRecordById bean representation created from the xml fragment.
105: * @throws MissingParameterValueException
106: * @throws InvalidParameterValueException
107: * @throws OGCWebServiceException
108: */
109: public static GetRecordById create(String id, Element root)
110: throws MissingParameterValueException,
111: InvalidParameterValueException, OGCWebServiceException {
112:
113: String version = null;
114: try {
115: // first try to read verdsion attribute which is optional for CSW 2.0.0 and 2.0.1
116: version = XMLTools.getNodeAsString(root, "./@version",
117: nsContext, null);
118: } catch (XMLParsingException e) {
119:
120: }
121: if (version == null) {
122: // if no version attribute has been set try mapping namespace URI to a version;
123: // this is not well defined for 2.0.0 and 2.0.1 which uses the same namespace.
124: // in this case 2.0.0 will be returned!
125: version = CSWPropertiesAccess.getString(root
126: .getNamespaceURI());
127: }
128:
129: // read class for version depenging parsing of GetRecords request from properties
130: String className = CSWPropertiesAccess
131: .getString("GetRecordById" + version);
132: Class clzz = null;
133: try {
134: clzz = Class.forName(className);
135: } catch (ClassNotFoundException e) {
136: LOG.logError(e.getMessage(), e);
137: throw new InvalidParameterValueException(e.getMessage(), e);
138: }
139: GetRecordByIdDocument document = null;
140: try {
141: document = (GetRecordByIdDocument) clzz.newInstance();
142: } catch (InstantiationException e) {
143: LOG.logError(e.getMessage(), e);
144: throw new InvalidParameterValueException(e.getMessage(), e);
145: } catch (IllegalAccessException e) {
146: LOG.logError(e.getMessage(), e);
147: throw new InvalidParameterValueException(e.getMessage(), e);
148: }
149:
150: document.setRootElement(root);
151:
152: return document.parse(id);
153:
154: }
155:
156: /**
157: * Creates a new <code>GetRecordById</code> instance from the values stored in the submitted
158: * Map. Keys (parameter names) in the Map must be uppercase.
159: *
160: * @TODO evaluate vendorSpecificParameter
161: *
162: * @param kvp
163: * Map containing the parameters
164: * @return a GetRecordById bean representation, the internal request id will be set to
165: * Long.toString( IDGenerator.getInstance().generateUniqueID() ).
166: * @exception InvalidParameterValueException
167: * @exception MissingParameterValueException
168: * @exception NonexistentCollectionException
169: * @exception NonexistentTypeException
170: */
171: public static GetRecordById create(Map<String, String> kvp) {
172:
173: String version = kvp.remove("VERSION");
174: String elementSetName = kvp.remove("ELEMENTSETNAME");
175: String tmp = kvp.remove("ID");
176: String[] ids = StringTools.toArray(tmp, ",", true);
177:
178: return new GetRecordById(Long.toString(IDGenerator
179: .getInstance().generateUniqueID()), version, kvp, ids,
180: elementSetName);
181: }
182:
183: /**
184: * Creates a new <code>GetRecordById</code> instance from the values stored in the submitted
185: * Map. Keys (parameter names) in the Map must be uppercase.
186: *
187: * @param id
188: * of the request, and not the requested ids.
189: *
190: * @TODO evaluate vendorSpecificParameter
191: *
192: * @param kvp
193: * Map containing the parameters
194: * @return a GetRecordById bean representation.
195: * @exception InvalidParameterValueException
196: * @exception MissingParameterValueException
197: * @exception NonexistentCollectionException
198: * @exception NonexistentTypeException
199: */
200: public static GetRecordById create(String id,
201: Map<String, String> kvp) {
202:
203: String version = kvp.remove("VERSION");
204: String elementSetName = kvp.remove("ELEMENTSETNAME");
205: String tmp = kvp.remove("ID");
206: String[] ids = StringTools.toArray(tmp, ",", true);
207:
208: return new GetRecordById(id, version, kvp, ids, elementSetName);
209: }
210:
211: /**
212: *
213: * @param ids
214: * identifiers of the requested catalogue entries
215: * @param elementSetName
216: * requested element set (brief|summary|full). Can be <code>null</code>; will be
217: * treaded as full.
218: */
219: GetRecordById(String id, String version,
220: Map<String, String> vendorSpecificParameters, String[] ids,
221: String elementSetName) {
222: super (version, id, vendorSpecificParameters);
223: this .ids = ids;
224: this .elementSetName = elementSetName;
225: }
226:
227: /**
228: * @return the requested element set name. If the returned value equals <code>null</code> a
229: * 'summary' request shall be performed. possible values are:
230: * <ul>
231: * <li>brief</li>
232: * <li>summary</li>
233: * <li>full</li>
234: * </ul>
235: *
236: */
237: public String getElementSetName() {
238: return elementSetName;
239: }
240:
241: /**
242: * @return the requested ids as an array of strings
243: */
244: public String[] getIds() {
245: return ids;
246: }
247: }
|