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.ArrayList;
019: import javax.xml.namespace.QName;
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.*;
024:
025: /**
026: * Binding object for the type http://www.opengis.net/gml:MultiPointType.
027: *
028: * <p>
029: * <pre>
030: * <code>
031: * <complexType name="MultiPointType">
032: * <annotation>
033: * <documentation>A MultiPoint is defined by one or more Points, referenced through pointMember elements.</documentation>
034: * </annotation>
035: * <complexContent>
036: * <extension base="gml:AbstractGeometricAggregateType">
037: * <sequence>
038: * <annotation>
039: * <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.
040: * NOTE: Array properties cannot reference remote geometry elements.</documentation>
041: * </annotation>
042: * <element maxOccurs="unbounded" minOccurs="0" ref="gml:pointMember"/>
043: * <element minOccurs="0" ref="gml:pointMembers"/>
044: * </sequence>
045: * </extension>
046: * </complexContent>
047: * </complexType>
048: *
049: * </code>
050: * </pre>
051: * </p>
052: *
053: * @generated
054: */
055: public class MultiPointTypeBinding extends AbstractComplexBinding {
056: GeometryFactory gFactory;
057:
058: public MultiPointTypeBinding(GeometryFactory gFactory) {
059: this .gFactory = gFactory;
060: }
061:
062: /**
063: * @generated
064: */
065: public QName getTarget() {
066: return GML.MultiPointType;
067: }
068:
069: /**
070: * <!-- begin-user-doc -->
071: * <!-- end-user-doc -->
072: *
073: * @generated modifiable
074: */
075: public Class getType() {
076: return MultiPoint.class;
077: }
078:
079: public int getExecutionMode() {
080: return BEFORE;
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: ArrayList points = new ArrayList();
092:
093: if (node.hasChild(Point.class)) {
094: points.addAll(node.getChildValues(Point.class));
095: }
096:
097: if (node.hasChild(Point[].class)) {
098: Point[] p = (Point[]) node.getChildValue(Point[].class);
099:
100: for (int i = 0; i < p.length; i++)
101: points.add(p[i]);
102: }
103:
104: return gFactory.createMultiPoint((Point[]) points
105: .toArray(new Point[points.size()]));
106: }
107:
108: public Object getProperty(Object object, QName name)
109: throws Exception {
110: if (GML.pointMember.equals(name)) {
111: MultiPoint multiPoint = (MultiPoint) object;
112: Point[] members = new Point[multiPoint.getNumGeometries()];
113:
114: for (int i = 0; i < members.length; i++) {
115: members[i] = (Point) multiPoint.getGeometryN(i);
116: }
117:
118: return members;
119: }
120:
121: return null;
122: }
123: }
|