You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/06/21 19:50:12 UTC
svn commit: r1495519 - in /sis/branches/JDK7/core:
sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/
sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/
sis-metadata/src/main/java/org/apache/sis/metadata/iso/identificatio...
Author: desruisseaux
Date: Fri Jun 21 17:50:11 2013
New Revision: 1495519
URL: http://svn.apache.org/r1495519
Log:
Added adapters for some quantities and unit of measurement.
Added:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java (with props)
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java (with props)
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java (with props)
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java (with props)
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/package-info.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/package-info.java?rev=1495519&r1=1495518&r2=1495519&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/package-info.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/package-info.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -106,7 +106,7 @@
@XmlJavaTypeAdapter(MI_TransferFunctionTypeCode.class),
// Java types, primitive types and basic OGC types handling
-// @XmlJavaTypeAdapter(UnitAdapter.class), // TODO
+ @XmlJavaTypeAdapter(UnitAdapter.class),
@XmlJavaTypeAdapter(LocaleAdapter.class),
@XmlJavaTypeAdapter(InternationalStringAdapter.class),
@XmlJavaTypeAdapter(GO_GenericName.class),
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java?rev=1495519&r1=1495518&r2=1495519&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -91,7 +91,7 @@
@XmlJavaTypeAdapter(MD_StandardOrderProcess.class),
// Java types, primitive types and basic OGC types handling
-// @XmlJavaTypeAdapter(UnitAdapter.class), // TODO
+ @XmlJavaTypeAdapter(UnitAdapter.class),
@XmlJavaTypeAdapter(LocalNameAdapter.class),
@XmlJavaTypeAdapter(InternationalStringAdapter.class),
@XmlJavaTypeAdapter(GO_DateTime.class),
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java?rev=1495519&r1=1495518&r2=1495519&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -22,11 +22,11 @@ import javax.xml.bind.annotation.XmlRoot
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.opengis.metadata.identification.RepresentativeFraction;
import org.opengis.metadata.identification.Resolution;
-// import org.apache.sis.internal.jaxb.gco.GO_Distance; // TODO
+import org.apache.sis.internal.jaxb.gco.GO_Distance;
+import org.apache.sis.internal.metadata.MetadataUtilities;
import org.apache.sis.metadata.iso.ISOMetadata;
import org.apache.sis.measure.ValueRange;
import org.apache.sis.util.resources.Messages;
-import org.apache.sis.internal.metadata.MetadataUtilities;
/**
@@ -169,8 +169,8 @@ public class DefaultResolution extends I
*/
@Override
@ValueRange(minimum=0, isMinIncluded=false)
-// @XmlJavaTypeAdapter(GO_Distance.class) // TODO
-// @XmlElement(name = "distance")
+ @XmlJavaTypeAdapter(GO_Distance.class)
+ @XmlElement(name = "distance")
public Double getDistance() {
return isDistance() ? (Double) scaleOrDistance : null;
}
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java?rev=1495519&r1=1495518&r2=1495519&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -139,7 +139,7 @@
@XmlJavaTypeAdapter(MX_DataFile.class),
// Java types, primitive types and basic OGC types handling
-// @XmlJavaTypeAdapter(UnitAdapter.class), // TODO
+ @XmlJavaTypeAdapter(UnitAdapter.class),
@XmlJavaTypeAdapter(StringAdapter.class),
@XmlJavaTypeAdapter(InternationalStringAdapter.class),
@XmlJavaTypeAdapter(GO_DateTime.class),
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java?rev=1495519&r1=1495518&r2=1495519&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -22,8 +22,8 @@ import javax.xml.bind.annotation.XmlRoot
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.opengis.metadata.spatial.Dimension;
import org.opengis.metadata.spatial.DimensionNameType;
+import org.apache.sis.internal.jaxb.gco.GO_Measure;
import org.apache.sis.metadata.iso.ISOMetadata;
-//import org.apache.sis.internal.jaxb.gco.GO_Measure;
import org.apache.sis.measure.ValueRange;
@@ -166,7 +166,7 @@ public class DefaultDimension extends IS
*/
@Override
@ValueRange(minimum=0, isMinIncluded=false)
-// @XmlJavaTypeAdapter(GO_Measure.class) // TODO
+ @XmlJavaTypeAdapter(GO_Measure.class)
@XmlElement(name = "resolution")
public Double getResolution() {
return resolution;
Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java?rev=1495519&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jaxb.gco;
+
+import javax.measure.unit.SI;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * The ISO-19103 {@code Distance} with a {@code unit of measure} defined, using the
+ * {@code gco} namespace linked to the {@code http://www.isotc211.org/2005/gco} URL.
+ *
+ * <p>This class is identical to {@link GO_Measure} except for the name of the element,
+ * which is {@code "Distance"}.</p>
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+public final class GO_Distance extends XmlAdapter<GO_Distance, Double> {
+ /**
+ * A proxy representation of the {@code <gco:Distance>} element.
+ */
+ @XmlElement(name = "Distance")
+ private Measure distance;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public GO_Distance() {
+ }
+
+ /**
+ * Constructs an adapter for the given value.
+ *
+ * @param value The value.
+ */
+ private GO_Distance(final Double value) {
+ distance = new Measure(value, SI.METRE);
+ }
+
+ /**
+ * Allows JAXB to generate a Double object using the value found in the adapter.
+ *
+ * @param value The value wrapped in an adapter.
+ * @return The double value extracted from the adapter.
+ */
+ @Override
+ public Double unmarshal(final GO_Distance value) {
+ if (value != null) {
+ final Measure distance = value.distance;
+ if (distance != null) {
+ return distance.value;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process, according to the
+ * ISO-19139 standard and its requirements about {@code measures}.
+ *
+ * @param value The double value we want to integrate into a {@code <gco:Distance>} element.
+ * @return An adaptation of the double value, that is to say a double value surrounded
+ * by {@code <gco:Distance>} element, with an {@code uom} attribute.
+ */
+ @Override
+ public GO_Distance marshal(final Double value) {
+ return (value != null) ? new GO_Distance(value) : null;
+ }
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java?rev=1495519&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jaxb.gco;
+
+import javax.measure.unit.SI;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * The ISO-19103 {@code Measure} with a unit of measure defined in the {@code gco} namespace
+ * associated to the {@code http://www.isotc211.org/2005/gco} URL.
+ *
+ * <p>This class is identical to {@link GO_Distance} except for the name of the element,
+ * which is {@code "Measure"}.</p>
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+public final class GO_Measure extends XmlAdapter<GO_Measure, Double> {
+ /**
+ * A proxy representation of the {@code <gco:Measure>} element.
+ */
+ @XmlElement(name = "Measure")
+ private Measure measure;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public GO_Measure() {
+ }
+
+ /**
+ * Constructs an adapter for the given value.
+ *
+ * @param value The value.
+ */
+ private GO_Measure(final Double value) {
+ measure = new Measure(value, SI.METRE);
+ }
+
+ /**
+ * Allows JAXB to generate a Double object using the value found in the adapter.
+ *
+ * @param value The value wrapped in an adapter.
+ * @return The double value extracted from the adapter.
+ */
+ @Override
+ public Double unmarshal(final GO_Measure value) {
+ if (value != null) {
+ final Measure measure = value.measure;
+ if (measure != null) {
+ return measure.value;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process, according to the
+ * ISO-19139 standard and its requirements about {@code measures}.
+ *
+ * @param value The double value we want to integrate into a {@code <gco:Measure>} element.
+ * @return An adaptation of the double value, that is to say a double value surrounded
+ * by {@code <gco:Measure>} element, with an {@code uom} attribute.
+ */
+ @Override
+ public GO_Measure marshal(final Double value) {
+ return (value != null) ? new GO_Measure(value) : null;
+ }
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java?rev=1495519&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jaxb.gco;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.measure.unit.Unit;
+import javax.measure.unit.NonSI;
+import javax.xml.bind.annotation.XmlValue;
+import javax.xml.bind.annotation.XmlAttribute;
+import org.apache.sis.internal.jaxb.gmd.CodeListProxy;
+import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.xml.ValueConverter;
+import org.apache.sis.util.CharSequences;
+
+
+/**
+ * A measurement value together with its unit of measure.
+ * This is used for marshalling an element defined by ISO-19103.
+ *
+ * <p>This class duplicates {@link org.apache.sis.measure.Measure}, but we have to do that way
+ * because that{@code Measure} extends {@link Number} and we are not allowed to use the
+ * {@code @XmlValue} annotation on a class that extends an other class.</p>
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see org.apache.sis.measure.Measure
+ *
+ * @todo We should annotate {@link org.apache.sis.measure.Measure} directly
+ * if we can find some way to use {@code @XmlValue} with that class.
+ */
+public final class Measure {
+ /**
+ * The value of the measure.
+ */
+ @XmlValue
+ public double value;
+
+ /**
+ * The unit of measure.
+ */
+ public Unit<?> unit;
+
+ /**
+ * Default empty constructor for JAXB. The value is initialized to NaN,
+ * but JAXB will overwrite this value if a XML value is presents.
+ */
+ public Measure() {
+ value = Double.NaN;
+ }
+
+ /**
+ * Constructs a representation of the measure as defined in ISO-19103 standard,
+ * with the UOM attribute like {@code "gmxUom.xml#xpointer(//*[@gml:id='m'])"}.
+ *
+ * @param value The value of the measure.
+ * @param unit The unit of measure to use.
+ */
+ public Measure(final double value, final Unit<?> unit) {
+ this.value = value;
+ this.unit = unit;
+ }
+
+ /**
+ * Constructs a string representation of the units as defined in the ISO-19103 standard.
+ * This method is invoked during XML marshalling. For example in the units are "metre",
+ * then this method returns:
+ *
+ * {@preformat text
+ * http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])
+ * }
+ *
+ * @return The string representation of the unit of measure.
+ */
+ @XmlAttribute(required = true)
+ public String getUOM() {
+ final Unit<?> unit = this.unit;
+ final String symbol;
+ if (unit == null || unit.equals(Unit.ONE)) {
+ symbol = "";
+ } else if (unit.equals(NonSI.PIXEL)) {
+ symbol = "pixel";
+ } else {
+ symbol = CodeListProxy.schema(Context.schema(Context.current(), "gmd", CodeListProxy.DEFAULT_SCHEMA),
+ "resources/uom", "gmxUom.xml", "xpointer(//*[@gml:id='" + unit + "'])");
+ }
+ return symbol;
+ }
+
+ /**
+ * Sets the unit of measure. This method is invoked by JAXB at unmarshalling time,
+ * and can be invoked only once.
+ *
+ * @param uom The unit of measure as a string.
+ * @throws URISyntaxException If the {@code uom} looks like a URI, but can not be parsed.
+ */
+ public void setUOM(String uom) throws URISyntaxException {
+ if (uom == null || (uom = CharSequences.trimWhitespaces(uom)).isEmpty()) {
+ unit = null;
+ return;
+ }
+ /*
+ * Try to guess if the UOM is a URN or URL. We looks for character that are usually
+ * part of URI but not part of unit symbols, for example ':'. We can not search for
+ * '/' and '.' since they are part of UCUM representation.
+ */
+ final Context context = Context.current();
+ final ValueConverter converter = Context.converter(context);
+ if (uom.indexOf(':') >= 0) {
+ final URI uri = converter.toURI(context, uom);
+ String part = uri.getFragment();
+ if (part != null) {
+ uom = part;
+ int i = uom.lastIndexOf("@gml:id=");
+ if (i >= 0) {
+ i += 8; // 8 is the length of "@gml:id="
+ for (final int length=uom.length(); i<length;) {
+ final int c = uom.codePointAt(i);
+ if (!Character.isWhitespace(c)) {
+ if (c == '\'') i++;
+ break;
+ }
+ i += Character.charCount(c);
+ }
+ final int stop = uom.lastIndexOf('\'');
+ uom = CharSequences.trimWhitespaces((stop > i) ? uom.substring(i, stop) : uom.substring(i));
+ }
+ } else if ((part = uri.getPath()) != null) {
+ uom = new File(part).getName();
+ }
+ }
+ unit = converter.toUnit(context, uom);
+ }
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java?rev=1495519&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jaxb.gco;
+
+import javax.measure.unit.Unit;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import org.apache.sis.internal.jaxb.Context;
+
+
+/**
+ * JAXB adapter for unit of measurement.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+public final class UnitAdapter extends XmlAdapter<String, Unit<?>> {
+ /**
+ * Returns a unit for the given string.
+ *
+ * @param value The unit symbol.
+ * @return The unit for the given symbol.
+ * @throws IllegalArgumentException if the given symbol is unknown.
+ */
+ @Override
+ public Unit<?> unmarshal(String value) throws IllegalArgumentException {
+ if (value != null) {
+ final Context context = Context.current();
+ return Context.converter(context).toUnit(context, value);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the symbol of the given unit.
+ *
+ * @param value The unit.
+ * @return The unit symbol.
+ */
+ @Override
+ public String marshal(final Unit<?> value) {
+ return (value != null) ? value.toString() : null;
+ }
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java?rev=1495519&r1=1495518&r2=1495519&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java [UTF-8] Fri Jun 21 17:50:11 2013
@@ -45,6 +45,11 @@ import org.apache.sis.internal.jaxb.Cont
@XmlType(name = "CodeList", propOrder = { "codeSpace", "codeListValue", "codeList" })
public final class CodeListProxy {
/**
+ * The default schema to be given to {@link Context#schema(Context, String, String)} (last argument).
+ */
+ public static final String DEFAULT_SCHEMA = "http://schemas.opengis.net/iso/19139/20070417/";
+
+ /**
* Returns the URL to given code list in the given XML file.
*
* @param context The current (un)marshalling context, or {@code null} if none.
@@ -53,7 +58,7 @@ public final class CodeListProxy {
* @return The URL to the given code list in the given schema.
*/
private static String schema(final Context context, final String file, final String identifier) {
- return schema(Context.schema(context, "gmd", "http://schemas.opengis.net/iso/19139/20070417/"),
+ return schema(Context.schema(context, "gmd", DEFAULT_SCHEMA),
"resources/Codelist", file, identifier);
}
@@ -77,7 +82,7 @@ public final class CodeListProxy {
* @param identifier The UML identifier of the code list.
* @return The URL to the given code list in the given schema.
*/
- private static String schema(final String schema, final String directory, final String file, final String identifier) {
+ public static String schema(final String schema, final String directory, final String file, final String identifier) {
final StringBuilder buffer = new StringBuilder(128);
buffer.append(schema);
final int length = buffer.length();