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

Lookup Methods

The flat namespace example uses in-memory storage; it does not support persistence. Whether a context implementation supports persistence typically is determined by the underlying naming/directory service or the requirements of the service provider.

Here is the implementation of lookup()(in the API reference documentation).

public Object lookup(Name name) throws NamingException {
    if (name.isEmpty()) {
        // Ask to look up this context itself; create and return
        // a new instance that has its own independent environment.
        return (createCtx(myEnv));
    } 

    // Extract the components that belong to this namespace
    String nm = getMyComponents(name);

    // Find the object in the internal hash table
    Object answer = bindings.get(nm);
    if (answer == null) {
        throw new NameNotFoundException(name + " not found");
    }
    return answer;
}
According to the JNDI specification, a lookup() of the empty name should return a copy of the context itself. After extracting the component that belongs to this context's namespace, the implementation proceeds to find the named binding from its internal data structure--a hash table. If it is not found, then it throws a NameNotFoundException(in the API reference documentation). In an actual implementation, you would access the underlying naming/directory service instead of accessing a hash table.

This example does not support link references, so this method does not look for LinkRefs(in the API reference documentation) or treat them specially.

LookupLink

This example's definition of lookupLink()(in the API reference documentation) is the same as its definition of lookup(). This example does not support link references. See the Miscellaneous (in the Building a Service Provider trail) lesson for a description of how to support link references.


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