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.AbstractComplexBinding;
024: import org.geotools.xml.ElementInstance;
025: import org.geotools.xml.Node;
026:
027: /**
028: * Binding object for the type http://www.opengis.net/gml:MultiSurfaceType.
029: *
030: * <p>
031: * <pre>
032: * <code>
033: * <complexType name="MultiSurfaceType">
034: * <annotation>
035: * <documentation>A MultiSurface is defined by one or more Surfaces, referenced through surfaceMember elements.</documentation>
036: * </annotation>
037: * <complexContent>
038: * <extension base="gml:AbstractGeometricAggregateType">
039: * <sequence>
040: * <annotation>
041: * <documentation>The members of the geometric aggregate can be specified either using the "standard" property or the array property style. It is also valid to use both the "standard" and the array property style in the same collection.
042: * NOTE: Array properties cannot reference remote geometry elements.</documentation>
043: * </annotation>
044: * <element maxOccurs="unbounded" minOccurs="0" ref="gml:surfaceMember"/>
045: * <element minOccurs="0" ref="gml:surfaceMembers"/>
046: * </sequence>
047: * </extension>
048: * </complexContent>
049: * </complexType>
050: *
051: * </code>
052: * </pre>
053: * </p>
054: *
055: * @generated
056: */
057: public class MultiSurfaceTypeBinding extends AbstractComplexBinding
058: implements Comparable {
059: GeometryFactory gf;
060:
061: public MultiSurfaceTypeBinding(GeometryFactory gf) {
062: this .gf = gf;
063: }
064:
065: /**
066: * @generated
067: */
068: public QName getTarget() {
069: return GML.MultiSurfaceType;
070: }
071:
072: /**
073: * <!-- begin-user-doc -->
074: * <!-- end-user-doc -->
075: *
076: * @generated modifiable
077: */
078: public Class getType() {
079: return MultiPolygon.class;
080: }
081:
082: public int getExecutionMode() {
083: return BEFORE;
084: }
085:
086: /**
087: * <!-- begin-user-doc -->
088: * <!-- end-user-doc -->
089: *
090: * @generated modifiable
091: */
092: public Object parse(ElementInstance instance, Node node,
093: Object value) throws Exception {
094: //<element maxOccurs="unbounded" minOccurs="0" ref="gml:surfaceMember"/>
095: List surfaces = node.getChildValues(Polygon.class);
096:
097: return gf.createMultiPolygon((Polygon[]) surfaces
098: .toArray(new Polygon[surfaces.size()]));
099: }
100:
101: public Object getProperty(Object object, QName name)
102: throws Exception {
103: if (GML.surfaceMember.equals(name)) {
104: MultiPolygon multiSurface = (MultiPolygon) object;
105: Polygon[] members = new Polygon[multiSurface
106: .getNumGeometries()];
107:
108: for (int i = 0; i < members.length; i++) {
109: members[i] = (Polygon) multiSurface.getGeometryN(i);
110: }
111:
112: return members;
113: }
114:
115: return null;
116: }
117:
118: public int compareTo(Object o) {
119: if (o instanceof MultiPolygonPropertyTypeBinding) {
120: return -1;
121: } else {
122: return 0;
123: }
124: }
125: }
|