Author: desruisseaux
Date: Sat Aug 15 13:47:27 2015
New Revision: 1696052
URL: http://svn.apache.org/r1696052
Log:
Partial JAXB annotations for GML (un)marshalling of DefaultParameterValue
(SIS-159).
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/IntegerList.java
(with props)
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
(with props)
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/Measure.java
- copied, changed from r1696051,
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/MeasureList.java
(with props)
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java
- copied, changed from r1696051,
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
Removed:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingTypes.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/package-info.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -1269,7 +1269,7 @@ public class Formatter implements Locali
final boolean appendValue(final Object value) {
if (value.getClass().isArray()) {
appendSeparator();
- buffer.appendCodePoint(symbols.getOpenSequence());
+ elementStart =
buffer.appendCodePoint(symbols.getOpenSequence()).length();
final int length = Array.getLength(value);
for (int i=0; i<length; i++) {
appendAny(Array.get(value, i));
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -22,7 +22,7 @@ import javax.measure.unit.Unit;
import org.opengis.referencing.datum.Ellipsoid;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.internal.jaxb.Context;
-import org.apache.sis.internal.jaxb.gco.Measure;
+import org.apache.sis.internal.jaxb.gml.Measure;
import org.apache.sis.util.resources.Errors;
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingTypes.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingTypes.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingTypes.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingTypes.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -18,6 +18,7 @@ package org.apache.sis.internal.referenc
import java.util.Collection;
import org.apache.sis.internal.jaxb.TypeRegistration;
+import org.apache.sis.parameter.DefaultParameterValue;
import org.apache.sis.referencing.AbstractIdentifiedObject;
@@ -37,5 +38,6 @@ public final class ReferencingTypes exte
@Override
public void getTypes(final Collection<Class<?>> addTo) {
addTo.add(AbstractIdentifiedObject.class);
+ addTo.add(DefaultParameterValue.class);
}
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -268,7 +268,7 @@ public final class ReferencingUtilities
/**
* Ensures that the given argument value is {@code false}. This method is
invoked by private setter methods,
* which are themselves invoked by JAXB at unmarshalling time. Invoking
this method from those setter methods
- * serves two purposes:
+ * serves three purposes:
*
* <ul>
* <li>Make sure that a singleton property is not defined twice in the
XML document.</li>
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -21,6 +21,10 @@ import java.io.File;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
import javax.measure.unit.Unit;
import javax.measure.converter.UnitConverter;
import javax.measure.converter.ConversionException;
@@ -33,13 +37,17 @@ import org.apache.sis.io.wkt.Formattable
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.Convention;
import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.internal.jaxb.gml.Measure;
+import org.apache.sis.internal.jaxb.gml.MeasureList;
import org.apache.sis.internal.referencing.WKTUtilities;
+import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.metadata.WKTKeywords;
import org.apache.sis.internal.util.PatchedUnitFormat;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.Numbers;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.LenientComparable;
+import org.apache.sis.util.ObjectConverters;
import org.apache.sis.util.resources.Errors;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -115,6 +123,11 @@ import java.nio.file.Path;
* @see DefaultParameterDescriptor
* @see DefaultParameterValueGroup
*/
+@XmlType(name = "ParameterValueType", propOrder = {
+ "xmlValue",
+// "operationParameter"
+})
+@XmlRootElement(name = "ParameterValue")
public class DefaultParameterValue<T> extends FormattableObject implements
ParameterValue<T>,
LenientComparable, Serializable, Cloneable
{
@@ -143,6 +156,14 @@ public class DefaultParameterValue<T> ex
private Unit<?> unit;
/**
+ * Default constructor for JAXB only. The descriptor is initialized to
{@code null},
+ * but will be assigned a value after XML unmarshalling.
+ */
+ private DefaultParameterValue() {
+ descriptor = null;
+ }
+
+ /**
* Creates a parameter value from the specified descriptor.
* The value will be initialized to the default value, if any.
*
@@ -544,7 +565,7 @@ public class DefaultParameterValue<T> ex
public void setValue(final boolean value) throws
InvalidParameterValueException {
// Use 'unit' instead than 'getUnit()' despite class Javadoc claims
because units are not expected
// to be involved in this method. We just want the current unit
setting to be unchanged.
- setValue(Boolean.valueOf(value), unit);
+ setValue(value, unit);
}
/**
@@ -561,7 +582,7 @@ public class DefaultParameterValue<T> ex
*/
@Override
public void setValue(final int value) throws
InvalidParameterValueException {
- Number n = Integer.valueOf(value);
+ Number n = value;
final Class<T> valueClass = descriptor.getValueClass();
if (Number.class.isAssignableFrom(valueClass)) {
@SuppressWarnings("unchecked")
@@ -962,4 +983,83 @@ public class DefaultParameterValue<T> ex
return formatter.hasContextualUnit(1) || // In WKT1
formatter.hasContextualUnit(2); // In WKT2
}
+
+ // ---- XML SUPPORT ----------------------------------------------------
+
+ /**
+ * Invoked by JAXB for obtaining the object to marshal.
+ * The property name depends on its type after conversion by this method.
+ */
+ @XmlElements({
+ @XmlElement(name = "value", type = Measure.class),
+ @XmlElement(name = "integerValue", type = Integer.class),
+ @XmlElement(name = "booleanValue", type = Boolean.class),
+ @XmlElement(name = "stringValue", type = String .class),
+ @XmlElement(name = "valueFile", type = URI .class),
+ @XmlElement(name = "integerValueList", type = IntegerList.class),
+ @XmlElement(name = "valueList", type = MeasureList.class)
+ })
+ private Object getXmlValue() {
+ if (value != null) {
+ if (value instanceof Number) {
+ final Number n = (Number) value;
+ if (Numbers.isInteger(n.getClass())) {
+ final int xmlValue = n.intValue();
+ if (xmlValue >= 0 && xmlValue == n.doubleValue()) {
+ return xmlValue;
+ }
+ }
+ return new Measure(((Number) value).doubleValue(), unit);
+ }
+ if (value instanceof CharSequence) {
+ return value.toString();
+ }
+ if (isFile(value)) {
+ return ObjectConverters.convert(value, URI.class);
+ }
+ final Class<?> type =
Numbers.primitiveToWrapper(value.getClass().getComponentType());
+ if (type != null && Number.class.isAssignableFrom(type)) {
+ if (Numbers.isInteger(type)) {
+ return new IntegerList(value);
+ }
+ return new MeasureList(value, type, unit);
+ }
+ }
+ return value;
+ }
+
+ /**
+ * Invoked by JAXB at unmarshalling time.
+ */
+ private void setXmlValue(Object xmlValue) {
+ if (ReferencingUtilities.canSetProperty(DefaultParameterValue.class,
+ "setXmlValue", "value", value != null || unit != null))
+ {
+ if (xmlValue instanceof Measure) {
+ final Measure measure = (Measure) xmlValue;
+ xmlValue = measure.value;
+ unit = measure.unit;
+ } else if (xmlValue instanceof MeasureList) {
+ final MeasureList measure = (MeasureList) xmlValue;
+ xmlValue = measure.toArray();
+ unit = measure.unit;
+ } else if (xmlValue instanceof IntegerList) {
+ xmlValue = ((IntegerList) xmlValue).toArray();
+ }
+ if (descriptor != null) {
+ value = ObjectConverters.convert(xmlValue,
descriptor.getValueClass());
+ } else {
+ /*
+ * Temporarily accept the value without checking its type.
This is required because the
+ * descriptor is normally defined after the value in a GML
document. The type will need
+ * to be verified when the descriptor will be set.
+ *
+ * There is no @SuppressWarnings("unchecked") annotation
because we can not prove that this
+ * cast is correct before the descriptor is set, and maybe
that descriptor will never be set
+ * (if the GML document is illegal).
+ */
+ value = (T) xmlValue;
+ }
+ }
+ }
}
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/IntegerList.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/IntegerList.java?rev=1696052&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/IntegerList.java
(added)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/IntegerList.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -0,0 +1,69 @@
+/*
+ * 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.parameter;
+
+import java.util.StringJoiner;
+import java.lang.reflect.Array;
+import javax.xml.bind.annotation.XmlValue;
+import org.apache.sis.util.CharSequences;
+
+
+/**
+ * XML representation of a sequence of integer values.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.6
+ * @version 0.6
+ * @module
+ *
+ * @see org.apache.sis.internal.jaxb.gml.MeasureList
+ */
+final class IntegerList {
+ /**
+ * The integer values.
+ */
+ @XmlValue
+ public String value;
+
+ /**
+ * Default empty constructor for JAXB. The value is initialized to null,
+ * but JAXB will overwrite that value if a XML value is present.
+ */
+ public IntegerList() {
+ }
+
+ /**
+ * Creates a list of integers backed by the given array.
+ *
+ * @param array The integer values as a Java array.
+ */
+ public IntegerList(final Object array) {
+ final StringJoiner builder = new StringJoiner(" ");
+ final int length = Array.getLength(array);
+ for (int i=0; i<length; i++) {
+ builder.add(String.valueOf(Array.get(array, i)));
+ }
+ value = builder.toString();
+ }
+
+ /**
+ * Returns the values as an array.
+ */
+ public int[] toArray() {
+ return CharSequences.parseInts(value, ' ', 10);
+ }
+}
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/IntegerList.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/IntegerList.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/package-info.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/package-info.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/package-info.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/package-info.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -88,4 +88,16 @@
* @version 0.6
* @module
*/
+@XmlSchema(elementFormDefault= XmlNsForm.QUALIFIED, namespace =
Namespaces.GML, xmlns = {
+ @XmlNs(prefix = "gml", namespaceURI = Namespaces.GML),
+ @XmlNs(prefix = "xsi", namespaceURI = Namespaces.XSI)
+})
+@XmlAccessorType(XmlAccessType.NONE)
package org.apache.sis.parameter;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import org.apache.sis.xml.Namespaces;
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -31,7 +31,7 @@ import org.opengis.referencing.datum.Ell
import org.apache.sis.geometry.DirectPosition2D;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.internal.jaxb.Context;
-import org.apache.sis.internal.jaxb.gco.Measure;
+import org.apache.sis.internal.jaxb.gml.Measure;
import org.apache.sis.internal.jaxb.referencing.SecondDefiningParameter;
import org.apache.sis.internal.referencing.Formulas;
import org.apache.sis.internal.metadata.WKTKeywords;
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -32,7 +32,7 @@ import org.apache.sis.referencing.Abstra
import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.util.PatchedUnitFormat;
import org.apache.sis.internal.metadata.WKTKeywords;
-import org.apache.sis.internal.jaxb.gco.Measure;
+import org.apache.sis.internal.jaxb.gml.Measure;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.Convention;
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -45,6 +45,7 @@ import static org.apache.sis.test.Metada
* @version 0.6
* @module
*/
+@SuppressWarnings("UnnecessaryBoxing")
@DependsOn(DefaultParameterDescriptorTest.class)
public final strictfp class DefaultParameterValueTest extends TestCase {
/**
Added:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java?rev=1696052&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
(added)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -0,0 +1,189 @@
+/*
+ * 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.parameter;
+
+import java.util.Collections;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.xml.bind.JAXBException;
+import javax.measure.unit.SI;
+import org.apache.sis.measure.Range;
+import org.apache.sis.measure.MeasurementRange;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.xml.Namespaces;
+import org.apache.sis.xml.XML;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+// Branch-dependent imports
+import java.util.Objects;
+
+
+/**
+ * Tests XML (un)marshalling of {@link DefaultParameterValue}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.6
+ * @version 0.6
+ * @module
+ */
+@DependsOn(DefaultParameterValueTest.class)
+public final strictfp class ParameterMarshallingTest extends XMLTestCase {
+ /**
+ * Creates a parameter value for marshalling test.
+ */
+ private static <T> DefaultParameterValue<T> create(final Class<T> type,
final Range<?> valueDomain) {
+ return new DefaultParameterValue<>(new DefaultParameterDescriptor<>(
+ Collections.singletonMap(DefaultParameterDescriptor.NAME_KEY,
type.getSimpleName()),
+ 1, 1, type, valueDomain, null, null));
+ }
+
+ /**
+ * Marshals the given object, then unmarshals it and compare with the
original value.
+ *
+ * @param parameter The parameter to marshal.
+ * @param expected The expected XML (ignoring {@code xmlns}).
+ */
+ private static void testMarshallAndUnmarshall(final
DefaultParameterValue<?> parameter, final String expected)
+ throws JAXBException
+ {
+ final String xml = XML.marshal(parameter);
+ assertXmlEquals(expected, xml, "xmlns:*");
+ final DefaultParameterValue<?> r = (DefaultParameterValue<?>)
XML.unmarshal(xml);
+ if (!Objects.deepEquals(parameter.getValue(), r.getValue())) {
+ assertEquals("value", parameter.getValue(), r.getValue()); //
Should always fail, but we want the error message.
+ }
+ assertEquals("unit", parameter.getUnit(), r.getUnit());
+ }
+
+ /**
+ * Tests (un)marshalling of a parameter with a string value.
+ *
+ * @throws JAXBException if an error occurred during marshalling or
unmarshalling.
+ */
+ @Test
+ public void testStringValue() throws JAXBException {
+ final DefaultParameterValue<String> parameter = create(String.class,
null);
+ parameter.setValue("A string value");
+ testMarshallAndUnmarshall(parameter,
+ "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
+ + " <gml:stringValue>A string value</gml:stringValue>\n"
+ + "</gml:ParameterValue>");
+ }
+
+ /**
+ * Tests (un)marshalling of a parameter with a URI value.
+ *
+ * @throws JAXBException if an error occurred during marshalling or
unmarshalling.
+ * @throws URISyntaxException should never happen.
+ */
+ @Test
+ @DependsOnMethod("testStringValue")
+ public void testURIValue() throws JAXBException, URISyntaxException {
+ final DefaultParameterValue<URI> parameter = create(URI.class, null);
+ parameter.setValue(new URI("http://www.opengis.org"));
+ testMarshallAndUnmarshall(parameter,
+ "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
+ + " <gml:valueFile>http://www.opengis.org</gml:valueFile>\n"
+ + "</gml:ParameterValue>");
+ }
+
+ /**
+ * Tests (un)marshalling of a parameter with an integer value.
+ *
+ * @throws JAXBException if an error occurred during marshalling or
unmarshalling.
+ */
+ @Test
+ @DependsOnMethod("testStringValue")
+ public void testBooleanValue() throws JAXBException {
+ final DefaultParameterValue<Boolean> parameter = create(Boolean.class,
null);
+ parameter.setValue(Boolean.TRUE);
+ testMarshallAndUnmarshall(parameter,
+ "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
+ + " <gml:booleanValue>true</gml:booleanValue>\n"
+ + "</gml:ParameterValue>");
+ }
+
+ /**
+ * Tests (un)marshalling of a parameter with an integer value.
+ *
+ * @throws JAXBException if an error occurred during marshalling or
unmarshalling.
+ */
+ @Test
+ @DependsOnMethod("testStringValue")
+ public void testIntegerValue() throws JAXBException {
+ final DefaultParameterValue<Integer> parameter = create(Integer.class,
null);
+ parameter.setValue(2000);
+ testMarshallAndUnmarshall(parameter,
+ "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
+ + " <gml:integerValue>2000</gml:integerValue>\n"
+ + "</gml:ParameterValue>");
+ }
+
+ /**
+ * Tests (un)marshalling of a parameter with a list of integer values.
+ *
+ * @throws JAXBException if an error occurred during marshalling or
unmarshalling.
+ */
+ @Test
+ @DependsOnMethod("testStringValue")
+ public void testIntegerValueList() throws JAXBException {
+ final DefaultParameterValue<int[]> parameter = create(int[].class,
null);
+ parameter.setValue(new int[] {101, 105, 208});
+ testMarshallAndUnmarshall(parameter,
+ "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
+ + " <gml:integerValueList>101 105 208</gml:integerValueList>\n"
+ + "</gml:ParameterValue>");
+ }
+
+ /**
+ * Tests (un)marshalling of a parameter with a floating point value.
+ *
+ * @throws JAXBException if an error occurred during marshalling or
unmarshalling.
+ */
+ @Test
+ @DependsOnMethod("testStringValue")
+ public void testValue() throws JAXBException {
+ final DefaultParameterValue<Double> parameter = create(Double.class,
+ new MeasurementRange<Double>(Double.class, null, false, null,
false, SI.METRE));
+ parameter.setValue(3000, SI.METRE);
+ testMarshallAndUnmarshall(parameter,
+ "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
+ + " <gml:value
uom=\"urn:ogc:def:uom:EPSG::9001\">3000.0</gml:value>\n"
+ + "</gml:ParameterValue>");
+ }
+
+ /**
+ * Tests (un)marshalling of a parameter with a list of floating point
values.
+ *
+ * @throws JAXBException if an error occurred during marshalling or
unmarshalling.
+ */
+ @Test
+ @DependsOnMethod("testStringValue")
+ public void testValueList() throws JAXBException {
+ final DefaultParameterValue<double[]> parameter =
create(double[].class,
+ new MeasurementRange<Double>(Double.class, null, false, null,
false, SI.METRE));
+ parameter.setValue(new double[] {203, 207, 204}, SI.METRE);
+ testMarshallAndUnmarshall(parameter,
+ "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
+ + " <gml:valueList uom=\"urn:ogc:def:uom:EPSG::9001\">203.0
207.0 204.0</gml:valueList>\n"
+ + "</gml:ParameterValue>");
+ }
+}
Propchange:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -70,6 +70,7 @@ import org.junit.BeforeClass;
org.apache.sis.parameter.MatrixParametersAlphaNumTest.class,
org.apache.sis.parameter.TensorValuesTest.class,
org.apache.sis.parameter.MapProjectionParametersTest.class,
+ org.apache.sis.parameter.ParameterMarshallingTest.class,
// Test transforms other than map projections.
org.apache.sis.referencing.operation.transform.CoordinateDomainTest.class,
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -19,6 +19,7 @@ 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;
+import org.apache.sis.internal.jaxb.gml.Measure;
/**
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -19,6 +19,7 @@ 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;
+import org.apache.sis.internal.jaxb.gml.Measure;
/**
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -19,6 +19,7 @@ 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;
+import org.apache.sis.internal.jaxb.gml.Measure;
import org.apache.sis.internal.util.PatchedUnitFormat;
Copied:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/Measure.java
(from r1696051,
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java)
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/Measure.java?p2=sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/Measure.java&p1=sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java&r1=1696051&r2=1696052&rev=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/Measure.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -14,12 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.internal.jaxb.gco;
+package org.apache.sis.internal.jaxb.gml;
import java.net.URISyntaxException;
import javax.measure.unit.Unit;
import javax.measure.unit.NonSI;
import javax.measure.quantity.Quantity;
+import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.XmlAttribute;
import org.apache.sis.internal.jaxb.Context;
@@ -34,7 +35,7 @@ import org.apache.sis.measure.Units;
* 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
+ * 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>
*
* <div class="section">XML marshalling</div>
@@ -63,9 +64,11 @@ import org.apache.sis.measure.Units;
* @version 0.4
* @module
*
- * @see UnitAdapter
* @see org.apache.sis.measure.Measure
+ * @see org.apache.sis.internal.jaxb.gml.MeasureList
+ * @see org.apache.sis.internal.jaxb.gco.UnitAdapter
*/
+@XmlType(name = "MeasureType")
public final class Measure {
/**
* The value of the measure.
@@ -74,7 +77,7 @@ public final class Measure {
public double value;
/**
- * The unit of measure.
+ * The unit of measurement.
*/
public Unit<?> unit;
@@ -82,11 +85,11 @@ public final class Measure {
* {@code true} if the units shall be formatted as {@code xpointer}.
* If {@code false} (the default), then this class will try to format the
units using the GML syntax.
*/
- boolean asXPointer;
+ public boolean asXPointer;
/**
* Default empty constructor for JAXB. The value is initialized to NaN,
- * but JAXB will overwrite this value if a XML value is presents.
+ * but JAXB will overwrite that value if a XML value is present.
*/
public Measure() {
value = Double.NaN;
@@ -97,7 +100,7 @@ public final class Measure {
* 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.
+ * @param unit The unit of measurement.
*/
public Measure(final double value, final Unit<?> unit) {
this.value = value;
@@ -139,7 +142,7 @@ public final class Measure {
* @param inAxis {@code true} for a unit used in Coordinate System Axis
definition.
* @return The string representation of the unit of measure.
*/
- static String getUOM(final Unit<?> unit, final boolean asXPointer, final
boolean inAxis) {
+ public static String getUOM(final Unit<?> unit, final boolean asXPointer,
final boolean inAxis) {
if (!asXPointer) {
final Integer code = Units.getEpsgCode(unit, inAxis);
if (code != null) {
Added:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/MeasureList.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/MeasureList.java?rev=1696052&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/MeasureList.java
(added)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/MeasureList.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -0,0 +1,123 @@
+/*
+ * 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.gml;
+
+import java.util.List;
+import java.util.AbstractList;
+import java.lang.reflect.Array;
+import java.net.URISyntaxException;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.measure.unit.Unit;
+import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.util.ObjectConverters;
+
+
+/**
+ * XML representation of a sequence of measurement values together with their
unit of measure.
+ * This is used only at XML marshalling time.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.6
+ * @version 0.6
+ * @module
+ *
+ * @see Measure
+ */
+@XmlType(name = "MeasureListType")
+public final class MeasureList {
+ /**
+ * The measure values.
+ */
+ @XmlValue
+ public List<Double> values;
+
+ /**
+ * The unit of measurement.
+ */
+ public Unit<?> unit;
+
+ /**
+ * Default empty constructor for JAXB. The value is initialized to null,
+ * but JAXB will overwrite that value if a XML value is present.
+ */
+ public MeasureList() {
+ }
+
+ /**
+ * Creates a list of measures backed by the given array.
+ *
+ * @param <E> Compile-time value of {@code elementType}.
+ * @param array The measure values as a Java array.
+ * @param elementType The type of elements in the given array. Primitive
type shall be replaced by their wrapper.
+ * @param unit The unit of measurement.
+ */
+ public <E> MeasureList(final Object array, final Class<E> elementType,
final Unit<?> unit) {
+ this.unit = unit;
+ final ObjectConverter<? super E, ? extends Double> converter =
+ ObjectConverters.find(elementType, Double.class);
+ values = new AbstractList<Double>() {
+ @Override public int size() {
+ return Array.getLength(array);
+ }
+
+ @Override@SuppressWarnings("unchecked")
+ public Double get(final int index) {
+ return converter.apply((E) Array.get(array, index));
+ }
+ };
+ }
+
+ /**
+ * Constructs a string representation of the units.
+ *
+ * @return A string representation of the unit.
+ */
+ @XmlAttribute(name = "uom", required = true)
+ public String getUOM() {
+ return Measure.getUOM(unit, false, false);
+ }
+
+ /**
+ * Sets the unit of measure. This method is invoked by JAXB at
unmarshalling time.
+ *
+ * @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 {
+ final Context context = Context.current();
+ unit = Context.converter(context).toUnit(context, uom);
+ }
+
+ /**
+ * Returns the values as an array.
+ *
+ * @return The values, or {@code null} if none.
+ */
+ public double[] toArray() {
+ if (values == null) {
+ return null;
+ }
+ final double[] array = new double[values.size()];
+ for (int i=0; i<array.length; i++) {
+ array[i] = values.get(i);
+ }
+ return array;
+ }
+}
Propchange:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/MeasureList.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/MeasureList.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Copied:
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java
(from r1696051,
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java)
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java?p2=sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java&p1=sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java&r1=1696051&r2=1696052&rev=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.internal.jaxb.gco;
+package org.apache.sis.internal.jaxb.gml;
import java.net.URISyntaxException;
import javax.measure.unit.Unit;
Modified:
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1696052&r1=1696051&r2=1696052&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Sat Aug 15 13:47:27 2015
@@ -141,10 +141,10 @@ import org.junit.BeforeClass;
org.apache.sis.internal.jaxb.IdentifierMapAdapterTest.class,
org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCasesTest.class,
org.apache.sis.internal.jaxb.gco.StringAdapterTest.class,
- org.apache.sis.internal.jaxb.gco.MeasureTest.class,
org.apache.sis.internal.jaxb.gco.PropertyTypeTest.class,
org.apache.sis.internal.jaxb.gmd.LanguageCodeTest.class,
org.apache.sis.internal.jaxb.gml.TimePeriodTest.class,
+ org.apache.sis.internal.jaxb.gml.MeasureTest.class,
org.apache.sis.util.iso.NameMarshallingTest.class
})
public final strictfp class UtilityTestSuite extends TestSuite {