Example usage for javax.naming.ldap LdapContext modifyAttributes

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

Introduction

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

Prototype

public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException;

Source Link

Document

Modifies the attributes associated with a named object.

Usage

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

/**
 * This will modify the supplied attributes for the supplied value given by
 * the modification operation. modOp must be one of: ADD_ATTRIBUTE,
 * REPLACE_ATTRIBUTE, REMOVE_ATTRIBUTE. The order of the modifications is not
 * specified. Where possible, the modifications are performed atomically. See
 * {@link javax.naming.DirContext#modifyAttributes( String, int, Attributes)}.
 *
 * @param  dn  <code>String</code> named object in the LDAP
 * @param  modOp  <code>int</code> modification operation
 * @param  attrs  <code>Attributes</code> attributes to be used for the
 * operation, may be null/* www.j av a  2 s. c  o m*/
 *
 * @throws  NamingException  if the LDAP returns an error
 */
protected void modifyAttributes(final String dn, final int modOp, final Attributes attrs)
        throws NamingException {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Modify attributes with the following parameters:");
        this.logger.debug("  dn = " + dn);
        this.logger.debug("  modOp = " + modOp);
        this.logger.debug("  attrs = " + attrs);
        if (this.logger.isTraceEnabled()) {
            this.logger.trace("  config = " + this.config.getEnvironment());
        }
    }

    LdapContext ctx = null;
    try {
        for (int i = 0; i <= this.config.getOperationRetry() || this.config.getOperationRetry() == -1; i++) {
            try {
                ctx = this.getContext();
                ctx.modifyAttributes(dn, modOp, attrs);
                break;
            } catch (NamingException e) {
                this.operationRetry(ctx, e, i);
            }
        }
    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}