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 org.w3c.dom.Document;
019: import org.w3c.dom.Element;
020: import javax.xml.namespace.QName;
021: import com.vividsolutions.jts.geom.Geometry;
022: import org.opengis.referencing.crs.CoordinateReferenceSystem;
023: import org.geotools.xml.*;
024:
025: /**
026: * Binding object for the type http://www.opengis.net/gml:AbstractGeometryType.
027: *
028: * <p>
029: * <pre>
030: * <code>
031: * <complexType abstract="true" name="AbstractGeometryType">
032: * <annotation>
033: * <documentation>All geometry elements are derived directly or indirectly from this abstract supertype. A geometry element may
034: * have an identifying attribute ("gml:id"), a name (attribute "name") and a description (attribute "description"). It may be associated
035: * with a spatial reference system (attribute "srsName"). The following rules shall be adhered: - Every geometry type shall derive
036: * from this abstract type. - Every geometry element (i.e. an element of a geometry type) shall be directly or indirectly in the
037: * substitution group of _Geometry.</documentation>
038: * </annotation>
039: * <complexContent>
040: * <extension base="gml:AbstractGMLType">
041: * <attribute name="gid" type="string" use="optional">
042: * <annotation>
043: * <documentation>This attribute is included for backward compatibility with GML 2 and is deprecated with GML 3.
044: * This identifer is superceded by "gml:id" inherited from AbstractGMLType. The attribute "gid" should not be used
045: * anymore and may be deleted in future versions of GML without further notice.</documentation>
046: * </annotation>
047: * </attribute>
048: * <attributeGroup ref="gml:SRSReferenceGroup"/>
049: * </extension>
050: * </complexContent>
051: * </complexType>
052: *
053: * </code>
054: * </pre>
055: * </p>
056: *
057: * @generated
058: */
059: public class AbstractGeometryTypeBinding extends AbstractComplexBinding {
060: /**
061: * @generated
062: */
063: public QName getTarget() {
064: return GML.AbstractGeometryType;
065: }
066:
067: /**
068: * <!-- begin-user-doc -->
069: * <!-- end-user-doc -->
070: *
071: * @generated modifiable
072: */
073: public Class getType() {
074: return Geometry.class;
075: }
076:
077: /**
078: * <!-- begin-user-doc -->
079: * <!-- end-user-doc -->
080: *
081: * @generated modifiable
082: */
083: public Object parse(ElementInstance instance, Node node,
084: Object value) throws Exception {
085: //set the crs
086: if (value instanceof Geometry) {
087: CoordinateReferenceSystem crs = GML3ParsingUtils.crs(node);
088:
089: if (crs != null) {
090: Geometry geometry = (Geometry) value;
091: geometry.setUserData(crs);
092: }
093: }
094:
095: return value;
096: }
097:
098: public Object getProperty(Object object, QName name)
099: throws Exception {
100: if ("srsName".equals(name.getLocalPart())) {
101: Geometry geometry = (Geometry) object;
102:
103: if (geometry.getUserData() instanceof CoordinateReferenceSystem) {
104: CoordinateReferenceSystem crs = (CoordinateReferenceSystem) geometry
105: .getUserData();
106:
107: return GML3EncodingUtils.crs(crs);
108: }
109: }
110:
111: return null;
112: }
113: }
|