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.PropertyType;
008: import net.opengis.wfs.WfsFactory;
009: import org.geotools.xml.AbstractComplexBinding;
010: import org.geotools.xml.ElementInstance;
011: import org.geotools.xml.Node;
012: import org.geotools.xs.bindings.XSQNameBinding;
013: import java.util.Map;
014: import javax.xml.namespace.NamespaceContext;
015: import javax.xml.namespace.QName;
016:
017: /**
018: * Binding object for the type http://www.opengis.net/wfs:PropertyType.
019: *
020: * <p>
021: * <pre>
022: * <code>
023: * <xsd:complexType name="PropertyType">
024: * <xsd:sequence>
025: * <xsd:element name="Name" type="xsd:string">
026: * <xsd:annotation>
027: * <xsd:documentation>
028: * The Name element contains the name of a feature property
029: * to be updated.
030: * </xsd:documentation>
031: * </xsd:annotation>
032: * </xsd:element>
033: * <xsd:element minOccurs="0" name="Value">
034: * <xsd:annotation>
035: * <xsd:documentation>
036: * The Value element contains the replacement value for the
037: * named property.
038: * </xsd:documentation>
039: * </xsd:annotation>
040: * </xsd:element>
041: * </xsd:sequence>
042: * </xsd:complexType>
043: *
044: * </code>
045: * </pre>
046: * </p>
047: *
048: * @generated
049: */
050: public class PropertyTypeBinding extends AbstractComplexBinding {
051: /**
052: * The wfs factory
053: */
054: WfsFactory wfsfactory;
055:
056: /**
057: * Namespace support
058: */
059: NamespaceContext namespaceContext;
060:
061: public PropertyTypeBinding(WfsFactory wfsfactory,
062: NamespaceContext namespaceContext) {
063: this .wfsfactory = wfsfactory;
064: this .namespaceContext = namespaceContext;
065: }
066:
067: /**
068: * @generated
069: */
070: public QName getTarget() {
071: return WFS.PROPERTYTYPE;
072: }
073:
074: /**
075: * <!-- begin-user-doc -->
076: * <!-- end-user-doc -->
077: *
078: * @generated modifiable
079: */
080: public Class getType() {
081: return PropertyType.class;
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: PropertyType property = wfsfactory.createPropertyType();
093:
094: //<xsd:element name="Name" type="xsd:string">
095: String name = (String) node.getChildValue("Name");
096:
097: //turn into qname
098: QName qName = (QName) new XSQNameBinding(namespaceContext)
099: .parse(null, name);
100: property.setName(qName);
101:
102: //<xsd:element minOccurs="0" name="Value">
103: if (node.hasChild("Value")) {
104: Object object = node.getChildValue("Value");
105:
106: //check for a map
107: if (object instanceof Map) {
108: Map map = (Map) object;
109:
110: //this means a complex element parsed by xs:AnyType binding
111: // try to pull out some text
112: if (!map.isEmpty()) {
113: //first check for some text
114: if (map.containsKey(null)) {
115: property.setValue(map.get(null));
116: } else {
117: //perhaps some other value
118: property.setValue(map.values().iterator()
119: .next());
120: }
121: }
122: } else {
123: property.setValue(object);
124: }
125: }
126:
127: return property;
128: }
129: }
|