Example usage for javax.naming.ldap LdapContext rename

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

Introduction

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

Prototype

public void rename(Name oldName, Name newName) throws NamingException;

Source Link

Document

Binds a new name to the object bound to an old name, and unbinds the old name.

Usage

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

/**
 * This will rename the supplied dn in the LDAP namespace. See {@link
 * javax.naming.Context#rename(String, String)}.
 *
 * @param  oldDn  <code>String</code> object to rename
 * @param  newDn  <code>String</code> new name
 *
 * @throws  NamingException  if the LDAP returns an error
 *//*w  w w .  j av  a 2  s . co  m*/
protected void rename(final String oldDn, final String newDn) throws NamingException {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Rename name with the following parameters:");
        this.logger.debug("  oldDn = " + oldDn);
        this.logger.debug("  newDn = " + newDn);
        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.rename(oldDn, newDn);
                break;
            } catch (NamingException e) {
                this.operationRetry(ctx, e, i);
            }
        }
    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}

From source file:org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper.java

/**
 * Renames an entry.//  w  w w  .j a  v a  2  s.c  o  m
 * 
 * @param oldDn the old Dn
 * @param newDn the new Dn
 * @param deleteOldRdn true to delete the old Rdn
 * @param controls the controls
 * @param monitor the progress monitor
 * @param referralsInfo the referrals info
 */
public void renameEntry(final String oldDn, final String newDn, final boolean deleteOldRdn,
        final Control[] controls, final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo) {
    if (connection.isReadOnly()) {
        monitor.reportError(
                new Exception(NLS.bind(Messages.error__connection_is_readonly, connection.getName())));
        return;
    }

    InnerRunnable runnable = new InnerRunnable() {
        public void run() {
            try {
                // create modify context
                LdapContext modCtx = context.newInstance(controls);

                // use "throw" as we handle referrals manually
                modCtx.addToEnvironment(Context.REFERRAL, REFERRAL_THROW);

                // delete old Rdn
                if (deleteOldRdn) {
                    modCtx.addToEnvironment(JAVA_NAMING_LDAP_DELETE_RDN, "true"); //$NON-NLS-1$
                } else {
                    modCtx.addToEnvironment(JAVA_NAMING_LDAP_DELETE_RDN, "false"); //$NON-NLS-1$
                }

                // rename entry
                modCtx.rename(getSaveJndiName(oldDn), getSaveJndiName(newDn));
            } catch (ReferralException re) {
                try {
                    ReferralsInfo newReferralsInfo = handleReferralException(re, referralsInfo);
                    Referral referral = newReferralsInfo.getNextReferral();
                    if (referral != null) {
                        Connection referralConnection = ConnectionWrapperUtils.getReferralConnection(referral,
                                monitor, this);
                        if (referralConnection != null) {
                            referralConnection.getConnectionWrapper().renameEntry(oldDn, newDn, deleteOldRdn,
                                    controls, monitor, newReferralsInfo);
                        } else {
                            canceled = true;
                        }
                    }
                } catch (NamingException ne) {
                    namingException = ne;
                }
            } catch (NamingException ne) {
                namingException = ne;
            }

            for (IJndiLogger logger : getJndiLoggers()) {
                logger.logChangetypeModDn(connection, oldDn, newDn, deleteOldRdn, controls, namingException);
            }
        }
    };

    try {
        checkConnectionAndRunAndMonitor(runnable, monitor);
    } catch (NamingException ne) {
        monitor.reportError(ne);
    }

    if (runnable.isCanceled()) {
        monitor.setCanceled(true);
    }
    if (runnable.getException() != null) {
        monitor.reportError(runnable.getException());
    }
}