Example usage for javax.naming.event EventDirContext addNamingListener

List of usage examples for javax.naming.event EventDirContext addNamingListener

Introduction

In this page you can find the example usage for javax.naming.event EventDirContext addNamingListener.

Prototype

void addNamingListener(String target, String filter, SearchControls ctls, NamingListener l)
        throws NamingException;

Source Link

Document

Adds a listener for receiving naming events fired when objects identified by the search filter filter at the object named by the string target name are modified.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    EventDirContext ctx = (EventDirContext) (new InitialContext(env).lookup("ou=People"));

    NamingListener listener = new SampleObjListener();

    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    String filter = "(mail=*)";

    ctx.addNamingListener("cn=YourName", filter, ctls, listener);
}