The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
Event and Service Provider Packages
Event Package
The
javax.naming.event package contains classes and interfaces for supporting event notification in naming and directory services. Event notification is described in detail in the
Event Notification trail.
- Events
- A
NamingEvent represents an event that is generated by a naming/directory service. The event contains a type that identifies the type of event. For example, event types are categorized into those that affect the namespace, such as "object added," and those that do not, such as "object changed."
- Listeners
- A
NamingListener is an object that listens for NamingEvents. Each category of event type has a corresponding type of NamingListener. For example, a
NamespaceChangeListener represents a listener interested in namespace change events and an
ObjectChangeListener represents a listener interested in object change events.
To receive event notifications, a listener must be registered with either an
EventContext or an
EventDirContext. Once registered, the listener will receive event notifications when the corresponding changes occur in the naming/directory service. The details about Event Notification can be found in the
JNDI Tutorial.
Service Provider Package
The
javax.naming.spi package provides the means by which developers of different naming/directory service providers can develop and hook up their implementations so that the corresponding services are accessible from applications that use the JNDI.
- Plug-In Architecture
- The javax.naming.spi package allows different implementations to be plugged in dynamically. These implementations include those for the
initial context and for contexts that can be reached from the initial context.
- Java Object Support
- The javax.naming.spi package supports implementors of
lookup and related methods to return Java objects that are natural and intuitive for the Java programmer. For example, if you look up a printer name from the directory, then you likely would expect to get back a printer object on which to operate. This support is provided in the form of
object factories.
This package also provides support for doing the reverse. That is, implementors of
Context.bind() and related methods can accept Java objects and store the objects in a format acceptable to the underlying naming/directory service. This support is provided in the form of
state factories.
- Multiple Naming Systems (Federation)
- JNDI operations allow applications to supply names that span multiple naming systems. In the process of completing an operation, one service provider might need to interact with another service provider, for example to pass on the operation to be continued in the next naming system. This package provides support for different providers to cooperate to complete JNDI operations.
The details about the Service Provider mechanism can be found in the
JNDI Tutorial.