ObjectChanges

try {
    // Get event context for registering listener
    EventDirContext ctx = (EventDirContext)(new InitialContext(env).lookup("ou=People"));

    // Create listener
    NamingListener listener = new SampleObjListener();

    // Specify to search the subtree
    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    // Specify the search filter of objects in which you're interested
    // Ask for objects that have "mail" attribute
    String filter = "(mail=*)";

    // Register listener for object change events
    ctx.addNamingListener("cn=John", filter, ctls, listener);
} catch (NamingException e) {
}

public class SampleObjListener implements ObjectChangeListener {
    public SampleObjListener() {
    }
    public void objectChanged(NamingEvent evt) {
        process(evt.getNewBinding());
        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.