From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: Replaced int sysKey Item identifier with UUID, which is now portable. ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers. --- src/main/java/com/c2kernel/lookup/AgentPath.java | 71 ++++++++++++++---------- 1 file changed, 43 insertions(+), 28 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/AgentPath.java') diff --git a/src/main/java/com/c2kernel/lookup/AgentPath.java b/src/main/java/com/c2kernel/lookup/AgentPath.java index a0bb7fd..fb4ce0e 100644 --- a/src/main/java/com/c2kernel/lookup/AgentPath.java +++ b/src/main/java/com/c2kernel/lookup/AgentPath.java @@ -12,10 +12,12 @@ package com.c2kernel.lookup; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.UUID; import org.apache.xerces.impl.dv.util.Base64; import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.SystemKey; import com.c2kernel.process.Gateway; @@ -31,29 +33,40 @@ public class AgentPath extends ItemPath private String mAgentName=null; private String mPassword=null; - public AgentPath(int syskey, String agentName) - throws InvalidAgentPathException,InvalidItemPathException - { - super(syskey); - if (agentName!=null && agentName.length()>0) - setAgentName(agentName); - else + public AgentPath(SystemKey syskey) throws InvalidAgentPathException { + super(syskey); + try { + findAgentName(); + } catch (ObjectNotFoundException e) { + throw new InvalidAgentPathException(); + } + } + public AgentPath(UUID uuid) throws InvalidAgentPathException { + super(uuid); + try { + findAgentName(); + } catch (ObjectNotFoundException e) { throw new InvalidAgentPathException(); + } } - - public AgentPath(int syskey) - throws InvalidItemPathException - { - super(syskey); + + public AgentPath(ItemPath itemPath) throws InvalidAgentPathException { + super(itemPath.mUUID); + try { + findAgentName(); + } catch (ObjectNotFoundException e) { + throw new InvalidAgentPathException(); + } } - - public AgentPath(ItemPath entity) { - super(); - try { - setSysKey(entity.getSysKey()); - } catch (InvalidItemPathException ex) { - //won't happen as the entity path was valid - } + + public AgentPath(ItemPath itemPath, String agentName) { + super(itemPath.mUUID); + mAgentName = agentName; + } + + public AgentPath(String agentName) { + super(); + mAgentName = agentName; } public void setAgentName(String agentID) @@ -64,14 +77,16 @@ public class AgentPath extends ItemPath public String getAgentName() { if (mAgentName==null) - { - try { - mAgentName = Gateway.getLookup().getAgentName(this); - } catch (ObjectNotFoundException e) { - mAgentName = ""; - } - } - return mAgentName; + try { + findAgentName(); + } catch (ObjectNotFoundException e) { + return null; + } + return mAgentName; + } + + private void findAgentName() throws ObjectNotFoundException { + mAgentName = Gateway.getLookup().getAgentName(this); } public RolePath[] getRoles() -- cgit v1.2.3