Example usage for javax.naming NamingEnumeration hasMore

List of usage examples for javax.naming NamingEnumeration hasMore

Introduction

In this page you can find the example usage for javax.naming NamingEnumeration hasMore.

Prototype

public boolean hasMore() throws NamingException;

Source Link

Document

Determines whether there are any more elements in the enumeration.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);

    NamingEnumeration e = ctx.list("child");
    while (e.hasMore()) {
        NameClassPair entry = (NameClassPair) e.next();
        System.out.println(entry.getName());
    }/*w w  w  .  j a va2s . com*/
}

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);

    DirContext ctx = new InitialDirContext(env);
    String[] attrIDs = { "sn", "number", "value", "mail" };

    Attributes answer = ctx.getAttributes("cn=yourName, ou=People", attrIDs);

    NamingEnumeration e = answer.getAll();
    while (e.hasMore()) {
        Attribute attr = (Attribute) e.next();
        System.out.println(attr.getID());
    }/*from  w  w w. j  a v a  2  s. co m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "yourURL");

    DirContext ctx = new InitialDirContext(env);

    DirContext tedClasses = ctx.getSchemaClassDefinition("cn=YourName, ou=People");

    NamingEnumeration e = tedClasses.search("", null);
    while (e.hasMore()) {
        DirContext entry = (DirContext) e.next();
        System.out.println(entry);
    }//  w w w  .j  a  v a 2s . c o m
}

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");

    Control[] connectCtls = new Control[] { null };
    LdapContext ctx = new InitialLdapContext(env, null);

    Control[] ctxCtls = new Control[] { new SortControl(new String[] { "cn" }, Control.CRITICAL) };

    ctx.setRequestControls(ctxCtls);//from   w  ww.j av a2 s  .c om

    NamingEnumeration answer = ctx.list("");

    while (answer.hasMore()) {
        NameClassPair item = (NameClassPair) answer.next();
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    String filter = "(&(sn=YourName)(mail=*))";

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "yourURL");

    DirContext ctx = new InitialDirContext(env);

    NamingEnumeration e = ctx.search("", filter, ctls);

    while (e.hasMore()) {
        SearchResult entry = (SearchResult) e.next();
        System.out.println(entry.getName());
    }//  w w w.ja v a 2s  .co m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Attributes matchAttrs = new BasicAttributes(true);
    matchAttrs.put(new BasicAttribute("sn", "YourName"));
    matchAttrs.put(new BasicAttribute("mail"));

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "yourURL");

    DirContext ctx = new InitialDirContext(env);

    NamingEnumeration e = ctx.search("ou=People", matchAttrs);

    if (e.hasMore()) {
        SearchResult entry = (SearchResult) e.next();
        // Abandon rest of results
        e.close();//from ww w. java 2  s  .  co  m
    }
}

From source file:FilterExample.java

public static void main(String[] argc) throws Exception {
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample");

    DirContext dctx = new InitialDirContext(env);

    String filter = "(&(cn=E*)(account>1005))";

    NamingEnumeration result = dctx.search("ou=People", filter, null);

    while (result.hasMore()) {
        SearchResult sr = (SearchResult) result.next();
        System.out.println("Result = " + sr.getName());
    }/*from   w w  w  . j  a va 2s.c  o  m*/

}

From source file:SearchControlsExample.java

public static void main(String[] argc) throws Exception {
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample");

    DirContext dctx = new InitialDirContext(env);

    String filter = "(&(cn=S*)(account>1005))";

    String[] attrIDs = { "cn", "email" };
    SearchControls sc = new SearchControls();
    sc.setReturningAttributes(attrIDs);//from  www  .j a  v a2s .co m

    NamingEnumeration result = dctx.search("ou=People", filter, sc);

    while (result.hasMore()) {
        SearchResult sr = (SearchResult) result.next();
        System.out.println("Result = " + sr.getName());
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] attrIDs = { "sn", "number", "value", "mail" };

    Attributes matchAttrs = new BasicAttributes(true);
    matchAttrs.put(new BasicAttribute("sn", "YourName"));
    matchAttrs.put(new BasicAttribute("mail"));

    Object obj = "yourObject";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "yourURL");

    DirContext ctx = new InitialDirContext(env);

    NamingEnumeration e = ctx.search("ou=People", matchAttrs, attrIDs);

    while (e.hasMore()) {
        SearchResult entry = (SearchResult) e.next();
        System.out.println(entry.getName());
    }/* w ww  .j  a v  a  2  s.c om*/
}

From source file:SearchScopeExample.java

public static void main(String[] argc) {
    Hashtable env = new Hashtable(11);

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample");

    try {//from  w w  w .jav a 2  s . c  o m
        DirContext dctx = new InitialDirContext(env);

        String filter = "(&(cn=S*)(account>1000))";

        String[] attrIDs = { "cn", "email" };
        SearchControls sc = new SearchControls();
        sc.setReturningAttributes(attrIDs);
        sc.setSearchScope(SearchControls.SUBTREE_SCOPE);

        NamingEnumeration result = dctx.search("ou=People", filter, sc);

        while (result.hasMore()) {
            SearchResult sr = (SearchResult) result.next();
            System.out.println("Result = " + sr.getName());
        }
    } catch (NamingException e) {
        System.out.println(e);
    }
}