| 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()`.

> >     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 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 `LinkRef`s or treat them specially.

> #### LookupLink

> This example's definition of `lookupLink()` is the same as its definition of `lookup()`. This example does not support link references. See the Miscellaneous lesson for a description of how to support link references.

| The Essential Components