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_0_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.filter.Filter;
016: import org.opengis.filter.expression.PropertyName;
017: import org.opengis.referencing.crs.CoordinateReferenceSystem;
018: import org.picocontainer.MutablePicoContainer;
019: import org.xml.sax.helpers.NamespaceSupport;
020:
021: import java.net.URI;
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025: import javax.xml.namespace.QName;
026:
027: /**
028: * Binding object for the type http://www.opengis.net/wfs:QueryType.
029: *
030: * <p>
031: * <pre>
032: * <code>
033: * <xsd:complexType name="QueryType">
034: * <xsd:annotation>
035: * <xsd:documentation>
036: * The Query element is of type
037: * QueryType.
038: * </xsd:documentation>
039: * </xsd:annotation>
040: * <xsd:sequence>
041: * <xsd:element
042: * maxOccurs="unbounded" minOccurs="0" ref="ogc:PropertyName">
043: * <xsd:annotation> <xsd:documentation>
044: * The PropertyName element is used to specify one or
045: * more properties of a feature whose
046: * values are to be retrieved by a Web
047: * Feature Service.
048: * While a Web Feature Service should endeavour to
049: * satisfy the exact request specified,
050: * in some instance this may not be
051: * possible. Specifically, a Web Feature Service
052: * must generate a valid GML2 response to a Query
053: * operation. The schema used to
054: * generate the output may include
055: * properties that are mandatory. In order that the
056: * output validates, these mandatory
057: * properties must be specified in the
058: * request. If they are not, a Web Feature Service
059: * may add them automatically to the Query before
060: * processing it. Thus a client
061: * application should, in general, be
062: * prepared to receive more properties than it
063: * requested. Of course, using the
064: * DescribeFeatureType request, a client
065: * application can determine which properties are
066: * mandatory and request them in the
067: * first place. </xsd:documentation>
068: * </xsd:annotation> </xsd:element> <xsd:element
069: * maxOccurs="1" minOccurs="0" ref="ogc:Filter">
070: * <xsd:annotation> <xsd:documentation>
071: * The Filter element is used to define spatial and/or
072: * non-spatial constraints on query.
073: * Spatial constrains use GML2 to specify
074: * the constraining geometry. A full description of
075: * the Filter element can be found in
076: * the Filter Encoding Implementation
077: * Specification. </xsd:documentation>
078: * </xsd:annotation> </xsd:element> </xsd:sequence>
079: * <xsd:attribute name="handle" type="xsd:string" use="optional"/>
080: * <xsd:attribute name="typeName" type="xsd:QName" use="required"/>
081: * <xsd:attribute name="featureVersion" type="xsd:string"
082: * use="optional"> <xsd:annotation>
083: * <xsd:documentation> For systems that
084: * implement versioning, the featureVersion
085: * attribute is used to specify which version of a
086: * particular feature instance is to be
087: * retrieved. A value of ALL means that all
088: * versions should be retrieved. An integer value
089: * 'i', means that the ith version should be
090: * retrieve if it exists or the most recent
091: * version otherwise. </xsd:documentation>
092: * </xsd:annotation> </xsd:attribute> </xsd:complexType>
093: *
094: * </code>
095: * </pre>
096: * </p>
097: *
098: * @generated
099: */
100: public class QueryTypeBinding extends AbstractComplexBinding {
101: /**
102: * Wfs Factory
103: */
104: WfsFactory wfsfactory;
105:
106: /**
107: * namespace mappings
108: */
109: NamespaceSupport namespaceSupport;
110:
111: public QueryTypeBinding(WfsFactory wfsfactory,
112: NamespaceSupport namespaceSupport) {
113: this .wfsfactory = wfsfactory;
114: this .namespaceSupport = namespaceSupport;
115: }
116:
117: /**
118: * @generated
119: */
120: public QName getTarget() {
121: return WFS.QUERYTYPE;
122: }
123:
124: /**
125: * <!-- begin-user-doc -->
126: * <!-- end-user-doc -->
127: *
128: * @generated modifiable
129: */
130: public Class getType() {
131: return QueryType.class;
132: }
133:
134: public void initializeChildContext(ElementInstance childInstance,
135: Node node, MutablePicoContainer context) {
136: //if an srsName is set for this geometry, put it in the context for
137: // children, so they can use it as well
138: if (node.hasAttribute("srsName")) {
139: try {
140: CoordinateReferenceSystem crs = GML2ParsingUtils
141: .crs(node);
142: if (crs != null) {
143: context.registerComponentInstance(
144: CoordinateReferenceSystem.class, crs);
145: }
146: } catch (Exception e) {
147: throw new WFSException(e, "InvalidParameterValue");
148: }
149: }
150: }
151:
152: /**
153: * <!-- begin-user-doc -->
154: * <!-- end-user-doc -->
155: *
156: * @generated modifiable
157: */
158: public Object parse(ElementInstance instance, Node node,
159: Object value) throws Exception {
160: QueryType queryType = wfsfactory.createQueryType();
161:
162: //<xsd:element maxOccurs="unbounded" minOccurs="0" ref="ogc:PropertyName">
163: //JD:difference in spec here, moved from ogc:PropertyName to string
164: List propertyNames = node.getChildValues(PropertyName.class);
165:
166: for (Iterator p = propertyNames.iterator(); p.hasNext();) {
167: PropertyName propertyName = (PropertyName) p.next();
168: queryType.getPropertyName().add(
169: propertyName.getPropertyName());
170: }
171:
172: //<xsd:element maxOccurs="1" minOccurs="0" ref="ogc:Filter">
173: Filter filter = (Filter) node.getChildValue(Filter.class);
174:
175: if (filter == null) {
176: filter = (Filter) Filter.INCLUDE;
177: }
178:
179: queryType.setFilter(filter);
180:
181: //<xsd:attribute name="handle" type="xsd:string" use="optional"/>
182: queryType.setHandle((String) node.getAttributeValue("handle"));
183:
184: //<xsd:attribute name="typeName" type="xsd:QName" use="required"/>
185: List typeNameList = new ArrayList();
186: typeNameList.add(node.getAttributeValue("typeName"));
187: queryType.setTypeName(typeNameList);
188:
189: //<xsd:attribute name="featureVersion" type="xsd:string" use="optional">
190: queryType.setFeatureVersion((String) node
191: .getAttributeValue("featureVersion"));
192:
193: //JD: even though reprojection is not supported in 1.0 we handle it
194: // anyways
195: //<xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
196: if (node.hasAttribute("srsName")) {
197: queryType.setSrsName(new URI((String) node
198: .getAttributeValue("srsName")));
199: }
200:
201: return queryType;
202: }
203: }
|