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.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.AbstractComplexBinding;
025: import org.geotools.xml.ElementInstance;
026: import org.geotools.xml.Node;
027:
028: /**
029: * Binding object for the type http://www.opengis.net/gml:PolygonType.
030: *
031: * <p>
032: * <pre>
033: * <code>
034: * <complexType name="PolygonType">
035: * <annotation>
036: * <documentation> A Polygon is defined by an outer
037: * boundary and zero or more inner boundaries which
038: * are in turn defined by LinearRings. </documentation>
039: * </annotation>
040: * <complexContent>
041: * <extension base="gml:AbstractGeometryType">
042: * <sequence>
043: * <element ref="gml:outerBoundaryIs"/>
044: * <element ref="gml:innerBoundaryIs" minOccurs="0" maxOccurs="unbounded"/>
045: * </sequence>
046: * </extension>
047: * </complexContent>
048: * </complexType>
049: *
050: * </code>
051: * </pre>
052: * </p>
053: *
054: * @generated
055: */
056: public class GMLPolygonTypeBinding extends AbstractComplexBinding {
057: GeometryFactory gFactory;
058:
059: public GMLPolygonTypeBinding(GeometryFactory gFactory) {
060: this .gFactory = gFactory;
061: }
062:
063: /**
064: * @generated
065: */
066: public QName getTarget() {
067: return GML.PolygonType;
068: }
069:
070: public int getExecutionMode() {
071: return BEFORE;
072: }
073:
074: /**
075: * <!-- begin-user-doc -->
076: * <!-- end-user-doc -->
077: *
078: * @generated modifiable
079: */
080: public Class getType() {
081: return Polygon.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: LinearRing shell = (LinearRing) node
093: .getChild("outerBoundaryIs").getValue();
094:
095: List innerRings = node.getChildren("innerBoundaryIs");
096: LinearRing[] holes = new LinearRing[innerRings.size()];
097:
098: for (int i = 0; i < innerRings.size(); i++) {
099: Node inode = (Node) innerRings.get(i);
100: holes[i] = (LinearRing) inode.getValue();
101: }
102:
103: return gFactory.createPolygon(shell, holes);
104: }
105:
106: public Object getProperty(Object object, QName name)
107: throws Exception {
108: Polygon polygon = (Polygon) object;
109:
110: if (GML.outerBoundaryIs.equals(name)) {
111: return polygon.getExteriorRing();
112: }
113:
114: if (GML.innerBoundaryIs.equals(name)) {
115: int n = polygon.getNumInteriorRing();
116:
117: if (n > 0) {
118: LineString[] interior = new LineString[n];
119:
120: for (int i = 0; i < n; i++) {
121: interior[i] = polygon.getInteriorRingN(i);
122: }
123:
124: return interior;
125: }
126: }
127:
128: return null;
129: }
130: }
|