Example usage for javax.naming.ldap LdapContext getSchema

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

Introduction

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

Prototype

public DirContext getSchema(Name name) throws NamingException;

Source Link

Document

Retrieves the schema associated with the named object.

Usage

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

/**
 * This will return the LDAP schema associated with the supplied dn. The
 * resulting <code>Iterator</code> is a deep copy of the original search
 * results. See {@link javax.naming.DirContext#getSchema(String)}.
 *
 * @param  dn  <code>String</code> named object in the LDAP
 *
 * @return  <code>Iterator</code> - LDAP search result
 *
 * @throws  NamingException  if the LDAP returns an error
 *//* ww  w .  j  a  v  a 2 s.  c  o m*/
protected Iterator<SearchResult> getSchema(final String dn) throws NamingException {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Schema search with the following parameters:");
        this.logger.debug("  dn = " + dn);
        if (this.logger.isTraceEnabled()) {
            this.logger.trace("  config = " + this.config.getEnvironment());
        }
    }

    List<SearchResult> results = null;
    LdapContext ctx = null;
    DirContext schema = null;
    NamingEnumeration<SearchResult> en = null;
    try {
        for (int i = 0; i <= this.config.getOperationRetry() || this.config.getOperationRetry() == -1; i++) {
            try {
                ctx = this.getContext();
                schema = ctx.getSchema(dn);
                en = schema.search("", null);

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

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