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