Example usage for javax.naming NamingException setRootCause

List of usage examples for javax.naming NamingException setRootCause

Introduction

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

Prototype

public void setRootCause(Throwable e) 

Source Link

Document

Records the root cause of this NamingException.

Usage

From source file:org.mule.transport.ldap.util.DSManager.java

/**
 * Imports the LDIF entries packaged with the Eve JNDI provider jar into the
 * newly created system partition to prime it up for operation. Note that
 * only ou=system entries will be added - entries for other partitions
 * cannot be imported and will blow chunks.
 * /* w  ww  .j a  v a  2  s.  c om*/
 * @throws NamingException
 *             if there are problems reading the ldif file and adding those
 *             entries to the system partition
 */
protected void importLdif(final InputStream in) throws NamingException {
    if (in == null) {
        throw new NullPointerException("in must not be null");
    }

    try {
        final Iterator<LdifEntry> iterator = new LdifReader(in).iterator();

        while (iterator.hasNext()) {
            final LdifEntry entry = iterator.next();

            final LdapDN dn = new LdapDN(entry.getDn());
            // dn.remove(0);
            // dn.remove(0);

            final Attributes attr = new BasicAttributes();

            final Iterator<EntryAttribute> iea = entry.getEntry().iterator();

            for (; iea.hasNext();) {
                final EntryAttribute ea = iea.next();

                attr.put(ea.getId(), ea.get().get());

                logger.debug("id " + ea.getId() + "//" + ea.get().get());
                logger.debug("size:" + ea.size());
            }

            logger.debug(" for dn:" + dn);

            root.createSubcontext(dn, attr);
        }
    } catch (final Exception e) {
        final String msg = "failed while trying to parse system ldif file";
        final NamingException ne = new LdapConfigurationException(msg);
        ne.setRootCause(e);
        throw ne;
    }
}

From source file:org.springframework.ldap.pool.DelegatingContext.java

/**
 * @see javax.naming.Context#close()// w  w  w .  jav  a  2s .com
 */
public void close() throws NamingException {
    final Context context = this.getInnermostDelegateContext();
    if (context == null) {
        return;
    }

    //Get a local reference so the member can be nulled earlier
    this.delegateContext = null;

    //Return the object to the Pool and then null the pool reference
    try {
        boolean valid = true;

        if (context instanceof FailureAwareContext) {
            FailureAwareContext failureAwareContext = (FailureAwareContext) context;
            if (failureAwareContext.hasFailed()) {
                valid = false;
            }
        }

        if (valid) {
            this.keyedObjectPool.returnObject(this.dirContextType, context);
        } else {
            this.keyedObjectPool.invalidateObject(this.dirContextType, context);
        }
    } catch (Exception e) {
        final NamingException namingException = new NamingException(
                "Failed to return delegate Context to pool.");
        namingException.setRootCause(e);
        throw namingException;
    } finally {
        this.keyedObjectPool = null;
    }
}