Example usage for javax.naming ContextNotEmptyException printStackTrace

List of usage examples for javax.naming ContextNotEmptyException printStackTrace

Introduction

In this page you can find the example usage for javax.naming ContextNotEmptyException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.geoserver.security.ldap.LDAPTestUtils.java

/**
 * Clear the directory sub-tree starting with the node represented by the
 * supplied distinguished name./*from ww w .  j a  va  2 s  .c o m*/
 *
 * @param ctx  The DirContext to use for cleaning the tree.
 * @param name the distinguished name of the root node.
 * @throws NamingException if anything goes wrong removing the sub-tree.
 */
public static void clearSubContexts(DirContext ctx, Name name) throws NamingException {

    NamingEnumeration enumeration = null;
    try {
        enumeration = ctx.listBindings(name);
        while (enumeration.hasMore()) {
            Binding element = (Binding) enumeration.next();
            DistinguishedName childName = new DistinguishedName(element.getName());
            childName.prepend((DistinguishedName) name);

            try {
                ctx.destroySubcontext(childName);
            } catch (ContextNotEmptyException e) {
                clearSubContexts(ctx, childName);
                ctx.destroySubcontext(childName);
            }
        }
    } catch (NamingException e) {
        e.printStackTrace();
    } finally {
        try {
            enumeration.close();
        } catch (Exception e) {
            // Never mind this
        }
    }
}