diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-09-22 16:01:18 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-09-22 16:02:11 +0200 |
| commit | a7cefce58cdb0f7f2d0868a1d5ee2f24f3890646 (patch) | |
| tree | 89c30cdb92d7edae5d735c2d6ef45f890cc7be82 /src/main/java/com/c2kernel/lookup | |
| parent | cfa70de9ec7745356ed00c1502d5bd55eee14181 (diff) | |
ItemPath.fromUUIDString unnecessary as ItemPath(String) supports both
plain UUIDs and an /entity prefix. Tightened that up and removed the
fromUUIDString method for a simpler API. Also switched AgentPath(String)
to a path argument for consistency. New AgentPaths should be created
with AgentPath(new ItemPath(), String) instead.
Diffstat (limited to 'src/main/java/com/c2kernel/lookup')
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/AgentPath.java | 12 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/ItemPath.java | 26 |
2 files changed, 20 insertions, 18 deletions
diff --git a/src/main/java/com/c2kernel/lookup/AgentPath.java b/src/main/java/com/c2kernel/lookup/AgentPath.java index f6d6ca4..9dab6a6 100644 --- a/src/main/java/com/c2kernel/lookup/AgentPath.java +++ b/src/main/java/com/c2kernel/lookup/AgentPath.java @@ -64,9 +64,13 @@ public class AgentPath extends ItemPath mAgentName = agentName;
}
- public AgentPath(String agentName) {
- super();
- mAgentName = agentName;
+ public AgentPath(String path) throws InvalidItemPathException {
+ super(path);
+ try {
+ findAgentName();
+ } catch (ObjectNotFoundException e) {
+ throw new InvalidAgentPathException();
+ }
}
public void setAgentName(String agentID)
@@ -135,7 +139,7 @@ public class AgentPath extends ItemPath public static AgentPath fromUUIDString(String uuid) throws InvalidAgentPathException {
try {
- return new AgentPath(ItemPath.fromUUIDString(uuid));
+ return new AgentPath(new ItemPath(uuid));
} catch (InvalidItemPathException ex) {
throw new InvalidAgentPathException(ex.getMessage());
}
diff --git a/src/main/java/com/c2kernel/lookup/ItemPath.java b/src/main/java/com/c2kernel/lookup/ItemPath.java index 793a0ed..befbfff 100644 --- a/src/main/java/com/c2kernel/lookup/ItemPath.java +++ b/src/main/java/com/c2kernel/lookup/ItemPath.java @@ -11,6 +11,7 @@ package com.c2kernel.lookup;
import java.nio.ByteBuffer;
+import java.util.Arrays;
import java.util.UUID;
import com.c2kernel.common.ObjectNotFoundException;
@@ -51,17 +52,21 @@ public class ItemPath extends Path public ItemPath(String path) throws InvalidItemPathException
{
super(path, Path.CONTEXT);
+ if (path == null) throw new InvalidItemPathException("Path cannot be null");
getSysKeyFromPath();
}
private void getSysKeyFromPath() throws InvalidItemPathException {
- if (mPath.length > 0) {
+ if (mPath.length == 1) {
try {
setSysKey(UUID.fromString(mPath[0]));
+ mType = Path.ENTITY;
} catch (IllegalArgumentException ex) {
throw new InvalidItemPathException(mPath[0]+" is not a valid UUID");
}
}
+ else
+ throw new InvalidItemPathException("Not a valid item path: "+Arrays.toString(mPath));
}
// EntityPaths root in /entity
@@ -85,27 +90,20 @@ public class ItemPath extends Path protected void setSysKey(UUID uuid) {
mUUID = uuid;
- mPath = new String[1];
- mPath[0] = mUUID.toString();
mSysKey = new SystemKey(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
- mType = Path.ENTITY;
+ setPathFromUUID(mUUID.toString());
}
protected void setSysKey(SystemKey sysKey) {
mSysKey = sysKey;
mUUID = new UUID(sysKey.msb, sysKey.lsb);
- mPath = new String[1];
- mPath[0] = mUUID.toString();
- mType = Path.ENTITY;
+ setPathFromUUID(mUUID.toString());
}
- public static ItemPath fromUUIDString(String uuid) throws InvalidItemPathException {
- if (uuid == null) throw new InvalidItemPathException("Null uuid");
- try {
- return new ItemPath(UUID.fromString(uuid));
- } catch (IllegalArgumentException ex) {
- throw new InvalidItemPathException("Illegal uuid: "+uuid);
- }
+ private void setPathFromUUID(String uuid) {
+ mPath = new String[1];
+ mPath[0] = uuid;
+ mType = Path.ENTITY;
}
}
|
