Example usage for javax.naming ContextNotEmptyException ContextNotEmptyException

List of usage examples for javax.naming ContextNotEmptyException ContextNotEmptyException

Introduction

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

Prototype

public ContextNotEmptyException(String explanation) 

Source Link

Document

Constructs a new instance of ContextNotEmptyException using an explanation.

Usage

From source file:org.apache.directory.studio.connection.core.io.api.DirectoryApiConnectionWrapper.java

/**
 * Checks the given response.//from w  w  w .  ja  v  a  2  s.c  o m
 *
 * @param response
 *      the response
 * @throws Exception
 *      if the LDAP result associated with the response is not a success
 */
private void checkResponse(ResultResponse response) throws Exception {
    if (response != null) {
        LdapResult ldapResult = response.getLdapResult();
        if (ldapResult != null) {
            // NOT_ALLOWED_ON_NON_LEAF error (thrown when deleting an entry with children)
            if (ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF.equals(ldapResult.getResultCode())) {
                throw new ContextNotEmptyException(ldapResult.getDiagnosticMessage());
            }
            // ENTRY_ALREADY_EXISTS error
            // (We need this conversion in the case where this error is thrown during an LDIF
            // import with the "Update existing entries" flag turned on)
            else if (ResultCodeEnum.ENTRY_ALREADY_EXISTS.equals(ldapResult.getResultCode())) {
                throw new NameAlreadyBoundException(ldapResult.getDiagnosticMessage());
            }
            // Different from SUCCESS, we throw a generic exception
            else if (!ResultCodeEnum.SUCCESS.equals(ldapResult.getResultCode())) {
                int code = ldapResult.getResultCode().getResultCode();
                String message = ldapResult.getDiagnosticMessage();

                // Checking if we got a message from the LDAP result
                if (StringUtils.isEmpty(message)) {
                    // Assigning the generic result code description
                    message = Utils.getResultCodeDescription(code);
                }

                throw new Exception(NLS.bind("[LDAP: error code {0} - {1}]", new String[] //$NON-NLS-1$
                { Integer.toString(code), message })); //$NON-NLS-1$
            }
        }
    }
}