In a naming system, we need to associate names with objects so clients can look them up. How do we represent the association between a name (like autoexec.bat) and the actual object it refers to (the file data on disk)?
A binding is an association of a name with an object. For example, autoexec.bat is bound to the file data on your hard disk. In JNDI, bindings are the fundamental associations that make up contexts—each context contains a set of bindings.
- A binding maps a name (atomic name) to an object
- In file system:
autoexec.bat→ file data on disk - In JNDI:
MyBean→ EJB Home Object reference - A compound name like
/usr/people/ed/.cshrcconsists of multiple bindings resolved sequentially - Bindings are created with
Context.bind(name, obj)and looked up withContext.lookup(name)
- Name → Object: The core association in naming systems
- Atomic name key: Bindings are keyed by atomic names within a context
- Mutable: Bindings can be added, removed, or changed
- Type-independent: The bound object can be any Java object
- Serializable: Objects bound in JNDI should typically be serializable
- Built from: Atomic Name — bindings use atomic names as keys
- Built from: JNDI Context — contexts contain bindings
- Builds into: Compound Name — compound names resolve through multiple bindings
- Related: JNDI Naming Concepts — bindings are a core concept
- Related: JNDI — JNDI provides the API for managing bindings
- Overwriting bindings: Rebinding a name replaces the existing binding
- Null bindings: Binding null may be allowed or may throw exception
- Object serialization: Bound objects must be serializable for some providers
- Garbage collection: Binding keeps a reference to the object (prevents GC)