sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1552879 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-refere...
Date Sat, 21 Dec 2013 06:19:53 GMT
Author: desruisseaux
Date: Sat Dec 21 06:19:52 2013
New Revision: 1552879

URL: http://svn.apache.org/r1552879
Log:
- Moved URIParser.xpointer to its own XPaths internal class.
- Renamed URIParser as DefinitionURI, which describe better what this object is about.
- Replaced the annotation on AbstractIdentifiedObject.identifiers by a pair of getter/setter methods,
  in order to get more control on the URN to be marshalled.

Added:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java
      - copied, changed from r1552063, sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
      - copied, changed from r1552063, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java
      - copied, changed from r1552063, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
      - copied, changed from r1552063, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/XPathsTest.java
      - copied, changed from r1552063, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java
Removed:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -113,8 +113,7 @@ final class PropertyInformation<E> exten
     private Object domainValue;
 
     /**
-     * Creates a new {@code PropertyInformation} instance from the annotations on the given
-     * getter method.
+     * Creates a new {@code PropertyInformation} instance from the annotations on the given getter method.
      *
      * @param  standard    The international standard that define the property, or {@code null} if none.
      * @param  property    The property name as defined by the international {@code standard}.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -16,12 +16,12 @@
  */
 package org.apache.sis.internal.jaxb.referencing;
 
+import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlValue;
 import javax.xml.bind.annotation.XmlAttribute;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.ReferenceIdentifier;
-import javax.xml.bind.annotation.XmlType;
-import org.apache.sis.internal.util.URIParser;
+import org.apache.sis.internal.util.DefinitionURI;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.citation.Citations;
 
@@ -79,7 +79,7 @@ public final class Code {
             if (codeSpace != null) {
                 buffer.append(codeSpace);
             }
-            codeSpace = buffer.append(URIParser.SEPARATOR).append(version).toString();
+            codeSpace = buffer.append(DefinitionURI.SEPARATOR).append(version).toString();
         }
     }
 
@@ -96,14 +96,14 @@ public final class Code {
         }
         Citation authority = null;
         String version = null, cs = codeSpace;
-        final URIParser parsed = URIParser.parse(c);
+        final DefinitionURI parsed = DefinitionURI.parse(c);
         if (parsed != null) {
             authority = Citations.fromName(cs); // May be null.
             cs        = parsed.authority;
             version   = parsed.version;
             c         = parsed.code;
         } else if (cs != null) {
-            final int s = cs.lastIndexOf(URIParser.SEPARATOR);
+            final int s = cs.lastIndexOf(DefinitionURI.SEPARATOR);
             if (s >= 0) {
                 version = cs.substring(s+1);
                 cs = cs.substring(0, s);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -60,7 +60,7 @@ public final class ReferencingUtilities 
 
     /**
      * The URN types for instances of {@link #TYPES}.
-     * See {@link URIParser} javadoc for a list of URN types.
+     * See {@link org.apache.sis.internal.util.DefinitionURI} javadoc for a list of URN types.
      */
     private static final String[] URN_TYPES = {
         "crs",
@@ -100,12 +100,12 @@ public final class ReferencingUtilities 
 
     /**
      * Returns the URN type for the given class, or {@code null} if unknown.
-     * See {@link URIParser} javadoc for a list of URN types.
+     * See {@link org.apache.sis.internal.util.DefinitionURI} javadoc for a list of URN types.
      *
      * @param  type The class for which to get the URN type.
      * @return The URN type, or {@code null} if unknown.
      *
-     * @see org.apache.sis.internal.util.URIParser
+     * @see org.apache.sis.internal.util.DefinitionURI
      */
     public static String toURNType(final Class<?> type) {
         for (int i=0; i<TYPES.length; i++) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -39,7 +39,6 @@ import org.opengis.referencing.Authority
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
-import org.apache.sis.internal.jaxb.referencing.RS_IdentifierSingleton;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.util.Immutable;
@@ -55,6 +54,7 @@ import static org.apache.sis.util.Utilit
 import static org.apache.sis.internal.util.CollectionsExt.nonNull;
 import static org.apache.sis.internal.util.CollectionsExt.nonEmpty;
 import static org.apache.sis.internal.util.CollectionsExt.immutableSet;
+import static org.apache.sis.internal.util.Utilities.appendUnicodeIdentifier;
 
 // Related to JDK7
 import java.util.Objects;
@@ -107,7 +107,7 @@ import java.util.Objects;
 @Immutable
 @ThreadSafe
 @XmlType(name="IdentifiedObjectType", propOrder={
-    "identifiers",
+    "identifier",
     "names",
     "remarks"
 })
@@ -150,19 +150,18 @@ public class AbstractIdentifiedObject ex
      * An identifier which references elsewhere the object's defining information.
      * Alternatively an identifier by which this object can be referenced.
      *
-     * <p>We must be prepared to handle either null or an empty set for
-     * "no identifiers" because we may get both on unmarshalling.</p>
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setIdentifier(ReferenceIdentifier)}</p>
      *
      * @see #getIdentifiers()
+     * @see #getIdentifier()
      */
-    @XmlElement(name = "identifier")
-    @XmlJavaTypeAdapter(RS_IdentifierSingleton.class)
-    private final Set<ReferenceIdentifier> identifiers;
+    private Set<ReferenceIdentifier> identifiers;
 
     /**
      * Comments on or information about this object, or {@code null} if none.
      */
-    @XmlElement(name = "remarks")
+    @XmlElement
     private final InternationalString remarks;
 
     /**
@@ -354,7 +353,7 @@ public class AbstractIdentifiedObject ex
      * separated by hyphens:</p>
      * <ul>
      *   <li>The code space in lower case, retaining only characters that are valid for Unicode identifiers.</li>
-     *   <li>The object type as defined in OGC's URN (see {@link org.apache.sis.internal.util.URIParser})</li>
+     *   <li>The object type as defined in OGC's URN (see {@link org.apache.sis.internal.util.DefinitionURI})</li>
      *   <li>The object code, retaining only characters that are valid for Unicode identifiers.</li>
      * </ul>
      *
@@ -375,9 +374,9 @@ public class AbstractIdentifiedObject ex
          */
         if (identifiers != null) {
             for (final ReferenceIdentifier identifier : identifiers) {
-                if (appendID(id, identifier.getCodeSpace(), true) | // Really |, not ||
-                    appendID(id, ReferencingUtilities.toURNType(getClass()), false) |
-                    appendID(id, identifier.getCode(), true))
+                if (appendUnicodeIdentifier(id, '-', identifier.getCodeSpace(), true) | // Really |, not ||
+                    appendUnicodeIdentifier(id, '-', ReferencingUtilities.toURNType(getClass()), false) |
+                    appendUnicodeIdentifier(id, '-', identifier.getCode(), true))
                 {
                     /*
                      * TODO: If we want to check for ID uniqueness or any other condition before to accept the ID,
@@ -389,47 +388,61 @@ public class AbstractIdentifiedObject ex
             }
         }
         // In last ressort, append code without codespace since the name are often verbose.
-        return appendID(id, name.getCode(), false) ? id.toString() : null;
+        return appendUnicodeIdentifier(id, '-', name.getCode(), false) ? id.toString() : null;
     }
 
     /**
-     * Appends only the characters that are valid for a Unicode identifier.
-     * If the buffer is non-empty and this method added at least one character,
-     * then a hyphen is inserted before the characters added by this method.
+     * Returns a single element from the {@code Set<ReferenceIdentifier>} collection, or {@code null} if none.
+     * We have to define this method because ISO 19111 defines the {@code identifiers} property as a collection
+     * while GML 3.2 defines it as a singleton.
      *
-     * @return {@code true} if at least one character has been added to the buffer.
+     * <p>This method searches for the following identifiers, in preference order:</p>
+     * <ul>
+     *   <li>The first identifier having a code that begin with {@code "urn:"}.</li>
+     *   <li>The first identifier having a code that begin with {@code "http:"}.</li>
+     *   <li>The first identifier, converted to the {@code "urn:} syntax if possible.</li>
+     * </ul>
      */
-    private static boolean appendID(final StringBuilder buffer, final String text, final boolean toLowerCase) {
-        boolean added = false;
-        if (text != null) {
-            for (int i=0; i<text.length();) {
-                final int c = text.codePointAt(i);
-                final boolean isFirst = buffer.length() == 0;
-                if (isFirst ? Character.isUnicodeIdentifierStart(c)
-                            : Character.isUnicodeIdentifierPart(c))
-                {
-                    if (!isFirst && !added) {
-                        buffer.append('-');
-                    }
-                    buffer.appendCodePoint(toLowerCase ? Character.toLowerCase(c) : c);
-                    added = true;
+    @XmlElement(name = "identifier")
+    final ReferenceIdentifier getIdentifier() {
+        if (identifiers != null) {
+            ReferenceIdentifier first = null, fallback = null;
+            for (final ReferenceIdentifier identifier : identifiers) {
+                final String code = identifier.getCode();
+                if (code == null) continue; // Paranoiac check.
+                if (code.regionMatches(true, 0, "urn:", 0, 4)) {
+                    return identifier;
                 }
-                i += Character.charCount(c);
+                if (fallback == null && code.regionMatches(true, 0, "http:", 0, 5)) {
+                    fallback = identifier;
+                }
+                if (first == null) {
+                    first = identifier;
+                }
+            }
+            if (fallback != null) {
+                return fallback;
+            }
+            /*
+             * If no "urn:" or "http:" form has been found, try to create a "urn:" form from the first identifier.
+             * For example "EPSG:4326" may be converted to "urn:ogc:def:crs:EPSG:8.2:4326". If the first identifier
+             * can not be converted to a "urn:" form, then it will be returned as-is.
+             */
+            if (first != null) {
+                // TODO: apply conversion here.
+                return first;
             }
         }
-        return added;
+        return null;
     }
 
     /**
-     * Returns the primary name by which this object is identified.
-     *
-     * @return The primary name.
-     *
-     * @see IdentifiedObjects#getName(IdentifiedObject, Citation)
+     * Invoked by JAXB at unmarshalling time for setting the identifier.
      */
-    @Override
-    public ReferenceIdentifier getName() {
-        return name;
+    private void setIdentifier(final ReferenceIdentifier identifier) {
+        if (identifier != null) {
+            identifiers = Collections.singleton(identifier);
+        }
     }
 
     /**
@@ -472,6 +485,18 @@ public class AbstractIdentifiedObject ex
     }
 
     /**
+     * Returns the primary name by which this object is identified.
+     *
+     * @return The primary name.
+     *
+     * @see IdentifiedObjects#getName(IdentifiedObject, Citation)
+     */
+    @Override
+    public ReferenceIdentifier getName() {
+        return name;
+    }
+
+    /**
      * Returns alternative names by which this object is identified.
      *
      * @return The aliases, or an empty collection if there is none.

Copied: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java (from r1552063, sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java?p2=sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java&p1=sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java&r1=1552063&r2=1552879&rev=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -28,16 +28,16 @@ import static org.junit.Assert.*;
 
 
 /**
- * Tests {@link RS_Identifier}.
+ * Tests {@link Code}, which is used by {@link RS_Identifier}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4
  * @module
  */
-public final strictfp class RS_IdentifierTest extends TestCase {
+public final strictfp class CodeTest extends TestCase {
     /**
-     * Tests {@link RS_Identifier.Value} with {@code "EPSG:4326"}.
+     * Tests with {@code "EPSG:4326"}.
      */
     @Test
     public void testSimple() {
@@ -57,7 +57,7 @@ public final strictfp class RS_Identifie
     }
 
     /**
-     * Tests {@link RS_Identifier.Value} with {@code "EPSG:8.3:4326"}.
+     * Tests with {@code "EPSG:8.3:4326"}.
      */
     @Test
     @DependsOnMethod("testSimple")
@@ -78,8 +78,8 @@ public final strictfp class RS_Identifie
     }
 
     /**
-     * Tests {@link RS_Identifier.Value} with {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
-     * This test simulate the {@code RS_Identifier.Value} object state that we get after
+     * Tests with {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
+     * This test simulate the {@code Code} object state that we get after
      * XML unmarshalling of an object from the EPSG registry.
      */
     @Test

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -19,6 +19,7 @@ package org.apache.sis.referencing;
 import java.util.Set;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.Locale;
 import java.util.Collections;
 import org.opengis.test.Validators;
@@ -44,14 +45,15 @@ import static org.apache.sis.metadata.is
  */
 @DependsOn({
     IdentifiedObjectsTest.class, NamedIdentifierTest.class,
-    org.apache.sis.internal.jaxb.referencing.RS_IdentifierTest.class
+    org.apache.sis.internal.jaxb.referencing.CodeTest.class
 })
 public final strictfp class AbstractIdentifiedObjectTest extends TestCase {
     /**
-     * Tests the {@link AbstractIdentifiedObject#AbstractIdentifiedObject(Map)} constructor.
+     * Creates a map of properties to be given to the {@link AbstractIdentifiedObject} constructor.
+     * The values in the map are consistent with the values expected by the {@link #validate} method.
+     * The map does not contain any {@code "identifiers"} entry.
      */
-    @Test
-    public void testCreateFromMap() {
+    private static Map<String,Object> properties() {
         final Map<String,Object> properties = new HashMap<>(8);
         assertNull(properties.put("name",       "GRS 1980"));
         assertNull(properties.put("codespace",  "EPSG"));
@@ -59,20 +61,19 @@ public final strictfp class AbstractIden
         assertNull(properties.put("alias",      "International 1979"));
         assertNull(properties.put("remarks",    "Adopted by IUGG 1979 Canberra"));
         assertNull(properties.put("remarks_fr", "Adopté par IUGG 1979 Canberra"));
-        validate(new AbstractIdentifiedObject(properties), Collections.<ReferenceIdentifier>emptySet(), "GRS1980");
-        /*
-         * Adds an identifier. This should change the choice made by AbstractIdentifiedObject.getID().
-         */
-        final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "7019");
-        assertNull(properties.put("identifiers", identifier));
-        validate(new AbstractIdentifiedObject(properties), Collections.singleton(identifier), "epsg-7019");
+        return properties;
     }
 
     /**
      * Validates the given object created by {@link #testCreateFromMap()}.
+     *
+     * @param object      The object to validate.
+     * @param identifiers The expected value of {@link AbstractIdentifiedObject#getIdentifiers()}.
+     * @param identifier  The expected value of {@link AbstractIdentifiedObject#getIdentifier()}.
+     * @param gmlID       The expected value of {@link AbstractIdentifiedObject#getID()}.
      */
-    private static void validate(final AbstractIdentifiedObject object,
-            final Set<ReferenceIdentifier> identifiers, final String gmlID)
+    private static void validate(final AbstractIdentifiedObject object, final Set<ReferenceIdentifier> identifiers,
+            final ReferenceIdentifier identifier, final String gmlID)
     {
         Validators.validate(object);
         final ReferenceIdentifier name = object.getName();
@@ -82,38 +83,58 @@ public final strictfp class AbstractIden
         assertEquals("aliases",     "International 1979",            getSingleton(object.getAlias()).toString());
         assertEquals("names",       Collections.singletonList(name), object.getNames());
         assertEquals("identifiers", identifiers,                     object.getIdentifiers());
+        assertEquals("identifier",  identifier,                      object.getIdentifier());
         assertEquals("ID",          gmlID,                           object.getID());
         assertEquals("remarks",     "Adopted by IUGG 1979 Canberra", object.getRemarks().toString(Locale.ENGLISH));
         assertEquals("remarks_fr",  "Adopté par IUGG 1979 Canberra", object.getRemarks().toString(Locale.FRENCH));
     }
 
     /**
-     * Tests identifiers getter. The methods of interest to this test are:
+     * Tests the {@link AbstractIdentifiedObject#AbstractIdentifiedObject(Map)} constructor without identifier.
+     * This method compares the property values against the expected values.
+     */
+    @Test
+    public void testCreateFromMap() {
+        final Map<String,Object> properties = properties();
+        validate(new AbstractIdentifiedObject(properties),
+                 Collections.<ReferenceIdentifier>emptySet(), null, "GRS1980");
+    }
+
+    /**
+     * Tests the {@link AbstractIdentifiedObject#AbstractIdentifiedObject(Map)} constructor
+     * with only one identifier. The methods of interest for this test are:
      *
      * <ul>
      *   <li>{@link AbstractIdentifiedObject#getIdentifiers()}</li>
+     *   <li>{@link AbstractIdentifiedObject#getIdentifier()}</li>
      *   <li>{@link AbstractIdentifiedObject#getID()}</li>
      * </ul>
-     *
-     * Note that {@code getID()} were also tested in {@link #testCreateFromMap()}
-     * but in the absence of identifiers.
      */
     @Test
     @DependsOnMethod("testCreateFromMap")
-    public void testGetIdentifiers() {
-        final Map<String,Object> properties = new HashMap<>(8);
-        assertNull(properties.put("name", "WGS 84"));
-        assertNull(properties.put("identifiers", new NamedIdentifier[] {
-            new NamedIdentifier(EPSG, "4326"),
-            new NamedIdentifier(EPSG, "IgnoreMe")
-        }));
-
-        final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties);
-        Validators.validate(object);
+    public void testCreateWithSingleIdentifier() {
+        final Map<String,Object> properties = properties();
+        final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "7019");
+        assertNull(properties.put("identifiers", identifier));
+        validate(new AbstractIdentifiedObject(properties),
+                 Collections.singleton(identifier), identifier, "epsg-7019");
+    }
 
-        assertEquals("name",        "WGS 84",                     object.getName().getCode());
-        assertEquals("identifiers", "[EPSG:4326, EPSG:IgnoreMe]", object.getIdentifiers().toString());
-        assertEquals("ID",          "epsg-4326",                  object.getID());
+    /**
+     * Tests the {@link AbstractIdentifiedObject#AbstractIdentifiedObject(Map)} constructor
+     * with more than one identifier. This method tries a different identifier implementation
+     * than the {@link #testCreateWithSingleIdentifier()} one.
+     */
+    @Test
+    @DependsOnMethod("testCreateWithSingleIdentifier")
+    public void testCreateWithManyIdentifiers() {
+        final Map<String,Object> properties = properties();
+        final Set<ReferenceIdentifier> identifiers = new LinkedHashSet<>(4);
+        final ReferenceIdentifier identifier = new NamedIdentifier(EPSG, "7019");
+        assertTrue(identifiers.add(identifier));
+        assertTrue(identifiers.add(new NamedIdentifier(EPSG, "IgnoreMe")));
+        assertNull(properties.put("identifiers", identifiers.toArray(new ReferenceIdentifier[2])));
+        validate(new AbstractIdentifiedObject(properties), identifiers, identifier, "epsg-7019");
     }
 
     /**
@@ -122,14 +143,10 @@ public final strictfp class AbstractIden
     @Test
     @DependsOnMethod("testCreateFromMap")
     public void testSerialization() {
-        final Map<String,Object> properties = new HashMap<>(8);
-        assertNull(properties.put("code",      "4326"));
-        assertNull(properties.put("codeSpace", "EPSG"));
-        assertNull(properties.put("remarks",   "There is remarks"));
-
+        final Map<String,Object> properties = properties();
         final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties);
-        Validators.validate(object);
-
-        assertNotSame(object, assertSerializedEquals(object));
+        final AbstractIdentifiedObject actual = assertSerializedEquals(object);
+        assertNotSame(object, actual);
+        validate(actual, Collections.<ReferenceIdentifier>emptySet(), null, "GRS1980");
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -48,7 +48,7 @@ import org.junit.BeforeClass;
     org.apache.sis.io.wkt.ConventionTest.class,
     org.apache.sis.io.wkt.SymbolsTest.class,
     org.apache.sis.io.wkt.FormatterTest.class,
-    org.apache.sis.internal.jaxb.referencing.RS_IdentifierTest.class,
+    org.apache.sis.internal.jaxb.referencing.CodeTest.class,
     org.apache.sis.referencing.IdentifiedObjectsTest.class,
     org.apache.sis.referencing.NamedIdentifierTest.class,
     org.apache.sis.referencing.AbstractIdentifiedObjectTest.class,

Copied: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java (from r1552063, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java?p2=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java&p1=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java&r1=1552063&r2=1552879&rev=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -18,13 +18,15 @@ package org.apache.sis.internal.util;
 
 import java.util.Map;
 import java.util.Collections;
+import org.opengis.referencing.ReferenceIdentifier;
 
 import static org.apache.sis.util.CharSequences.*;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.internal.util.Utilities.appendUnicodeIdentifier;
 
 
 /**
- * Utility methods for parsing OGC's URI (URN or URL). This is not a general-purpose parser.
+ * Utility methods for parsing OGC's URI (URN or URL) in the {@code "urn:ogc:def"} namespace.
  *
  * <p>For example, all the following URIs are for the same object:</p>
  * <ul>
@@ -97,7 +99,7 @@ import static org.apache.sis.util.Argume
  * @see <a href="http://portal.opengeospatial.org/files/?artifact_id=24045">Definition identifier URNs in OGC namespace</a>
  * @see <a href="http://www.opengeospatial.org/ogcna">OGC Naming Authority</a>
  */
-public final class URIParser {
+public final class DefinitionURI {
     /**
      * The URN separator.
      */
@@ -158,7 +160,7 @@ public final class URIParser {
     /**
      * For {@link #parse(String)} usage only.
      */
-    private URIParser() {
+    private DefinitionURI() {
     }
 
     /**
@@ -167,9 +169,9 @@ public final class URIParser {
      * @param  uri The URI to parse.
      * @return The parse result, or {@code null} if the given URI is not recognized.
      */
-    public static URIParser parse(final String uri) {
+    public static DefinitionURI parse(final String uri) {
         ensureNonNull("uri", uri);
-        URIParser result = null;
+        DefinitionURI result = null;
         int upper = -1;
         for (int p=0; p<=6; p++) {
             final int lower = upper + 1;
@@ -188,7 +190,7 @@ public final class URIParser {
                  * to "ogc". The actual verification is performed after the 'switch' case.
                  */
                 case 0: if (regionMatches("http", uri, lower, upper)) {
-                            result = new URIParser();
+                            result = new DefinitionURI();
                             return codeForHTTP(null, null, uri, upper+1, result) != null ? result : null;
                         }
                         require = "urn";   break;
@@ -204,7 +206,7 @@ public final class URIParser {
                         value = null;
                     }
                     switch (p) {
-                        case 3:  result = new URIParser();
+                        case 3:  result = new DefinitionURI();
                                  result.type      = value; break;
                         case 4:  result.authority = value; break;
                         case 5:  result.version   = value; break;
@@ -237,7 +239,7 @@ public final class URIParser {
      * @param  upper     Index after the last character in {@code urn} to compare, ignoring whitespaces.
      * @return {@code true} if the given sub-region of {@code urn} match the given component.
      */
-    private static boolean regionMatches(final String component, final String urn, int lower, int upper) {
+    static boolean regionMatches(final String component, final String urn, int lower, int upper) {
         lower = skipLeadingWhitespaces (urn, lower, upper);
         upper = skipTrailingWhitespaces(urn, lower, upper);
         final int length = upper - lower;
@@ -377,7 +379,7 @@ public final class URIParser {
      * @param result    If non-null, store the type, authority and code in that object.
      */
     private static String codeForHTTP(final String type, String authority, final String url, int lower,
-            final URIParser result)
+            final DefinitionURI result)
     {
         Map<String, String> paths = PATHS;
         if (type != null) {
@@ -431,53 +433,27 @@ public final class URIParser {
     }
 
     /**
-     * Parses a URL which contains a pointer to a XML fragment.
-     * The current implementation recognizes the following types:
+     * Format a {@code "ogc:urn:def:"} identifier. The identifier code space, version and code are
+     * formatted in lower case, ignoring all characters that are not valid for a Unicode identifier.
      *
-     * <ul>
-     *   <li>{@code uom} for Unit Of Measurement (example:
-     *       {@code "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"})</li>
-     * </ul>
-     *
-     * @param  type The object type.
-     * @param  url  The URL to parse.
-     * @return The reference, or {@code null} if none.
-     */
-    public static String xpointer(final String type, final String url) {
-        if (type.equals("uom")) {
-            final int f = url.indexOf('#');
-            if (f >= 1) {
-                /*
-                 * For now we accept any path as long as it ends with the "gmxUom.xml" file
-                 * because resources may be hosted on different servers, or the path may be
-                 * relative instead than absolute.
-                 */
-                int i = url.lastIndexOf('/', f-1) + 1;
-                if (regionMatches("gmxUom.xml", url, i, f) || regionMatches("ML_gmxUom.xml", url, i, f)) {
-                    /*
-                     * The fragment should typically be of the form "xpointer(//*[@gml:id='m'])".
-                     * However sometime we found no "xpointer", but directly the unit instead.
-                     */
-                    i = url.indexOf('(', f+1);
-                    if (i >= 0 && regionMatches("xpointer", url, f+1, i)) {
-                        i = url.indexOf("@gml:id=", i+1);
-                        if (i >= 0) {
-                            i = skipLeadingWhitespaces(url, i+8, url.length()); // 8 is the length of "@gml:id="
-                            final int c = url.charAt(i);
-                            if (c == '\'' || c == '"') {
-                                final int s = url.indexOf(c, ++i);
-                                if (s >= 0) {
-                                    return trimWhitespaces(url, i, s).toString();
-                                }
-                            }
-                        }
-                    } else {
-                        return trimWhitespaces(url, f+1, url.length()).toString();
-                    }
-                }
+     * @param  type The object type, as one of the type documented in class javadoc.
+     * @param  identifier The identifier to format.
+     * @return The URN.
+     */
+    public static String format(final String type, final ReferenceIdentifier identifier) {
+        final StringBuilder buffer = new StringBuilder("urn:ogc:def");
+        for (int p=0; p<4; p++) {
+            final String component;
+            switch (p) {
+                case 0:  component = type;                      break;
+                case 1:  component = identifier.getCodeSpace(); break;
+                case 2:  component = identifier.getVersion();   break;
+                case 3:  component = identifier.getCode();      break;
+                default: throw new AssertionError(p);
             }
+            appendUnicodeIdentifier(buffer.append(SEPARATOR), '\u0000', component, p != 0);
         }
-        return null;
+        return buffer.toString();
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -40,6 +40,52 @@ public final class Utilities extends Sta
     }
 
     /**
+     * Appends to the given buffer only the characters that are valid for a Unicode identifier.
+     * The given separator character is append before the given {@code text} only if the buffer
+     * is not empty and at least one {@code text} character is valid.
+     *
+     * {@section Relationship with <code>gml:id</code>}
+     * This method may be invoked for building {@code gml:id} values. Strictly speaking this is not appropriate
+     * since the {@code xsd:ID} type defines valid identifiers as containing only letters, digits, underscores,
+     * hyphens, and periods. This differ from Unicode identifier in two ways:
+     *
+     * <ul>
+     *   <li>Unicode identifiers accept Japanese or Chinese ideograms for instance, which are considered as letters.</li>
+     *   <li>Unicode identifiers do not accept the {@code '-'} and {@code ':'} characters. However this restriction
+     *       fits well our need, since those characters are typical values for the {@code separator} argument.</li>
+     *   <li>Note that {@code '_'} is valid both in {@code xsd:ID} and Unicode identifier.</li>
+     * </ul>
+     *
+     * @param  appendTo    The buffer where to append the valid characters.
+     * @param  separator   The separator to append before the valid characters, or 0 if none.
+     * @param  text        The text from which to get the valid character to append in the given buffer.
+     * @param  toLowerCase {@code true} for converting the characters to lower case.
+     * @return {@code true} if at least one character has been added to the buffer.
+     */
+    public static boolean appendUnicodeIdentifier(final StringBuilder appendTo,
+            final char separator, final String text, final boolean toLowerCase)
+    {
+        boolean added = false;
+        if (text != null) {
+            for (int i=0; i<text.length();) {
+                final int c = text.codePointAt(i);
+                final boolean isFirst = appendTo.length() == 0;
+                if (isFirst ? Character.isUnicodeIdentifierStart(c)
+                            : Character.isUnicodeIdentifierPart(c))
+                {
+                    if (!isFirst && !added && separator != 0) {
+                        appendTo.append(separator);
+                    }
+                    appendTo.appendCodePoint(toLowerCase ? Character.toLowerCase(c) : c);
+                    added = true;
+                }
+                i += Character.charCount(c);
+            }
+        }
+        return added;
+    }
+
+    /**
      * Returns a string representation of an instance of the given class having the given properties.
      * This is a convenience method for implementation of {@link Object#toString()} methods that are
      * used mostly for debugging purpose.

Copied: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java (from r1552063, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java?p2=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java&p1=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java&r1=1552063&r2=1552879&rev=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/URIParser.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -16,418 +16,25 @@
  */
 package org.apache.sis.internal.util;
 
-import java.util.Map;
-import java.util.Collections;
+import org.apache.sis.util.Static;
 
 import static org.apache.sis.util.CharSequences.*;
-import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.internal.util.DefinitionURI.regionMatches;
 
 
 /**
- * Utility methods for parsing OGC's URI (URN or URL). This is not a general-purpose parser.
- *
- * <p>For example, all the following URIs are for the same object:</p>
- * <ul>
- *   <li>{@code "4326"} (codespace inferred by the caller)</li>
- *   <li>{@code "EPSG:4326"} (older format)</li>
- *   <li>{@code "EPSG::4326"} (often seen for similarity with URN below)</li>
- *   <li>{@code "urn:ogc:def:crs:EPSG::4326"} (version number is omitted)</li>
- *   <li>{@code "urn:ogc:def:crs:EPSG:8.2:4326"} (explicit version number, here 8.2)</li>
- *   <li>{@code "urn:x-ogc:def:crs:EPSG::4326"} (prior registration of {@code "ogc"} to IANA)</li>
- *   <li>{@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}</li>
- * </ul>
- *
- * {@section Components or URN}
- * URN begins with {@code "urn:ogc:def:"} (formerly {@code "urn:x-ogc:def:"}) followed by:
- * <ul>
- *   <li>an object {@linkplain #type}</li>
- *   <li>an {@linkplain #authority}</li>
- *   <li>an optional {@linkplain #version} number (often omitted)</li>
- *   <li>the {@linkplain #code}</li>
- *   <li>an arbitrary amount of {@linkplain #parameters}</li>
- * </ul>
- *
- * The <cite>object type</cite> can be:
- * <table class="sis">
- *   <tr><th>Object type</th>         <th>Meaning</th></tr>
- *   <tr><td>axis</td>                <td>Coordinate system axe definition</td></tr>
- *   <tr><td>axisDirection</td>       <td>Axis direction code definition</td></tr>
- *   <tr><td>coordinateOperation</td> <td>Coordinate operation definition</td></tr>
- *   <tr><td>crs</td>                 <td>Coordinate reference system definition</td></tr>
- *   <tr><td>cs</td>                  <td>Coordinate system definition</td></tr>
- *   <tr><td>datum</td>               <td>Datum definition</td></tr>
- *   <tr><td>dataType</td>            <td>Data type definition</td></tr>
- *   <tr><td>derivedCRSType</td>      <td>Derived CRS type code definition</td></tr>
- *   <tr><td>documentType</td>        <td>Document type definition</td></tr>
- *   <tr><td>ellipsoid</td>           <td>Ellipsoid definition</td></tr>
- *   <tr><td>featureType</td>         <td>Feature type definition</td></tr>
- *   <tr><td>group</td>               <td>Operation parameter group definition</td></tr>
- *   <tr><td>meaning</td>             <td>Parameter meaning definition</td></tr>
- *   <tr><td>meridian</td>            <td>Prime meridian definition</td></tr>
- *   <tr><td>method</td>              <td>Operation method definition</td></tr>
- *   <tr><td>nil</td>                 <td>Explanations for missing information</td></tr>
- *   <tr><td>parameter</td>           <td>Operation parameter definition</td></tr>
- *   <tr><td>phenomenon</td>          <td>Observable property definition</td></tr>
- *   <tr><td>pixelInCell</td>         <td>Pixel in cell code definition</td></tr>
- *   <tr><td>rangeMeaning</td>        <td>Range meaning code definition</td></tr>
- *   <tr><td>referenceSystem</td>     <td>Value reference system definition</td></tr>
- *   <tr><td>uom</td>                 <td>Unit of measure definition</td></tr>
- *   <tr><td>verticalDatumType</td>   <td>Vertical datum type code definition</td></tr>
- * </table>
- *
- * Some example of <cite>authorities</cite> are:
- * <table class="sis">
- *   <tr><th>Authority</th>      <th>Purpose</th></tr>
- *   <tr><td>{@code "OGC"}</td>  <td>Objects defined by the Open Geospatial Consortium.</td></tr>
- *   <tr><td>{@code "EPSG"}</td> <td>Referencing objects defined in the EPSG database.</td></tr>
- *   <tr><td>{@code "EDCS"}</td> <td>Environmental Data Coding Specification.</td></tr>
- *   <tr><td>{@code "SI"}</td>   <td>International System of Units.</td></tr>
- *   <tr><td>{@code "UCUM"}</td> <td>Unified Code for Units of Measure.</td></tr>
- * </table>
- *
- * {@section Combined URNs}
- * This implementation does not handle combined URNs. An example of combined URN would be
- * {@code "urn:ogc:def:crs,crs:EPSG:6.3:27700,crs:EPSG:6.3:5701"}.
+ * Utility methods related to x-paths.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4
  * @module
- *
- * @see <a href="http://portal.opengeospatial.org/files/?artifact_id=24045">Definition identifier URNs in OGC namespace</a>
- * @see <a href="http://www.opengeospatial.org/ogcna">OGC Naming Authority</a>
  */
-public final class URIParser {
-    /**
-     * The URN separator.
-     */
-    public static final char SEPARATOR = ':';
-
-    /**
-     * Server and path portions of HTTP URL for various types (currently {@code "crs"}).
-     * For each URL, value starts after the protocol part and finishes before the authority filename.
-     *
-     * <p>As of Apache SIS 0.4, this map has a single entry. However more entries may be added in future SIS versions.
-     * If new entries are added, then see the TODO comment in the {@link #codeForHTTP(String, String, String, int)}
-     * method.</p>
-     */
-    private static final Map<String,String> PATHS = Collections.singletonMap("crs", "//www.opengis.net/gml/srs/");
-
-    /**
-     * {@code true} if the URI is a {@code "http://www.opengis.net/gml/…"} URL, or
-     * {@code false} if the URI is a {@code "urn:ogc:def:…"} URN.
-     */
-    public boolean isHTTP;
-
-    /**
-     * The type part of a URI, or {@code null} if none (empty).
-     *
-     * {@example In the <code>"urn:ogc:def:crs:EPSG:8.2:4326"</code> URN, this is <code>"crs"</code>}.
-     */
-    public String type;
-
-    /**
-     * The authority part of a URI, or {@code null} if none (empty).
-     *
-     * {@example In the <code>"urn:ogc:def:crs:EPSG:8.2:4326"</code> URN, this is <code>"EPSG"</code>}.
-     */
-    public String authority;
-
-    /**
-     * The version part of a URI, or {@code null} if none (empty).
-     *
-     * {@example In the <code>"urn:ogc:def:crs:EPSG:8.2:4326"</code> URN, this is <code>"8.2"</code>}.
-     */
-    public String version;
-
-    /**
-     * The code part of a URI, or {@code null} if none (empty).
-     *
-     * {@example In the <code>"urn:ogc:def:crs:EPSG:8.2:4326"</code> URN, this is <code>"4326"</code>}.
-     */
-    public String code;
-
-    /**
-     * The parameters, or {@code null} if none.
-     *
-     * {@example In the <code>"urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"</code> URN,
-     *           this is <code>{"1", "-100", "45"}</code>}.
-     */
-    public String[] parameters;
-
-    /**
-     * For {@link #parse(String)} usage only.
-     */
-    private URIParser() {
-    }
-
-    /**
-     * Parses the given URI.
-     *
-     * @param  uri The URI to parse.
-     * @return The parse result, or {@code null} if the given URI is not recognized.
-     */
-    public static URIParser parse(final String uri) {
-        ensureNonNull("uri", uri);
-        URIParser result = null;
-        int upper = -1;
-        for (int p=0; p<=6; p++) {
-            final int lower = upper + 1;
-            upper = uri.indexOf(SEPARATOR, lower);
-            if (upper < 0) {
-                if (p != 6) {
-                    return null; // No more components.
-                }
-                upper = uri.length();
-            }
-            final String require;
-            switch (p) {
-                /*
-                 * Verifies that the 3 first components are ""urn:ogc:def:" without storing them.
-                 * In the particular case of second component, we also accept "x-ogc" in addition
-                 * to "ogc". The actual verification is performed after the 'switch' case.
-                 */
-                case 0: if (regionMatches("http", uri, lower, upper)) {
-                            result = new URIParser();
-                            return codeForHTTP(null, null, uri, upper+1, result) != null ? result : null;
-                        }
-                        require = "urn";   break;
-                case 1: if (regionMatches("ogc", uri, lower, upper)) continue;
-                        require = "x-ogc"; break;
-                case 2: require = "def";   break;
-                default: {
-                    /*
-                     * For all components after the first 3 ones, trim whitespaces and store non-empty values.
-                     */
-                    String value = trimWhitespaces(uri, lower, upper).toString();
-                    if (value.isEmpty()) {
-                        value = null;
-                    }
-                    switch (p) {
-                        case 3:  result = new URIParser();
-                                 result.type      = value; break;
-                        case 4:  result.authority = value; break;
-                        case 5:  result.version   = value; break;
-                        case 6:  result.code      = value; break;
-                        default: throw new AssertionError(p);
-                    }
-                    continue;
-                }
-            }
-            if (!regionMatches(require, uri, lower, upper)) {
-                return null;
-            }
-        }
-        /*
-         * Take every remaining components as parameters.
-         */
-        if (++upper < uri.length()) {
-            result.parameters = (String[]) split(uri.substring(upper), SEPARATOR);
-        }
-        return result;
-    }
-
-    /**
-     * Returns {@code true} if a sub-region of {@code urn} matches the given {@code component},
-     * ignoring case, leading and trailing whitespaces.
-     *
-     * @param  component The expected component ({@code "urn"}, {@code "ogc"}, {@code "def"}, <i>etc.</i>)
-     * @param  urn       The URN for which to test a subregion.
-     * @param  lower     Index of the first character in {@code urn} to compare, after skipping whitespaces.
-     * @param  upper     Index after the last character in {@code urn} to compare, ignoring whitespaces.
-     * @return {@code true} if the given sub-region of {@code urn} match the given component.
-     */
-    private static boolean regionMatches(final String component, final String urn, int lower, int upper) {
-        lower = skipLeadingWhitespaces (urn, lower, upper);
-        upper = skipTrailingWhitespaces(urn, lower, upper);
-        final int length = upper - lower;
-        return (length == component.length()) && urn.regionMatches(true, lower, component, 0, length);
-    }
-
-    /**
-     * Returns the substring of the given URN, ignoring whitespaces and version number if present.
-     * The substring is expected to contains at most one {@code ':'} character. If such separator
-     * character is present, then that character and everything before it are ignored. The ignored
-     * part should be the version number, but this is not verified.
-     *
-     * <p>If the remaining substring is empty or contains more {@code ':'} characters, then this method
-     * returns {@code null}. The presence of more {@code ':'} characters means that the code has parameters,
-     * (e.g. {@code "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"}) which are not handled by this method.</p>
-     *
-     * @param  urn The URN from which to get the code.
-     * @param  fromIndex Index of the first character in {@code urn} to check.
-     * @return The code part of the URN, or {@code null} if empty or invalid.
-     */
-    private static String codeIgnoreVersion(final String urn, int fromIndex) {
-        final int length = urn.length();
-        fromIndex = skipLeadingWhitespaces(urn, fromIndex, length);
-        if (fromIndex >= length) {
-            return null; // Empty code.
-        }
-        final int s = urn.indexOf(SEPARATOR, fromIndex);
-        if (s >= 0) {
-            // Ignore the version number (actually everything up to the first ':').
-            fromIndex = skipLeadingWhitespaces(urn, s+1, length);
-            if (fromIndex >= length || urn.indexOf(SEPARATOR, fromIndex) >= 0) {
-                return null; // Empty code, or the code is followed by parameters.
-            }
-        }
-        return urn.substring(fromIndex, skipTrailingWhitespaces(urn, fromIndex, length));
-    }
-
+public final class XPaths extends Static {
     /**
-     * Returns the code part of the given URI, provided that it matches the given object type and authority.
-     * This lightweight method is useful when:
-     *
-     * <ul>
-     *   <li>the URI is expected to have a specific <cite>object type</cite> and <cite>authority</cite>;</li>
-     *   <li>the version number is considered irrelevant;</li>
-     *   <li>the code is expected to have no parameters.</li>
-     * </ul>
-     *
-     * This method accepts the following URI representations:
-     *
-     * <ul>
-     *   <li>Code alone, without any {@code ':'} character (e.g. {@code "4326"}).</li>
-     *   <li>The given authority followed by the code (e.g. {@code "EPSG:4326"}).</li>
-     *   <li>The URN form (e.g. {@code "urn:ogc:def:crs:EPSG::4326"}), ignoring version number.
-     *       This method accepts also the former {@code "x-ogc"} in place of {@code "ogc"}.</li>
-     *   <li>The HTTP form (e.g. {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}).</li>
-     * </ul>
-     *
-     * @param  type      The expected object type (e.g. {@code "crs"}) in lower cases. See class javadoc for a list of types.
-     * @param  authority The expected authority, typically {@code "epsg"}. See class javadoc for a list of authorities.
-     * @param  uri       The URI to parse.
-     * @return The code part of the given URI, or {@code null} if the codespace does not match the given type
-     *         and authority, the code is empty, or the code is followed by parameters.
+     * Do not allow instantiation of this class.
      */
-    public static String codeOf(final String type, final String authority, final String uri) {
-        ensureNonNull("type",      type);
-        ensureNonNull("authority", authority);
-        ensureNonNull("uri",       uri);
-        /*
-         * Get the part before the first ':' character. If none, assume that the given URI is already the code.
-         * Otherwise the part may be either "http" or "urn" protocol, or the given authority (typically "EPSG").
-         * In the later case, we return immediately the code after the authority part.
-         */
-        int upper = uri.indexOf(SEPARATOR);
-        if (upper < 0) {
-            return trimWhitespaces(uri);
-        }
-        int lower  = skipLeadingWhitespaces(uri, 0, upper);
-        int length = skipTrailingWhitespaces(uri, lower, upper) - lower;
-        if (length == authority.length() && uri.regionMatches(true, lower, authority, 0, length)) {
-            return codeIgnoreVersion(uri, upper+1);
-        }
-        /*
-         * Check for supported protocols: only "urn" and "http" at this time.
-         * All other protocols are rejected as unrecognized.
-         */
-        String component;
-        switch (length) {
-            case 3:  component = "urn";  break;
-            case 4:  component = "http"; break;
-            default: return null;
-        }
-        if (!uri.regionMatches(true, lower, component, 0, length)) {
-            return null;
-        }
-        if (length == 4) {
-            return codeForHTTP(type, authority, uri, upper+1, null);
-        }
-        /*
-         * At this point we have determined that the protocol is URN. The next components after "urn"
-         * shall be "ogc" or "x-ogc", then "def", then the type and authority given in arguments.
-         */
-        for (int p=0; p!=4; p++) {
-            lower = upper + 1;
-            upper = uri.indexOf(SEPARATOR, lower);
-            if (upper < 0) {
-                return null; // No more components.
-            }
-            switch (p) {
-                case 0: if (regionMatches("ogc", uri, lower, upper)) {
-                            continue; // "ogc" is tested before "x-ogc" because more common.
-                        }
-                        component = "x-ogc";   break; // Fallback if the component is not "ogc".
-                case 1: component = "def";     break;
-                case 2: component = type;      break;
-                case 3: component = authority; break;
-                default: throw new AssertionError(p);
-            }
-            if (!regionMatches(component, uri, lower, upper)) {
-                return null;
-            }
-        }
-        return codeIgnoreVersion(uri, upper+1);
-    }
-
-    /**
-     * Implementation of URI parser for the HTTP forms.
-     * The current implementation recognizes the following types:
-     *
-     * <ul>
-     *   <li>{@code crs} for Coordinate Reference System objects
-     *       (example: {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"})</li>
-     * </ul>
-     *
-     * @param type      The expected type in lower cases, or {@code null} for any.
-     * @param authority The expected authority, or {@code null} for any.
-     * @param url       The URL to parse.
-     * @param result    If non-null, store the type, authority and code in that object.
-     */
-    private static String codeForHTTP(final String type, String authority, final String url, int lower,
-            final URIParser result)
-    {
-        Map<String, String> paths = PATHS;
-        if (type != null) {
-            final String path = paths.get(type);
-            if (path == null) {
-                return null;
-            }
-            // TODO: For now do nothing since PATHS is a singleton. However if a future SIS version
-            //       defines more PATHS entries, then we should replace here the 'paths' reference by
-            //       a new Collection.singletonMap containing only the entry of interest.
-        }
-        for (final Map.Entry<String,String> entry : paths.entrySet()) {
-            final String path = entry.getValue();
-            if (url.regionMatches(true, lower, path, 0, path.length())) {
-                lower += path.length();
-                if (authority == null) {
-                    authority = url.substring(lower, skipIdentifierPart(url, lower));
-                } else if (!url.regionMatches(true, lower, authority, 0, authority.length())) {
-                    continue;
-                }
-                lower += authority.length();
-                int upper = url.length();
-                if (lower < upper && url.charAt(lower) == '.') {
-                    // Ignore the extension (typically ".xml", but we accept anything).
-                    if ((lower = url.indexOf('#', lower+1)) >= 0) {
-                        final String code = trimWhitespaces(url, lower+1, upper).toString();
-                        if (result != null) {
-                            result.isHTTP    = true;
-                            result.type      = entry.getKey();
-                            result.authority = authority;
-                            result.code      = code;
-                        }
-                        return code;
-                    }
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Returns the index after the last identifier character.
-     */
-    private static int skipIdentifierPart(final String text, int i) {
-        while (i < text.length()) {
-            final int c = text.codePointAt(i);
-            if (!Character.isUnicodeIdentifierPart(c)) break;
-            i += Character.charCount(c);
-        }
-        return i;
+    private XPaths() {
     }
 
     /**
@@ -479,49 +86,4 @@ public final class URIParser {
         }
         return null;
     }
-
-    /**
-     * Returns a URN representation of this URI.
-     *
-     * @return A URN representation of this URI.
-     */
-    public String toURN() {
-        final StringBuilder buffer = new StringBuilder("urn:ogc:def");
-        int n = 4;
-        if (parameters != null) {
-            n += parameters.length;
-        }
-        for (int p=0; p<n; p++) {
-            String component;
-            switch (p) {
-                case 0:  component = type;            break;
-                case 1:  component = authority;       break;
-                case 2:  component = version;         break;
-                case 3:  component = code;            break;
-                default: component = parameters[p-4]; break;
-            }
-            buffer.append(SEPARATOR);
-            if (component != null) {
-                buffer.append(component);
-            }
-        }
-        return buffer.toString();
-    }
-
-    /**
-     * Returns a string representation of this URI. If the URI were originally a HTTP URL,
-     * then this method format the URI as such. Otherwise this method returns {@link #toURN()}.
-     *
-     * @return The string representation of this URI.
-     */
-    @Override
-    public String toString() {
-        if (isHTTP) {
-            final String path = PATHS.get(type);
-            if (path != null) {
-                return "http:" + path + authority + ".xml#" + code;
-            }
-        }
-        return toURN();
-    }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -31,7 +31,8 @@ import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.util.URIParser;
+import org.apache.sis.internal.util.DefinitionURI;
+import org.apache.sis.internal.util.XPaths;
 
 import static java.lang.Math.PI;
 import static java.lang.Math.abs;
@@ -338,20 +339,20 @@ public final class Units extends Static 
          * If the unit is not an authority code (which is the most common case), then we
          * will check for hard-coded unit symbols.
          *
-         * URIParser.codeOf(…) returns 'uom' directly (provided that whitespaces were already trimmed)
+         * DefinitionURI.codeOf(…) returns 'uom' directly (provided that whitespaces were already trimmed)
          * if no ':' character were found, in which case the string is assumed to be the code directly.
          * This is the intended behavior for AuthorityFactory, but in the particular case of this method
          * we want to try to parse as a xpointer before to give up.
          */
         if (isURI(uom)) {
-            String code = URIParser.codeOf("uom", "EPSG", uom);
+            String code = DefinitionURI.codeOf("uom", "EPSG", uom);
             if (code != null && code != uom) try { // Really identity check, see above comment.
                 return valueOfEPSG(Integer.parseInt(code));
             } catch (NumberFormatException e) {
                 throw new IllegalArgumentException(Errors.format(
                         Errors.Keys.IllegalArgumentValue_2, "uom", uom), e);
             }
-            code = URIParser.xpointer("uom", uom);
+            code = XPaths.xpointer("uom", uom);
             if (code != null) {
                 uom = code;
             }

Copied: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java (from r1552063, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java?p2=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java&p1=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java&r1=1552063&r2=1552879&rev=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.sis.internal.util;
 
+import org.opengis.referencing.ReferenceIdentifier;
+import org.apache.sis.internal.simple.SimpleReferenceIdentifier;
+import org.apache.sis.internal.simple.SimpleCitation;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -24,24 +27,24 @@ import static org.junit.Assert.*;
 
 
 /**
- * Tests {@link URIParser}.
+ * Tests {@link DefinitionURI}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4
  * @module
  */
-public final strictfp class URIParserTest extends TestCase {
+public final strictfp class DefinitionURITest extends TestCase {
     /**
-     * Tests {@link URIParser#parse(String)} on {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
+     * Tests {@link DefinitionURI#parse(String)} on {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
      * This is a URN without parameters defined by EPSG.
      */
     @Test
     public void testParse() {
-        assertNull(URIParser.parse("EPSG:4326"));
+        assertNull(DefinitionURI.parse("EPSG:4326"));
 
-        URIParser parsed = URIParser.parse(" urn:ogc:def: crs : EPSG: 8.2 :4326 ");
-        assertNotNull("URIParser", parsed);
+        DefinitionURI parsed = DefinitionURI.parse(" urn:ogc:def: crs : EPSG: 8.2 :4326 ");
+        assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    false,   parsed.isHTTP);
         assertEquals ("type",      "crs",   parsed.type);
         assertEquals ("authority", "EPSG",  parsed.authority);
@@ -50,8 +53,8 @@ public final strictfp class URIParserTes
         assertNull   ("parameters",         parsed.parameters);
         assertEquals ("toString()", "urn:ogc:def:crs:EPSG:8.2:4326", parsed.toString());
 
-        parsed = URIParser.parse("URN :X-OGC: Def:crs:EPSG::4326");
-        assertNotNull("URIParser", parsed);
+        parsed = DefinitionURI.parse("URN :X-OGC: Def:crs:EPSG::4326");
+        assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    false,   parsed.isHTTP);
         assertEquals ("type",      "crs",   parsed.type);
         assertEquals ("authority", "EPSG",  parsed.authority);
@@ -62,14 +65,14 @@ public final strictfp class URIParserTes
     }
 
     /**
-     * Tests {@link URIParser#parse(String)} on {@code "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"}.
+     * Tests {@link DefinitionURI#parse(String)} on {@code "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"}.
      * This is a URN with parameters defined in WMS specification.
      */
     @Test
     @DependsOnMethod("testParse")
     public void testParseWithParameters() {
-        final URIParser parsed = URIParser.parse("urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45");
-        assertNotNull("URIParser", parsed);
+        final DefinitionURI parsed = DefinitionURI.parse("urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45");
+        assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    false,       parsed.isHTTP);
         assertEquals ("type",      "crs",       parsed.type);
         assertEquals ("authority", "OGC",       parsed.authority);
@@ -81,13 +84,13 @@ public final strictfp class URIParserTes
     }
 
     /**
-     * Tests {@link URIParser#parse(String)} on {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
+     * Tests {@link DefinitionURI#parse(String)} on {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
      */
     @Test
     @DependsOnMethod("testParse")
     public void testParseHTTP() {
-        final URIParser parsed = URIParser.parse("http://www.opengis.net/gml/srs/epsg.xml#4326");
-        assertNotNull("URIParser", parsed);
+        final DefinitionURI parsed = DefinitionURI.parse("http://www.opengis.net/gml/srs/epsg.xml#4326");
+        assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    true,   parsed.isHTTP);
         assertEquals ("type",      "crs",  parsed.type);
         assertEquals ("authority", "epsg", parsed.authority);
@@ -98,59 +101,58 @@ public final strictfp class URIParserTes
     }
 
     /**
-     * Tests {@link URIParser#codeOf(String, String, String)} with URI like {@code "EPSG:4326"}.
+     * Tests {@link DefinitionURI#codeOf(String, String, String)} with URI like {@code "EPSG:4326"}.
      */
     @Test
     public void testCodeOfEPSG() {
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "EPSG:4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "EPSG::4326"));
-        assertNull  (        URIParser.codeOf("crs", "EPSG", "EPSG:::4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "EPSG:8.2:4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", " epsg : 4326 "));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", " epsg :: 4326 "));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", " epsg : : 4326 "));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", "4326"));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", "EPSG:4326"));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", "EPSG::4326"));
+        assertNull  (        DefinitionURI.codeOf("crs", "EPSG", "EPSG:::4326"));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", "EPSG:8.2:4326"));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", " epsg : 4326 "));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", " epsg :: 4326 "));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", " epsg : : 4326 "));
     }
 
     /**
-     * Tests {@link URIParser#codeOf(String, String, String)} with URN like
+     * Tests {@link DefinitionURI#codeOf(String, String, String)} with URN like
      * {@code "urn:ogc:def:crs:EPSG::4326"}.
      */
     @Test
     public void testCodeOfURN() {
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG:4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG::4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG:8.2:4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:x-ogc:def:crs:EPSG::4326"));
-        assertNull  (         URIParser.codeOf("crs", "EPSG", "urn:n-ogc:def:crs:EPSG::4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", " urn : ogc : def : crs : epsg : : 4326"));
-        assertNull  (         URIParser.codeOf("crs", "EPSG", "urn:ogc:def:uom:EPSG:9102"));
-        assertEquals("9102",  URIParser.codeOf("uom", "EPSG", "urn:ogc:def:uom:EPSG:9102"));
-        assertNull  (         URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:OGC:1.3:CRS84"));
-        assertEquals("CRS84", URIParser.codeOf("crs", "OGC",  "urn:ogc:def:crs:OGC:1.3:CRS84"));
-        assertNull  (         URIParser.codeOf("crs", "OGC",  "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"));
+        assertEquals("4326",  DefinitionURI.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG:4326"));
+        assertEquals("4326",  DefinitionURI.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG::4326"));
+        assertEquals("4326",  DefinitionURI.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG:8.2:4326"));
+        assertEquals("4326",  DefinitionURI.codeOf("crs", "EPSG", "urn:x-ogc:def:crs:EPSG::4326"));
+        assertNull  (         DefinitionURI.codeOf("crs", "EPSG", "urn:n-ogc:def:crs:EPSG::4326"));
+        assertEquals("4326",  DefinitionURI.codeOf("crs", "EPSG", " urn : ogc : def : crs : epsg : : 4326"));
+        assertNull  (         DefinitionURI.codeOf("crs", "EPSG", "urn:ogc:def:uom:EPSG:9102"));
+        assertEquals("9102",  DefinitionURI.codeOf("uom", "EPSG", "urn:ogc:def:uom:EPSG:9102"));
+        assertNull  (         DefinitionURI.codeOf("crs", "EPSG", "urn:ogc:def:crs:OGC:1.3:CRS84"));
+        assertEquals("CRS84", DefinitionURI.codeOf("crs", "OGC",  "urn:ogc:def:crs:OGC:1.3:CRS84"));
+        assertNull  (         DefinitionURI.codeOf("crs", "OGC",  "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"));
     }
 
     /**
-     * Tests {@link URIParser#codeOf(String, String, String)} with URL like
+     * Tests {@link DefinitionURI#codeOf(String, String, String)} with URL like
      * {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
      */
     @Test
     public void testCodeOfHTTP() {
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
-        assertNull  (        URIParser.codeOf("crs", "OGC",  "http://www.opengis.net/gml/srs/epsg.xml#4326"));
-        assertNull  (        URIParser.codeOf("uom", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
-        assertNull  (        URIParser.codeOf("uom", "EPSG", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
+        assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
+        assertNull  (        DefinitionURI.codeOf("crs", "OGC",  "http://www.opengis.net/gml/srs/epsg.xml#4326"));
+        assertNull  (        DefinitionURI.codeOf("uom", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
+        assertNull  (        DefinitionURI.codeOf("uom", "EPSG", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
     }
 
     /**
-     * Tests {@link URIParser#xpointer(String, String)}.
+     * Tests {@link DefinitionURI#format(String, ReferenceIdentifier)}.
      */
     @Test
-    public void testXPointer() {
-        assertEquals("m", URIParser.xpointer("uom", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#m"));
-        assertEquals("m", URIParser.xpointer("uom", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
-        assertEquals("m", URIParser.xpointer("uom", "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/uom/ML_gmxUom.xml#xpointer(//*[@gml:id='m'])"));
-        assertEquals("m", URIParser.xpointer("uom", "../uom/ML_gmxUom.xml#xpointer(//*[@gml:id='m'])"));
+    public void testFormatIdentifier() {
+        final SimpleCitation epsg = new SimpleCitation("EPSG");
+        assertEquals("urn:ogc:def:crs:epsg::4326",
+                DefinitionURI.format("crs", new SimpleReferenceIdentifier(epsg, "4326")));
     }
 }

Copied: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/XPathsTest.java (from r1552063, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/XPathsTest.java?p2=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/XPathsTest.java&p1=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java&r1=1552063&r2=1552879&rev=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/URIParserTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/XPathsTest.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.internal.util;
 
-import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -24,133 +23,22 @@ import static org.junit.Assert.*;
 
 
 /**
- * Tests {@link URIParser}.
+ * Tests {@link XPaths}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4
  * @module
  */
-public final strictfp class URIParserTest extends TestCase {
+public final strictfp class XPathsTest extends TestCase {
     /**
-     * Tests {@link URIParser#parse(String)} on {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
-     * This is a URN without parameters defined by EPSG.
-     */
-    @Test
-    public void testParse() {
-        assertNull(URIParser.parse("EPSG:4326"));
-
-        URIParser parsed = URIParser.parse(" urn:ogc:def: crs : EPSG: 8.2 :4326 ");
-        assertNotNull("URIParser", parsed);
-        assertEquals ("isHTTP",    false,   parsed.isHTTP);
-        assertEquals ("type",      "crs",   parsed.type);
-        assertEquals ("authority", "EPSG",  parsed.authority);
-        assertEquals ("version",   "8.2",   parsed.version);
-        assertEquals ("code",      "4326",  parsed.code);
-        assertNull   ("parameters",         parsed.parameters);
-        assertEquals ("toString()", "urn:ogc:def:crs:EPSG:8.2:4326", parsed.toString());
-
-        parsed = URIParser.parse("URN :X-OGC: Def:crs:EPSG::4326");
-        assertNotNull("URIParser", parsed);
-        assertEquals ("isHTTP",    false,   parsed.isHTTP);
-        assertEquals ("type",      "crs",   parsed.type);
-        assertEquals ("authority", "EPSG",  parsed.authority);
-        assertNull   ("version",            parsed.version);
-        assertEquals ("code",      "4326",  parsed.code);
-        assertNull   ("parameters",         parsed.parameters);
-        assertEquals ("toString()", "urn:ogc:def:crs:EPSG::4326", parsed.toString());
-    }
-
-    /**
-     * Tests {@link URIParser#parse(String)} on {@code "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"}.
-     * This is a URN with parameters defined in WMS specification.
-     */
-    @Test
-    @DependsOnMethod("testParse")
-    public void testParseWithParameters() {
-        final URIParser parsed = URIParser.parse("urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45");
-        assertNotNull("URIParser", parsed);
-        assertEquals ("isHTTP",    false,       parsed.isHTTP);
-        assertEquals ("type",      "crs",       parsed.type);
-        assertEquals ("authority", "OGC",       parsed.authority);
-        assertEquals ("version",   "1.3",       parsed.version);
-        assertEquals ("code",      "AUTO42003", parsed.code);
-        assertNotNull("parameters",             parsed.parameters);
-        assertArrayEquals("parameters", new String[] {"1", "-100", "45"}, parsed.parameters);
-        assertEquals("toString()", "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45", parsed.toString());
-    }
-
-    /**
-     * Tests {@link URIParser#parse(String)} on {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
-     */
-    @Test
-    @DependsOnMethod("testParse")
-    public void testParseHTTP() {
-        final URIParser parsed = URIParser.parse("http://www.opengis.net/gml/srs/epsg.xml#4326");
-        assertNotNull("URIParser", parsed);
-        assertEquals ("isHTTP",    true,   parsed.isHTTP);
-        assertEquals ("type",      "crs",  parsed.type);
-        assertEquals ("authority", "epsg", parsed.authority);
-        assertNull   ("version",           parsed.version);
-        assertEquals ("code",      "4326", parsed.code);
-        assertNull   ("parameters",        parsed.parameters);
-        assertEquals ("toString()", "http://www.opengis.net/gml/srs/epsg.xml#4326", parsed.toString());
-    }
-
-    /**
-     * Tests {@link URIParser#codeOf(String, String, String)} with URI like {@code "EPSG:4326"}.
-     */
-    @Test
-    public void testCodeOfEPSG() {
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "EPSG:4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "EPSG::4326"));
-        assertNull  (        URIParser.codeOf("crs", "EPSG", "EPSG:::4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "EPSG:8.2:4326"));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", " epsg : 4326 "));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", " epsg :: 4326 "));
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", " epsg : : 4326 "));
-    }
-
-    /**
-     * Tests {@link URIParser#codeOf(String, String, String)} with URN like
-     * {@code "urn:ogc:def:crs:EPSG::4326"}.
-     */
-    @Test
-    public void testCodeOfURN() {
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG:4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG::4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:EPSG:8.2:4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", "urn:x-ogc:def:crs:EPSG::4326"));
-        assertNull  (         URIParser.codeOf("crs", "EPSG", "urn:n-ogc:def:crs:EPSG::4326"));
-        assertEquals("4326",  URIParser.codeOf("crs", "EPSG", " urn : ogc : def : crs : epsg : : 4326"));
-        assertNull  (         URIParser.codeOf("crs", "EPSG", "urn:ogc:def:uom:EPSG:9102"));
-        assertEquals("9102",  URIParser.codeOf("uom", "EPSG", "urn:ogc:def:uom:EPSG:9102"));
-        assertNull  (         URIParser.codeOf("crs", "EPSG", "urn:ogc:def:crs:OGC:1.3:CRS84"));
-        assertEquals("CRS84", URIParser.codeOf("crs", "OGC",  "urn:ogc:def:crs:OGC:1.3:CRS84"));
-        assertNull  (         URIParser.codeOf("crs", "OGC",  "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"));
-    }
-
-    /**
-     * Tests {@link URIParser#codeOf(String, String, String)} with URL like
-     * {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
-     */
-    @Test
-    public void testCodeOfHTTP() {
-        assertEquals("4326", URIParser.codeOf("crs", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
-        assertNull  (        URIParser.codeOf("crs", "OGC",  "http://www.opengis.net/gml/srs/epsg.xml#4326"));
-        assertNull  (        URIParser.codeOf("uom", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
-        assertNull  (        URIParser.codeOf("uom", "EPSG", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
-    }
-
-    /**
-     * Tests {@link URIParser#xpointer(String, String)}.
+     * Tests {@link XPaths#xpointer(String, String)}.
      */
     @Test
     public void testXPointer() {
-        assertEquals("m", URIParser.xpointer("uom", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#m"));
-        assertEquals("m", URIParser.xpointer("uom", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
-        assertEquals("m", URIParser.xpointer("uom", "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/uom/ML_gmxUom.xml#xpointer(//*[@gml:id='m'])"));
-        assertEquals("m", URIParser.xpointer("uom", "../uom/ML_gmxUom.xml#xpointer(//*[@gml:id='m'])"));
+        assertEquals("m", XPaths.xpointer("uom", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#m"));
+        assertEquals("m", XPaths.xpointer("uom", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
+        assertEquals("m", XPaths.xpointer("uom", "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/uom/ML_gmxUom.xml#xpointer(//*[@gml:id='m'])"));
+        assertEquals("m", XPaths.xpointer("uom", "../uom/ML_gmxUom.xml#xpointer(//*[@gml:id='m'])"));
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -50,7 +50,8 @@ import static org.apache.sis.test.Assert
  */
 @DependsOn({
     SexagesimalConverterTest.class,
-    org.apache.sis.internal.util.URIParserTest.class
+    org.apache.sis.internal.util.DefinitionURITest.class,
+    org.apache.sis.internal.util.XPathsTest.class
 })
 public final strictfp class UnitsTest extends TestCase {
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1552879&r1=1552878&r2=1552879&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] Sat Dec 21 06:19:52 2013
@@ -78,7 +78,8 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.util.CollectionsExtTest.class,
 
     // GeoAPI most basic types.
-    org.apache.sis.internal.util.URIParserTest.class,
+    org.apache.sis.internal.util.DefinitionURITest.class,
+    org.apache.sis.internal.util.XPathsTest.class,
     org.apache.sis.util.iso.TypesTest.class,
     org.apache.sis.util.iso.SimpleInternationalStringTest.class,
     org.apache.sis.util.iso.DefaultInternationalStringTest.class,



Mime
View raw message