Search in sources :

Example 6 with NameSpace

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

the class NameValue method setName.

/**
 * 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();
    }
}
Also used : NameSpace(org.opengis.util.NameSpace)

Example 7 with NameSpace

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

the class NamedIdentifierTest method testCreateFromName.

/**
 * 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.getIdentifier(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());
}
Also used : NameSpace(org.opengis.util.NameSpace) NameFactory(org.opengis.util.NameFactory) Test(org.junit.Test)

Example 8 with NameSpace

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

the class AbstractName method toFullyQualifiedName.

/**
 * 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;
}
Also used : GenericName(org.opengis.util.GenericName) NameSpace(org.opengis.util.NameSpace)

Example 9 with NameSpace

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

the class DefaultNameSpace method forName.

/**
 * Returns a namespace having the given name and separators.
 * This method returns an existing instance when possible.
 *
 * @param name
 *          the name for the namespace to obtain, or {@code null}.
 * @param headSeparator
 *          the separator to insert between the namespace and the
 *          {@linkplain AbstractName#head() head} of any name in that namespace.
 * @param separator
 *          the separator to insert between the {@linkplain AbstractName#getParsedNames()
 *          parsed names} of any name in that namespace.
 * @return a namespace having the given name, or {@code null} if name was null.
 */
static DefaultNameSpace forName(final GenericName name, final String headSeparator, final String separator) {
    if (name == null) {
        return null;
    }
    final List<? extends LocalName> parsedNames = name.getParsedNames();
    final ListIterator<? extends LocalName> it = parsedNames.listIterator(parsedNames.size());
    NameSpace scope;
    /*
         * Searches for the last parsed name having a DefaultNameSpace implementation as its
         * scope. It should be the tip in most cases. If we don't find any, we will recreate
         * the whole chain starting with the global scope.
         */
    do {
        if (!it.hasPrevious()) {
            scope = GlobalNameSpace.GLOBAL;
            break;
        }
        scope = it.previous().scope();
    } while (!(scope instanceof DefaultNameSpace));
    /*
         * We have found a scope. Adds to it the supplemental names.
         * In most cases we should have only the tip to add.
         */
    DefaultNameSpace ns = (DefaultNameSpace) scope;
    while (it.hasNext()) {
        final LocalName tip = it.next();
        ns = ns.child(tip.toString(), tip.toInternationalString(), headSeparator, separator);
    }
    return ns;
}
Also used : NameSpace(org.opengis.util.NameSpace) LocalName(org.opengis.util.LocalName)

Example 10 with NameSpace

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

the class TypeNames method toTypeName.

/**
 * Infers the type name from the given class.
 *
 * @param  factory     the same factory than the one given to the constructor.
 * @param  valueClass  the value class for which to get a type name.
 * @return a type name for the given class (never {@code null}).
 */
final TypeName toTypeName(final NameFactory factory, final Class<?> valueClass) {
    String name;
    NameSpace ns = ogcNS;
    if (CharSequence.class.isAssignableFrom(valueClass)) {
        name = InternationalString.class.isAssignableFrom(valueClass) ? "FreeText" : "CharacterString";
    } else if (Number.class.isAssignableFrom(valueClass)) {
        name = Numbers.isInteger(valueClass) ? "Integer" : "Real";
    } else {
        /*
             * Iterate over the special cases, excluding the numbers and character sequences
             * since they were verified in the above statements.
             */
        final Iterator<Map.Entry<String, Class<?>>> it = MAPPING.entrySet().iterator();
        Class<?> base;
        do {
            final Map.Entry<String, Class<?>> entry = it.next();
            base = entry.getValue();
            if (base.isAssignableFrom(valueClass)) {
                name = entry.getKey();
                return factory.createTypeName(ns, name);
            }
        } while (// See MAPPING javadoc for the role of Boolean as a sentinel value.
        base != Boolean.class);
        /*
             * Found no special case. Checks for the UML annotation, to be also formatted in the "OGC:" namespace.
             * If no UML identifier is found, then we will format the Java class in the "class:" namespace. We use
             * Class.getName() - not Class.getCanonicalName() - because we want a name readable by Class.forName(…).
             */
        name = Types.getStandardName(valueClass);
        if (name == null) {
            ns = classNS;
            // See above comment.
            name = valueClass.getName();
        }
    }
    /*
         * Now create the name and remember the 'valueClass' for that name if the implementation allows that.
         */
    final TypeName t = factory.createTypeName(ns, name);
    if (t instanceof DefaultTypeName) {
        ((DefaultTypeName) t).setValueClass(ns, name, valueClass);
    }
    return t;
}
Also used : TypeName(org.opengis.util.TypeName) Iterator(java.util.Iterator) NameSpace(org.opengis.util.NameSpace) InternationalString(org.opengis.util.InternationalString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

NameSpace (org.opengis.util.NameSpace)10 InternationalString (org.opengis.util.InternationalString)4 Test (org.junit.Test)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 GenericName (org.opengis.util.GenericName)2 LocalName (org.opengis.util.LocalName)2 NameFactory (org.opengis.util.NameFactory)2 TypeName (org.opengis.util.TypeName)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 DeprecatedCode (org.apache.sis.internal.referencing.DeprecatedCode)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)1 DefaultNameSpace (org.apache.sis.util.iso.DefaultNameSpace)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1