Search in sources :

Example 6 with LocalName

use of org.opengis.util.LocalName in project sis by apache.

the class NameMarshallingTest method testLocalNameWithScope.

/**
 * Tests XML of a {@link LocalName} with a scope.
 *
 * @throws JAXBException if (un)marshalling failed.
 */
@Test
@DependsOnMethod("testLocalName")
public void testLocalNameWithScope() throws JAXBException {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final NameSpace scope = factory.createNameSpace(factory.createLocalName(null, "A code space"), null);
    final LocalName name = factory.createLocalName(scope, "A name in a scope");
    assertEquals("A name in a scope", name.toString());
    final String expected = "<gml:IO_IdentifiedObject xmlns:gml=\"" + Namespaces.GML + '"' + " xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" + "  <gml:alias>\n" + "    <gco:LocalName codeSpace=\"A code space\">A name in a scope</gco:LocalName>\n" + "  </gml:alias>\n" + "</gml:IO_IdentifiedObject>\n";
    final String actual = marshal(name);
    assertXmlEquals(expected, actual, "xmlns:*");
    assertEquals(name, unmarshal(expected));
}
Also used : NameSpace(org.opengis.util.NameSpace) NameFactory(org.opengis.util.NameFactory) LocalName(org.opengis.util.LocalName) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 7 with LocalName

use of org.opengis.util.LocalName in project sis by apache.

the class NameMarshallingTest method testLocalName.

/**
 * Tests XML of a {@link LocalName}.
 *
 * @throws JAXBException if (un)marshalling failed.
 */
@Test
public void testLocalName() throws JAXBException {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final LocalName name = factory.createLocalName(null, "An ordinary local name");
    assertEquals("An ordinary local name", name.toString());
    final String expected = "<gml:IO_IdentifiedObject xmlns:gml=\"" + Namespaces.GML + '"' + " xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" + "  <gml:alias>\n" + "    <gco:LocalName>An ordinary local name</gco:LocalName>\n" + "  </gml:alias>\n" + "</gml:IO_IdentifiedObject>\n";
    final String actual = marshal(name);
    assertXmlEquals(expected, actual, "xmlns:*");
    assertEquals(name, unmarshal(expected));
}
Also used : NameFactory(org.opengis.util.NameFactory) LocalName(org.opengis.util.LocalName) Test(org.junit.Test)

Example 8 with LocalName

use of org.opengis.util.LocalName in project sis by apache.

the class NamesTest method testCreateScopedName.

/**
 * Tests {@link Names#createScopedName(GenericName, String, CharSequence)}.
 */
@Test
@DependsOnMethod("testCreateLocalName")
public void testCreateScopedName() {
    final LocalName scope = Names.createLocalName("Apache", null, "sis");
    final ScopedName name = Names.createScopedName(scope, null, "identifier");
    assertSame("path()", scope, name.path());
    assertEquals("tail()", "identifier", name.tail().toString());
    assertEquals("toString()", "sis:identifier", name.toString());
    assertEquals("full", "Apache:sis:identifier", name.toFullyQualifiedName().toString());
    assertEquals("tail().full", "Apache:sis:identifier", name.tail().toFullyQualifiedName().toString());
}
Also used : ScopedName(org.opengis.util.ScopedName) LocalName(org.opengis.util.LocalName) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 9 with LocalName

use of org.opengis.util.LocalName in project sis by apache.

the class BuilderTest method testAddName.

/**
 * 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();
    // EPSG version 7.6 and later.
    assertSame(builder, builder.addName("Mercator (variant A)"));
    // EPSG before version 7.6.
    assertSame(builder, builder.addName("Mercator (1SP)"));
    // OGC
    assertSame(builder, builder.addName("Mercator_1SP"));
    // GeoTIFF
    assertSame(builder, builder.addName("CT_Mercator"));
    builder.onCreate(false);
    assertEquals(name, builder.getName());
    assertArrayEquals(new GenericName[] { alias1, alias2, alias3 }, builder.getAliases());
}
Also used : NameFactory(org.opengis.util.NameFactory) LocalName(org.opengis.util.LocalName) Test(org.junit.Test)

Example 10 with LocalName

use of org.opengis.util.LocalName in project sis by apache.

the class AbstractName method castOrCopy.

/**
 * Returns a SIS name implementation with the values of the given arbitrary implementation.
 * This method performs the first applicable action in the following choices:
 *
 * <ul>
 *   <li>If the given object is {@code null}, then this method returns {@code null}.</li>
 *   <li>Otherwise if the given object is an instance of {@link LocalName}, then this
 *       method delegates to {@link DefaultLocalName#castOrCopy(LocalName)}.</li>
 *   <li>Otherwise if the given object is already an instance of {@code AbstractName},
 *       then it is returned unchanged.</li>
 *   <li>Otherwise a new instance of an {@code AbstractName} subclass is created using the
 *       {@link DefaultNameFactory#createGenericName(NameSpace, CharSequence[])} method.</li>
 * </ul>
 *
 * @param  object  the object to get as a SIS implementation, or {@code null} if none.
 * @return a SIS implementation containing the values of the given object (may be the
 *         given object itself), or {@code null} if the argument was null.
 */
public static AbstractName castOrCopy(final GenericName object) {
    if (object instanceof LocalName) {
        return DefaultLocalName.castOrCopy((LocalName) object);
    }
    if (object == null || object instanceof AbstractName) {
        return (AbstractName) object;
    }
    /*
         * Recreates a new name for the given name in order to get
         * a SIS implementation from an arbitrary implementation.
         */
    final List<? extends LocalName> parsedNames = object.getParsedNames();
    final CharSequence[] names = new CharSequence[parsedNames.size()];
    int i = 0;
    for (final LocalName component : parsedNames) {
        names[i++] = component.toInternationalString();
    }
    if (i != names.length) {
        throw new ConcurrentModificationException(Errors.format(Errors.Keys.UnexpectedChange_1, "parsedNames"));
    }
    /*
         * Following cast should be safe because DefaultFactories.forBuildin(Class) filters the factories in
         * order to return the Apache SIS implementation, which is known to create AbstractName instances.
         */
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    return (AbstractName) factory.createGenericName(object.scope(), names);
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) LocalName(org.opengis.util.LocalName) NameFactory(org.opengis.util.NameFactory)

Aggregations

LocalName (org.opengis.util.LocalName)12 Test (org.junit.Test)7 NameFactory (org.opengis.util.NameFactory)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 NameSpace (org.opengis.util.NameSpace)2 ScopedName (org.opengis.util.ScopedName)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)1 DefaultLocalName (org.apache.sis.util.iso.DefaultLocalName)1 DefaultMemberName (org.apache.sis.util.iso.DefaultMemberName)1 DefaultTypeName (org.apache.sis.util.iso.DefaultTypeName)1 GenericName (org.opengis.util.GenericName)1 MemberName (org.opengis.util.MemberName)1 TypeName (org.opengis.util.TypeName)1