/** * Returns a view of this name as a fully-qualified name. The {@linkplain #scope() scope} * of a fully qualified name will be {@linkplain NameSpace#isGlobal() global}. If the scope * of this name is already global, then this method returns {@code this}. * * @return the fully-qualified name (never {@code null}). */ @Override public GenericName toFullyQualifiedName() { if (scope == null || scope.isGlobal()) { return this; } throw new UnsupportedOperationException(); }
/** * Null-safe getter for the namespace argument to be given to {@link #toClass(String, String)}. */ static String namespace(final NameSpace ns) { if (ns != null && !ns.isGlobal()) { final GenericName name = ns.name(); if (name != null) { return name.toString(); } } return null; }
/** * Null-safe getter for the namespace argument to be given to {@link #toClass(String, String)}. */ static String namespace(final NameSpace ns) { if (ns != null && !ns.isGlobal()) { final GenericName name = ns.name(); if (name != null) { return name.toString(); } } return null; }
/** * Returns the scope of the given name if it is not global. * This method is null-safe, including paranoiac checks against null scope. * * @param name the name from which to get the scope, or {@code null}. * @return the scope of the given name, or {@code null} if the given name was null or has a global scope. */ private static GenericName scope(final GenericName name) { if (name != null) { final NameSpace scope = name.scope(); if (scope != null && !scope.isGlobal()) { return scope.name(); } } return null; }
/** * Returns the scope of the given name if it is not global. * This method is null-safe, including paranoiac checks against null scope. * * @param name the name from which to get the scope, or {@code null}. * @return the scope of the given name, or {@code null} if the given name was null or has a global scope. */ private static GenericName scope(final GenericName name) { if (name != null) { final NameSpace scope = name.scope(); if (scope != null && !scope.isGlobal()) { return scope.name(); } } return null; }
/** * Returns a view of this name as a fully-qualified name. The {@linkplain #scope() scope} * of a fully qualified name is {@linkplain DefaultNameSpace#isGlobal() global}. If the * scope of this name is already global, then this method returns {@code this}. */ @Override public synchronized GenericName toFullyQualifiedName() { if (fullyQualified == null) { final NameSpace scope = scope(); if (scope.isGlobal()) { fullyQualified = this; } else { final GenericName prefix = scope.name(); assert prefix.scope().isGlobal() : prefix; fullyQualified = new DefaultScopedName(prefix, this); } } return fullyQualified; }
/** * Formats the given name in <cite>expanded form</cite> close to the Java Content Repository (JCR) definition. * The expanded form is defined as below: * * <blockquote><pre> ExpandedName ::= '{' NameSpace '}' LocalPart * NameSpace ::= name.{@linkplain AbstractName#scope() scope()}.{@linkplain DefaultNameSpace#name() name()}.toString() * LocalPart ::= name.{@linkplain AbstractName#toString() toString()}</pre></blockquote> * * @param name the generic name to format in expanded form, or {@code null}. * @return expanded form of the given generic name, or {@code null} if the given name was null. * * @see DefaultNameSpace#toString() */ public static String toExpandedString(final GenericName name) { if (name == null) { return null; } final String localPart = name.toString(); final NameSpace scope = name.scope(); if (scope == null || scope.isGlobal()) { return localPart; } final String ns = scope.name().toString(); return new StringBuilder(ns.length() + localPart.length() + 2) .append('{').append(ns).append('}').append(localPart).toString(); } }
/** * Formats the given name in <cite>expanded form</cite> close to the Java Content Repository (JCR) definition. * The expanded form is defined as below: * * <blockquote><pre> ExpandedName ::= '{' NameSpace '}' LocalPart * NameSpace ::= name.{@linkplain AbstractName#scope() scope()}.{@linkplain DefaultNameSpace#name() name()}.toString() * LocalPart ::= name.{@linkplain AbstractName#toString() toString()}</pre></blockquote> * * @param name the generic name to format in expanded form, or {@code null}. * @return expanded form of the given generic name, or {@code null} if the given name was null. * * @see DefaultNameSpace#toString() */ public static String toExpandedString(final GenericName name) { if (name == null) { return null; } final String localPart = name.toString(); final NameSpace scope = name.scope(); if (scope == null || scope.isGlobal()) { return localPart; } final String ns = scope.name().toString(); return new StringBuilder(ns.length() + localPart.length() + 2) .append('{').append(ns).append('}').append(localPart).toString(); } }
/** * Returns a view of this name as a fully-qualified name. The {@linkplain #scope() scope} * of a fully qualified name is {@linkplain DefaultNameSpace#isGlobal() global}. * If the scope of this name is already global, then this method returns {@code this}. * * @return the fully-qualified name (never {@code null}). */ @Override public synchronized GenericName toFullyQualifiedName() { if (fullyQualified == null) { final NameSpace scope = scope(); if (scope.isGlobal()) { fullyQualified = this; } else { final GenericName prefix = scope.name(); assert prefix.scope().isGlobal() : prefix; fullyQualified = new DefaultScopedName(prefix, this); } } return fullyQualified; }
/** * Returns a view of this name as a fully-qualified name. The {@linkplain #scope() scope} * of a fully qualified name is {@linkplain DefaultNameSpace#isGlobal() global}. * If the scope of this name is already global, then this method returns {@code this}. * * @return the fully-qualified name (never {@code null}). */ @Override public synchronized GenericName toFullyQualifiedName() { if (fullyQualified == null) { final NameSpace scope = scope(); if (scope.isGlobal()) { fullyQualified = this; } else { final GenericName prefix = scope.name(); assert prefix.scope().isGlobal() : prefix; fullyQualified = new DefaultScopedName(prefix, this); } } return fullyQualified; }
/** * Sets the value from the given name. * * @param name the name to marshal. */ public final void setName(final GenericName name) { this.value = name.toString(); final NameSpace scope = name.scope(); if (scope != null && !scope.isGlobal()) { codeSpace = scope.name().toString(); } }
/** * Sets the value from the given name. * * @param name the name to marshal. */ public final void setName(final GenericName name) { this.value = name.toString(); final NameSpace scope = name.scope(); if (scope != null && !scope.isGlobal()) { codeSpace = scope.name().toString(); } }
/** * Ensures that ISO 19103 or GeoAPI restrictions apply. * * @param object The object to validate, or {@code null}. */ public void validate(final NameSpace object) { if (object == null) { return; } final GenericName name = object.name(); mandatory("NameSpace: must have a name.", name); if (name != null) { final NameSpace scope = name.scope(); mandatory("NameSpace: must have a scope.", scope); if (scope != null) { assertTrue("NameSpace: scope must be global.", scope.isGlobal()); } // Following test is a consequence of the previous one, so we check the scope first in // order to report the error as a bad scope before to reference this GeoAPI extension. assertSame("NameSpace: the name must be fully qualified.", name, name.toFullyQualifiedName()); } if (object.isGlobal()) { assertInstanceOf("NameSpace: global namespace must have a local name.", LocalName.class, name); } validate(name, name.getParsedNames()); }
/** * Tests {@link Builder#addName(Citation, CharSequence)} and {@link Builder#addName(CharSequence)} with codespace. */ @Test @DependsOnMethod({"testAddName", "testSetCodeSpace"}) public void testAddNameWithScope() { final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class); // Expected values to be used later in the test. final String name = "Mercator (variant A)"; final GenericName alias1 = factory.createLocalName(scope(factory, "EPSG"), "Mercator (1SP)"); final GenericName alias2 = new NamedIdentifier(Citations.OGC, "Mercator_1SP"); final GenericName alias3 = new NamedIdentifier(Citations.GEOTIFF, "CT_Mercator"); assertTrue ("That name should not have a scope.", alias3.scope().isGlobal()); assertTrue ("That name should not have a scope.", alias2.scope().isGlobal()); assertFalse("That name should be in EPSG scope.", alias1.scope().isGlobal()); assertEquals("EPSG", alias1.scope().name().toString()); assertEquals("Mercator (1SP)", alias1.toString()); assertEquals("OGC:Mercator_1SP", alias2.toString()); assertEquals("GeoTIFF:CT_Mercator", alias3.toString()); // The test. final BuilderMock builder = createMercator(true, false); assertEquals(name, builder.getName()); assertArrayEquals(new GenericName[] {alias1, alias2, alias3}, builder.getAliases()); }
/** * Tests {@link Builder#addName(CharSequence)} without codespace. */ @Test public void testAddName() { final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class); // Expected values to be used later in the test. final String name = "Mercator (variant A)"; final LocalName alias1 = factory.createLocalName(null, "Mercator (1SP)"); final LocalName alias2 = factory.createLocalName(null, "Mercator_1SP"); final LocalName alias3 = factory.createLocalName(null, "CT_Mercator"); assertTrue("That name should not have a scope.", alias1.scope().isGlobal()); assertTrue("That name should not have a scope.", alias2.scope().isGlobal()); assertTrue("That name should not have a scope.", alias3.scope().isGlobal()); assertEquals("Mercator (1SP)", alias1.toString()); assertEquals("Mercator_1SP", alias2.toString()); assertEquals("CT_Mercator", alias3.toString()); // The test. final BuilderMock builder = new BuilderMock(); assertSame(builder, builder.addName("Mercator (variant A)")); // EPSG version 7.6 and later. assertSame(builder, builder.addName("Mercator (1SP)")); // EPSG before version 7.6. assertSame(builder, builder.addName("Mercator_1SP")); // OGC assertSame(builder, builder.addName("CT_Mercator")); // GeoTIFF builder.onCreate(false); assertEquals(name, builder.getName()); assertArrayEquals(new GenericName[] {alias1, alias2, alias3}, builder.getAliases()); }
/** * Tests the creation of {@code "EPSG:4326"} as local names. First the {@code "EPSG"} * namespace is created. Then a {@code "4326"} local name is created in that namespace. * This test uses the following factory methods: * <p> * <ul> * <li>{@link NameFactory#createLocalName}</li> * <li>{@link NameFactory#createNameSpace}</li> * </ul> */ @Test public void testLocalName() { assumeNotNull(factory); final String EPSG = "EPSG"; final LocalName authority = factory.createLocalName(null, EPSG); validate(authority); assertTrue(authority.scope().isGlobal()); assertEquals(EPSG, authority.toString()); assertEquals(EPSG, authority.toInternationalString().toString()); final NameSpace ns = createNameSpace(authority, ":", ":"); validate(ns); assertEquals(authority, ns.name()); final String WGS84 = "4326"; final LocalName code = factory.createLocalName(ns, WGS84); validate(code); assertEquals(ns, code.scope()); assertEquals(WGS84, code.toString()); assertEquals(EPSG + ':' + WGS84, code.toFullyQualifiedName().toString()); }
/** * Tests the creation of {@code "EPSG:4326"} as local names. First the {@code "EPSG"} * namespace is created. Then a {@code "4326"} local name is created in that namespace. * This test uses the following factory methods: * * <ul> * <li>{@link NameFactory#createLocalName(NameSpace, CharSequence)}</li> * <li>{@link NameFactory#createNameSpace(GenericName, Map)}</li> * </ul> */ @Test public void testLocalName() { assumeNotNull(factory); final String EPSG = "EPSG"; final LocalName authority = factory.createLocalName(null, EPSG); validators.validate(authority); assertTrue(authority.scope().isGlobal()); assertEquals(EPSG, authority.toString()); assertEquals(EPSG, authority.toInternationalString().toString()); final NameSpace ns = createNameSpace(authority, ":", ":"); validators.validate(ns); assertEquals(authority, ns.name()); final String WGS84 = "4326"; final LocalName code = factory.createLocalName(ns, WGS84); validators.validate(code); assertEquals(ns, code.scope()); assertEquals(WGS84, code.toString()); assertEquals(EPSG + ':' + WGS84, code.toFullyQualifiedName().toString()); }
/** * Tests the {@link NamedIdentifier#NamedIdentifier(Citation, String, CharSequence, String, InternationalString)} * constructor. */ @Test public void testCreateFromCode() { final NamedIdentifier identifier = new NamedIdentifier(Citations.EPSG, "EPSG", "4326", "8.3", null); Validators.validate((ReferenceIdentifier) identifier); Validators.validate((GenericName) identifier); // ImmutableIdentifier properties assertEquals("code", "4326", identifier.getCode()); assertEquals("codeSpace", "EPSG", identifier.getCodeSpace()); assertSame ("authority", Citations.EPSG, identifier.getAuthority()); assertEquals("version", "8.3", identifier.getVersion()); assertNull ("description", identifier.getDescription()); // NamedIdentifier properties assertEquals("depth", 2, identifier.depth()); assertEquals("tip", "4326", identifier.tip().toString()); assertEquals("head", "EPSG", identifier.head().toString()); assertEquals("name", "EPSG:4326", identifier.toString()); assertTrue ("scope.isGlobal", identifier.scope().isGlobal()); }
/** * Tests the {@link NamedIdentifier#NamedIdentifier(GenericName)} constructor. */ @Test public void testCreateFromName() { final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class); final NameSpace scope = factory.createNameSpace(factory.createLocalName(null, "IOGP"), null); final NamedIdentifier identifier = new NamedIdentifier(factory.createGenericName(scope, "EPSG", "4326")); Validators.validate((ReferenceIdentifier) identifier); Validators.validate((GenericName) identifier); // ImmutableIdentifier properties assertEquals("code", "4326", identifier.getCode()); assertEquals("codeSpace", "EPSG", identifier.getCodeSpace()); assertEquals("authority", "IOGP", Citations.toCodeSpace(identifier.getAuthority())); assertNull ("version", identifier.getVersion()); assertNull ("description", identifier.getDescription()); // NamedIdentifier properties assertEquals("depth", 2, identifier.depth()); assertEquals("tip", "4326", identifier.tip().toString()); assertEquals("head", "EPSG", identifier.head().toString()); assertEquals("name", "EPSG:4326", identifier.toString()); assertSame ("scope", scope, identifier.scope()); assertFalse ("scope.isGlobal", scope.isGlobal()); assertEquals("scope", "IOGP", scope.name().toString()); }
/** * Tests the {@link NamedIdentifier#NamedIdentifier(Citation, CharSequence)} constructor. */ @Test @DependsOnMethod("testCreateFromCode") public void testCreateFromInternationalString() { final NamedIdentifier identifier = createI18N(); Validators.validate((ReferenceIdentifier) identifier); Validators.validate((GenericName) identifier); // ImmutableIdentifier properties assertEquals("code", "name", identifier.getCode()); assertEquals("codeSpace", "EPSG", identifier.getCodeSpace()); assertSame ("authority", Citations.EPSG, identifier.getAuthority()); assertNull ("version", identifier.getVersion()); assertNull ("description", identifier.getDescription()); // NamedIdentifier properties assertEquals("depth", 2, identifier.depth()); assertEquals("tip", "name", identifier.tip().toInternationalString().toString(Locale.ENGLISH)); assertEquals("tip", "nom", identifier.tip().toInternationalString().toString(Locale.FRENCH)); assertEquals("tip", "名前", identifier.tip().toInternationalString().toString(Locale.JAPANESE)); assertEquals("head", "EPSG", identifier.head().toString()); assertEquals("name", "EPSG:name", identifier.toInternationalString().toString(Locale.ENGLISH)); assertEquals("name", "EPSG:nom", identifier.toInternationalString().toString(Locale.FRENCH)); assertEquals("name", "EPSG:名前", identifier.toInternationalString().toString(Locale.JAPANESE)); assertTrue ("scope.isGlobal", identifier.scope().isGlobal()); }