# 活动和服务提供商包

> 原文： [https://docs.oracle.com/javase/tutorial/jndi/overview/event.html](https://docs.oracle.com/javase/tutorial/jndi/overview/event.html)

## 活动包

[`javax.naming.event` ](https://docs.oracle.com/javase/8/docs/api/javax/naming/event/package-summary.html)包中包含用于支持命名和目录服务中的事件通知的类和接口。事件通知在跟踪中详细描述。

Events

A [`NamingEvent`](https://docs.oracle.com/javase/8/docs/api/javax/naming/event/NamingEvent.html) 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`](https://docs.oracle.com/javase/8/docs/api/javax/naming/event/NamingListener.html) is an object that listens for `NamingEvent`s. Each category of event type has a corresponding type of `NamingListener`. For example, a [`NamespaceChangeListener`](https://docs.oracle.com/javase/8/docs/api/javax/naming/event/NamespaceChangeListener.html) represents a listener interested in namespace change events and an [`ObjectChangeListener`](https://docs.oracle.com/javase/8/docs/api/javax/naming/event/ObjectChangeListener.html) represents a listener interested in object change events.

要接收事件通知，必须使用 [`EventContext`](https://docs.oracle.com/javase/8/docs/api/javax/naming/event/EventContext.html)或 [`EventDirContext`](https://docs.oracle.com/javase/8/docs/api/javax/naming/event/EventDirContext.html)注册侦听器。注册后，当命名/目录服务中发生相应的更改时，侦听器将接收事件通知。有关事件通知的详细信息，请参见 [JNDI 教程](https://docs.oracle.com/javase/jndi/tutorial/beyond/event/index.html)。

## 服务提供商包

[`javax.naming.spi` ](https://docs.oracle.com/javase/8/docs/api/javax/naming/spi/package-summary.html)包提供了不同命名/目录服务提供者的开发人员可以开发和连接他们的实现的方法，以便可以从使用的应用程序访问相应的服务 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](../ops/index.html) and for contexts that can be reached from the initial context.

Java Object Support

The `javax.naming.spi` package supports implementors of [lookup](../ops/lookup.html) 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](../objects/index.html#OBJFAC).

该软件包还支持反向操作。也就是说， [`Context.bind（）`](https://docs.oracle.com/javase/8/docs/api/javax/naming/Context.html#bind-javax.naming.Name-java.lang.Object-) 的实现者和相关方法可以接受 Java 对象并以底层命名/目录服务可接受的格式存储对象。这种支持以[州工厂](../objects/index.html#STATEFAC)的形式提供。

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.

有关服务提供商机制的详细信息，请参见 [JNDI 教程](https://docs.oracle.com/javase/jndi/tutorial/provider/index.html)。