From e64e6fada90a93be37f171277b484630db263266 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 3 Oct 2014 17:31:22 +0200 Subject: Adapt to new Exceptions --- .../com/c2kernel/lookup/ldap/LDAPLookupUtils.java | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java') diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java index e1c8ac4..0aa0ca6 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java @@ -6,9 +6,9 @@ package com.c2kernel.lookup.ldap; //import netscape.ldap.*; //import netscape.ldap.util.*; -import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectAlreadyExists; import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; import com.c2kernel.utils.Logger; import com.novell.ldap.LDAPAttribute; import com.novell.ldap.LDAPAttributeSet; @@ -30,7 +30,7 @@ final public class LDAPLookupUtils static final char[] META_CHARS = {'+', '=', '"', ',', '<', '>', ';', '/'}; static final String[] META_ESCAPED = {"2B", "3D", "22", "2C", "3C", "3E", "3B", "2F"}; static public LDAPEntry getEntry(LDAPConnection ld, String dn,int dereference) - throws ObjectNotFoundException + throws ObjectNotFound { try { LDAPSearchConstraints searchCons = new LDAPSearchConstraints(); @@ -39,9 +39,9 @@ final public class LDAPLookupUtils LDAPEntry thisEntry = ld.read(dn,searchCons); if (thisEntry != null) return thisEntry; } catch (LDAPException ex) { - throw new ObjectNotFoundException("LDAP Exception for dn:"+dn+": \n"+ex.getMessage(), ""); + throw new ObjectNotFound("LDAP Exception for dn:"+dn+": \n"+ex.getMessage()); } - throw new ObjectNotFoundException(dn+" does not exist", ""); + throw new ObjectNotFound(dn+" does not exist"); } @@ -72,26 +72,26 @@ final public class LDAPLookupUtils //Given a DN, return an LDAP Entry static public LDAPEntry getEntry(LDAPConnection ld, String dn) - throws ObjectNotFoundException + throws ObjectNotFound { return getEntry(ld, dn, LDAPSearchConstraints.DEREF_NEVER); } - static public String getFirstAttributeValue(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException + static public String getFirstAttributeValue(LDAPEntry anEntry, String attribute) throws ObjectNotFound { LDAPAttribute attr = anEntry.getAttribute(attribute); if (attr==null) - throw new ObjectNotFoundException("No attributes named '"+attribute+"'", ""); + throw new ObjectNotFound("No attributes named '"+attribute+"'"); return (String)attr.getStringValues().nextElement(); } - static public String[] getAllAttributeValues(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException + static public String[] getAllAttributeValues(LDAPEntry anEntry, String attribute) throws ObjectNotFound { LDAPAttribute attr = anEntry.getAttribute(attribute); if (attr!=null) return attr.getStringValueArray(); - throw new ObjectNotFoundException("No attributes named '"+attribute+"'", ""); + throw new ObjectNotFound("No attributes named '"+attribute+"'"); } @@ -108,24 +108,24 @@ final public class LDAPLookupUtils } return false; } - static public boolean hasOneAttributeValue(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException + static public boolean hasOneAttributeValue(LDAPEntry anEntry, String attribute) throws ObjectNotFound { int j =0; LDAPAttribute attr = anEntry.getAttribute(attribute); if (attr==null) - throw new ObjectNotFoundException("No attributes named '"+attribute+"'", ""); + throw new ObjectNotFound("No attributes named '"+attribute+"'"); j=attr.size(); return j==1; } //this is for a single-valued attribute static public void setAttributeValue(LDAPConnection ld, LDAPEntry anEntry, String attribute, String newValue) - throws ObjectNotFoundException, ObjectCannotBeUpdated + throws ObjectNotFound, ObjectCannotBeUpdated { try { if (!hasOneAttributeValue(anEntry, attribute)) - throw new ObjectCannotBeUpdated("Attribute "+attribute + " of entry " + anEntry.getDN()+" has more than one value", ""); - } catch (ObjectNotFoundException ex) { + throw new ObjectCannotBeUpdated("Attribute "+attribute + " of entry " + anEntry.getDN()+" has more than one value"); + } catch (ObjectNotFound ex) { addAttributeValue(ld, anEntry, attribute, newValue); } try @@ -135,7 +135,7 @@ final public class LDAPLookupUtils catch (LDAPException ex) { Logger.error(ex); - throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be modified", ""); + throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be modified"); } } @@ -151,7 +151,7 @@ final public class LDAPLookupUtils catch (LDAPException ex) { Logger.error(ex); - throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be added.", ""); + throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be added."); } } @@ -166,7 +166,7 @@ final public class LDAPLookupUtils catch (LDAPException ex) { Logger.error(ex); - throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be deleted", ""); + throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be deleted"); } } @@ -186,7 +186,7 @@ final public class LDAPLookupUtils } static public void addEntry(LDAPConnection ld,LDAPEntry myEntry) - throws ObjectAlreadyExistsException, LDAPException + throws ObjectAlreadyExists, LDAPException { try { @@ -194,7 +194,7 @@ final public class LDAPLookupUtils } catch( LDAPException ex ) { if (ex.getResultCode() == LDAPException.ENTRY_ALREADY_EXISTS) - throw new ObjectAlreadyExistsException("Entry already present." + myEntry.getDN(), ""); + throw new ObjectAlreadyExists("Entry already present." + myEntry.getDN()); throw ex; } } -- cgit v1.2.3