Search in sources :

Example 11 with LocalName

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

the class AbstractName method toString.

/**
 * Returns a string representation of this generic name. This string representation
 * is local-independent. It contains all elements listed by {@link #getParsedNames()}
 * separated by a namespace-dependent character (usually {@code ':'} or {@code '/'}).
 * This rule implies that the result may or may not be fully qualified.
 * Special cases:
 *
 * <ul>
 *   <li><code>{@linkplain #toFullyQualifiedName()}.toString()</code> is guaranteed to
 *       contain the {@linkplain #scope() scope} (if any).</li>
 *   <li><code>{@linkplain #tip()}.toString()</code> is guaranteed to not contain
 *       any scope.</li>
 * </ul>
 *
 * @return a local-independent string representation of this name.
 */
@Override
public synchronized String toString() {
    if (asString == null) {
        boolean insertSeparator = false;
        final StringBuilder buffer = new StringBuilder();
        for (final LocalName name : getParsedNames()) {
            if (insertSeparator) {
                buffer.append(separator(name));
            }
            insertSeparator = true;
            buffer.append(name);
        }
        asString = buffer.toString();
    }
    /*
         * Note: there is no need to invoke InternationalString.toString(Locale.ROOT) for
         * the unlocalized version, because our International inner class is implemented in
         * such a way that InternationalString.toString() returns AbstractName.toString().
         */
    return asString.toString();
}
Also used : LocalName(org.opengis.util.LocalName)

Example 12 with LocalName

use of org.opengis.util.LocalName 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)

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