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.PropertyType;
008: import net.opengis.wfs.WfsFactory;
009: import org.geoserver.platform.GeoServerExtensions;
010: import org.geoserver.wfs.xml.GML3Profile;
011: import org.geoserver.wfs.xml.PropertyTypePropertyExtractor;
012: import org.geoserver.wfs.xml.TypeMappingProfile;
013: import org.geoserver.wfs.xml.XSProfile;
014: import org.geotools.xml.AbstractComplexBinding;
015: import org.geotools.xml.AbstractComplexEMFBinding;
016: import org.geotools.xml.ElementInstance;
017: import org.geotools.xml.Node;
018: import org.geotools.xs.bindings.XS;
019: import org.opengis.feature.type.Name;
020: import org.w3c.dom.Document;
021: import org.w3c.dom.Element;
022: import java.util.ArrayList;
023: import java.util.Arrays;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Map;
027: import javax.xml.namespace.QName;
028:
029: /**
030: * Binding object for the type http://www.opengis.net/wfs:PropertyType.
031: *
032: * <p>
033: * <pre>
034: * <code>
035: * <xsd:complexType name="PropertyType">
036: * <xsd:sequence>
037: * <xsd:element name="Name" type="xsd:QName">
038: * <xsd:annotation>
039: * <xsd:documentation>
040: * The Name element contains the name of a feature property
041: * to be updated.
042: * </xsd:documentation>
043: * </xsd:annotation>
044: * </xsd:element>
045: * <xsd:element minOccurs="0" name="Value">
046: * <xsd:annotation>
047: * <xsd:documentation>
048: * The Value element contains the replacement value for the
049: * named property.
050: * </xsd:documentation>
051: * </xsd:annotation>
052: * </xsd:element>
053: * </xsd:sequence>
054: * </xsd:complexType>
055: *
056: * </code>
057: * </pre>
058: * </p>
059: *
060: * @generated
061: */
062: public class PropertyTypeBinding extends AbstractComplexBinding {
063: WfsFactory wfsfactory;
064:
065: public PropertyTypeBinding(WfsFactory wfsfactory) {
066: this .wfsfactory = wfsfactory;
067: }
068:
069: /**
070: * @generated
071: */
072: public QName getTarget() {
073: return WFS.PROPERTYTYPE;
074: }
075:
076: /**
077: * <!-- begin-user-doc -->
078: * <!-- end-user-doc -->
079: *
080: * @generated modifiable
081: */
082: public Class getType() {
083: return PropertyType.class;
084: }
085:
086: /**
087: * <!-- begin-user-doc -->
088: * <!-- end-user-doc -->
089: *
090: * @generated modifiable
091: */
092: public Object parse(ElementInstance instance, Node node,
093: Object value) throws Exception {
094: //TODO: much of this method is duplicated in the 1.1.0 binding, it
095: // would be nice if we could sync them up somewhow....
096: PropertyType property = wfsfactory.createPropertyType();
097:
098: //<xsd:element name="Name" type="xsd:QName">
099: property.setName((QName) node.getChildValue(QName.class));
100:
101: //<xsd:element minOccurs="0" name="Value">
102: if (node.hasChild("Value")) {
103: Object object = node.getChildValue("Value");
104:
105: //check for a map
106: if (object instanceof Map) {
107: Map map = (Map) object;
108:
109: //this means a complex element parsed by xs:AnyType binding
110: // try to pull out some text
111: if (!map.isEmpty()) {
112: //first check for some text
113: if (map.containsKey(null)) {
114: property.setValue(map.get(null));
115: } else {
116: //perhaps some other value
117: property.setValue(map.values().iterator()
118: .next());
119: }
120: }
121: } else {
122: property.setValue(object);
123: }
124: }
125:
126: return property;
127: }
128:
129: /**
130: * This method does nothing, its functionality is implemented by
131: * {@link PropertyTypePropertyExtractor}.
132: */
133: public Object getProperty(Object object, QName name)
134: throws Exception {
135: return null;
136: }
137: }
|