The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.naming.event  [2 examples]

e493. Registering for Namespace Changes in the Directory

This example registers with the directory to receive notification when changes are made to the namespace.
    try {
        // Get event context for registering listener
        EventContext ctx = (EventContext)(new InitialContext(env).lookup("ou=People"));
    
        // Create listener
        NamingListener listener = new SampleNCListener();
    
        // Register listener for namespace change events
        ctx.addNamingListener("cn=John", EventContext.ONELEVEL_SCOPE, listener);
    } catch (NamingException e) {
    }
    
    public class SampleNCListener implements NamespaceChangeListener {
        public SampleNCListener() {
        }
        public void objectAdded(NamingEvent evt) {
            process(evt.getNewBinding());
        }
        public void objectRemoved(NamingEvent evt) {
            process(evt.getOldBinding());
        }
    
        public void objectRenamed(NamingEvent evt) {
            process(evt.getOldBinding());
        }
    
        public void namingExceptionThrown(NamingExceptionEvent evt) {
            processException(evt.getException());
        }
    }

 Related Examples
e494. Registering for Object Changes in the Directory


© 2002 Addison-Wesley.