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.IdentifierGenerationOptionType;
008: import net.opengis.wfs.InsertElementType;
009: import net.opengis.wfs.WfsFactory;
010:
011: import org.geoserver.wfs.WFSException;
012: import org.geotools.feature.Feature;
013: import org.geotools.feature.FeatureCollection;
014: import org.geotools.gml2.bindings.GML2ParsingUtils;
015: import org.geotools.gml3.bindings.GML;
016: import org.geotools.xml.AbstractComplexEMFBinding;
017: import org.geotools.xml.ElementInstance;
018: import org.geotools.xml.Node;
019: import org.opengis.referencing.crs.CoordinateReferenceSystem;
020: import org.picocontainer.MutablePicoContainer;
021:
022: import java.net.URI;
023: import javax.xml.namespace.QName;
024:
025: /**
026: * Binding object for the type http://www.opengis.net/wfs:InsertElementType.
027: *
028: * <p>
029: * <pre>
030: * <code>
031: * <xsd:complexType name="InsertElementType">
032: * <xsd:annotation>
033: * <xsd:documentation>
034: * An Insert element may contain a feature collection or one
035: * or more feature instances to be inserted into the
036: * repository.
037: * </xsd:documentation>
038: * </xsd:annotation>
039: * <xsd:choice>
040: * <xsd:element ref="gml:_FeatureCollection"/>
041: * <xsd:sequence>
042: * <xsd:element maxOccurs="unbounded" ref="gml:_Feature"/>
043: * </xsd:sequence>
044: * </xsd:choice>
045: * <xsd:attribute default="GenerateNew" name="idgen"
046: * type="wfs:IdentifierGenerationOptionType" use="optional">
047: * <xsd:annotation>
048: * <xsd:documentation>
049: * The idgen attribute control how a WFS generates identifiers
050: * from newly created feature instances using the Insert action.
051: * The default action is to have the WFS generate a new id for
052: * the features. This is also backward compatible with WFS 1.0
053: * where the only action was for the WFS to generate an new id.
054: * </xsd:documentation>
055: * </xsd:annotation>
056: * </xsd:attribute>
057: * <xsd:attribute name="handle" type="xsd:string" use="optional">
058: * <xsd:annotation>
059: * <xsd:documentation>
060: * The handle attribute allows a client application
061: * to assign a client-generated request identifier
062: * to an Insert action. The handle is included to
063: * facilitate error reporting. If an Insert action
064: * in a Transaction request fails, then a WFS may
065: * include the handle in an exception report to localize
066: * the error. If no handle is included of the offending
067: * Insert element then a WFS may employee other means of
068: * localizing the error (e.g. line number).
069: * </xsd:documentation>
070: * </xsd:annotation>
071: * </xsd:attribute>
072: * <xsd:attribute default="text/xml; subtype=gml/3.1.1"
073: * name="inputFormat" type="xsd:string" use="optional">
074: * <xsd:annotation>
075: * <xsd:documentation>
076: * This inputFormat attribute is used to indicate
077: * the format used to encode a feature instance in
078: * an Insert element. The default value of
079: * 'text/xml; subtype=gml/3.1.1' is used to indicate
080: * that feature encoding is GML3. Another example
081: * might be 'text/xml; subtype=gml/2.1.2' indicating
082: * that the feature us encoded in GML2. A WFS must
083: * declare in the capabilities document, using a
084: * Parameter element, which version of GML it supports.
085: * </xsd:documentation>
086: * </xsd:annotation>
087: * </xsd:attribute>
088: * <xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
089: * <xsd:annotation>
090: * <xsd:documentation>
091: * The optional srsName attribute is used to assert the SRS of the
092: * incoming feature data, which can be useful if the incoming feature
093: * data does not have an SRS declared for each geometry. If the
094: * srsName attribute exists on an <Insert> element, its value shall
095: * be equivalent to the value of <DefaultSRS> or any of the
096: * <OtherSRS> of the relevant feature types. If, however, the SRS is
097: * not supported, the WFS shall raise an exception as described in
098: * subclause 7.7. If the srsName is not specified on the <Insert>
099: * element, the WFS shall interpret this to mean that the feature
100: * data is given in the <DefaultSRS> list, except where an SRS is
101: * specified on the feature geometry. In this case, if the SRS for
102: * such a geometry is one of the <DefaultSRS> or <OtherSR> values
103: * for the respective feature types, it will be transformed as
104: * required before insertion. However, if the aforesaid SRS is not
105: * supported for the respective feature type, the entire transaction
106: * shall fail and the WFS shall raise an exception as described in
107: * subclause 7.7. If atomic transactions are not supported by the
108: * underlying DBMS, the WFS shall skip any feature with an
109: * unsupported SRS and continue
110: * </xsd:documentation>
111: * </xsd:annotation>
112: * </xsd:attribute>
113: * </xsd:complexType>
114: *
115: * </code>
116: * </pre>
117: * </p>
118: *
119: * @generated
120: */
121: public class InsertElementTypeBinding extends AbstractComplexEMFBinding {
122: WfsFactory wfsfactory;
123:
124: public InsertElementTypeBinding(WfsFactory wfsfactory) {
125: this .wfsfactory = wfsfactory;
126: }
127:
128: /**
129: * @generated
130: */
131: public QName getTarget() {
132: return WFS.INSERTELEMENTTYPE;
133: }
134:
135: /**
136: * <!-- begin-user-doc -->
137: * <!-- end-user-doc -->
138: *
139: * @generated modifiable
140: */
141: public Class getType() {
142: return InsertElementType.class;
143: }
144:
145: public void initializeChildContext(ElementInstance childInstance,
146: Node node, MutablePicoContainer context) {
147: //if an srsName is set for this geometry, put it in the context for
148: // children, so they can use it as well
149: if (node.hasAttribute("srsName")) {
150: try {
151: CoordinateReferenceSystem crs = GML2ParsingUtils
152: .crs(node);
153: if (crs != null) {
154: context.registerComponentInstance(
155: CoordinateReferenceSystem.class, crs);
156: }
157: } catch (Exception e) {
158: throw new WFSException(e, "InvalidParameterValue");
159: }
160: }
161: }
162:
163: /**
164: * <!-- begin-user-doc -->
165: * <!-- end-user-doc -->
166: *
167: * @generated modifiable
168: */
169: public Object parse(ElementInstance instance, Node node,
170: Object value) throws Exception {
171: InsertElementType insertElement = wfsfactory
172: .createInsertElementType();
173:
174: //<xsd:choice>
175: // <xsd:element ref="gml:_FeatureCollection"/>
176: // <xsd:sequence>
177: // <xsd:element maxOccurs="unbounded" ref="gml:_Feature"/>
178: // </xsd:sequence>
179: //</xsd:choice>
180: if (node.hasChild(FeatureCollection.class)) {
181: FeatureCollection fc = (FeatureCollection) node
182: .getChildValue(FeatureCollection.class);
183: insertElement.getFeature().addAll(fc);
184: } else if (node.hasChild(Feature.class)) {
185: insertElement.getFeature().addAll(
186: node.getChildValues(Feature.class));
187: }
188:
189: //<xsd:attribute default="GenerateNew" name="idgen"
190: // type="wfs:IdentifierGenerationOptionType" use="optional">
191: if (node.hasAttribute("idgen")) {
192: insertElement
193: .setIdgen((IdentifierGenerationOptionType) node
194: .getAttributeValue("idgen"));
195: }
196:
197: //<xsd:attribute name="handle" type="xsd:string" use="optional">
198: if (node.hasAttribute("handle")) {
199: insertElement.setHandle((String) node
200: .getAttributeValue("handle"));
201: }
202:
203: //<xsd:attribute default="text/xml; subtype=gml/3.1.1"
204: // name="inputFormat" type="xsd:string" use="optional">
205: if (node.hasAttribute("inputFormat")) {
206: insertElement.setInputFormat((String) node
207: .getAttributeValue("inputFormat"));
208: }
209:
210: //<xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
211: if (node.hasAttribute("srsName")) {
212: insertElement.setSrsName((URI) node
213: .getAttributeValue("srsName"));
214: }
215:
216: return insertElement;
217: }
218:
219: public Object getProperty(Object object, QName name)
220: throws Exception {
221: InsertElementType insert = (InsertElementType) object;
222:
223: if (GML._Feature.equals(name)) {
224: return insert.getFeature();
225: }
226:
227: return super.getProperty(object, name);
228: }
229: }
|