summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lookup/ItemPath.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-22 16:01:18 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-22 16:02:11 +0200
commita7cefce58cdb0f7f2d0868a1d5ee2f24f3890646 (patch)
tree89c30cdb92d7edae5d735c2d6ef45f890cc7be82 /src/main/java/com/c2kernel/lookup/ItemPath.java
parentcfa70de9ec7745356ed00c1502d5bd55eee14181 (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/ItemPath.java')
-rw-r--r--src/main/java/com/c2kernel/lookup/ItemPath.java26
1 files changed, 12 insertions, 14 deletions
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;
}
}