Previous | Next | Trail Map | Building a Service Provider | The Essential Components

More Names

The Context(in the API reference documentation) interface contains two name-related methods: Context.getNameInNamespace()(in the API reference documentation) and Context.composeName()(in the API reference documentation). They allow the API user to manipulate names with respect to a context.

Fully Qualified Names

The API user uses Context.getNameInNamespace() to get a Context instance's fully qualified name within its namespace. The definition of this method depends on the underlying naming/directory service. In an actual implementation, this method might access the underlying naming/directory service or use bookkeeping information stored in the Context instance to generate an answer.

The hierarchical example maintains a back pointer to determine the fully qualified name of a context. Here is its getNameInNamespace() definition.

public String getNameInNamespace() throws NamingException {
    HierCtx ancestor = parent;

    // No ancestor; at root of namespace
    if (ancestor == null) {
        return "";
    }

    Name name = myParser.parse("");
    name.add(myAtomicName);

    // Get the parent's names
    while (ancestor != null && ancestor.myAtomicName != null) {
        name.add(0, ancestor.myAtomicName);
	ancestor = ancestor.parent;
    }
	    
    return name.toString();
}

Compose Name

The API user uses Context.composeName()(in the API reference documentation) to compose names that span possibly multiple namespaces. The What's in a Name? (in the Beyond the Basics trail) lesson describes this in more detail.

Because the hierarchical namespace example does not support federation, its composeName() name deals only with compound names. Here is its definition.

public Name composeName(Name name, Name prefix) throws NamingException {
    Name result;

    // Both are compound names; compose using compound name rules
    if (!(name instanceof CompositeName) &&
        !(prefix instanceof CompositeName)) {
        result = (Name)(prefix.clone());
	result.addAll(name);
	return new CompositeName().add(result.toString());
    }

    // Simplistic implementation; do not support federation
    throw new OperationNotSupportedException(
	"Do not support composing composite names");
}


Previous | Next | Trail Map | Building a Service Provider | The Essential Components