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 java.util.List;
019: import javax.xml.namespace.QName;
020: import com.vividsolutions.jts.geom.GeometryFactory;
021: import com.vividsolutions.jts.geom.LineString;
022: import com.vividsolutions.jts.geom.LinearRing;
023: import com.vividsolutions.jts.geom.Polygon;
024: import org.geotools.xml.*;
025:
026: /**
027: * Binding object for the type http://www.opengis.net/gml:PolygonType.
028: *
029: * <p>
030: * <pre>
031: * <code>
032: * <complexType name="PolygonType">
033: * <annotation>
034: * <documentation>A Polygon is a special surface that is defined by a single surface patch. The boundary of this patch is coplanar and the polygon uses planar interpolation in its interior. It is backwards compatible with the Polygon of GML 2, GM_Polygon of ISO 19107 is implemented by PolygonPatch.</documentation>
035: * </annotation>
036: * <complexContent>
037: * <extension base="gml:AbstractSurfaceType">
038: * <sequence>
039: * <element minOccurs="0" ref="gml:exterior"/>
040: * <element maxOccurs="unbounded" minOccurs="0" ref="gml:interior"/>
041: * </sequence>
042: * </extension>
043: * </complexContent>
044: * </complexType>
045: *
046: * </code>
047: * </pre>
048: * </p>
049: *
050: * @generated
051: */
052: public class PolygonTypeBinding extends AbstractComplexBinding {
053: GeometryFactory gFactory;
054:
055: public PolygonTypeBinding(GeometryFactory gFactory) {
056: this .gFactory = gFactory;
057: }
058:
059: /**
060: * @generated
061: */
062: public QName getTarget() {
063: return GML.PolygonType;
064: }
065:
066: public int getExecutionMode() {
067: return BEFORE;
068: }
069:
070: /**
071: * <!-- begin-user-doc -->
072: * <!-- end-user-doc -->
073: *
074: * @generated modifiable
075: */
076: public Class getType() {
077: return Polygon.class;
078: }
079:
080: /**
081: * <!-- begin-user-doc -->
082: * <!-- end-user-doc -->
083: *
084: * @generated modifiable
085: */
086: public Object parse(ElementInstance instance, Node node,
087: Object value) throws Exception {
088: //TODO: schema allows no exterior ring, but what the heck is that all about ?
089: LinearRing exterior = (LinearRing) node
090: .getChildValue("exterior");
091: LinearRing[] interior = null;
092:
093: if (node.hasChild("interior")) {
094: List list = node.getChildValues("interior");
095: interior = (LinearRing[]) list.toArray(new LinearRing[list
096: .size()]);
097: }
098:
099: return gFactory.createPolygon(exterior, interior);
100: }
101:
102: public Object getProperty(Object object, QName name)
103: throws Exception {
104: Polygon polygon = (Polygon) object;
105:
106: if (name.equals(GML.exterior)) {
107: return polygon.getExteriorRing();
108: }
109:
110: if (name.equals(GML.interior)) {
111: int n = polygon.getNumInteriorRing();
112:
113: if (n > 0) {
114: LineString[] interior = new LineString[n];
115:
116: for (int i = 0; i < n; i++) {
117: interior[i] = polygon.getInteriorRingN(i);
118: }
119:
120: return interior;
121: }
122: }
123:
124: return null;
125: }
126: }
|