sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1624897 - in /sis/branches/JDK8/core/sis-utility/src: main/java/org/apache/sis/util/ main/java/org/apache/sis/util/iso/ test/java/org/apache/sis/util/iso/
Date Sun, 14 Sep 2014 19:13:24 GMT
Author: desruisseaux
Date: Sun Sep 14 19:13:24 2014
New Revision: 1624897

URL: http://svn.apache.org/r1624897
Log:
Added a test.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/UnknownNameException.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.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

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/UnknownNameException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/UnknownNameException.java?rev=1624897&r1=1624896&r2=1624897&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/UnknownNameException.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/UnknownNameException.java
[UTF-8] Sun Sep 14 19:13:24 2014
@@ -20,7 +20,8 @@ package org.apache.sis.util;
 /**
  * Thrown when an operation can not complete because a given name is unrecognized.
  * The unrecognized name may be a {@link org.opengis.util.GenericName}, an
- * {@link org.opengis.metadata.Identifier} or a {@link String} for instance.
+ * {@link org.opengis.metadata.Identifier}, a {@link String} used as a name or identifier,
+ * or any other objects with similar purpose.
  *
  * <p><b>Note:</b> in the particular case of objects created from a {@link
org.opengis.util.Factory},
  * the exception for unrecognized identifiers is rather {@link org.opengis.util.NoSuchIdentifierException}.</p>

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java?rev=1624897&r1=1624896&r2=1624897&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
[UTF-8] Sun Sep 14 19:13:24 2014
@@ -415,12 +415,15 @@ public class DefaultNameFactory extends 
      * and {@code TypeName} objects as documented in the {@link DefaultTypeName} javadoc.
      *
      * <p>In order to protect against potential changes in the {@code Class} ↔ {@code
TypeName} mapping, users are
-     * encouraged to retrieve the {@code valueClass} by invoking the {@link DefaultTypeName#toClass()}
method
-     * instead than parsing the name.</p>
+     * encouraged to retrieve the {@code valueClass} by invoking the {@link Names#toClass(TypeName)}
method instead
+     * than parsing the name.</p>
      *
      * @param  valueClass The Java class for which to get a type name, or {@code null}.
      * @return A suggested type name, or {@code null} if the given class was null.
      *
+     * @see DefaultTypeName#toClass()
+     * @see Names#toClass(TypeName)
+     *
      * @since 0.5
      */
     public TypeName toTypeName(final Class<?> valueClass) {

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=1624897&r1=1624896&r2=1624897&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 19:13:24 2014
@@ -172,6 +172,9 @@ public class DefaultTypeName extends Def
      *         the {@linkplain #scope() scope} is not one of the supported namespaces.
      * @throws UnknownNameException if the scope is one of the supported namespaces, but
the name is not recognized.
      *
+     * @see Names#toClass(TypeName)
+     * @see DefaultNameFactory#toTypeName(Class)
+     *
      * @since 0.5
      */
     public Class<?> toClass() throws UnknownNameException {

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=1624897&r1=1624896&r2=1624897&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 19:13:24 2014
@@ -234,6 +234,9 @@ public final class Names extends Static 
      *         is null or if the {@linkplain #scope() scope} is not one of the supported
namespaces.
      * @throws UnknownNameException if the scope is one of the supported namespaces, but
the name is not recognized.
      *
+     * @see DefaultTypeName#toClass()
+     * @see DefaultNameFactory#toTypeName(Class)
+     *
      * @since 0.5
      */
     public static Class<?> toClass(final TypeName type) throws UnknownNameException
{

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=1624897&r1=1624896&r2=1624897&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 19:13:24 2014
@@ -16,7 +16,14 @@
  */
 package org.apache.sis.util.iso;
 
+import java.util.List;
+import org.opengis.util.GenericName;
+import org.opengis.util.TypeName;
 import org.opengis.util.LocalName;
+import org.opengis.util.InternationalString;
+import org.opengis.util.NameSpace;
+import org.opengis.util.ScopedName;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -45,4 +52,31 @@ public final strictfp class NamesTest ex
         assertEquals("http://www.opengis.net/gml/srs/epsg.xml#4326",  name.toFullyQualifiedName().toString());
         assertEquals("{http://www.opengis.net/gml/srs/epsg.xml}4326", Names.toExpandedString(name));
     }
+
+    /**
+     * Test {@link Names#toClass(TypeName)}.
+     */
+    @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")));
+
+        // Tests detection with an implementation which is not the SIS one.
+        assertEquals(String.class, 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();}
+            @Override public LocalName                 tip()                    {return type.tip();}
+            @Override public NameSpace                 scope()                  {return type.scope();}
+            @Override public GenericName               toFullyQualifiedName()   {return type.toFullyQualifiedName();}
+            @Override public ScopedName                push(GenericName scope)  {return type.push(scope);}
+            @Override public String                    toString()               {return type.toString();}
+            @Override public InternationalString       toInternationalString()  {return type.toInternationalString();}
+            @Override public int                       compareTo(GenericName o) {return type.compareTo(o);}
+        }));
+    }
 }



Mime
View raw message