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 javax.xml.namespace.QName;
019: import com.vividsolutions.jts.geom.GeometryCollection;
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:MultiPolygonType.
029: *
030: * <p>
031: * <pre>
032: * <code>
033: * <complexType name="MultiPolygonType">
034: * <annotation>
035: * <documentation> A MultiPolygon is defined by one or more
036: * Polygons, referenced through polygonMember
037: * elements. </documentation>
038: * </annotation>
039: * <complexContent>
040: * <restriction base="gml:GeometryCollectionType">
041: * <sequence>
042: * <element ref="gml:polygonMember" maxOccurs="unbounded"/>
043: * </sequence>
044: * <attribute name="gid" type="ID" use="optional"/>
045: * <attribute name="srsName" type="anyURI" use="required"/>
046: * </restriction>
047: * </complexContent>
048: * </complexType>
049: *
050: * </code>
051: * </pre>
052: * </p>
053: *
054: * @generated
055: */
056: public class GMLMultiPolygonTypeBinding extends AbstractComplexBinding {
057: GeometryFactory gFactory;
058:
059: public GMLMultiPolygonTypeBinding(GeometryFactory gFactory) {
060: this .gFactory = gFactory;
061: }
062:
063: /**
064: * @generated
065: */
066: public QName getTarget() {
067: return GML.MultiPolygonType;
068: }
069:
070: /**
071: * <!-- begin-user-doc -->
072: * <!-- end-user-doc -->
073: *
074: *
075: * @generated modifiable
076: */
077: public int getExecutionMode() {
078: return AFTER;
079: }
080:
081: /**
082: * <!-- begin-user-doc -->
083: * <!-- end-user-doc -->
084: *
085: * @generated modifiable
086: */
087: public Class getType() {
088: return MultiPolygon.class;
089: }
090:
091: /**
092: * <!-- begin-user-doc -->
093: * <!-- end-user-doc -->
094: *
095: * @generated modifiable
096: */
097: public Object parse(ElementInstance instance, Node node,
098: Object value) throws Exception {
099: GeometryCollection gc = (GeometryCollection) value;
100: Polygon[] polygons = new Polygon[gc.getNumGeometries()];
101:
102: for (int i = 0; i < gc.getNumGeometries(); i++) {
103: polygons[i] = (Polygon) gc.getGeometryN(i);
104: }
105:
106: MultiPolygon multiPolygon = gFactory
107: .createMultiPolygon(polygons);
108: multiPolygon.setUserData(gc.getUserData());
109:
110: return multiPolygon;
111: }
112:
113: public Object getProperty(Object object, QName name)
114: throws Exception {
115: if (GML.polygonMember.equals(name)) {
116: return GML2ParsingUtils.asCollection((MultiPolygon) object);
117: }
118:
119: return null;
120: }
121: }
|