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 java.net.URI;
008:
009: import net.opengis.wfs.InsertElementType;
010: import net.opengis.wfs.WfsFactory;
011:
012: import org.geoserver.wfs.WFSException;
013: import org.geotools.feature.Feature;
014: import org.geotools.gml2.bindings.GML2ParsingUtils;
015: import org.geotools.xml.AbstractComplexBinding;
016: import org.geotools.xml.ElementInstance;
017: import org.geotools.xml.Node;
018: import org.opengis.referencing.crs.CoordinateReferenceSystem;
019: import org.picocontainer.MutablePicoContainer;
020:
021: import javax.xml.namespace.QName;
022:
023: /**
024: * Binding object for the type http://www.opengis.net/wfs:InsertElementType.
025: *
026: * <p>
027: * <pre>
028: * <code>
029: * <xsd:complexType name="InsertElementType">
030: * <xsd:sequence>
031: * <xsd:element maxOccurs="unbounded" ref="gml:_Feature"/>
032: * </xsd:sequence>
033: * <xsd:attribute name="handle" type="xsd:string" use="optional"/>
034: * </xsd:complexType>
035: *
036: * </code>
037: * </pre>
038: * </p>
039: *
040: * @generated
041: */
042: public class InsertElementTypeBinding extends AbstractComplexBinding {
043: WfsFactory wfsfactory;
044:
045: public InsertElementTypeBinding(WfsFactory wfsfactory) {
046: this .wfsfactory = wfsfactory;
047: }
048:
049: /**
050: * @generated
051: */
052: public QName getTarget() {
053: return WFS.INSERTELEMENTTYPE;
054: }
055:
056: /**
057: * <!-- begin-user-doc -->
058: * <!-- end-user-doc -->
059: *
060: * @generated modifiable
061: */
062: public Class getType() {
063: return InsertElementTypeBinding.class;
064: }
065:
066: public void initializeChildContext(ElementInstance childInstance,
067: Node node, MutablePicoContainer context) {
068: //if an srsName is set for this geometry, put it in the context for
069: // children, so they can use it as well
070: if (node.hasAttribute("srsName")) {
071: try {
072: CoordinateReferenceSystem crs = GML2ParsingUtils
073: .crs(node);
074: if (crs != null) {
075: context.registerComponentInstance(
076: CoordinateReferenceSystem.class, crs);
077: }
078: } catch (Exception e) {
079: throw new WFSException(e, "InvalidParameterValue");
080: }
081: }
082: }
083:
084: /**
085: * <!-- begin-user-doc -->
086: * <!-- end-user-doc -->
087: *
088: * @generated modifiable
089: */
090: public Object parse(ElementInstance instance, Node node,
091: Object value) throws Exception {
092: InsertElementType insertElement = wfsfactory
093: .createInsertElementType();
094:
095: //features
096: insertElement.getFeature().addAll(
097: node.getChildValues(Feature.class));
098:
099: //handle
100: if (node.hasAttribute("handle")) {
101: insertElement.setHandle((String) node
102: .getAttributeValue("handle"));
103: }
104:
105: //NOTE: officially this is not supported for wfs 1.0, but we support it
106: // here as an extension to wfs 1.0, also since its not actualy in the
107: // schema it comes to us as a string, not a uri
108: //<xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
109: if (node.hasAttribute("srsName")) {
110: String srsName = (String) node.getAttributeValue("srsName");
111: insertElement.setSrsName(new URI(srsName));
112: }
113: return insertElement;
114: }
115: }
|