List of usage examples for javax.naming CommunicationException setRootCause
public void setRootCause(Throwable e)
From source file:org.lsc.jndi.JndiServices.java
private boolean doApply(final JndiModifications jm) throws CommunicationException { if (jm == null) { return true; }// ww w.j av a2 s . c om try { switch (jm.getOperation()) { case ADD_ENTRY: ctx.createSubcontext(new LdapName(rewriteBase(jm.getDistinguishName())), getAttributes(jm.getModificationItems(), true)); break; case DELETE_ENTRY: if (recursiveDelete) { deleteChildrenRecursively(rewriteBase(jm.getDistinguishName())); } else { ctx.destroySubcontext(new LdapName(rewriteBase(jm.getDistinguishName()))); } break; case MODIFY_ENTRY: Object[] table = jm.getModificationItems().toArray(); ModificationItem[] mis = new ModificationItem[table.length]; System.arraycopy(table, 0, mis, 0, table.length); ctx.modifyAttributes(new LdapName(rewriteBase(jm.getDistinguishName())), mis); break; case MODRDN_ENTRY: //We do not display this warning if we do not apply the modification with the option modrdn = false LOGGER.warn( "WARNING: updating the RDN of the entry will cancel other modifications! Relaunch synchronization to complete update."); ctx.rename(new LdapName(rewriteBase(jm.getDistinguishName())), new LdapName(rewriteBase(jm.getNewDistinguishName()))); break; default: LOGGER.error("Unable to identify the right modification type: {}", jm.getOperation()); return false; } return true; } catch (ContextNotEmptyException e) { LOGGER.error( "Object {} not deleted because it has children (LDAP error code 66 received). To delete this entry and it's subtree, set the dst.java.naming.recursivedelete property to true", jm.getDistinguishName()); return false; } catch (NamingException ne) { if (LOGGER.isErrorEnabled()) { StringBuilder errorMessage = new StringBuilder("Error while "); switch (jm.getOperation()) { case ADD_ENTRY: errorMessage.append("adding"); break; case MODIFY_ENTRY: errorMessage.append("modifying"); break; case MODRDN_ENTRY: errorMessage.append("renaming"); break; case DELETE_ENTRY: if (recursiveDelete) { errorMessage.append("recursively "); } errorMessage.append("deleting"); break; } errorMessage.append(" entry ").append(jm.getDistinguishName()); errorMessage.append(" in directory :").append(ne.toString()); LOGGER.error(errorMessage.toString()); } if (ne instanceof CommunicationException) { // we lost the connection to the source or destination, stop everything! throw (CommunicationException) ne; } if (ne instanceof ServiceUnavailableException) { // we lost the connection to the source or destination, stop everything! CommunicationException ce = new CommunicationException(ne.getExplanation()); ce.setRootCause(ne); throw ce; } return false; } }