Search in sources :

Example 1 with LocalName

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

the class GO_GenericName method getValue.

/**
 * Returns the {@code LocalName} or {@code ScopedName} to marshal. Returns {@code null} if the name
 * is a {@link TypeName} or a {@link MemberName}, in order to use {@link #getName()} instead.
 * Example:
 *
 * {@preformat xml
 *   <gml:alias>
 *     <gco:LocalName codeSpace=\"A code space\">A name in a scope</gco:LocalName>
 *   </gml:alias>
 * }
 *
 * @return the code for the current name, or {@code null} if none.
 */
@XmlElementRef
public final NameValue getValue() {
    final GenericName name = this.name;
    final NameValue code;
    if (name instanceof LocalName) {
        if (name instanceof TypeName || name instanceof MemberName) {
            return null;
        } else if (FilterByVersion.LEGACY_METADATA.accept()) {
            code = new NameValue.Local();
        } else {
            // ISO 19115-3:2016 does not seem to define gco:LocalName anymore.
            code = new NameValue.Scoped();
        }
    } else if (name instanceof ScopedName) {
        code = new NameValue.Scoped();
    } else {
        return null;
    }
    code.setName(name);
    return code;
}
Also used : GenericName(org.opengis.util.GenericName) DefaultTypeName(org.apache.sis.util.iso.DefaultTypeName) TypeName(org.opengis.util.TypeName) ScopedName(org.opengis.util.ScopedName) DefaultMemberName(org.apache.sis.util.iso.DefaultMemberName) MemberName(org.opengis.util.MemberName) LocalName(org.opengis.util.LocalName) DefaultLocalName(org.apache.sis.util.iso.DefaultLocalName) XmlElementRef(javax.xml.bind.annotation.XmlElementRef)

Example 2 with LocalName

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

the class NameMarshallingTest method testLocalNameWithAmp.

/**
 * Tests XML of a {@link LocalName} with {@code &} symbol.
 *
 * @throws JAXBException if (un)marshalling failed.
 */
@Test
@DependsOnMethod("testLocalName")
public void testLocalNameWithAmp() throws JAXBException {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final LocalName name = factory.createLocalName(null, "A name with & and > and <.");
    assertEquals("A name with & and > and <.", name.toString());
    final String expected = "<gml:IO_IdentifiedObject xmlns:gml=\"" + Namespaces.GML + '"' + " xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" + "  <gml:alias>\n" + "    <gco:LocalName>A name with &amp; and &gt; and &lt;.</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) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with LocalName

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

the class NamesTest method testCreateLocalName.

/**
 * Tests {@link Names#createLocalName(CharSequence, String, CharSequence)}.
 */
@Test
public void testCreateLocalName() {
    final LocalName name = Names.createLocalName("http://www.opengis.net/gml/srs/epsg.xml", "#", "4326");
    assertEquals("http://www.opengis.net/gml/srs/epsg.xml", name.scope().name().toString());
    assertEquals("4326", name.toString());
    assertEquals("http://www.opengis.net/gml/srs/epsg.xml#4326", name.toFullyQualifiedName().toString());
    assertEquals("{http://www.opengis.net/gml/srs/epsg.xml}4326", Names.toExpandedString(name));
}
Also used : LocalName(org.opengis.util.LocalName) Test(org.junit.Test)

Example 4 with LocalName

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

the class FeatureNamingTest method testQualifiedAndUnqualifiedName.

/**
 * Tests two names having the same tip, but where only one of the two names have a namespace.
 *
 * @throws IllegalNameException if an unexpected error occurred while adding or getting an element.
 */
@Test
@DependsOnMethod("testAmbiguity")
public void testQualifiedAndUnqualifiedName() throws IllegalNameException {
    final DataStoreMock store = new DataStoreMock("testDataStore");
    final LocalName local = Names.createLocalName(null, null, "A");
    FeatureNaming<Integer> map = new FeatureNaming<>();
    map.add(store, local, 3);
    map.add(store, A, 2);
    map.add(store, B, 5);
    map.add(store, otherA, 7);
    assertEquals("B", Integer.valueOf(5), map.get(store, "B"));
    assertEquals("A", Integer.valueOf(3), map.get(store, "A"));
    assertEquals("myNS:A", Integer.valueOf(2), map.get(store, "myNS:A"));
    assertEquals("other:A", Integer.valueOf(7), map.get(store, "other:A"));
    /*
         * Same tests, but with elements added in different order.
         */
    map = new FeatureNaming<>();
    map.add(store, otherA, 7);
    map.add(store, B, 5);
    map.add(store, A, 2);
    map.add(store, local, 3);
    assertEquals("B", Integer.valueOf(5), map.get(store, "B"));
    assertEquals("A", Integer.valueOf(3), map.get(store, "A"));
    assertEquals("myNS:A", Integer.valueOf(2), map.get(store, "myNS:A"));
    assertEquals("other:A", Integer.valueOf(7), map.get(store, "other:A"));
}
Also used : LocalName(org.opengis.util.LocalName) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 5 with LocalName

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

the class AbstractName method compareTo.

/**
 * Compares this name with the specified name for order. Returns a negative integer,
 * zero, or a positive integer as this name lexicographically precedes, is equal to,
 * or follows the specified name. The comparison is performed in the following way:
 *
 * <ul>
 *   <li>For each element of the {@linkplain #getParsedNames() list of parsed names} taken
 *       in iteration order, compare the {@link LocalName}. If a name lexicographically
 *       precedes or follows the corresponding element of the specified name, returns
 *       a negative or a positive integer respectively.</li>
 *   <li>If all elements in both names are lexicographically equal, then if this name has less
 *       or more elements than the specified name, returns a negative or a positive integer
 *       respectively.</li>
 *   <li>Otherwise, returns 0.</li>
 * </ul>
 *
 * @param  name  the other name to compare with this name.
 * @return -1 if this name precedes the given one, +1 if it follows, 0 if equals.
 */
@Override
public int compareTo(final GenericName name) {
    final Iterator<? extends LocalName> thisNames = this.getParsedNames().iterator();
    final Iterator<? extends LocalName> thatNames = name.getParsedNames().iterator();
    while (thisNames.hasNext()) {
        if (!thatNames.hasNext()) {
            return +1;
        }
        final LocalName thisNext = thisNames.next();
        final LocalName thatNext = thatNames.next();
        if (thisNext == this && thatNext == name) {
            // Never-ending loop: usually an implementation error
            throw new IllegalStateException(Errors.format(Errors.Keys.CircularReference));
        }
        final int compare = thisNext.compareTo(thatNext);
        if (compare != 0) {
            return compare;
        }
    }
    return thatNames.hasNext() ? -1 : 0;
}
Also used : LocalName(org.opengis.util.LocalName)

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