001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/csw/discovery/Query.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:
045: package org.deegree.ogcwebservices.csw.discovery;
046:
047: import java.util.ArrayList;
048: import java.util.HashMap;
049: import java.util.List;
050: import java.util.Map;
051:
052: import org.deegree.datatypes.QualifiedName;
053: import org.deegree.model.filterencoding.Filter;
054: import org.deegree.ogcbase.PropertyPath;
055: import org.deegree.ogcbase.PropertyPathFactory;
056: import org.deegree.ogcbase.SortProperty;
057:
058: /**
059: * Main component of a <code>GetRecords</code> request. A <code>GetRecords</code> request may
060: * consist of several <code>Query</code> elements.
061: *
062: * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
063: *
064: * @author last edited by: $Author: apoth $
065: *
066: * @version $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
067: */
068:
069: public class Query {
070:
071: private String elementSetName;
072:
073: private List<PropertyPath> elementNamesAsPropertyPaths;
074:
075: private Filter constraint;
076:
077: private SortProperty[] sortProperties;
078:
079: private List<QualifiedName> typeNames;
080:
081: private Map<String, QualifiedName> declaredTypeNameVariables;
082:
083: private List<QualifiedName> elementSetNameTypeNamesList;
084:
085: private Map<String, QualifiedName> elementSetNameVariables;
086:
087: /**
088: * Creates a new Query instance.
089: *
090: * @param elementSetName
091: * @param elementNames
092: * a String array containing the requested ElementName propertypaths. If not null,
093: * they will be converted to an ArrayList<PropertyPath>.
094: * @param sortProperties
095: * @param constraint
096: * @param typeNames
097: * which will be transformed to a list of qualified names.
098: */
099: Query(String elementSetName, String[] elementNames,
100: Filter constraint, SortProperty[] sortProperties,
101: String[] typeNames) {
102: List<QualifiedName> list = new ArrayList<QualifiedName>(
103: ((typeNames != null) ? typeNames.length : 0));
104: if (typeNames != null) {
105: for (String tName : typeNames) {
106: list.add(new QualifiedName(tName));
107: }
108: }
109: this .elementSetName = elementSetName;
110: this .elementSetNameTypeNamesList = new ArrayList<QualifiedName>();
111: elementNamesAsPropertyPaths = new ArrayList<PropertyPath>();
112: if (elementNames != null) {
113: for (String en : elementNames) {
114: elementNamesAsPropertyPaths.add(PropertyPathFactory
115: .createPropertyPath(new QualifiedName(en)));
116: }
117: }
118:
119: this .constraint = constraint;
120: this .sortProperties = sortProperties;
121: this .typeNames = list;
122: this .elementSetNameVariables = new HashMap<String, QualifiedName>();
123: this .declaredTypeNameVariables = new HashMap<String, QualifiedName>();
124: }
125:
126: /**
127: * @param elementSetName
128: * @param elementSetNameTypeNames
129: * the typenames (not the variables) which should be returned inside a
130: * GetRecordsReponse
131: * @param elementSetNameVariables
132: * the variables (and their mapping to the TypeName) which were requested.
133: * @param elementNames
134: * a list of propertyPath of propertys a client is interested in.
135: * @param constraint
136: * @param sortProperties
137: * @param typeNames
138: * list of QualifiedNames which were defined in the query element.
139: * @param typeNameVariables
140: * the variables (strings starting with an $-sign) which were declared
141: * typeNameattribtue in the Query element.
142: */
143: public Query(String elementSetName,
144: List<QualifiedName> elementSetNameTypeNames,
145: Map<String, QualifiedName> elementSetNameVariables,
146: List<PropertyPath> elementNames, Filter constraint,
147: SortProperty[] sortProperties,
148: List<QualifiedName> typeNames,
149: Map<String, QualifiedName> typeNameVariables) {
150: this .elementSetName = elementSetName;
151: this .elementSetNameTypeNamesList = elementSetNameTypeNames;
152: this .elementSetNameVariables = elementSetNameVariables;
153: this .elementNamesAsPropertyPaths = elementNames;
154: this .constraint = constraint;
155: this .sortProperties = sortProperties;
156: this .typeNames = typeNames;
157: this .declaredTypeNameVariables = typeNameVariables;
158: }
159:
160: /**
161: * Zero or one (Optional); If <tt>null</tt> then getElementNames may return a list of
162: * requested elements. If both methods returns <tt>null</tt> the default action is to present
163: * all metadata elements.
164: * <p>
165: * The ElementName parameter is used to specify one or more metadata record elements that the
166: * query should present in the response to the a GetRecords operation. Well known sets of
167: * element may be named, in which case the ElementSetName parameter may be used (e. g.brief,
168: * summary or full).
169: * <p>
170: * If neither parameter is specified, then a CSW shall present all metadata record elements
171: *
172: * @return the textual value (brief, summary, full) of the elementSetName node or null if none
173: * was given.
174: */
175: public String getElementSetName() {
176: return elementSetName;
177: }
178:
179: /**
180: * @return an Array of element names returned by a getRecord request.
181: * @deprecated this method is replaced with the more correct
182: * {@link #getElementNamesAsPropertyPaths()}. For now it just returns the values of
183: * {@link PropertyPath#getAsString()} method or <code>null</code> if no
184: * elementName were requested.
185: *
186: */
187: @Deprecated
188: public String[] getElementsNames() {
189: if (elementNamesAsPropertyPaths == null) {
190: return null;
191: }
192: String[] r = new String[elementNamesAsPropertyPaths.size()];
193: for (int i = 0; i < elementNamesAsPropertyPaths.size(); ++i) {
194: r[i] = elementNamesAsPropertyPaths.get(i).getAsString();
195: }
196: return r;
197: }
198:
199: /**
200: * Zero or one (Optional); Default action is to execute an unconstrained query
201: *
202: * @return the Filter which was given in the query.
203: */
204: public Filter getContraint() {
205: return this .constraint;
206: }
207:
208: /**
209: * Ordered list of names of metadata elements to use for sorting the response. Format of each
210: * list item is metadata_elemen_ name:A indicating an ascending sort or metadata_ element_name:D
211: * indicating descending sort
212: * <p>
213: * The result set may be sorted by specifying one or more metadata record elements upon which to
214: * sort.
215: * <p>
216: *
217: * @todo verify return type URI[] or String
218: * @return an Array of properties for sorting the response.
219: */
220: public SortProperty[] getSortProperties() {
221: return this .sortProperties;
222: }
223:
224: /**
225: * The typeName parameter specifies the record type name that defines a set of metadata record
226: * element names which will be constrained in the predicate of the query. In addition, all or
227: * some of the these names may be specified in the query to define which metadata record
228: * elements the query should present in the response to the GetRecords operation.
229: *
230: * @return the type names of the query.
231: * @deprecated this function actually creates an Array of Strings using the values returned from
232: * the {@link QualifiedName#getFormattedString()} method or <code>null</code> if
233: * no typenames were requested. It is more correct to use the values of the
234: * {@link #getTypeNamesAsList()} method
235: */
236: @Deprecated
237: public String[] getTypeNames() {
238: if (typeNames == null) {
239: return null;
240: }
241: String[] tNames = new String[typeNames.size()];
242: for (int i = 0; i < typeNames.size(); ++i) {
243: tNames[i] = typeNames.get(i).getFormattedString();
244: }
245: return tNames;
246: }
247:
248: /**
249: * The typeName parameter specifies the record type name that defines a set of metadata record
250: * element names which will be constrained in the predicate of the query. In addition, all or
251: * some of the these names may be specified in the query to define which metadata record
252: * elements the query should present in the response to the GetRecords operation.
253: *
254: * @return the type names of the query.
255: */
256: public List<QualifiedName> getTypeNamesAsList() {
257: return typeNames;
258: }
259:
260: /**
261: * @return the variables (with a leading $ (dollar_sign) as a String), declared with the
262: * typeNames (given as {@link QualifiedName} ).
263: */
264: public Map<String, QualifiedName> getDeclaredTypeNameVariables() {
265: return declaredTypeNameVariables;
266: }
267:
268: /**
269: * @return the requested elementNames as a list of PropertyPaths.
270: */
271: public List<PropertyPath> getElementNamesAsPropertyPaths() {
272: return elementNamesAsPropertyPaths;
273: }
274:
275: /**
276: * @return the variables which were requested in the ElementSetNames/@typeNames attribute and
277: * the mapping to their typenames.
278: */
279: public Map<String, QualifiedName> getElementSetNameVariables() {
280: return elementSetNameVariables;
281: }
282:
283: /**
284: * @return the typenames which were requested in the ElementSetNames/@typeNames attribute.
285: */
286: public List<QualifiedName> getElementSetNameTypeNamesList() {
287: return elementSetNameTypeNamesList;
288: }
289:
290: }
|