Example usage for javax.naming.ldap LdapContext destroySubcontext

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

Introduction

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

Prototype

public void destroySubcontext(Name name) throws NamingException;

Source Link

Document

Destroys the named context and removes it from the namespace.

Usage

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

/**
 * This will delete the supplied dn from the LDAP namespace. Note that this
 * method does not throw NameNotFoundException if the supplied dn does not
 * exist. See {@link javax.naming.Context#destroySubcontext(String)}.
 *
 * @param  dn  <code>String</code> named object in the LDAP
 *
 * @throws  NamingException  if the LDAP returns an error
 *//* w w w.jav  a2  s . co  m*/
protected void delete(final String dn) throws NamingException {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Delete name with the following parameters:");
        this.logger.debug("  dn = " + dn);
        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.destroySubcontext(dn);
                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

/**
 * Deletes an entry./*w  w  w.  j av  a 2 s.  c o  m*/
 * 
 * @param dn the Dn of the entry to delete
 * @param controls the controls
 * @param monitor the progress monitor
 * @param referralsInfo the referrals info
 */
public void deleteEntry(final String dn, 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 entry
                modCtx.destroySubcontext(getSaveJndiName(dn));
            } 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) {
                            List<String> urls = new ArrayList<>(referral.getLdapUrls());

                            String referralDn = new LdapUrl(urls.get(0)).getDn().getName();
                            referralConnection.getConnectionWrapper().deleteEntry(referralDn, controls, monitor,
                                    newReferralsInfo);
                        } else {
                            canceled = true;
                        }
                    }
                } catch (NamingException ne) {
                    namingException = ne;
                } catch (LdapURLEncodingException e) {
                    namingException = new NamingException(e.getMessage());
                }
            } catch (NamingException ne) {
                namingException = ne;
            }

            for (IJndiLogger logger : getJndiLoggers()) {
                logger.logChangetypeDelete(connection, dn, 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());
    }
}