Example usage for javax.naming.ldap LdapContext listBindings

List of usage examples for javax.naming.ldap LdapContext listBindings

Introduction

In this page you can find the example usage for javax.naming.ldap LdapContext listBindings.

Prototype

public NamingEnumeration<Binding> listBindings(Name name) throws NamingException;

Source Link

Document

Enumerates the names bound in the named context, along with the objects bound to them.

Usage

From source file:edu.vt.middleware.ldap.AbstractLdap.java

/**
 * This will enumerate the names bounds to the specified context, along with
 * the objects bound to them. The resulting <code>Iterator</code> is a deep
 * copy of the original search results. See {@link
 * javax.naming.Context#listBindings(String)}.
 *
 * @param  dn  <code>String</code> LDAP context to list
 *
 * @return  <code>Iterator</code> - LDAP search result
 *
 * @throws  NamingException  if the LDAP returns an error
 *///  ww  w  . j a va  2  s.com
protected Iterator<Binding> listBindings(final String dn) throws NamingException {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("listBindings with the following parameters:");
        this.logger.debug("  dn = " + dn);
        if (this.logger.isTraceEnabled()) {
            this.logger.trace("  config = " + this.config.getEnvironment());
        }
    }

    List<Binding> results = null;
    LdapContext ctx = null;
    NamingEnumeration<Binding> en = null;
    try {
        for (int i = 0; i <= this.config.getOperationRetry() || this.config.getOperationRetry() == -1; i++) {
            try {
                ctx = this.getContext();
                en = ctx.listBindings(dn);

                results = BINDING_COPY_RESULT_HANDLER.process(null, en,
                        this.config.getHandlerIgnoreExceptions());

                break;
            } catch (NamingException e) {
                this.operationRetry(ctx, e, i);
            }
        }
    } finally {
        if (en != null) {
            en.close();
        }
        if (ctx != null) {
            ctx.close();
        }
    }
    return results.iterator();
}