001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.gml2.bindings;
017:
018: import java.math.BigDecimal;
019: import javax.xml.namespace.QName;
020: import com.vividsolutions.jts.geom.Coordinate;
021: import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
022: import org.geotools.xml.AbstractComplexBinding;
023: import org.geotools.xml.ElementInstance;
024: import org.geotools.xml.Node;
025:
026: /**
027: * Binding object for the type http://www.opengis.net/gml:CoordType.
028: *
029: * <p>
030: * <pre>
031: * <code>
032: * <complexType name="CoordType">
033: * <annotation>
034: * <documentation> Represents a coordinate tuple in one,
035: * two, or three dimensions. </documentation>
036: * </annotation>
037: * <sequence>
038: * <element name="X" type="decimal"/>
039: * <element name="Y" type="decimal" minOccurs="0"/>
040: * <element name="Z" type="decimal" minOccurs="0"/>
041: * </sequence>
042: * </complexType>
043: *
044: * </code>
045: * </pre>
046: * </p>
047: *
048: * @generated
049: */
050: public class GMLCoordTypeBinding extends AbstractComplexBinding {
051: CoordinateSequenceFactory csFactory;
052:
053: public GMLCoordTypeBinding(CoordinateSequenceFactory csFactory) {
054: this .csFactory = csFactory;
055: }
056:
057: /**
058: * @generated
059: */
060: public QName getTarget() {
061: return GML.CoordType;
062: }
063:
064: /**
065: * <!-- begin-user-doc -->
066: * <!-- end-user-doc -->
067: *
068: * @generated modifiable
069: */
070: public Class getType() {
071: return Coordinate.class;
072: }
073:
074: /**
075: * <!-- begin-user-doc -->
076: * Returns a coordinate sequence with a single coordinate in it.
077: * <!-- end-user-doc -->
078: *
079: * @generated modifiable
080: */
081: public Object parse(ElementInstance instance, Node node,
082: Object value) throws Exception {
083: int dimension = 1;
084: double x;
085: double y;
086: double z;
087: x = y = z = Double.NaN;
088:
089: x = ((BigDecimal) node.getChild("X").getValue()).doubleValue();
090:
091: if (!node.getChildren("Y").isEmpty()) {
092: dimension++;
093: y = ((BigDecimal) node.getChild("Y").getValue())
094: .doubleValue();
095: }
096:
097: if (!node.getChildren("Z").isEmpty()) {
098: dimension++;
099: z = ((BigDecimal) node.getChild("Z").getValue())
100: .doubleValue();
101: }
102:
103: return new Coordinate(x, y, z);
104: }
105:
106: public Object getProperty(Object object, QName name)
107: throws Exception {
108: Coordinate c = (Coordinate) object;
109:
110: if ("X".equals(name.getLocalPart())) {
111: return new Double(c.x);
112: }
113:
114: if ("Y".equals(name.getLocalPart())) {
115: return new Double(c.y);
116: }
117:
118: if ("Z".equals(name.getLocalPart()) && !new Double(c.z).isNaN()) {
119: return new Double(c.z);
120: }
121:
122: return null;
123: }
124: }
|