sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1624921 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ core/sis-metadata/src/main/java/org/apache/sis/metadata/...
Date Sun, 14 Sep 2014 22:53:59 GMT
Author: desruisseaux
Date: Sun Sep 14 22:53:58 2014
New Revision: 1624921

URL: http://svn.apache.org/r1624921
Log:
Start using the Identifier <-> TypeName mapping in ServiceParameter.
An open issue in this commit is the fact that ISO 19139 does not include the namespace of
TypeName objects in XML document,
so we currently fail to infer the java.lang.Class from an unmarshalled XML TypeName because
of the missing "OGC" or "class" namespace.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/SV_Parameter.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameterTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/service/DefaultCoupledResourceTest.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/UninitializedParameter.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/Names.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/NamesTest.java
    sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/DirectReferenceSystem.java
    sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/IndirectReferenceSystem.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/SV_Parameter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/SV_Parameter.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/SV_Parameter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/SV_Parameter.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -78,7 +78,7 @@ public final class SV_Parameter extends 
      * @return The metadata to be marshalled.
      */
     @XmlElementRef
-    public ServiceParameter<?> getElement() {
+    public ServiceParameter getElement() {
         return ServiceParameter.castOrCopy(metadata);
     }
 
@@ -87,7 +87,7 @@ public final class SV_Parameter extends 
      *
      * @param metadata The unmarshalled metadata.
      */
-    public void setElement(final ServiceParameter<?> metadata) {
+    public void setElement(final ServiceParameter metadata) {
         this.metadata = metadata;
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -32,11 +32,16 @@ import org.opengis.parameter.ParameterDe
 import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.internal.simple.SimpleIdentifiedObject;
 import org.apache.sis.internal.jaxb.metadata.direct.GO_MemberName;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.iso.Names;
 import org.apache.sis.xml.Namespaces;
 
 import static org.apache.sis.internal.util.CollectionsExt.nonNull;
 import static org.apache.sis.internal.jaxb.gco.PropertyType.LEGACY_XML;
 
+// Branch-dependent imports
+import java.util.Objects;
+
 
 /**
  * Parameter information conform to the ISO 19115:2014 specification.
@@ -48,7 +53,12 @@ import static org.apache.sis.internal.ja
  * parsing and formatting. For real parameter framework, consider using {@link org.apache.sis.parameter}
  * package instead.</p>
  *
- * @param <T> The type of parameter values.
+ * {@section Note about raw-type usage}
+ * We use raw type (i.e. we implement {@code ParameterDescriptor} instead of {@code ParameterDescriptor<T>})
+ * because there is no way we can know {@code <T>} for sure at unmarshalling time.
This is not a recommended
+ * practice, so <strong>this class shall not be in public API</strong>.  However
it should be okay to create
+ * {@code ServiceMetadata} instances in Apache SIS internal code if all methods creating
such instances declare
+ * {@code ParameterDescriptor<?>} as their return type.
  *
  * @author  Rémi Maréchal (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -56,8 +66,9 @@ import static org.apache.sis.internal.ja
  * @since   0.5
  * @module
  */
+@SuppressWarnings("rawtypes") // For the omission of <T> in ParameterDescriptor<T>
- see javadoc.
 @XmlType(name = "SV_Parameter_Type", namespace = Namespaces.SRV, propOrder = {
-    "name",
+    "memberName",
     "direction",
     "description",
     "optionality",
@@ -65,7 +76,7 @@ import static org.apache.sis.internal.ja
     "valueType"
 })
 @XmlRootElement(name = "SV_Parameter", namespace = Namespaces.SRV)
-public final class ServiceParameter<T> extends SimpleIdentifiedObject implements ParameterDescriptor<T>
{
+public final class ServiceParameter extends SimpleIdentifiedObject implements ParameterDescriptor
{
     /**
      * Serial number for compatibility with different versions.
      */
@@ -76,21 +87,21 @@ public final class ServiceParameter<T> e
      *
      * @see #getValueType()
      */
-    @XmlElement(required = true)
+    @XmlElement(required=true, name="name")
     @XmlJavaTypeAdapter(GO_MemberName.class)
-    public MemberName name;
+    MemberName memberName;
 
     /**
      * Indication if the parameter is an input to the service, an output or both.
      */
     @XmlElement
-    public ParameterDirection direction;
+    ParameterDirection direction;
 
     /**
      * A narrative explanation of the role of the parameter.
      */
     @XmlElement
-    public InternationalString description;
+    InternationalString description;
 
     /**
      * Indication if the parameter is required.
@@ -114,15 +125,19 @@ public final class ServiceParameter<T> e
     /**
      * Creates an initially empty parameter.
      * This constructor is needed by JAXB.
+     *
+     * <p><strong>Consider this constructor as private</strong> except
for testing purpose.
+     * See <cite>Note about raw-type usage</cite> in class javadoc.</p>
      */
-    public ServiceParameter() {
+    ServiceParameter() {
     }
 
     /**
      * Creates a parameter initialized to the values of the given one.
      */
-    private ServiceParameter(final ParameterDescriptor<T> parameter) {
-        name          = getName(parameter);
+    private ServiceParameter(final ParameterDescriptor<?> parameter) {
+        super(parameter);
+        memberName    = getMemberName(parameter);
         direction     = parameter.getDirection();
         description   = parameter.getDescription();
         optionality   = parameter.getMinimumOccurs() > 0;
@@ -135,11 +150,11 @@ public final class ServiceParameter<T> e
      * @param  parameter The parameter (may be {@code null}).
      * @return The service parameter, or {@code null} if the given argument was null.
      */
-    public static ServiceParameter<?> castOrCopy(final ParameterDescriptor<?>
parameter) {
-        if (parameter == null || parameter instanceof ServiceParameter<?>) {
-            return (ServiceParameter<?>) parameter;
+    public static ServiceParameter castOrCopy(final ParameterDescriptor<?> parameter)
{
+        if (parameter == null || parameter instanceof ServiceParameter) {
+            return (ServiceParameter) parameter;
         }
-        return new ServiceParameter<>(parameter);
+        return new ServiceParameter(parameter);
     }
 
     /**
@@ -150,7 +165,7 @@ public final class ServiceParameter<T> e
      * @param  parameter The parameter from which to get the name (may be {@code null}).
      * @return The member name, or {@code null} if none.
      */
-    public static MemberName getName(final ParameterDescriptor<?> parameter) {
+    public static MemberName getMemberName(final ParameterDescriptor<?> parameter)
{
         if (parameter != null) {
             final ReferenceIdentifier id = parameter.getName();
             if (id instanceof MemberName) {
@@ -166,7 +181,7 @@ public final class ServiceParameter<T> e
                 if (valueClass != null) {
                     final String code = id.getCode();
                     if (code != null) {
-                        // TODO return Names.createMemberName(id.getCodeSpace(), ":", code,
valueClass);
+                        return Names.createMemberName(id.getCodeSpace(), ":", code, valueClass);
                     }
                 }
             }
@@ -174,9 +189,37 @@ public final class ServiceParameter<T> e
         return null;
     }
 
+    /**
+     * Returns the name as an {@code Identifier}, which is the type requested by ISO 19111.
+     * Note that this is different than the type requested by ISO 19115, which is {@link
MemberName}.
+     *
+     * This method is the converse of {@link #getMemberName(ParameterDescriptor)}.
+     *
+     * @return The parameter name as an identifier (the type specified by ISO 19111).
+     */
     @Override
-    public Class<T> getValueClass() {
-        throw new UnsupportedOperationException("Not supported yet."); // TODO
+    public ReferenceIdentifier getName() {
+        if (name == null && memberName != null) {
+            if (memberName instanceof ReferenceIdentifier) {
+                name = (ReferenceIdentifier) memberName;
+            } else {
+                // TODO: name = new NameToIdentifier(memberName);
+            }
+        }
+        return name;
+    }
+
+    /**
+     * Infers the value class from the attribute type.
+     * This method is the reason why we can not parameterize this {@code ServiceParameter}
class
+     * (see <cite>Note about raw-type usage</cite> in class javadoc), since there
is no way we
+     * can ensure that the returned class is really for type {@code <T>}.
+     *
+     * @return The value class inferred from the attribute type, or {@code null} if unknown.
+     */
+    @Override
+    public Class<?> getValueClass() {
+        return (memberName != null) ? Names.toClass(memberName.getAttributeType()) : null;
     }
 
     /**
@@ -186,14 +229,24 @@ public final class ServiceParameter<T> e
      */
     @XmlElement(name = "valueType")
     final TypeName getValueType() {
-        return (LEGACY_XML && name != null) ? name.getAttributeType() : null;
+        return (LEGACY_XML && memberName != null) ? memberName.getAttributeType()
: null;
     }
 
+    /**
+     * Returns an indication if the parameter is an input to the service, an output or both.
+     *
+     * @return Indication if the parameter is an input or output to the service, or {@code
null} if unspecified.
+     */
     @Override
     public ParameterDirection getDirection() {
         return direction;
     }
 
+    /**
+     * Returns a narrative explanation of the role of the parameter.
+     *
+     * @return A narrative explanation of the role of the parameter, or {@code null} if none.
+     */
     @Override
     public InternationalString getDescription() {
         return description;
@@ -217,24 +270,66 @@ public final class ServiceParameter<T> e
         }
     }
 
+    /**
+     * The minimum number of times that values for this parameter group or parameter are
required.
+     *
+     * @return The minimum occurrence.
+     */
     @Override
     public int getMinimumOccurs() {
         return optionality ? 0 : 1;
     }
 
+    /**
+     * The maximum number of times that values for this parameter group or parameter can
be included.
+     *
+     * @return The maximum occurrence.
+     */
     @Override
     public int getMaximumOccurs() {
         return repeatability ? Integer.MAX_VALUE : 1;
     }
 
-    @Override public Set<T>        getValidValues()  {return null;}
-    @Override public Comparable<T> getMinimumValue() {return null;}
-    @Override public Comparable<T> getMaximumValue() {return null;}
-    @Override public T             getDefaultValue() {return null;}
+    /**
+     * Optional properties.
+     * @return {@code null}.
+     */
+    @Override public Set<?>        getValidValues()  {return null;} // Really null,
not an empty set. See method contract.
+    @Override public Comparable<?> getMinimumValue() {return null;}
+    @Override public Comparable<?> getMaximumValue() {return null;}
+    @Override public Object        getDefaultValue() {return null;}
     @Override public Unit<?>       getUnit()         {return null;}
 
     @Override
-    public ParameterValue<T> createValue() {
+    public ParameterValue<?> createValue() {
         throw new UnsupportedOperationException("Not supported yet."); // TODO
     }
+
+    /**
+     * Compares this object with the given one for equality.
+     *
+     * @param  object The object to compare with this reference system.
+     * @param  mode The strictness level of the comparison.
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public boolean equals(final Object object, final ComparisonMode mode) {
+        if (super.equals(object, mode) && object instanceof ParameterDescriptor<?>)
{
+            final ParameterDescriptor<?> that = (ParameterDescriptor<?>) object;
+            if (that.getUnit()         == null &&
+                that.getDefaultValue() == null /*&&
+                that.getValueClass()   == getValueClass()*/) // TODO
+            {
+                if (mode.ordinal() >= ComparisonMode.IGNORE_METADATA.ordinal()) {
+                    return true;
+                }
+                return that.getMinimumOccurs() == getMinimumOccurs() &&
+                       that.getMaximumOccurs() == getMaximumOccurs() &&
+                       that.getValidValues()   == null &&
+                       that.getMinimumValue()  == null &&
+                       that.getMaximumValue()  == null;
+            }
+        }
+        return false;
+    }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -217,10 +217,10 @@ public class ImmutableIdentifier extends
      *
      * @param authority
      *          Organization or party responsible for definition and maintenance of the code
-     *          space or code.
+     *          space or code, or {@code null} if not available.
      * @param codeSpace
-     *          Name or identifier of the person or organization responsible for namespace.
-     *          This is often an abbreviation of the authority name.
+     *          Name or identifier of the person or organization responsible for namespace,
or
+     *          {@code null} if not available. This is often an abbreviation of the authority
name.
      * @param code
      *          Identifier code or name, optionally from a controlled list or pattern defined
by
      *          a code space. The code can not be null.

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameterTest.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameterTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameterTest.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -17,14 +17,13 @@
 package org.apache.sis.internal.jaxb.metadata.replace;
 
 import javax.xml.bind.JAXBException;
-import org.opengis.util.TypeName;
 import org.opengis.util.MemberName;
 import org.opengis.parameter.ParameterDirection;
-import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.util.iso.Names;
 import org.apache.sis.xml.Namespaces;
+import org.apache.sis.test.XMLTestCase;
 import org.junit.Test;
 
-import static org.apache.sis.internal.system.DefaultFactories.SIS_NAMES;
 import static org.apache.sis.test.Assert.*;
 
 
@@ -42,24 +41,32 @@ public final strictfp class ServiceParam
      *
      * @return The test parameter.
      */
-    public static ServiceParameter<?> create() {
-        final TypeName   valueType = SIS_NAMES.createTypeName(null, "CharacterString");
-        final MemberName paramName = SIS_NAMES.createMemberName(null, "Version", valueType);
-        final ServiceParameter<?> param = new ServiceParameter<>();
-        param.name          = paramName;
+    public static ServiceParameter create() {
+        final MemberName paramName = Names.createMemberName(null, ":", "Version", String.class);
+        final ServiceParameter param = new ServiceParameter();
+        param.memberName    = paramName;
         param.optionality   = true;
         param.repeatability = false;
         param.direction     = ParameterDirection.IN;
-        assertSame("valueType", valueType, param.getValueType());
         return param;
     }
 
     /**
+     * Tests {@link ServiceParameter#getValueType()} and {@link ServiceParameter#getValueClass()}.
+     */
+    @Test
+    public void testGetValueType() {
+        final ServiceParameter param = create();
+        assertEquals("valueType", "OGC:CharacterString", param.getValueType().toFullyQualifiedName().toString());
+        assertEquals("valueClass", String.class, param.getValueClass());
+    }
+
+    /**
      * Tests {@link ServiceParameter#getOptionality()} and {@link ServiceParameter#setOptionality(String)}.
      */
     @Test
     public void testOptionalityLabel() {
-        final ServiceParameter<?> param = create();
+        final ServiceParameter param = create();
         assertEquals("Optional", param.getOptionality());
 
         param.optionality = false;
@@ -81,7 +88,7 @@ public final strictfp class ServiceParam
      */
     @Test
     public void testMarshalEmpty() throws JAXBException {
-        final String xml = marshal(new ServiceParameter<>());
+        final String xml = marshal(new ServiceParameter());
         assertXmlEquals(
                 "<srv:SV_Parameter xmlns:srv=\"" + Namespaces.SRV + '"' +
                                  " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/service/DefaultCoupledResourceTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/service/DefaultCoupledResourceTest.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/service/DefaultCoupledResourceTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/service/DefaultCoupledResourceTest.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -17,6 +17,7 @@
 package org.apache.sis.metadata.iso.service;
 
 import org.opengis.util.ScopedName;
+import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.metadata.citation.OnlineResource;
 import org.opengis.metadata.service.OperationMetadata;
 import org.opengis.metadata.service.DistributedComputingPlatform;
@@ -47,7 +48,7 @@ public final strictfp class DefaultCoupl
     static DefaultCoupledResource create() {
         final DefaultOperationMetadata operation = new DefaultOperationMetadata("Get Map",
                 DistributedComputingPlatform.WEB_SERVICES, null);
-        operation.setParameters(singleton(ServiceParameterTest.create()));
+        operation.setParameters(singleton((ParameterDescriptor<?>) ServiceParameterTest.create()));
         operation.setConnectPoints(singleton(NilReason.MISSING.createNilObject(OnlineResource.class)));
 
         final DefaultCoupledResource resource = new DefaultCoupledResource();

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=1624921&r1=1624920&r2=1624921&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] Sun Sep 14 22:53:58 2014
@@ -41,11 +41,21 @@ abstract class AbstractParameterDescript
         super(other);
     }
 
+    /**
+     * Returns an indication if the parameter is an input to the service, an output or both.
+     *
+     * @return Indication if the parameter is an input or output to the service, or {@code
null} if unspecified.
+     */
     @Override
     public ParameterDirection getDirection() {
         return ParameterDirection.IN;
     }
 
+    /**
+     * Returns a narrative explanation of the role of the parameter.
+     *
+     * @return A narrative explanation of the role of the parameter, or {@code null} if none.
+     */
     @Override
     public InternationalString getDescription() {
         return null;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/UninitializedParameter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/UninitializedParameter.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/UninitializedParameter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/UninitializedParameter.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -33,7 +33,7 @@ import org.apache.sis.referencing.Identi
  * @version 0.4
  * @module
  */
-final class UninitializedParameter implements GeneralParameterValue, Serializable {
+final class UninitializedParameter implements GeneralParameterValue, Serializable { // Intentionally
non-Cloneable.
     /**
      * For cross-version serialization compatibility.
      */

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -44,9 +44,10 @@ import java.util.Objects;
  *
  * <p>{@code DefaultLocalName} can be instantiated by any of the following methods:</p>
  * <ul>
- *   <li>{@link DefaultNameFactory#createLocalName(NameSpace, CharSequence)}</li>
- *   <li>{@link DefaultNameFactory#createGenericName(NameSpace, CharSequence[])} with
an array of length 1</li>
- *   <li>{@link DefaultNameFactory#parseGenericName(NameSpace, CharSequence)} without
separator</li>
+ *   <li>{@link DefaultNameFactory#createLocalName(NameSpace, CharSequence)}.</li>
+ *   <li>{@link DefaultNameFactory#createGenericName(NameSpace, CharSequence[])} with
an array of length 1.</li>
+ *   <li>{@link DefaultNameFactory#parseGenericName(NameSpace, CharSequence)} with
no occurrence of the separator in the path.</li>
+ *   <li>Similar static convenience methods in {@link Names}.</li>
  * </ul>
  *
  * {@section Immutability and thread safety}

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -35,6 +35,7 @@ import java.util.Objects;
  *
  * <ul>
  *   <li>{@link DefaultNameFactory#createMemberName(NameSpace, CharSequence, TypeName)}</li>
+ *   <li>Similar static convenience method in {@link Names}.</li>
  * </ul>
  *
  * {@section Immutability and thread safety}

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -37,8 +37,9 @@ import org.apache.sis.internal.util.Unmo
  *
  * <p>{@code DefaultScopedName} can be instantiated by any of the following methods:</p>
  * <ul>
- *   <li>{@link DefaultNameFactory#createGenericName(NameSpace, CharSequence[])} with
an array of length 2 or more</li>
- *   <li>{@link DefaultNameFactory#parseGenericName(NameSpace, CharSequence)} with
at least one separator</li>
+ *   <li>{@link DefaultNameFactory#createGenericName(NameSpace, CharSequence[])} with
an array of length 2 or more.</li>
+ *   <li>{@link DefaultNameFactory#parseGenericName(NameSpace, CharSequence)} with
at least one occurrence of the separator in the path.</li>
+ *   <li>Similar static convenience methods in {@link Names}.</li>
  * </ul>
  *
  * {@section Immutability and thread safety}

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -202,6 +202,6 @@ public class DefaultTypeName extends Def
             }
             valueClass = c;
         }
-        return c;
+        return (c != Void.TYPE) ? c : null;
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/Names.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/Names.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/Names.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/Names.java [UTF-8]
Sun Sep 14 22:53:58 2014
@@ -19,6 +19,7 @@ package org.apache.sis.util.iso;
 import java.util.Collections;
 import org.opengis.util.TypeName;
 import org.opengis.util.LocalName;
+import org.opengis.util.MemberName;
 import org.opengis.util.GenericName;
 import org.opengis.util.NameSpace;
 import org.opengis.util.InternationalString;
@@ -190,28 +191,28 @@ public final class Names extends Static 
     }
 
     /**
-     * Formats the given name in <cite>expanded form</cite> close to the Java
Content Repository (JCR) definition.
-     * The expanded form is defined as below:
-     *
-     * <blockquote><pre> ExpandedName ::= '{' NameSpace '}' LocalPart
-     * NameSpace    ::= name.{@linkplain AbstractName#scope() scope()}.{@linkplain DefaultNameSpace#name()
name()}.toString()
-     * LocalPart    ::= name.{@linkplain AbstractName#toString() toString()}</pre></blockquote>
+     * Creates a member name for values of the given class. A {@link TypeName} will be inferred
+     * from the given {@code valueClass} as documented in the {@link DefaultTypeName} javadoc.
      *
-     * @param  name The generic name to format in expanded form.
-     * @return Expanded form of the given generic name.
+     * <div class="note"><b>Performance note:</b> this method is okay for
<em>casual</em> use. If many names
+     * need to be created, then {@link DefaultNameFactory#createMemberName(NameSpace, CharSequence,
TypeName)}
+     * is more efficient since it allows to create the {@code NameSpace} and {@code TypeName}
objects only once.</div>
      *
-     * @see DefaultNameSpace#toString()
+     * @param  namespace  The namespace, or {@code null} for the global namespace.
+     * @param  separator  The separator between the namespace and the local part.
+     * @param  localPart  The name which is locale in the given namespace.
+     * @param  valueClass The type of values, used for inferring a {@link TypeName} instance.
+     * @return A member name in the given namespace for values of the given type.
      */
-    public static String toExpandedString(final GenericName name) {
-        ensureNonNull("name", name);
-        final String localPart = name.toString();
-        final NameSpace scope = name.scope();
-        if (scope == null || scope.isGlobal()) {
-            return localPart;
-        }
-        final String ns = scope.name().toString();
-        return new StringBuilder(ns.length() + localPart.length() + 2)
-                .append('{').append(ns).append('}').append(localPart).toString();
+    public static MemberName createMemberName(final CharSequence namespace, final String
separator,
+            final CharSequence localPart, final Class<?> valueClass)
+    {
+        ensureNonNull("localPart",  localPart);
+        ensureNonNull("separator",  separator);
+        ensureNonNull("valueClass", valueClass);
+        return DefaultFactories.NAMES.createMemberName(
+                createNameSpace(namespace, separator), localPart,
+                DefaultFactories.SIS_NAMES.toTypeName(valueClass));
     }
 
     /**
@@ -261,4 +262,31 @@ public final class Names extends Static 
         }
         return c;
     }
+
+    /**
+     * Formats the given name in <cite>expanded form</cite> close to the Java
Content Repository (JCR) definition.
+     * The expanded form is defined as below:
+     *
+     * <blockquote><pre> ExpandedName ::= '{' NameSpace '}' LocalPart
+     * NameSpace    ::= name.{@linkplain AbstractName#scope() scope()}.{@linkplain DefaultNameSpace#name()
name()}.toString()
+     * LocalPart    ::= name.{@linkplain AbstractName#toString() toString()}</pre></blockquote>
+     *
+     * @param  name The generic name to format in expanded form, or {@code null}.
+     * @return Expanded form of the given generic name, or {@code null} if the given name
was null.
+     *
+     * @see DefaultNameSpace#toString()
+     */
+    public static String toExpandedString(final GenericName name) {
+        if (name == null) {
+            return null;
+        }
+        final String localPart = name.toString();
+        final NameSpace scope = name.scope();
+        if (scope == null || scope.isGlobal()) {
+            return localPart;
+        }
+        final String ns = scope.name().toString();
+        return new StringBuilder(ns.length() + localPart.length() + 2)
+                .append('{').append(ns).append('}').append(localPart).toString();
+    }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/NamesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/NamesTest.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/NamesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/NamesTest.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -54,19 +54,34 @@ public final strictfp class NamesTest ex
     }
 
     /**
-     * Test {@link Names#toClass(TypeName)}.
+     * Tests {@link Names#toClass(TypeName)} with a known type name.
      */
     @Test
     public void testToClass() {
         final TypeName type = DefaultFactories.SIS_NAMES.toTypeName(String.class);
         assertEquals("OGC:CharacterString", type.toFullyQualifiedName().toString());
-        assertEquals(String.class, Names.toClass(type));
 
         // Tests detection from the name.
         assertEquals(InternationalString.class, Names.toClass(new DefaultTypeName(type.scope(),
"FreeText")));
+        assertValueClassEquals(String.class, type);
+    }
+
+    /**
+     * Tests {@link Names#toClass(TypeName)} with an unknown type name.
+     */
+    @Test
+    public void testUnknownType() {
+        assertValueClassEquals(null, Names.createTypeName("MyOrg", ":", "CharacterString"));
+    }
+
+    /**
+     * Asserts that calls to {@link Names#toClass(TypeName)} returns the expected value class.
+     */
+    private static void assertValueClassEquals(final Class<?> expected, final TypeName
type) {
+        assertEquals(expected, Names.toClass(type));
 
         // Tests detection with an implementation which is not the SIS one.
-        assertEquals(String.class, Names.toClass(new TypeName() {
+        assertEquals(expected, Names.toClass(new TypeName() {
             @Override public int                       depth()                  {return type.depth();}
             @Override public List<? extends LocalName> getParsedNames()         {return
type.getParsedNames();}
             @Override public LocalName                 head()                   {return type.head();}

Modified: sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/DirectReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/DirectReferenceSystem.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/DirectReferenceSystem.java
[UTF-8] (original)
+++ sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/DirectReferenceSystem.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlRoot
 import org.opengis.referencing.ReferenceSystem;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata;
+import org.apache.sis.util.ComparisonMode;
 
 
 /**
@@ -73,4 +74,16 @@ public class DirectReferenceSystem exten
     public DirectReferenceSystem(final ReferenceIdentifier identifier) {
         super(identifier);
     }
+
+    /**
+     * Compares this object with the given one for equality.
+     *
+     * @param  object The object to compare with this reference system.
+     * @param  mode The strictness level of the comparison.
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public boolean equals(final Object object, final ComparisonMode mode) {
+        return super.equals(object, mode) && (object instanceof DirectReferenceSystem);
+    }
 }

Modified: sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/IndirectReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/IndirectReferenceSystem.java?rev=1624921&r1=1624920&r2=1624921&view=diff
==============================================================================
--- sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/IndirectReferenceSystem.java
[UTF-8] (original)
+++ sis/branches/JDK8/profiles/sis-french-profile/src/main/java/org/apache/sis/internal/profile/fra/IndirectReferenceSystem.java
[UTF-8] Sun Sep 14 22:53:58 2014
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlRoot
 import org.opengis.referencing.ReferenceSystem;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata;
+import org.apache.sis.util.ComparisonMode;
 
 
 /**
@@ -73,4 +74,16 @@ public class IndirectReferenceSystem ext
     public IndirectReferenceSystem(final ReferenceIdentifier identifier) {
         super(identifier);
     }
+
+    /**
+     * Compares this object with the given one for equality.
+     *
+     * @param  object The object to compare with this reference system.
+     * @param  mode The strictness level of the comparison.
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public boolean equals(final Object object, final ComparisonMode mode) {
+        return super.equals(object, mode) && (object instanceof IndirectReferenceSystem);
+    }
 }



Mime
View raw message