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.gml3.bindings;
017:
018: import org.eclipse.xsd.XSDElementDeclaration;
019: import org.w3c.dom.Document;
020: import org.w3c.dom.Element;
021: import javax.xml.namespace.QName;
022: import com.vividsolutions.jts.geom.Coordinate;
023: import com.vividsolutions.jts.geom.CoordinateSequence;
024: import com.vividsolutions.jts.geom.GeometryFactory;
025: import com.vividsolutions.jts.geom.Point;
026: import org.opengis.geometry.DirectPosition;
027: import org.geotools.geometry.DirectPosition2D;
028: import org.geotools.xml.*;
029:
030: /**
031: * Binding object for the type http://www.opengis.net/gml:PointType.
032: *
033: * <p>
034: * <pre>
035: * <code>
036: * <complexType name="PointType">
037: * <annotation>
038: * <documentation>A Point is defined by a single coordinate tuple.</documentation>
039: * </annotation>
040: * <complexContent>
041: * <extension base="gml:AbstractGeometricPrimitiveType">
042: * <sequence>
043: * <choice>
044: * <annotation>
045: * <documentation>GML supports two different ways to specify the direct poisiton of a point. 1. The "pos" element is of type
046: * DirectPositionType.</documentation>
047: * </annotation>
048: * <element ref="gml:pos"/>
049: * <element ref="gml:coordinates">
050: * <annotation>
051: * <documentation>Deprecated with GML version 3.1.0 for coordinates with ordinate values that are numbers. Use "pos"
052: * instead. The "coordinates" element shall only be used for coordinates with ordinates that require a string
053: * representation, e.g. DMS representations.</documentation>
054: * </annotation>
055: * </element>
056: * <element ref="gml:coord">
057: * <annotation>
058: * <documentation>Deprecated with GML version 3.0. Use "pos" instead. The "coord" element is included for
059: * backwards compatibility with GML 2.</documentation>
060: * </annotation>
061: * </element>
062: * </choice>
063: * </sequence>
064: * </extension>
065: * </complexContent>
066: * </complexType>
067: *
068: * </code>
069: * </pre>
070: * </p>
071: *
072: * @generated
073: */
074: public class PointTypeBinding extends AbstractComplexBinding {
075: GeometryFactory gFactory;
076:
077: public PointTypeBinding(GeometryFactory gFactory) {
078: this .gFactory = gFactory;
079: }
080:
081: /**
082: * @generated
083: */
084: public QName getTarget() {
085: return GML.PointType;
086: }
087:
088: public int getExecutionMode() {
089: return BEFORE;
090: }
091:
092: /**
093: * <!-- begin-user-doc -->
094: * <!-- end-user-doc -->
095: *
096: * @generated modifiable
097: */
098: public Class getType() {
099: return Point.class;
100: }
101:
102: /**
103: * <!-- begin-user-doc -->
104: * <!-- end-user-doc -->
105: *
106: * @generated modifiable
107: */
108: public Object parse(ElementInstance instance, Node node,
109: Object value) throws Exception {
110: if (node.hasChild(DirectPosition.class)) {
111: DirectPosition dp = (DirectPosition) node
112: .getChildValue(DirectPosition.class);
113:
114: return gFactory.createPoint(new Coordinate(dp
115: .getOrdinate(0), dp.getOrdinate(1)));
116: }
117:
118: if (node.hasChild(Coordinate.class)) {
119: return gFactory.createPoint((Coordinate) node
120: .getChildValue(Coordinate.class));
121: }
122:
123: if (node.hasChild(CoordinateSequence.class)) {
124: return gFactory.createPoint((CoordinateSequence) node
125: .getChildValue(CoordinateSequence.class));
126: }
127:
128: return null;
129: }
130:
131: public Object getProperty(Object object, QName name) {
132: if (GML.pos.equals(name)) {
133: Point point = (Point) object;
134:
135: DirectPosition2D dp = new DirectPosition2D();
136: dp.setOrdinate(0, point.getX());
137: dp.setOrdinate(1, point.getY());
138:
139: return dp;
140: }
141:
142: return null;
143: }
144: }
|