sis-commits mailing list archives

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

URL: http://svn.apache.org/r1624885
Log:
More robust check about whether it is safe to associate a value class to a TypeName.

Modified:
    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/TypeNames.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypeNamesTest.java

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=1624885&r1=1624884&r2=1624885&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 17:53:59 2014
@@ -451,10 +451,6 @@ public class DefaultNameFactory extends 
                 }
             }
         }
-        final TypeName name = t.toTypeName(this, valueClass);
-        if (name instanceof DefaultTypeName) {
-            ((DefaultTypeName) name).valueClass = valueClass;
-        }
-        return name;
+        return t.toTypeName(this, 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=1624885&r1=1624884&r2=1624885&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 17:53:59 2014
@@ -93,9 +93,10 @@ public class DefaultTypeName extends Def
      * This is necessary {@link DefaultNameFactory#pool} cache integrity. Users who want
to explicitely
      * specify their own value class can override {@link #toClass()} instead.</p>
      *
+     * @see #setValueClass(NameSpace, String, Class)
      * @see #toClass()
      */
-    transient Class<?> valueClass;
+    private transient Class<?> valueClass;
 
     /**
      * Empty constructor to be used by JAXB only. Despite its "final" declaration,
@@ -143,6 +144,19 @@ public class DefaultTypeName extends Def
     }
 
     /**
+     * Sets {@link #valueClass} to the given value, only if the scope and the name of this
{@code TypeName}
+     * are equal to the given values. The check for scope and name is a protection against
renaming that user
+     * could apply if they subclass {@link DefaultNameFactory}. If the user performed such
renaming, then the
+     * value class may be wrong, so we will ignore the given value class and let {@link #toClass()}
computes
+     * the class itself.
+     */
+    final void setValueClass(final NameSpace scope, final String name, final Class<?>
valueClass) {
+        if (scope == super.scope() && name.equals(super.toString())) {
+            this.valueClass = valueClass;
+        }
+    }
+
+    /**
      * Returns the Java class associated to this type name.
      * The default implementation performs the following choices:
      *

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/TypeNames.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/TypeNames.java?rev=1624885&r1=1624884&r2=1624885&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/TypeNames.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/TypeNames.java
[UTF-8] Sun Sep 14 17:53:59 2014
@@ -123,7 +123,14 @@ final class TypeNames {
                 name = valueClass.getCanonicalName();
             }
         }
-        return factory.createTypeName(ns, name);
+        /*
+         * Now create the name and remember the 'valueClass' for that name if the implementation
allows that.
+         */
+        final TypeName t = factory.createTypeName(ns, name);
+        if (t instanceof DefaultTypeName) {
+            ((DefaultTypeName) t).setValueClass(ns, name, valueClass);
+        }
+        return t;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypeNamesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypeNamesTest.java?rev=1624885&r1=1624884&r2=1624885&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypeNamesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypeNamesTest.java
[UTF-8] Sun Sep 14 17:53:59 2014
@@ -55,7 +55,7 @@ public final strictfp class TypeNamesTes
     {
         final TypeName type = DefaultFactories.SIS_NAMES.toTypeName(valueClass);
         assertNotNull(name, type);
-        assertSame   (name, valueClass, ((DefaultTypeName) type).valueClass);
+        assertSame   (name, valueClass, ((DefaultTypeName) type).toClass());
         assertEquals (name, namespace,  type.scope().name().toString());
         assertEquals (name, name,       type.toString());
         assertEquals (name, valueClass, TypeNames.toClass(namespace, name));



Mime
View raw message