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 java.net.URI;
021: import javax.units.BaseUnit;
022: import javax.units.Unit;
023: import javax.xml.namespace.QName;
024: import org.geotools.measure.Measure;
025: import org.geotools.xml.*;
026:
027: /**
028: * Binding object for the type http://www.opengis.net/gml:MeasureType.
029: *
030: * <p>
031: * <pre>
032: * <code>
033: * <complexType name="MeasureType">
034: * <annotation>
035: * <documentation>Number with a scale.
036: * The value of uom (Units Of Measure) attribute is a reference to a Reference System for the amount, either a ratio or position scale. </documentation>
037: * </annotation>
038: * <simpleContent>
039: * <extension base="double">
040: * <attribute name="uom" type="anyURI" use="required"/>
041: * </extension>
042: * </simpleContent>
043: * </complexType>
044: *
045: * </code>
046: * </pre>
047: * </p>
048: *
049: * @generated
050: */
051: public class MeasureTypeBinding extends AbstractComplexBinding {
052: /**
053: * @generated
054: */
055: public QName getTarget() {
056: return GML.MeasureType;
057: }
058:
059: /**
060: * <!-- begin-user-doc -->
061: * <!-- end-user-doc -->
062: *
063: * @generated modifiable
064: */
065: public Class getType() {
066: return Measure.class;
067: }
068:
069: /**
070: * <!-- begin-user-doc -->
071: * <!-- end-user-doc -->
072: *
073: * @generated modifiable
074: */
075: public Object parse(ElementInstance instance, Node node,
076: Object value) throws Exception {
077: Double d = Double.valueOf(node.getComponent().getText());
078: URI uom = (URI) node.getAttributeValue(URI.class);
079:
080: if (uom != null) {
081: return new Measure(d.doubleValue(), new BaseUnit(uom
082: .toString()) {
083: });
084: }
085:
086: return new Measure(d.doubleValue(), null);
087: }
088:
089: public Element encode(Object object, Document document,
090: Element value) throws Exception {
091: Measure measure = (Measure) object;
092: value.appendChild(document.createTextNode(""
093: + measure.doubleValue()));
094:
095: return value;
096: }
097:
098: public Object getProperty(Object object, QName name)
099: throws Exception {
100: if ("uom".equals(name.getLocalPart())) {
101: Measure measure = (Measure) object;
102:
103: if (measure.getUnit() != null) {
104: return new URI(((BaseUnit) measure.getUnit())
105: .getSymbol());
106: }
107: }
108:
109: return null;
110: }
111: }
|