001 //$HeadURL: http://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/csw/discovery/Query.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036
037 package org.deegree.ogcwebservices.csw.discovery;
038
039 import java.util.ArrayList;
040 import java.util.HashMap;
041 import java.util.List;
042 import java.util.Map;
043
044 import org.deegree.datatypes.QualifiedName;
045 import org.deegree.model.filterencoding.Filter;
046 import org.deegree.ogcbase.PropertyPath;
047 import org.deegree.ogcbase.PropertyPathFactory;
048 import org.deegree.ogcbase.SortProperty;
049
050 /**
051 * Main component of a <code>GetRecords</code> request. A <code>GetRecords</code> request may
052 * consist of several <code>Query</code> elements.
053 *
054 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
055 *
056 * @author last edited by: $Author: apoth $
057 *
058 * @version $Revision: 29965 $, $Date: 2011-03-09 15:04:12 +0100 (Wed, 09 Mar 2011) $
059 */
060
061 public class Query {
062
063 private String elementSetName;
064
065 private List<PropertyPath> elementNamesAsPropertyPaths;
066
067 private Filter constraint;
068
069 private SortProperty[] sortProperties;
070
071 private List<QualifiedName> typeNames;
072
073 private Map<String, QualifiedName> declaredTypeNameVariables;
074
075 private List<QualifiedName> elementSetNameTypeNamesList;
076
077 private Map<String, QualifiedName> elementSetNameVariables;
078
079 /**
080 * Creates a new Query instance.
081 *
082 * @param elementSetName
083 * @param elementNames
084 * a String array containing the requested ElementName propertypaths. If not null,
085 * they will be converted to an ArrayList<PropertyPath>.
086 * @param sortProperties
087 * @param constraint
088 * @param typeNames
089 * which will be transformed to a list of qualified names.
090 */
091 Query( String elementSetName, String[] elementNames, Filter constraint,
092 SortProperty[] sortProperties, String[] typeNames ) {
093 List<QualifiedName> list = new ArrayList<QualifiedName>(
094 ( ( typeNames != null ) ? typeNames.length
095 : 0 ) );
096 if ( typeNames != null ) {
097 for ( String tName : typeNames ) {
098 list.add( new QualifiedName( tName ) );
099 }
100 }
101 this.elementSetName = elementSetName;
102 this.elementSetNameTypeNamesList = new ArrayList<QualifiedName>();
103 elementNamesAsPropertyPaths = new ArrayList<PropertyPath>();
104 if ( elementNames != null ) {
105 for ( String en : elementNames ) {
106 elementNamesAsPropertyPaths.add( PropertyPathFactory.createPropertyPath( new QualifiedName(
107 en ) ) );
108 }
109 }
110
111 this.constraint = constraint;
112 this.sortProperties = sortProperties;
113 this.typeNames = list;
114 this.elementSetNameVariables = new HashMap<String, QualifiedName>();
115 this.declaredTypeNameVariables = new HashMap<String, QualifiedName>();
116 }
117
118 /**
119 * @param elementSetName
120 * @param elementSetNameTypeNames
121 * the typenames (not the variables) which should be returned inside a
122 * GetRecordsReponse
123 * @param elementSetNameVariables
124 * the variables (and their mapping to the TypeName) which were requested.
125 * @param elementNames
126 * a list of propertyPath of propertys a client is interested in.
127 * @param constraint
128 * @param sortProperties
129 * @param typeNames
130 * list of QualifiedNames which were defined in the query element.
131 * @param typeNameVariables
132 * the variables (strings starting with an $-sign) which were declared
133 * typeNameattribtue in the Query element.
134 */
135 public Query( String elementSetName, List<QualifiedName> elementSetNameTypeNames,
136 Map<String, QualifiedName> elementSetNameVariables,
137 List<PropertyPath> elementNames, Filter constraint,
138 SortProperty[] sortProperties, List<QualifiedName> typeNames,
139 Map<String, QualifiedName> typeNameVariables ) {
140 this.elementSetName = elementSetName;
141 this.elementSetNameTypeNamesList = elementSetNameTypeNames;
142 this.elementSetNameVariables = elementSetNameVariables;
143 this.elementNamesAsPropertyPaths = elementNames;
144 this.constraint = constraint;
145 this.sortProperties = sortProperties;
146 this.typeNames = typeNames;
147 this.declaredTypeNameVariables = typeNameVariables;
148 }
149
150 /**
151 * Zero or one (Optional); If <tt>null</tt> then getElementNames may return a list of
152 * requested elements. If both methods returns <tt>null</tt> the default action is to present
153 * all metadata elements.
154 * <p>
155 * The ElementName parameter is used to specify one or more metadata record elements that the
156 * query should present in the response to the a GetRecords operation. Well known sets of
157 * element may be named, in which case the ElementSetName parameter may be used (e. g.brief,
158 * summary or full).
159 * <p>
160 * If neither parameter is specified, then a CSW shall present all metadata record elements
161 *
162 * @return the textual value (brief, summary, full) of the elementSetName node or null if none
163 * was given.
164 */
165 public String getElementSetName() {
166 return elementSetName;
167 }
168
169
170
171 /**
172 * Zero or one (Optional); Default action is to execute an unconstrained query
173 *
174 * @return the Filter which was given in the query.
175 */
176 public Filter getContraint() {
177 return this.constraint;
178 }
179
180 /**
181 * Ordered list of names of metadata elements to use for sorting the response. Format of each
182 * list item is metadata_elemen_ name:A indicating an ascending sort or metadata_ element_name:D
183 * indicating descending sort
184 * <p>
185 * The result set may be sorted by specifying one or more metadata record elements upon which to
186 * sort.
187 * <p>
188 *
189 * @todo verify return type URI[] or String
190 * @return an Array of properties for sorting the response.
191 */
192 public SortProperty[] getSortProperties() {
193 return this.sortProperties;
194 }
195
196 /**
197 * The typeName parameter specifies the record type name that defines a set of metadata record
198 * element names which will be constrained in the predicate of the query. In addition, all or
199 * some of the these names may be specified in the query to define which metadata record
200 * elements the query should present in the response to the GetRecords operation.
201 *
202 * @return the type names of the query.
203 * @deprecated this function actually creates an Array of Strings using the values returned from
204 * the {@link QualifiedName#getFormattedString()} method or <code>null</code> if
205 * no typenames were requested. It is more correct to use the values of the
206 * {@link #getTypeNamesAsList()} method
207 */
208 @Deprecated
209 public String[] getTypeNames() {
210 if ( typeNames == null ) {
211 return null;
212 }
213 String[] tNames = new String[typeNames.size()];
214 for ( int i = 0; i < typeNames.size(); ++i ) {
215 tNames[i] = typeNames.get( i ).getFormattedString();
216 }
217 return tNames;
218 }
219
220 /**
221 * The typeName parameter specifies the record type name that defines a set of metadata record
222 * element names which will be constrained in the predicate of the query. In addition, all or
223 * some of the these names may be specified in the query to define which metadata record
224 * elements the query should present in the response to the GetRecords operation.
225 *
226 * @return the type names of the query.
227 */
228 public List<QualifiedName> getTypeNamesAsList() {
229 return typeNames;
230 }
231
232 /**
233 * @return the variables (with a leading $ (dollar_sign) as a String), declared with the
234 * typeNames (given as {@link QualifiedName} ).
235 */
236 public Map<String, QualifiedName> getDeclaredTypeNameVariables() {
237 return declaredTypeNameVariables;
238 }
239
240 /**
241 * @return the requested elementNames as a list of PropertyPaths.
242 */
243 public List<PropertyPath> getElementNamesAsPropertyPaths() {
244 return elementNamesAsPropertyPaths;
245 }
246
247 /**
248 * @return the variables which were requested in the ElementSetNames/@typeNames attribute and
249 * the mapping to their typenames.
250 */
251 public Map<String, QualifiedName> getElementSetNameVariables() {
252 return elementSetNameVariables;
253 }
254
255 /**
256 * @return the typenames which were requested in the ElementSetNames/@typeNames attribute.
257 */
258 public List<QualifiedName> getElementSetNameTypeNamesList() {
259 return elementSetNameTypeNamesList;
260 }
261
262 }