001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.geoserver.wfs.xml.v1_1_0;
006:
007: import net.opengis.wfs.QueryType;
008: import net.opengis.wfs.WfsFactory;
009:
010: import org.geoserver.wfs.WFSException;
011: import org.geotools.gml2.bindings.GML2ParsingUtils;
012: import org.geotools.xml.AbstractComplexBinding;
013: import org.geotools.xml.ElementInstance;
014: import org.geotools.xml.Node;
015: import org.opengis.feature.Property;
016: import org.opengis.filter.Filter;
017: import org.opengis.filter.expression.Literal;
018: import org.opengis.filter.expression.PropertyName;
019: import org.opengis.filter.sort.SortBy;
020: import org.opengis.referencing.crs.CoordinateReferenceSystem;
021: import org.picocontainer.MutablePicoContainer;
022:
023: import java.net.URI;
024: import java.util.Iterator;
025: import java.util.List;
026: import javax.xml.namespace.QName;
027:
028: /**
029: * Binding object for the type http://www.opengis.net/wfs:QueryType.
030: *
031: * <p>
032: * <pre>
033: * <code>
034: * <xsd:complexType name="QueryType">
035: * <xsd:annotation>
036: * <xsd:documentation>
037: * The Query element is of type QueryType.
038: * </xsd:documentation>
039: * </xsd:annotation>
040: * <xsd:sequence>
041: * <xsd:choice maxOccurs="unbounded" minOccurs="0">
042: * <xsd:element ref="wfs:PropertyName">
043: * <xsd:annotation>
044: * <xsd:documentation>
045: * The Property element is used to specify one or more
046: * properties of a feature whose values are to be retrieved
047: * by a Web Feature Service.
048: *
049: * While a Web Feature Service should endeavour to satisfy
050: * the exact request specified, in some instance this may
051: * not be possible. Specifically, a Web Feature Service
052: * must generate a valid GML3 response to a Query operation.
053: * The schema used to generate the output may include
054: * properties that are mandatory. In order that the output
055: * validates, these mandatory properties must be specified
056: * in the request. If they are not, a Web Feature Service
057: * may add them automatically to the Query before processing
058: * it. Thus a client application should, in general, be
059: * prepared to receive more properties than it requested.
060: *
061: * Of course, using the DescribeFeatureType request, a client
062: * application can determine which properties are mandatory
063: * and request them in the first place.
064: * </xsd:documentation>
065: * </xsd:annotation>
066: * </xsd:element>
067: * <xsd:element ref="ogc:Function">
068: * <xsd:annotation>
069: * <xsd:documentation>
070: * A function may be used as a select item in a query.
071: * However, if a function is used, care must be taken
072: * to ensure that the result type matches the type in the
073: *
074: * </xsd:documentation>
075: * </xsd:annotation>
076: * </xsd:element>
077: * </xsd:choice>
078: * <xsd:element maxOccurs="1" minOccurs="0" ref="ogc:Filter">
079: * <xsd:annotation>
080: * <xsd:documentation>
081: * The Filter element is used to define spatial and/or non-spatial
082: * constraints on query. Spatial constrains use GML3 to specify
083: * the constraining geometry. A full description of the Filter
084: * element can be found in the Filter Encoding Implementation
085: * Specification.
086: * </xsd:documentation>
087: * </xsd:annotation>
088: * </xsd:element>
089: * <xsd:element maxOccurs="1" minOccurs="0" ref="ogc:SortBy">
090: * <xsd:annotation>
091: * <xsd:documentation>
092: * The SortBy element is used specify property names whose
093: * values should be used to order (upon presentation) the
094: * set of feature instances that satisfy the query.
095: * </xsd:documentation>
096: * </xsd:annotation>
097: * </xsd:element>
098: * </xsd:sequence>
099: * <xsd:attribute name="handle" type="xsd:string" use="optional">
100: * <xsd:annotation>
101: * <xsd:documentation>
102: * The handle attribute allows a client application
103: * to assign a client-generated identifier for the
104: * Query. The handle is included to facilitate error
105: * reporting. If one Query in a GetFeature request
106: * causes an exception, a WFS may report the handle
107: * to indicate which query element failed. If the a
108: * handle is not present, the WFS may use other means
109: * to localize the error (e.g. line numbers).
110: * </xsd:documentation>
111: * </xsd:annotation>
112: * </xsd:attribute>
113: * <xsd:attribute name="typeName" type="wfs:TypeNameListType" use="required">
114: * <xsd:annotation>
115: * <xsd:documentation>
116: * The typeName attribute is a list of one or more
117: * feature type names that indicate which types
118: * of feature instances should be included in the
119: * reponse set. Specifying more than one typename
120: * indicates that a join operation is being performed.
121: * All the names in the typeName list must be valid
122: * types that belong to this query's feature content
123: * as defined by the GML Application Schema.
124: * </xsd:documentation>
125: * </xsd:annotation>
126: * </xsd:attribute>
127: * <xsd:attribute name="featureVersion" type="xsd:string" use="optional">
128: * <xsd:annotation>
129: * <xsd:documentation>
130: * For systems that implement versioning, the featureVersion
131: * attribute is used to specify which version of a particular
132: * feature instance is to be retrieved. A value of ALL means
133: * that all versions should be retrieved. An integer value
134: * 'i', means that the ith version should be retrieve if it
135: * exists or the most recent version otherwise.
136: * </xsd:documentation>
137: * </xsd:annotation>
138: * </xsd:attribute>
139: * <xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
140: * <xsd:annotation>
141: * <xsd:documentation>
142: * This attribute is used to specify a specific WFS-supported SRS
143: * that should be used for returned feature geometries. The value
144: * may be the WFS StorageSRS value, DefaultRetrievalSRS value, or
145: * one of AdditionalSRS values. If no srsName value is supplied,
146: * then the features will be returned using either the
147: * DefaultRetrievalSRS, if specified, and StorageSRS otherwise.
148: * For feature types with no spatial properties, this attribute
149: * must not be specified or ignored if it is specified.
150: * </xsd:documentation>
151: * </xsd:annotation>
152: * </xsd:attribute>
153: * </xsd:complexType>
154: *
155: * </code>
156: * </pre>
157: * </p>
158: *
159: * @generated
160: */
161: public class QueryTypeBinding extends AbstractComplexBinding {
162: WfsFactory wfsfactory;
163:
164: public QueryTypeBinding(WfsFactory wfsfactory) {
165: this .wfsfactory = wfsfactory;
166: }
167:
168: /**
169: * @generated
170: */
171: public QName getTarget() {
172: return WFS.QUERYTYPE;
173: }
174:
175: /**
176: * <!-- begin-user-doc -->
177: * <!-- end-user-doc -->
178: *
179: * @generated modifiable
180: */
181: public Class getType() {
182: return QueryType.class;
183: }
184:
185: public void initializeChildContext(ElementInstance childInstance,
186: Node node, MutablePicoContainer context) {
187: //if an srsName is set for this geometry, put it in the context for
188: // children, so they can use it as well
189: if (node.hasAttribute("srsName")) {
190: try {
191: CoordinateReferenceSystem crs = GML2ParsingUtils
192: .crs(node);
193: if (crs != null) {
194: context.registerComponentInstance(
195: CoordinateReferenceSystem.class, crs);
196: }
197: } catch (Exception e) {
198: throw new WFSException(e, "InvalidParameterValue");
199: }
200: }
201: }
202:
203: /**
204: * <!-- begin-user-doc -->
205: * <!-- end-user-doc -->
206: *
207: * @generated modifiable
208: */
209: public Object parse(ElementInstance instance, Node node,
210: Object value) throws Exception {
211: QueryType query = wfsfactory.createQueryType();
212:
213: //<xsd:choice maxOccurs="unbounded" minOccurs="0">
214: //<xsd:element ref="wfs:PropertyName">
215: if (node.hasChild("PropertyName")) {
216: //HACK, stripping of namespace prefix
217: for (Iterator p = node.getChildValues("PropertyName")
218: .iterator(); p.hasNext();) {
219: Object property = p.next();
220: String propertyName;
221: if (property instanceof String)
222: propertyName = (String) property;
223: else
224: propertyName = (String) ((PropertyName) property)
225: .getPropertyName();
226:
227: if (propertyName.indexOf(':') != -1) {
228: propertyName = propertyName.substring(propertyName
229: .indexOf(':') + 1);
230: }
231:
232: query.getPropertyName().add(propertyName);
233: }
234: }
235:
236: //<xsd:element ref="ogc:Function">
237: if (node.hasChild("Function")) {
238: query.getFunction().add(node.getChildValues("Function"));
239: }
240:
241: //</xsd:choice>
242:
243: //<xsd:element maxOccurs="1" minOccurs="0" ref="ogc:Filter">
244: if (node.hasChild(Filter.class)) {
245: query.setFilter((Filter) node.getChildValue(Filter.class));
246: }
247:
248: //<xsd:element maxOccurs="1" minOccurs="0" ref="ogc:SortBy">
249: if (node.hasChild(SortBy[].class)) {
250: SortBy[] sortBy = (SortBy[]) node
251: .getChildValue(SortBy[].class);
252:
253: for (int i = 0; i < sortBy.length; i++)
254: query.getSortBy().add(sortBy[i]);
255: }
256:
257: //<xsd:attribute name="handle" type="xsd:string" use="optional">
258: if (node.hasAttribute("handle")) {
259: query.setHandle((String) node.getAttributeValue("handle"));
260: }
261:
262: //<xsd:attribute name="typeName" type="wfs:TypeNameListType" use="required">
263: query.setTypeName((List) node.getAttributeValue("typeName"));
264:
265: //<xsd:attribute name="featureVersion" type="xsd:string" use="optional">
266: if (node.hasAttribute("featureVersion")) {
267: query.setFeatureVersion((String) node
268: .getAttributeValue("featureVersion"));
269: }
270:
271: //<xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
272: if (node.hasAttribute("srsName")) {
273: query.setSrsName((URI) node.getAttributeValue("srsName"));
274: }
275:
276: return query;
277: }
278: }
|