From 4579d480441683973121cf6288aae21b475d75c0 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 19 Sep 2014 15:45:11 +0200 Subject: Switch from UUID.fromString to ItemPath.fromUUIDString --- .../java/com/c2kernel/lookup/ldap/LDAPLookup.java | 37 +++++++++------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java index 0d3cbd4..e5497f2 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java @@ -9,7 +9,6 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Iterator; import java.util.StringTokenizer; -import java.util.UUID; import org.omg.CORBA.Object; @@ -33,7 +32,6 @@ import com.c2kernel.utils.Logger; import com.novell.ldap.LDAPAttribute; import com.novell.ldap.LDAPAttributeSet; import com.novell.ldap.LDAPConnection; -import com.novell.ldap.LDAPDN; import com.novell.ldap.LDAPEntry; import com.novell.ldap.LDAPException; import com.novell.ldap.LDAPSearchConstraints; @@ -178,16 +176,11 @@ public class LDAPLookup implements LookupManager{ + entityKey); String objClass = LDAPLookupUtils.getFirstAttributeValue(domEntry, "objectClass"); - try { - ItemPath referencedPath = new ItemPath(UUID.fromString(entityKey)); - if (objClass.equals("cristalagent")) - return new AgentPath(referencedPath); - - return referencedPath; - } catch (IllegalArgumentException ex) { - throw new InvalidItemPathException(entityKey); - } + ItemPath referencedPath = ItemPath.fromUUIDString(entityKey); + if (objClass.equals("cristalagent")) + return new AgentPath(referencedPath); + return referencedPath; } @@ -371,7 +364,7 @@ public class LDAPLookup implements LookupManager{ } @Override - public ItemPath getItemPath(UUID uuid) throws ObjectNotFoundException, InvalidItemPathException { + public ItemPath getItemPath(String uuid) throws ObjectNotFoundException, InvalidItemPathException { String[] attr = { LDAPConnection.ALL_USER_ATTRS }; try { ItemPath item = new ItemPath(uuid); @@ -397,23 +390,23 @@ public class LDAPLookup implements LookupManager{ * 'ior' and 'uniquemember' * @throws ObjectNotFoundException * @throws ObjectNotFoundException + * @throws */ protected Path nodeToPath(LDAPEntry entry) throws InvalidItemPathException, ObjectNotFoundException { String dn = entry.getDN(); - UUID entityKey; + ItemPath entityKey; org.omg.CORBA.Object ior; // extract syskey try { - String entityKeyStr = LDAPLookupUtils.getFirstAttributeValue(entry,"cn"); - entityKey = UUID.fromString(entityKeyStr); + String entityKeyStr = LDAPLookupUtils.getFirstAttributeValue(entry, "cn"); + entityKey = ItemPath.fromUUIDString(entityKeyStr); } catch (ObjectNotFoundException ex) { entityKey = null; - } catch (IllegalArgumentException ex) { + } catch (InvalidItemPathException ex) { entityKey = null; } - // extract IOR try { @@ -428,7 +421,7 @@ public class LDAPLookup implements LookupManager{ if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalagent")) { //cristalagent String agentID = LDAPLookupUtils.getFirstAttributeValue(entry,"uid"); - thisPath = new AgentPath(new ItemPath(entityKey), agentID); + thisPath = new AgentPath(entityKey, agentID); } else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalrole")) { //cristalrole @@ -446,15 +439,15 @@ public class LDAPLookup implements LookupManager{ (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalcontext") && dn.endsWith(mItemTypeRoot))) { if(dn.endsWith(mItemTypeRoot)) { - ItemPath entityPath = new ItemPath(entityKey); - thisPath = entityPath; + if (entityKey == null) throw new InvalidItemPathException(entry.getDN()+" was not a valid itemPath"); + thisPath = entityKey; } else - throw new ObjectNotFoundException("Entity found outside entity tree"); + throw new ObjectNotFoundException("Entity found outside entity tree", ""); } else { - throw new ObjectNotFoundException("Unrecognised LDAP entry. Not a cristal entry"); + throw new ObjectNotFoundException("Unrecognised LDAP entry. Not a cristal entry", ""); } //set IOR if we have one -- cgit v1.2.3