In a hierarchical naming system, we need containers that group related name-to-object associations together. How do we represent a “folder” in the naming tree that contains multiple bindings?
A context is a set of zero or more bindings, where each binding has a distinct atomic name. In the UNIX file system, a folder like /etc is a context containing bindings to files like mtab and exports. Each context is also a subcontext of its parent.
- Context implements
javax.naming.Contextinterface - Contains bindings: name → object mappings
- Operations:
lookup(name),bind(name, obj),unbind(name),list() - Subcontext: A context within a context (like
/usr/peoplewithin/usr) - Each subcontext is a full context itself, capable of containing more bindings
In JNDI, the root context is obtained via new InitialContext(). Subcontexts are created with createSubcontext().
- Container of bindings: Groups related name→object associations
- Hierarchical: Can contain subcontexts, forming a tree
- Context operations: lookup, bind, unbind, rename, list, createSubcontext
- InitialContext: The entry point for JNDI operations
- Serializable: Contexts can be bound into other contexts
- Built from: JNDI Binding — contexts contain bindings
- Built from: JNDI Naming Concepts — contexts are central to JNDI
- Builds into: Subcontext — a context within a context
- Related: JNDI — JNDI provides the Context API
- Related: Atomic Name — bindings in a context have atomic names
- Closing contexts: Always close contexts to free resources
- Concurrent access: Context operations may not be thread-safe
- Lazy loading: Large contexts may not load all bindings immediately
- Context destruction: Destroying a context may not recursively destroy subcontexts