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 java.net.URI;
019: import java.util.logging.Logger;
020: import javax.xml.namespace.QName;
021: import com.vividsolutions.jts.geom.Geometry;
022: import org.opengis.referencing.crs.CoordinateReferenceSystem;
023: import org.geotools.referencing.CRS;
024: import org.geotools.xml.AbstractComplexBinding;
025: import org.geotools.xml.ElementInstance;
026: import org.geotools.xml.Node;
027:
028: /**
029: * Binding object for the type http://www.opengis.net/gml:AbstractGeometryType.
030: *
031: * <p>
032: * <pre>
033: * <code>
034: * <complexType name="AbstractGeometryType" abstract="true">
035: * <annotation>
036: * <documentation> All geometry elements are derived from
037: * this abstract supertype; a geometry element may
038: * have an identifying attribute (gid). It may be
039: * associated with a spatial reference system. </documentation>
040: * </annotation>
041: * <complexContent>
042: * <restriction base="anyType">
043: * <attribute name="gid" type="ID" use="optional"/>
044: * <attribute name="srsName" type="anyURI" use="optional"/>
045: * </restriction>
046: * </complexContent>
047: * </complexType>
048: *
049: * </code>
050: * </pre>
051: * </p>
052: *
053: * @generated
054: */
055: public class GMLAbstractGeometryTypeBinding extends
056: AbstractComplexBinding {
057: Logger logger;
058:
059: public GMLAbstractGeometryTypeBinding(Logger logger) {
060: this .logger = logger;
061: }
062:
063: /**
064: * @generated
065: */
066: public QName getTarget() {
067: return GML.ABSTRACTGEOMETRYTYPE;
068: }
069:
070: /**
071: * <!-- begin-user-doc -->
072: * <!-- end-user-doc -->
073: *
074: * @generated modifiable
075: */
076: public int getExecutionMode() {
077: return OVERRIDE;
078: }
079:
080: /**
081: * <!-- begin-user-doc -->
082: * <!-- end-user-doc -->
083: *
084: * @generated modifiable
085: */
086: public Class getType() {
087: return Geometry.class;
088: }
089:
090: /**
091: * <!-- begin-user-doc -->
092: * <!-- end-user-doc -->
093: *
094: * @generated modifiable
095: */
096: public Object parse(ElementInstance instance, Node node,
097: Object value) throws Exception {
098: if (value instanceof Geometry) {
099: Geometry geometry = (Geometry) value;
100:
101: //<attribute name="srsName" type="anyURI" use="optional"/>
102: if (node.hasAttribute("srsName")) {
103: URI srs = (URI) node.getAttributeValue("srsName");
104: CoordinateReferenceSystem crs = CRS.decode(srs
105: .toString());
106:
107: if (crs != null) {
108: geometry.setUserData(crs);
109: } else {
110: logger
111: .warning("Could not create Coordinate Reference System for "
112: + srs);
113: }
114: }
115:
116: //TODO: process the ID attribute
117: }
118:
119: return value;
120: }
121:
122: public Object getProperty(Object object, QName name)
123: throws Exception {
124: if ("srsName".equals(name.getLocalPart())) {
125: Geometry geometry = (Geometry) object;
126:
127: if (geometry.getUserData() instanceof CoordinateReferenceSystem) {
128: return GML2EncodingUtils
129: .crs((CoordinateReferenceSystem) geometry
130: .getUserData());
131: }
132: }
133:
134: return null;
135: }
136: }
|