sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1697073 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/parameter/ main/java/org/apache/sis/referencing/ main/java/org/apache/sis/referencing/cs/ main/java/org/apach...
Date Sat, 22 Aug 2015 03:13:38 GMT
Author: desruisseaux
Date: Sat Aug 22 03:13:38 2015
New Revision: 1697073

URL: http://svn.apache.org/r1697073
Log:
Completed JAXB annotations for <gml:ParameterValueGroup> support.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.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/AbstractParameterDescriptor.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.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/DefaultParameterValueGroup.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NameIterator.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -26,6 +26,8 @@ import org.opengis.metadata.extent.Exten
 import org.apache.sis.xml.NilReason;
 import org.apache.sis.xml.NilObject;
 import org.apache.sis.io.wkt.UnformattableObjectException;
+import org.apache.sis.referencing.NamedIdentifier;
+import org.apache.sis.util.resources.Vocabulary;
 
 
 /**
@@ -36,11 +38,25 @@ import org.apache.sis.io.wkt.Unformattab
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  */
 public final class NilReferencingObject implements NilObject, ReferenceSystem {
     /**
+     * The default name of {@code NilReferencingObject} instances.
+     * We use this value because {@link ReferenceSystem#getName()}
+     * is a mandatory property and not all code is tolerant to null name.
+     *
+     * <div class="note"><b>Note:</b>
+     * in theory we do not need a default name because it will be replaced by
+     * the value of the {@code <gml:name>} element anyway at XML unmarshalling time.
+     * But not all XML documents are valid, so the {@code <gml:name>} may be missing.</div>
+     *
+     * @since 0.6
+     */
+    public static final Identifier UNNAMED = new NamedIdentifier(null, Vocabulary.format(Vocabulary.Keys.Unnamed));
+
+    /**
      * The unique instance.
      */
     public static final NilReferencingObject INSTANCE = new NilReferencingObject();
@@ -64,7 +80,7 @@ public final class NilReferencingObject
      * Returning null for collection are okay in the particular case of SIS implementation,
      * because the constructor will replace empty collections by null references anyway.
      */
-    @Override public Identifier               getName()        {return null;}
+    @Override public Identifier               getName()        {return UNNAMED;}
     @Override public Collection<GenericName>  getAlias()       {return null;}
     @Override public Set<Identifier>          getIdentifiers() {return null;}
     @Override public InternationalString      getRemarks()     {return null;}

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=1697073&r1=1697072&r2=1697073&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 22 03:13:38 2015
@@ -28,7 +28,6 @@ import org.opengis.referencing.datum.Pri
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
@@ -210,7 +209,7 @@ public final class ReferencingUtilities
                 return (GeographicCRS) crs;
             }
             return new DefaultGeographicCRS(
-                    singletonMap(DefaultGeographicCRS.NAME_KEY, Vocabulary.format(Vocabulary.Keys.Unnamed)),
+                    singletonMap(DefaultGeographicCRS.NAME_KEY, NilReferencingObject.UNNAMED),
                     ((GeodeticCRS) crs).getDatum(), (EllipsoidalCS) cs);
         }
         if (crs instanceof CompoundCRS) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -196,7 +196,7 @@ public abstract class AbstractParameterD
         }
         if (maximumOccurs > 0xFFFE && maximumOccurs != Integer.MAX_VALUE) {
             throw new IllegalArgumentException(Errors.getResources(properties).getString(
-                    Errors.Keys.TooManyOccurrences_2, 0xFFFE, super.getName()));
+                    Errors.Keys.TooManyOccurrences_2, 0xFFFE, super.getName().getCode()));
         }
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -21,6 +21,7 @@ import java.util.Set;
 import java.util.List;
 import java.util.HashSet;
 import java.util.Collections;
+import java.util.LinkedHashMap;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -31,8 +32,8 @@ import org.opengis.parameter.GeneralPara
 import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.parameter.InvalidParameterNameException;
 import org.apache.sis.referencing.IdentifiedObjects;
-import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ComparisonMode;
@@ -186,6 +187,8 @@ public class DefaultParameterDescriptorG
 
     /**
      * Ensures that the given name array does not contain duplicate values.
+     *
+     * @param properties The properties given to the constructor, or {@code null} if unknown.
      */
     private static void verifyNames(final Map<String,?> properties, final GeneralParameterDescriptor[]
parameters) {
         for (int i=0; i<parameters.length; i++) {
@@ -194,7 +197,7 @@ public class DefaultParameterDescriptorG
             for (int j=0; j<i; j++) {
                 if (IdentifiedObjects.isHeuristicMatchForName(parameters[j], name)) {
                     throw new InvalidParameterNameException(Errors.getResources(properties).getString(
-                            Errors.Keys.DuplicatedParameterName_4, parameters[j].getName().getCode(),
j, name, i),
+                            Errors.Keys.DuplicatedParameterName_4, Verifier.getDisplayName(parameters[j]),
j, name, i),
                             name);
                 }
             }
@@ -364,8 +367,10 @@ public class DefaultParameterDescriptorG
             return fallback;
         }
         throw new ParameterNotFoundException(ambiguity != null
-                ? Errors.format(Errors.Keys.AmbiguousName_3, fallback.getName(), ambiguity.getName(),
name)
-                : Errors.format(Errors.Keys.ParameterNotFound_2, getName(), name), name);
+                ? Errors.format(Errors.Keys.AmbiguousName_3,
+                        IdentifiedObjects.toString(fallback.getName()),
+                        IdentifiedObjects.toString(ambiguity.getName()), name)
+                : Errors.format(Errors.Keys.ParameterNotFound_2, Verifier.getDisplayName(this),
name), name);
     }
 
     /**
@@ -426,13 +431,35 @@ public class DefaultParameterDescriptorG
     }
 
     /**
-     * Invoked by JAXB for setting the unmarshalled parameters.
-     */
-    private void setDescriptors(final GeneralParameterDescriptor[] parameters) {
-        if (ReferencingUtilities.canSetProperty(DefaultParameterValue.class,
-                "setDescriptors", "parameter", !descriptors.isEmpty()))
-        {
-            descriptors = asList(parameters);
+     * Invoked by JAXB or by {@link DefaultParameterValueGroup} for setting the unmarshalled
parameters.
+     * If parameters already exist, them this method computes the union of the two parameter
collections
+     * with the new parameters having precedence over the old ones.
+     *
+     * <div class="note"><b>Rational:</b>
+     * this method is invoked twice during {@link DefaultParameterValueGroup} unmarshalling:
+     * <ol>
+     *   <li>First, this method is invoked during unmarshalling of this {@code DefaultParameterDescriptorGroup}.
+     *       But the value class of {@code ParameterDescriptor} components are unknown because
this information
+     *       is not part of GML.</li>
+     *   <li>Next, this method is invoked during unmarshalling of the {@code DefaultParameterValueGroup}
enclosing
+     *       element with the descriptors found inside the {@code ParameterValue} components.
The later do have the
+     *       {@code valueClass} information, so we want to use them in replacement of descriptors
of step 1.</li>
+     * </ol>
+     * </div>
+     */
+    final void setDescriptors(GeneralParameterDescriptor[] parameters) {
+        verifyNames(null, parameters);
+        if (!descriptors.isEmpty()) {
+            final Map<String,GeneralParameterDescriptor> union =
+                    new LinkedHashMap<>(Containers.hashMapCapacity(descriptors.size()));
+            for (final GeneralParameterDescriptor p : descriptors) {
+                union.put(p.getName().getCode(), p);
+            }
+            for (final GeneralParameterDescriptor p : parameters) {
+                union.put(p.getName().getCode(), p);
+            }
+            parameters = union.values().toArray(new GeneralParameterDescriptor[union.size()]);
         }
+        descriptors = asList(parameters);
     }
 }

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=1697073&r1=1697072&r2=1697073&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 22 03:13:38 2015
@@ -379,7 +379,7 @@ public class DefaultParameterValue<T> ex
     private UnitConverter getConverterTo(final Unit<?> unit) {
         final Unit<?> source = getUnit();
         if (source == null) {
-            throw new IllegalStateException(Errors.format(Errors.Keys.UnitlessParameter_1,
Verifier.getName(descriptor)));
+            throw new IllegalStateException(Errors.format(Errors.Keys.UnitlessParameter_1,
Verifier.getDisplayName(descriptor)));
         }
         ensureNonNull("unit", unit);
         final short expectedID = Verifier.getUnitMessageID(source);
@@ -500,7 +500,7 @@ public class DefaultParameterValue<T> ex
         } catch (URISyntaxException exception) {
             cause = exception;
         }
-        final String name = Verifier.getName(descriptor);
+        final String name = Verifier.getDisplayName(descriptor);
         if (value != null) {
             throw new InvalidParameterTypeException(getClassTypeError(), name);
         }
@@ -518,7 +518,7 @@ public class DefaultParameterValue<T> ex
      * Returns the exception to throw when an incompatible method is invoked for the value
type.
      */
     private IllegalStateException missingOrIncompatibleValue(final Object value) {
-        final String name = Verifier.getName(descriptor);
+        final String name = Verifier.getDisplayName(descriptor);
         if (value != null) {
             return new InvalidParameterTypeException(getClassTypeError(), name);
         }
@@ -636,7 +636,7 @@ public class DefaultParameterValue<T> ex
             // to be involved in this method. We just want the current unit setting to be
unchanged.
             setValue(wrap(value, descriptor.getValueClass()), unit);
         } catch (IllegalArgumentException e) {
-            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor),
value);
+            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getDisplayName(descriptor),
value);
         }
     }
 
@@ -659,7 +659,7 @@ public class DefaultParameterValue<T> ex
         try {
             setValue(wrap(value, descriptor.getValueClass()), unit);
         } catch (IllegalArgumentException e) {
-            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor),
value);
+            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getDisplayName(descriptor),
value);
         }
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -32,7 +32,7 @@ import org.opengis.parameter.GeneralPara
 import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.parameter.InvalidParameterCardinalityException;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
-import org.apache.sis.util.collection.Containers;
+import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.util.LenientComparable;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
@@ -267,7 +267,7 @@ public class DefaultParameterValueGroup
             final GeneralParameterDescriptor descriptor = values.descriptor.descriptor(name);
             if (!(descriptor instanceof ParameterDescriptor<?>) || descriptor.getMaximumOccurs()
== 0) {
                 throw new ParameterNotFoundException(Errors.format(Errors.Keys.ParameterNotFound_2,
-                        values.descriptor.getName(), name), name);
+                        Verifier.getDisplayName(values.descriptor), name), name);
             }
             /*
              * Create the optional parameter and add it to our internal list. Note that this
is
@@ -326,7 +326,8 @@ public class DefaultParameterValueGroup
                 return (ParameterValue<?>) values.get(fallback);   // May lazily create
a ParameterValue.
             }
             throw new ParameterNotFoundException(Errors.format(Errors.Keys.AmbiguousName_3,
-                    values.descriptor(fallback).getName(), values.descriptor(ambiguity).getName(),
name), name);
+                    IdentifiedObjects.toString(values.descriptor(fallback) .getName()),
+                    IdentifiedObjects.toString(values.descriptor(ambiguity).getName()), name),
name);
         }
         return null;
     }
@@ -515,32 +516,41 @@ public class DefaultParameterValueGroup
     }
 
     /**
-     * Invoked by JAXB for setting the unmarshalled parameters.
+     * Invoked by JAXB for setting the unmarshalled parameters. This method should be invoked
last
+     * (after {@link #setDescriptor(ParameterDescriptorGroup)}) even if the {@code parameterValue}
+     * elements were first in the XML document. This is the case at least with the JAXB reference
+     * implementation.
      */
     private void setValues(final GeneralParameterValue[] parameters) {
-        if (ReferencingUtilities.canSetProperty(DefaultParameterValue.class,
-                "setValues", "parameterValue", !Containers.isNullOrEmpty(values)))
-        {
-            if (values == null) {
-                values = new ParameterValueList(parameters);
-            } else {
-                values.addAll(Arrays.asList(parameters));
-            }
+        final GeneralParameterDescriptor[] descriptors = new GeneralParameterDescriptor[parameters.length];
+        for (int i=0; i<descriptors.length; i++) {
+            descriptors[i] = parameters[i].getDescriptor();
         }
+        if (values == null) {
+            // Should never happen, unless the XML document is invalid and does not have
a 'group' element.
+            
+        } else {
+            // We known that the descriptor is an instance of our DefaultParameterDescriptorGroup
+            // implementation because this is what we declare to the JAXBContext and in adapters.
+            ((DefaultParameterDescriptorGroup) values.descriptor).setDescriptors(descriptors);
+            values.clear();  // Because references to parameter descriptors have changed.
+        }
+        values.addAll(Arrays.asList(parameters));
     }
 
     /**
-     * Invoked by JAXB for setting the parameter descriptor.
+     * Invoked by JAXB for setting the group parameter descriptor. Those parameter are redundant
with
+     * the parameters associated to the values given to {@link #setValues(GeneralParameterValue[])},
+     * except the the group identification (name, <i>etc.</i>) and for any optional
parameters which
+     * were not present in the above {@code GeneralParameterValue} array.
      *
      * @see #getDescriptor()
      */
     private void setDescriptor(final ParameterDescriptorGroup descriptor) {
-        if (values == null) {
-// TODO     values = new ParameterValueList(descriptor);
-        } else if (ReferencingUtilities.canSetProperty(DefaultParameterValue.class,
-                "setDescriptor", "group", values.descriptor != null))
+        if (ReferencingUtilities.canSetProperty(DefaultParameterValue.class,
+                "setDescriptor", "group", values != null))
         {
-            values.descriptor = descriptor;
+            values = new ParameterValueList(descriptor);
         }
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -62,12 +62,8 @@ final class ParameterValueList extends A
      *
      * <p>This descriptor shall not be used in {@link #equals(Object)} and {@link #hashCode()}
      * implementations in order to stay consistent with the {@link List} contract.</p>
-     *
-     * <p><b>Consider this field as final!</b>
-     * This field is modified only at unmarshalling time by
-     * {@link DefaultParameterValueGroup#setDescriptor(ParameterDescriptorGroup)}.</p>
      */
-    ParameterDescriptorGroup descriptor;
+    final ParameterDescriptorGroup descriptor;
 
     /**
      * The parameter values in the group. The length of this array is the list capacity.
@@ -81,17 +77,6 @@ final class ParameterValueList extends A
     private int size;
 
     /**
-     * Constructs a parameter without descriptor and with the given parameters.
-     * <b>It is caller's responsibility to assign an instance to the {@link #descriptor}
field.</b>
-     *
-     * <p>This constructor shall be used only at JAXB unmarshalling time, when the
descriptor is not yet known.</p>
-     */
-    ParameterValueList(final GeneralParameterValue[] parameters) {
-        values = parameters;
-        size = parameters.length;
-    }
-
-    /**
      * Constructs an initially empty parameter list.
      *
      * @param descriptor The descriptor for this list.
@@ -259,8 +244,8 @@ final class ParameterValueList extends A
                             Errors.Keys.MismatchedParameterDescriptor_1, name));
                 }
             }
-            throw new InvalidParameterNameException(Errors.format(
-                    Errors.Keys.ParameterNotFound_2, descriptor.getName(), name), name.getCode());
+            throw new InvalidParameterNameException(Errors.format(Errors.Keys.ParameterNotFound_2,
+                    Verifier.getDisplayName(descriptor), name), name.getCode());
         }
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -180,7 +180,7 @@ public abstract class Parameters impleme
             // the later case we could have (to be strict) to return a <? extends T>
type.
             if (!valueClass.equals(actual)) {
                 throw new ClassCastException(Errors.format(Errors.Keys.IllegalParameterType_2,
-                        descriptor.getName().getCode(), actual));
+                        Verifier.getDisplayName(descriptor), actual));
             }
         }
         return (ParameterDescriptor<T>) descriptor;
@@ -210,7 +210,7 @@ public abstract class Parameters impleme
             final Class<?> actual = descriptor.getValueClass();
             if (!valueClass.equals(actual)) {   // Same comment than cast(ParameterDescriptor).
                 throw new ClassCastException(Errors.format(Errors.Keys.IllegalParameterType_2,
-                        descriptor.getName().getCode(), actual));
+                        Verifier.getDisplayName(descriptor), actual));
             }
         }
         return (ParameterValue<T>) parameter;
@@ -441,8 +441,8 @@ public abstract class Parameters impleme
         if (value != null) {
             return value;
         } else {
-            throw new IllegalStateException(Errors.format(
-                    Errors.Keys.MissingValueForParameter_1, Verifier.getName(parameter)));
+            throw new IllegalStateException(Errors.format(Errors.Keys.MissingValueForParameter_1,
+                    Verifier.getDisplayName(parameter)));
         }
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -108,7 +108,7 @@ final class Verifier {
         if (unit != null) {
             final Unit<?> def = descriptor.getUnit();
             if (def == null) {
-                final String name = getName(descriptor);
+                final String name = getDisplayName(descriptor);
                 throw new InvalidParameterValueException(Errors.format(Errors.Keys.UnitlessParameter_1,
name), name, unit);
             }
             if (!unit.equals(def)) {
@@ -122,7 +122,7 @@ final class Verifier {
                  */
                 if (value != null) {
                     if (!valueClass.isInstance(value)) {
-                        final String name = getName(descriptor);
+                        final String name = getDisplayName(descriptor);
                         throw new InvalidParameterValueException(
                                 Errors.format(Errors.Keys.IllegalParameterValueClass_3,
                                 name, valueClass, value.getClass()), name, value);
@@ -148,7 +148,8 @@ final class Verifier {
                         try {
                             convertedValue = Numbers.cast(n, valueClass.asSubclass(Number.class));
                         } catch (IllegalArgumentException e) {
-                            throw new InvalidParameterValueException(e.getLocalizedMessage(),
getName(descriptor), value);
+                            throw new InvalidParameterValueException(e.getLocalizedMessage(),
+                                    getDisplayName(descriptor), value);
                         }
                     } else {
                         /*
@@ -165,7 +166,7 @@ final class Verifier {
                                 n = Numbers.cast(n, componentType.asSubclass(Number.class));
                             } catch (IllegalArgumentException e) {
                                 throw new InvalidParameterValueException(e.getLocalizedMessage(),
-                                        getName(descriptor) + '[' + i + ']', value);
+                                        getDisplayName(descriptor) + '[' + i + ']', value);
                             }
                             Array.set(convertedValue, i, n);
                         }
@@ -190,7 +191,7 @@ final class Verifier {
             }
             if (error != null) {
                 error.convertRange(converter);
-                final String name = getName(descriptor);
+                final String name = getDisplayName(descriptor);
                 throw new InvalidParameterValueException(error.message(null, name, value),
name, value);
             }
         }
@@ -312,8 +313,15 @@ final class Verifier {
      * Convenience method returning the name of the specified descriptor.
      * This method is used mostly for output to be read by human, not for processing.
      * Consequently, we may consider to returns a localized name in a future version.
+     *
+     * <p>This method is null-safe even if none of the references checked here should
be null.
+     * We make this method safe because it is indirectly invoked by methods like {@code toString()}
+     * which are not expected to fail even if the object is invalid.</p>
+     *
+     * <p><b>This method should NOT be invoked for programmatic usage</b>
(e.g. setting a parameter
+     * value) because the string returned in case of invalid descriptor is arbitrary.</p>
      */
-    static String getName(final GeneralParameterDescriptor descriptor) {
+    static String getDisplayName(final GeneralParameterDescriptor descriptor) {
         if (descriptor != null) {
             final Identifier name = descriptor.getName();
             if (name != null) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -46,6 +46,7 @@ import org.apache.sis.internal.util.Unmo
 import org.apache.sis.internal.metadata.NameToIdentifier;
 import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.internal.referencing.NilReferencingObject;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.io.wkt.Formatter;
@@ -613,7 +614,7 @@ public class AbstractIdentifiedObject ex
      * for access to private fields without compiler-generated bridge methods.
      */
     final void addName(final Identifier id) {
-        if (name == null) {
+        if (name == NilReferencingObject.UNNAMED) {
             name = id;
         } else {
             /*

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NameIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NameIterator.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NameIterator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NameIterator.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -20,6 +20,7 @@ import java.util.Iterator;
 import org.opengis.util.GenericName;
 import org.opengis.metadata.Identifier;
 import org.opengis.referencing.IdentifiedObject;
+import org.apache.sis.internal.referencing.NilReferencingObject;
 
 
 /**
@@ -53,7 +54,8 @@ final class NameIterator implements Iter
     NameIterator(final IdentifiedObject object) {
         alias = object.getAlias().iterator();
         next = object.getName();
-        if (next == null) { // Should never be null in a well-formed IdentifiedObject, but
let be safe.
+        // Should never be null in a well-formed IdentifiedObject, but let be safe.
+        if (next == null || next == NilReferencingObject.UNNAMED) {
             next();
         }
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -43,13 +43,11 @@ import org.apache.sis.internal.metadata.
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.referencing.IdentifiedObjects;
-import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Units;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.Convention;
@@ -64,6 +62,14 @@ import static org.apache.sis.util.Argume
 import static org.apache.sis.util.CharSequences.trimWhitespaces;
 import static org.apache.sis.util.collection.Containers.property;
 
+/*
+ * The identifier for axis of unknown name. We have to use this identifier when the axis
direction changed,
+ * because such change often implies a name change too (e.g. "Westing" → "Easting"), and
we can not always
+ * guess what the new name should be. This constant is used as a sentinel value set by Normalizer
and checked
+ * by DefaultCoordinateSystemAxis for skipping axis name comparisons when the axis name is
unknown.
+ */
+import static org.apache.sis.internal.referencing.NilReferencingObject.UNNAMED;
+
 // Branch-dependent imports
 import java.util.Objects;
 
@@ -125,16 +131,6 @@ public class DefaultCoordinateSystemAxis
     public static final String RANGE_MEANING_KEY = "rangeMeaning";
 
     /**
-     * The identifier for axis of unknown name. We have to use this identifier when the axis
direction changed,
-     * because such change often implies a name change too (e.g. "Westing" → "Easting"),
and we can not always
-     * guess what the new name should be.
-     *
-     * <p>This constant is used as a sentinel value for skipping axis name comparisons
when the axis name is
-     * unknown.</p>
-     */
-    static final NamedIdentifier UNNAMED = new NamedIdentifier(null, Vocabulary.format(Vocabulary.Keys.Unnamed));
-
-    /**
      * Some names to be treated as equivalent. This is needed because axis names are the
primary way to
      * distinguish between {@link CoordinateSystemAxis} instances. Those names are strictly
defined by
      * ISO 19111 as "Geodetic latitude" and "Geodetic longitude" among others, but the legacy
WKT

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -36,6 +36,14 @@ import static java.util.Collections.sing
 import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
 import static org.opengis.referencing.IdentifiedObject.IDENTIFIERS_KEY;
 
+/*
+ * The identifier for axis of unknown name. We have to use this identifier when the axis
direction changed,
+ * because such change often implies a name change too (e.g. "Westing" → "Easting"), and
we can not always
+ * guess what the new name should be. This constant is used as a sentinel value set by Normalizer
and checked
+ * by DefaultCoordinateSystemAxis for skipping axis name comparisons when the axis name is
unknown.
+ */
+import static org.apache.sis.internal.referencing.NilReferencingObject.UNNAMED;
+
 
 /**
  * Derives an coordinate system from an existing one for {@link AxesConvention}.
@@ -165,7 +173,7 @@ final class Normalizer implements Compar
         if (newAbbr.equals(abbreviation)) {
             properties.putAll(IdentifiedObjects.getProperties(axis, EXCLUDES));
         } else {
-            properties.put(NAME_KEY, DefaultCoordinateSystemAxis.UNNAMED);
+            properties.put(NAME_KEY, UNNAMED);
         }
         /*
          * Converts the axis range and build the new axis.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java?rev=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -31,9 +31,9 @@ import org.apache.sis.util.Utilities;
 import org.apache.sis.util.Workaround;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.internal.util.Citations;
 import org.apache.sis.internal.metadata.WKTKeywords;
+import org.apache.sis.internal.referencing.NilReferencingObject;
 import org.apache.sis.parameter.Parameterized;
 import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.referencing.IdentifiedObjects;
@@ -255,7 +255,7 @@ public class DefaultOperationMethod exte
                 return getProperties(parameters, null);
             }
         }
-        return Collections.singletonMap(NAME_KEY, Vocabulary.format(Vocabulary.Keys.Unnamed));
+        return Collections.singletonMap(NAME_KEY, NilReferencingObject.UNNAMED);
     }
 
     /**

Modified: 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=1697073&r1=1697072&r2=1697073&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
[UTF-8] Sat Aug 22 03:13:38 2015
@@ -27,6 +27,7 @@ import javax.measure.unit.NonSI;
 import org.opengis.test.Validators;
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.apache.sis.measure.Range;
@@ -285,14 +286,25 @@ public final strictfp class ParameterMar
     @Test
     @DependsOnMethod("testDoubleValue")
     public void testDescriptorGroup() throws JAXBException {
+        // Test marshalling.
         assertMarshalEqualsFile("ParameterDescriptorGroup.xml",
                 ParameterFormatTest.createMercatorParameters(), "xmlns:*", "xsi:schemaLocation");
 
-        final DefaultParameterDescriptorGroup group = unmarshalFile(
-                DefaultParameterDescriptorGroup.class, "ParameterDescriptorGroup.xml");
+        // Test unmarshalling.
+        verifyDescriptorGroup(unmarshalFile(DefaultParameterDescriptorGroup.class, "ParameterDescriptorGroup.xml"));
+    }
+
+    /**
+     * Verifies that the properties of the given parameter descriptor group are the expected
properties,
+     * ignoring the {@code valueClass} and {@code unit} (because not part of GML schema for
descriptors).
+     *
+     * @param group The descriptor group to verify.
+     */
+    private static void verifyDescriptorGroup(final ParameterDescriptorGroup group) {
         assertEpsgIdentifierEquals(9804, group.getIdentifiers());
         assertIdentifierEquals("name", "##unrestricted", "EPSG", null, "Mercator (variant
A)", group.getName());
 
+        // Verify the ParameterDescriptors properties.
         final Iterator<GeneralParameterDescriptor> it = group.descriptors().iterator();
         verifyDescriptor(8801, "Latitude of natural origin",     "latitude_of_origin", true,
 it.next());
         verifyDescriptor(8802, "Longitude of natural origin",    "central_meridian",   true,
 it.next());
@@ -303,29 +315,13 @@ public final strictfp class ParameterMar
     }
 
     /**
-     * Tests (un)marshalling of a parameter value group.
-     *
-     * @throws JAXBException if an error occurred during marshalling or unmarshalling.
-     */
-    @Test
-    @DependsOnMethod("testDescriptorGroup")
-    public void testValueGroup() throws JAXBException {
-        assertMarshalEqualsFile("ParameterValueGroup.xml",
-                ParameterFormatTest.createMercatorParameters().createValue(),
-                "xmlns:*", "xsi:schemaLocation", "gml:id");
-
-        final DefaultParameterValueGroup group = unmarshalFile(
-                DefaultParameterValueGroup.class, "ParameterValueGroup.xml");
-
-        final Iterator<GeneralParameterValue> it = group.values().iterator();
-        verifyParameter(8801, "Latitude of natural origin",     "latitude_of_origin", true,
 40, NonSI.DEGREE_ANGLE, it.next());
-        verifyParameter(8802, "Longitude of natural origin",    "central_meridian",   true,
-60, NonSI.DEGREE_ANGLE, it.next());
-        verifyParameter(8805, "Scale factor at natural origin", "scale_factor",       true,
  1, Unit.ONE,           it.next());
-        assertFalse("Unexpected parameter.", it.hasNext());
-    }
-
-    /**
      * Verifies that the given parameter descriptor has the expected EPSG code, name and
OGC alias.
+     *
+     * @param code       The expected EPSG code.
+     * @param name       The expected EPSG name.
+     * @param alias      The expected OGC alias.
+     * @param required   {@code true} if the parameter should be mandatory, or {@code false}
if optional.
+     * @param descriptor The parameter descriptor to verify.
      */
     private static void verifyDescriptor(final int code, final String name, final String
alias,
             final boolean required, final GeneralParameterDescriptor descriptor)
@@ -339,18 +335,54 @@ public final strictfp class ParameterMar
 
     /**
      * Verifies that the given parameter value has the expected value and descriptor properties.
+     *
+     * @param code       The expected EPSG code.
+     * @param name       The expected EPSG name.
+     * @param alias      The expected OGC alias.
+     * @param value      The expected value.
+     * @param unit       The expected unit of measurement for both the value and the descriptor.
+     * @param descriptor The expected parameter descriptor associated to the parameter value.
+     * @param parameter  The parameter value to verify.
      */
     private static void verifyParameter(final int code, final String name, final String alias,
-            final boolean required, final double value, final Unit<?> unit,
+            final double value, final Unit<?> unit, final GeneralParameterDescriptor
descriptor,
             final GeneralParameterValue parameter)
     {
-        verifyDescriptor(code, name, alias, required, parameter.getDescriptor());
         assertInstanceOf(name, ParameterValue.class, parameter);
         final ParameterValue<?> p = (ParameterValue<?>) parameter;
         final ParameterDescriptor<?> d = p.getDescriptor();
+        verifyDescriptor(code, name, alias, true, d);
+        assertSame  ("descriptor", descriptor,   d);
         assertEquals("value",      value,        p.doubleValue(), STRICT);
         assertEquals("unit",       unit,         p.getUnit());
         assertEquals("valueClass", Double.class, d.getValueClass());
         assertEquals("unit",       unit,         d.getUnit());
     }
+
+    /**
+     * Tests (un)marshalling of a parameter value group.
+     *
+     * @throws JAXBException if an error occurred during marshalling or unmarshalling.
+     */
+    @Test
+    @DependsOnMethod("testDescriptorGroup")
+    public void testValueGroup() throws JAXBException {
+        // Test marshalling.
+        assertMarshalEqualsFile("ParameterValueGroup.xml",
+                ParameterFormatTest.createMercatorParameters().createValue(),
+                "xmlns:*", "xsi:schemaLocation", "gml:id");
+
+        // Test unmarshalling.
+        final DefaultParameterValueGroup group = unmarshalFile(
+                DefaultParameterValueGroup.class, "ParameterValueGroup.xml");
+
+        // Verify the ParameterValues properties.
+        verifyDescriptorGroup(group.getDescriptor());
+        final Iterator<GeneralParameterValue> it = group.values().iterator();
+        final Iterator<GeneralParameterDescriptor> itd = group.getDescriptor().descriptors().iterator();
+        verifyParameter(8801, "Latitude of natural origin",     "latitude_of_origin", 40,
NonSI.DEGREE_ANGLE, itd.next(), it.next());
+        verifyParameter(8802, "Longitude of natural origin",    "central_meridian",  -60,
NonSI.DEGREE_ANGLE, itd.next(), it.next());
+        verifyParameter(8805, "Scale factor at natural origin", "scale_factor",        1,
Unit.ONE,           itd.next(), it.next());
+        assertFalse("Unexpected parameter.", it.hasNext());
+    }
 }



Mime
View raw message