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.MultiPolygon;
022: import com.vividsolutions.jts.geom.Polygon;
023: import org.geotools.xml.*;
024:
025: /**
026: * Binding object for the type http://www.opengis.net/gml:MultiPolygonType.
027: *
028: * <p>
029: * <pre>
030: * <code>
031: * <complexType name="MultiPolygonType">
032: * <annotation>
033: * <documentation>A MultiPolygon is defined by one or more Polygons, referenced through polygonMember elements. Deprecated with GML version 3.0. Use MultiSurfaceType instead.</documentation>
034: * </annotation>
035: * <complexContent>
036: * <extension base="gml:AbstractGeometricAggregateType">
037: * <sequence>
038: * <element maxOccurs="unbounded" minOccurs="0" ref="gml:polygonMember"/>
039: * </sequence>
040: * </extension>
041: * </complexContent>
042: * </complexType>
043: *
044: * </code>
045: * </pre>
046: * </p>
047: *
048: * @generated
049: */
050: public class MultiPolygonTypeBinding extends AbstractComplexBinding
051: implements Comparable {
052: GeometryFactory gFactory;
053:
054: public MultiPolygonTypeBinding(GeometryFactory gFactory) {
055: this .gFactory = gFactory;
056: }
057:
058: /**
059: * @generated
060: */
061: public QName getTarget() {
062: return GML.MultiPolygonType;
063: }
064:
065: public int getExecutionMode() {
066: return BEFORE;
067: }
068:
069: /**
070: * <!-- begin-user-doc -->
071: * <!-- end-user-doc -->
072: *
073: * @generated modifiable
074: */
075: public Class getType() {
076: return MultiPolygon.class;
077: }
078:
079: /**
080: * <!-- begin-user-doc -->
081: * <!-- end-user-doc -->
082: *
083: * @generated modifiable
084: */
085: public Object parse(ElementInstance instance, Node node,
086: Object value) throws Exception {
087: List polys = node.getChildValues(Polygon.class);
088:
089: return gFactory.createMultiPolygon((Polygon[]) polys
090: .toArray(new Polygon[polys.size()]));
091: }
092:
093: public Object getProperty(Object object, QName name)
094: throws Exception {
095: if (GML.polygonMember.equals(name)) {
096: MultiPolygon multiPolygon = (MultiPolygon) object;
097: Polygon[] members = new Polygon[multiPolygon
098: .getNumGeometries()];
099:
100: for (int i = 0; i < members.length; i++) {
101: members[i] = (Polygon) multiPolygon.getGeometryN(i);
102: }
103:
104: return members;
105: }
106:
107: return null;
108: }
109:
110: public int compareTo(Object o) {
111: if (o instanceof MultiSurfacePropertyTypeBinding) {
112: return 1;
113: } else {
114: return 0;
115: }
116: }
117: }
|