Search in sources :

Example 1 with NameFactory

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

the class Names method createLocalName.

/**
 * Creates a name which is local in the given namespace.
 * The character sequences can be either {@link String} or {@link InternationalString} instances.
 * Those character sequences are taken verbatim; they are <em>not</em> parsed into their components.
 *
 * <div class="note"><b>Note:</b> it is possible to split the {@code namespace} and {@code localPart}
 * strings into smaller name components (e.g. namespaces contained in other namespaces). If such finer
 * grain control is desired, one can use {@link DefaultNameFactory} instead of this {@code Names} class.</div>
 *
 * The following table shows where the strings given in argument will go:
 *
 * <blockquote><table class="sis">
 *   <caption>Mapping from arguments to name components</caption>
 *   <tr><th>Argument</th> <th>Mapped to</th></tr>
 *   <tr><td>{@code namespace}</td> <td><code>name.{@linkplain DefaultLocalName#scope() scope()}.name().toString()</code></td></tr>
 *   <tr><td>{@code localPart}</td> <td><code>name.{@linkplain DefaultLocalName#toString() toString()}</code></td></tr>
 * </table></blockquote>
 *
 * <div class="note"><b>Example:</b>
 * for a name created by {@code createLocalName("http://www.opengis.net/gml/srs/epsg.xml", "#", "4326")}:
 * <blockquote><table class="compact" summary="Examples of return values for a name built by this method.">
 *   <tr><td>• <code>name.{@linkplain DefaultLocalName#toString() toString()}</code></td>
 *       <td>returns the {@code "4326"} string.</td></tr>
 *   <tr><td>• <code>name.{@linkplain DefaultLocalName#scope() scope()}</code></td>
 *       <td>returns the {@code "http://www.opengis.net/gml/srs/epsg.xml"} namespace.</td></tr>
 *   <tr><td>• <code>name.{@linkplain DefaultLocalName#toFullyQualifiedName() toFullyQualifiedName()}</code></td>
 *       <td>returns the {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"} name.
 *   <tr><td>• <code>{@linkplain #toExpandedString(GenericName) toExpandedString}(name)</code></td>
 *       <td>returns the {@code "{http://www.opengis.net/gml/srs/epsg.xml}4326"} string.</td></tr>
 * </table></blockquote></div>
 *
 * <div class="note"><b>Performance note:</b> this method is okay for <em>casual</em> use. If many names need
 * to be created in the same namespace, then {@link DefaultNameFactory#createLocalName(NameSpace, CharSequence)}
 * is more efficient since it allows to create the {@code NameSpace} object only once.</div>
 *
 * @param  namespace  the namespace, or {@code null} for the global namespace.
 * @param  separator  the separator between the namespace and the local part, or {@code null}
 *                    for the {@linkplain DefaultNameSpace#DEFAULT_SEPARATOR default separator}.
 * @param  localPart  the name which is locale in the given namespace.
 * @return a local name in the given namespace.
 *
 * @see DefaultNameFactory#createLocalName(NameSpace, CharSequence)
 */
public static LocalName createLocalName(final CharSequence namespace, final String separator, final CharSequence localPart) {
    ensureNonNull("localPart", localPart);
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    return factory.createLocalName(createNameSpace(factory, namespace, separator), localPart);
}
Also used : NameFactory(org.opengis.util.NameFactory)

Example 2 with NameFactory

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

the class BuilderTest method testAddNameWithScope.

/**
 * 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());
}
Also used : GenericName(org.opengis.util.GenericName) NameFactory(org.opengis.util.NameFactory) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with NameFactory

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

the class CustomMetadataTest method testSubtypeAttributes.

/**
 * Tests that the attributes defined in subtypes are also marshalled.
 *
 * @throws JAXBException if an error occurred during (un)marshalling.
 *
 * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-108">GEOTK-108</a>
 */
@Test
public void testSubtypeAttributes() throws JAXBException {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final DataIdentification identification = new DataIdentification() {

        @Override
        public InternationalString getAbstract() {
            Map<Locale, String> names = new HashMap<>();
            names.put(Locale.ENGLISH, "Description");
            return factory.createInternationalString(names);
        }

        @Override
        public InternationalString getEnvironmentDescription() {
            Map<Locale, String> names = new HashMap<>();
            names.put(Locale.ENGLISH, "Environment");
            return factory.createInternationalString(names);
        }

        @Override
        public InternationalString getSupplementalInformation() {
            return null;
        }

        @Override
        public Citation getCitation() {
            return null;
        }

        @Override
        public InternationalString getPurpose() {
            return null;
        }

        @Override
        public Collection<SpatialRepresentationType> getSpatialRepresentationTypes() {
            return null;
        }

        @Override
        public Collection<Resolution> getSpatialResolutions() {
            return null;
        }

        @Override
        public Collection<Locale> getLanguages() {
            return null;
        }

        @Override
        public Collection<CharacterSet> getCharacterSets() {
            return null;
        }

        @Override
        public Collection<TopicCategory> getTopicCategories() {
            return null;
        }

        @Override
        public Collection<Extent> getExtents() {
            return null;
        }

        @Override
        public Collection<String> getCredits() {
            return null;
        }

        @Override
        public Collection<Progress> getStatus() {
            return null;
        }

        @Override
        public Collection<ResponsibleParty> getPointOfContacts() {
            return null;
        }

        @Override
        public Collection<MaintenanceInformation> getResourceMaintenances() {
            return null;
        }

        @Override
        public Collection<BrowseGraphic> getGraphicOverviews() {
            return null;
        }

        @Override
        public Collection<Format> getResourceFormats() {
            return null;
        }

        @Override
        public Collection<Keywords> getDescriptiveKeywords() {
            return null;
        }

        @Override
        public Collection<Usage> getResourceSpecificUsages() {
            return null;
        }

        @Override
        public Collection<Constraints> getResourceConstraints() {
            return null;
        }

        @Deprecated
        @Override
        public Collection<AggregateInformation> getAggregationInfo() {
            return null;
        }
    };
    final DefaultMetadata data = new DefaultMetadata();
    data.setIdentificationInfo(singleton(identification));
    final String xml = XML.marshal(data);
    /*
         * A few simple checks.
         */
    assertTrue("Missing Identification attribute.", xml.contains("Description"));
    assertTrue("Missing DataIdentification attribute.", xml.contains("Environment"));
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) Extent(org.opengis.metadata.extent.Extent) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) ResponsibleParty(org.opengis.metadata.citation.ResponsibleParty) Format(org.opengis.metadata.distribution.Format) Constraints(org.opengis.metadata.constraint.Constraints) MaintenanceInformation(org.opengis.metadata.maintenance.MaintenanceInformation) NameFactory(org.opengis.util.NameFactory) SpatialRepresentationType(org.opengis.metadata.spatial.SpatialRepresentationType) Test(org.junit.Test)

Example 4 with NameFactory

use of org.opengis.util.NameFactory 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 5 with NameFactory

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

the class NameMarshallingTest method testTypeName.

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

Aggregations

NameFactory (org.opengis.util.NameFactory)20 Test (org.junit.Test)13 DependsOnMethod (org.apache.sis.test.DependsOnMethod)6 GenericName (org.opengis.util.GenericName)5 LocalName (org.opengis.util.LocalName)5 InternationalString (org.opengis.util.InternationalString)4 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)2 NameSpace (org.opengis.util.NameSpace)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 IdentifiedObjectMock (org.apache.sis.test.mock.IdentifiedObjectMock)1 DefaultNameFactory (org.apache.sis.util.iso.DefaultNameFactory)1 Citation (org.opengis.metadata.citation.Citation)1 ResponsibleParty (org.opengis.metadata.citation.ResponsibleParty)1 Constraints (org.opengis.metadata.constraint.Constraints)1 Format (org.opengis.metadata.distribution.Format)1 Extent (org.opengis.metadata.extent.Extent)1 MaintenanceInformation (org.opengis.metadata.maintenance.MaintenanceInformation)1