From 482b98e869d07802310e249d09d784c63f9a86b6 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 19 Sep 2014 15:40:50 +0200 Subject: 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. --- src/main/java/com/c2kernel/lookup/ItemPath.java | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/ItemPath.java') 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); + } + } } -- cgit v1.2.3