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 ChangeListener {
    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());
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.