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();
}
}
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());
}
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;
}
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;
}
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;
}
Aggregations