summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lookup/ItemPath.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-19 15:40:50 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-19 15:40:50 +0200
commit482b98e869d07802310e249d09d784c63f9a86b6 (patch)
treebd6c55d5d5ebf967fb22b5cf1ceb9f3f6a7bbdd9 /src/main/java/com/c2kernel/lookup/ItemPath.java
parent3743d182d99dbed9d2be84dc357f6839ffe4d2ec (diff)
Introduced static method ItemPath.fromUUIDString and made the UUID
constructor protected to better handle ItemPath and AgentPath construction with String UUIDs, throwing the right exceptions.
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/ItemPath.java')
-rw-r--r--src/main/java/com/c2kernel/lookup/ItemPath.java25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/main/java/com/c2kernel/lookup/ItemPath.java b/src/main/java/com/c2kernel/lookup/ItemPath.java
index 2219c8a..793a0ed 100644
--- a/src/main/java/com/c2kernel/lookup/ItemPath.java
+++ b/src/main/java/com/c2kernel/lookup/ItemPath.java
@@ -27,19 +27,15 @@ public class ItemPath extends Path
{
public ItemPath() {
- this(UUID.randomUUID());
+ setSysKey(UUID.randomUUID());
}
- public ItemPath(UUID uuid) {
+ protected ItemPath(UUID uuid) {
setSysKey(uuid);
- mPath = new String[1];
- mPath[0] = mUUID.toString();
}
public ItemPath(SystemKey syskey) {
setSysKey(syskey);
- mPath = new String[1];
- mPath[0] = mUUID.toString();
}
/*
@@ -82,13 +78,15 @@ public class ItemPath extends Path
public byte[] getOID() {
if (mType == Path.CONTEXT) return null;
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
- bb.putLong(mUUID.getMostSignificantBits());
- bb.putLong(mUUID.getLeastSignificantBits());
+ bb.putLong(mSysKey.msb);
+ bb.putLong(mSysKey.lsb);
return bb.array();
}
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;
}
@@ -96,7 +94,18 @@ public class ItemPath extends Path
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;
}
+
+ 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);
+ }
+ }
}