All Implemented Interfaces:
All Known Implementing Classes:
If a service only supports registration for existing targets, an attempt to register for a nonexistent target results in a NameNotFoundException being thrown as early as possible, preferably at the time addNamingListener() is called, or if that is not possible, the listener will receive the exception through the NamingExceptionEvent.
Also, for service providers that only support registration for existing targets, when the target that a listener has registered for is subsequently removed from the namespace, the listener is notified via a NamingExceptionEvent (containing a NameNotFoundException).
An application can use the method targetMustExist() to check whether a EventContext supports registration of nonexistent targets.
For example, suppose a listener makes the following registration:
When an object named "x/y" is subsequently deleted, the corresponding NamingEvent (evt) must contain:NamespaceChangeListener listener = ...; src.addNamingListener("x", SUBTREE_SCOPE, listener);
evt.getEventContext() == src evt.getOldBinding().getName().equals("x/y")
Furthermore, listener registration/deregistration is with the EventContext instance, and not with the corresponding object in the namespace. If the program intends at some point to remove a listener, then it needs to keep a reference to the EventContext instance on which it invoked addNamingListener() (just as it needs to keep a reference to the listener in order to remove it later). It cannot expect to do a lookup() and get another instance of a EventContext on which to perform the deregistration.
|public static final int||OBJECT_SCOPE||Constant for expressing interest in events concerning the object named
by the target.
The value of this constant is 0.
|public static final int||ONELEVEL_SCOPE||Constant for expressing interest in events concerning objects
in the context named by the target,
excluding the context named by the target.
The value of this constant is 1.
|public static final int||SUBTREE_SCOPE||Constant for expressing interest in events concerning objects
in the subtree of the object named by the target, including the object
named by the target.
The value of this constant is 2.
|Method from javax.naming.event.EventContext Summary:|
|addNamingListener, addNamingListener, removeNamingListener, targetMustExist|
|Method from javax.naming.event.EventContext Detail:|
public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException
target needs to name a context only when scope is ONELEVEL_SCOPE. target may name a non-context if scope is either OBJECT_SCOPE or SUBTREE_SCOPE. Using SUBTREE_SCOPE for a non-context might be useful, for example, if the caller does not know in advance whether target is a context and just wants to register interest in the (possibly degenerate subtree) rooted at target.
When the listener is notified of an event, the listener may in invoked in a thread other than the one in which addNamingListener() is executed. Care must be taken when multiple threads are accessing the same EventContext concurrently. See the package description for more information on threading issues.
public void addNamingListener(String target, int scope, NamingListener l) throws NamingException
public void removeNamingListener(NamingListener l) throws NamingException
public boolean targetMustExist() throws NamingException