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. --- .../com/c2kernel/collection/AggregationMember.java | 6 +++--- .../com/c2kernel/collection/CollectionMember.java | 3 ++- .../com/c2kernel/collection/DependencyMember.java | 6 +++--- .../java/com/c2kernel/entity/TraceableLocator.java | 4 ++-- .../com/c2kernel/entity/agent/ActiveLocator.java | 10 ++++----- src/main/java/com/c2kernel/entity/agent/Job.java | 7 +++--- .../c2kernel/entity/imports/ImportAggregation.java | 10 ++++----- .../c2kernel/entity/imports/ImportDependency.java | 6 +++--- .../com/c2kernel/entity/transfer/TransferItem.java | 6 +++--- src/main/java/com/c2kernel/events/Event.java | 19 ++++++---------- .../com/c2kernel/lifecycle/instance/Workflow.java | 6 +++--- .../instance/predefined/AddMemberToCollection.java | 3 +-- .../lifecycle/instance/predefined/AddNewSlot.java | 3 +-- .../instance/predefined/AssignItemToSlot.java | 3 +-- .../predefined/RemoveSlotFromCollection.java | 3 +-- .../routingHelpers/ViewpointDataHelper.java | 4 +--- src/main/java/com/c2kernel/lookup/AgentPath.java | 12 +++++++++-- src/main/java/com/c2kernel/lookup/ItemPath.java | 25 +++++++++++++++------- src/main/java/com/c2kernel/lookup/Lookup.java | 3 +-- .../c2kernel/persistency/outcome/Viewpoint.java | 7 +++--- src/main/java/com/c2kernel/process/Bootstrap.java | 15 +++++++------ .../java/com/c2kernel/process/ItemHTTPBridge.java | 6 +++--- .../com/c2kernel/process/module/ModuleImport.java | 7 +++--- 23 files changed, 89 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/c2kernel/collection/AggregationMember.java b/src/main/java/com/c2kernel/collection/AggregationMember.java index cb8c355..ba2524c 100644 --- a/src/main/java/com/c2kernel/collection/AggregationMember.java +++ b/src/main/java/com/c2kernel/collection/AggregationMember.java @@ -1,11 +1,11 @@ package com.c2kernel.collection; import java.util.StringTokenizer; -import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.graph.model.GraphableVertex; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.process.Gateway; @@ -143,8 +143,8 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb } @Override - public void setChildUUID(String uuid) throws MembershipException { - setItemPath(new ItemPath(UUID.fromString(uuid))); + public void setChildUUID(String uuid) throws MembershipException, InvalidItemPathException { + setItemPath(ItemPath.fromUUIDString(uuid)); } diff --git a/src/main/java/com/c2kernel/collection/CollectionMember.java b/src/main/java/com/c2kernel/collection/CollectionMember.java index 4fc7e3d..247ada5 100644 --- a/src/main/java/com/c2kernel/collection/CollectionMember.java +++ b/src/main/java/com/c2kernel/collection/CollectionMember.java @@ -4,6 +4,7 @@ import java.io.Serializable; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.proxy.ItemProxy; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.utils.CastorHashMap; @@ -24,7 +25,7 @@ public interface CollectionMember extends Serializable { public void setItemPath(ItemPath itemPath) throws MembershipException; public ItemPath getItemPath(); - public void setChildUUID(String uuid) throws MembershipException; + public void setChildUUID(String uuid) throws MembershipException, InvalidItemPathException; public String getChildUUID(); public void assignItem(ItemPath itemPath) throws MembershipException; diff --git a/src/main/java/com/c2kernel/collection/DependencyMember.java b/src/main/java/com/c2kernel/collection/DependencyMember.java index b5a8b13..4dbb8f1 100644 --- a/src/main/java/com/c2kernel/collection/DependencyMember.java +++ b/src/main/java/com/c2kernel/collection/DependencyMember.java @@ -1,10 +1,10 @@ package com.c2kernel.collection; import java.util.StringTokenizer; -import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.proxy.ItemProxy; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.process.Gateway; @@ -142,8 +142,8 @@ public class DependencyMember implements CollectionMember @Override - public void setChildUUID(String uuid) throws MembershipException { - mItemPath = new ItemPath(UUID.fromString(uuid)); + public void setChildUUID(String uuid) throws MembershipException, InvalidItemPathException { + mItemPath = ItemPath.fromUUIDString(uuid); } diff --git a/src/main/java/com/c2kernel/entity/TraceableLocator.java b/src/main/java/com/c2kernel/entity/TraceableLocator.java index e370ed6..a1dc702 100644 --- a/src/main/java/com/c2kernel/entity/TraceableLocator.java +++ b/src/main/java/com/c2kernel/entity/TraceableLocator.java @@ -14,9 +14,9 @@ package com.c2kernel.entity; import java.nio.ByteBuffer; import java.sql.Timestamp; -import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.SystemKey; import com.c2kernel.lookup.ItemPath; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; @@ -51,7 +51,7 @@ public class TraceableLocator extends org.omg.PortableServer.ServantLocatorPOA ByteBuffer bb = ByteBuffer.wrap(oid); long msb = bb.getLong(); long lsb = bb.getLong(); - ItemPath syskey = new ItemPath(new UUID(msb, lsb)); + ItemPath syskey = new ItemPath(new SystemKey(msb, lsb)); Logger.msg(1,"==========================================================="); Logger.msg(1,"Item called at "+new Timestamp( System.currentTimeMillis()) +": " + operation + diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java b/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java index 966b265..a1561ed 100644 --- a/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java +++ b/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java @@ -14,11 +14,11 @@ package com.c2kernel.entity.agent; import java.nio.ByteBuffer; import java.sql.Timestamp; -import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.SystemKey; import com.c2kernel.lookup.AgentPath; -import com.c2kernel.lookup.InvalidAgentPathException; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; @@ -55,7 +55,7 @@ public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA ByteBuffer bb = ByteBuffer.wrap(oid); long msb = bb.getLong(); long lsb = bb.getLong(); - AgentPath syskey = new AgentPath(new UUID(msb, lsb)); + AgentPath syskey = new AgentPath(new SystemKey(msb, lsb)); Logger.msg(1,"==========================================================="); Logger.msg(1,"Agent called at "+new Timestamp( System.currentTimeMillis()) +": " + operation + @@ -68,8 +68,8 @@ public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA { Logger.error("ObjectNotFoundException::ActiveLocator::preinvoke() "+ex.toString()); throw new org.omg.CORBA.OBJECT_NOT_EXIST(); - } catch (InvalidAgentPathException ex) { - Logger.error("InvalidAgentPathException::ActiveLocator::preinvoke() "+ex.toString()); + } catch (InvalidItemPathException ex) { + Logger.error("InvalidItemPathException::ActiveLocator::preinvoke() "+ex.toString()); throw new org.omg.CORBA.INV_OBJREF(); } } diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java index 13bd268..97f8eef 100644 --- a/src/main/java/com/c2kernel/entity/agent/Job.java +++ b/src/main/java/com/c2kernel/entity/agent/Job.java @@ -1,7 +1,6 @@ package com.c2kernel.entity.agent; import java.util.HashMap; -import java.util.UUID; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; @@ -132,9 +131,9 @@ public class Job implements C2KLocalObject item = null; } - public void setItemUUID( String uuid ) + public void setItemUUID( String uuid ) throws InvalidItemPathException { - setItemPath(new ItemPath(UUID.fromString(uuid))); + setItemPath(ItemPath.fromUUIDString(uuid)); } public String getItemUUID() { @@ -189,7 +188,7 @@ public class Job implements C2KLocalObject { if (uuid != null) try { - setAgentPath(new AgentPath(UUID.fromString(uuid))); + setAgentPath(AgentPath.fromUUIDString(uuid)); } catch (InvalidAgentPathException e) { Logger.error("Invalid agent path in Job: "+uuid); } diff --git a/src/main/java/com/c2kernel/entity/imports/ImportAggregation.java b/src/main/java/com/c2kernel/entity/imports/ImportAggregation.java index 2f19452..2d8f0a2 100644 --- a/src/main/java/com/c2kernel/entity/imports/ImportAggregation.java +++ b/src/main/java/com/c2kernel/entity/imports/ImportAggregation.java @@ -1,12 +1,12 @@ package com.c2kernel.entity.imports; import java.util.ArrayList; -import java.util.UUID; import com.c2kernel.collection.MembershipException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.graph.model.GraphPoint; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.property.PropertyDescription; import com.c2kernel.property.PropertyDescriptionList; @@ -36,8 +36,8 @@ public class ImportAggregation implements java.io.Serializable { if (thisMem.itemDescriptionPath != null && thisMem.itemDescriptionPath.length()>0) { ItemPath itemPath; try { - itemPath = new ItemPath(UUID.fromString(thisMem.itemDescriptionPath)); - } catch (IllegalArgumentException ex) { + itemPath = ItemPath.fromUUIDString(thisMem.itemDescriptionPath); + } catch (InvalidItemPathException ex) { itemPath = new DomainPath(thisMem.itemDescriptionPath).getItemPath(); } PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath); @@ -50,8 +50,8 @@ public class ImportAggregation implements java.io.Serializable { if (thisMem.itemPath != null && thisMem.itemPath.length()>0) { ItemPath itemPath; try { - itemPath = new ItemPath(UUID.fromString(thisMem.itemPath)); - } catch (IllegalArgumentException ex) { + itemPath = ItemPath.fromUUIDString(thisMem.itemPath); + } catch (InvalidItemPathException ex) { itemPath = new DomainPath(thisMem.itemPath).getItemPath(); } if (itemPath == null) diff --git a/src/main/java/com/c2kernel/entity/imports/ImportDependency.java b/src/main/java/com/c2kernel/entity/imports/ImportDependency.java index a43f6e3..87e6b11 100644 --- a/src/main/java/com/c2kernel/entity/imports/ImportDependency.java +++ b/src/main/java/com/c2kernel/entity/imports/ImportDependency.java @@ -1,11 +1,11 @@ package com.c2kernel.entity.imports; import java.util.ArrayList; -import java.util.UUID; import com.c2kernel.collection.MembershipException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.property.PropertyDescription; import com.c2kernel.property.PropertyDescriptionList; @@ -58,8 +58,8 @@ public class ImportDependency implements java.io.Serializable { for (ImportDependencyMember thisMem : dependencyMemberList) { ItemPath itemPath; try { - itemPath = new ItemPath(UUID.fromString(thisMem.itemPath)); - } catch (IllegalArgumentException ex) { + itemPath = ItemPath.fromUUIDString(thisMem.itemPath); + } catch (InvalidItemPathException ex) { itemPath = new DomainPath(thisMem.itemPath).getItemPath(); } diff --git a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java index bcbbe65..4ec8953 100644 --- a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java +++ b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java @@ -3,7 +3,6 @@ package com.c2kernel.entity.transfer; import java.io.File; import java.util.ArrayList; import java.util.Iterator; -import java.util.UUID; import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionArrayList; @@ -13,6 +12,7 @@ import com.c2kernel.entity.TraceableEntity; import com.c2kernel.lifecycle.instance.Workflow; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.lookup.Path; import com.c2kernel.persistency.ClusterStorage; @@ -55,9 +55,9 @@ public class TransferItem { this.domainPaths = domainPaths; } - public void setUUID( String uuid ) + public void setUUID( String uuid ) throws InvalidItemPathException { - itemPath = new ItemPath(UUID.fromString(uuid)); + itemPath = ItemPath.fromUUIDString(uuid); } public String getUUID() { diff --git a/src/main/java/com/c2kernel/events/Event.java b/src/main/java/com/c2kernel/events/Event.java index 267f135..bf9be68 100644 --- a/src/main/java/com/c2kernel/events/Event.java +++ b/src/main/java/com/c2kernel/events/Event.java @@ -10,16 +10,14 @@ package com.c2kernel.events; import java.util.Calendar; -import java.util.UUID; import com.c2kernel.common.GTimeStamp; import com.c2kernel.common.InvalidDataException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lookup.AgentPath; -import com.c2kernel.lookup.InvalidAgentPathException; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.utils.Logger; /** @@ -82,24 +80,21 @@ public class Event implements C2KLocalObject mItemPath = itemPath; } - public void setItemUUID( String uuid ) + public void setItemUUID( String uuid ) throws InvalidItemPathException { - setItemPath(new ItemPath(UUID.fromString(uuid))); + setItemPath(ItemPath.fromUUIDString(uuid)); } public String getItemUUID() { return getItemPath().getUUID().toString(); } - public void setAgentUUID( String uuid ) + public void setAgentUUID( String uuid ) throws InvalidItemPathException { - if (uuid == null) mAgentPath = null; + if (uuid == null || uuid.length() == 0) + mAgentPath = null; else - try { - setAgentPath(new AgentPath(UUID.fromString(uuid))); - } catch (InvalidAgentPathException e) { - Logger.error("Invalid agent path in Event: "+uuid); - } + setAgentPath(AgentPath.fromUUIDString(uuid)); } public String getAgentUUID() { diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java index 33c80a4..304c604 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java @@ -1,6 +1,5 @@ package com.c2kernel.lifecycle.instance; import java.util.ArrayList; -import java.util.UUID; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; @@ -16,6 +15,7 @@ import com.c2kernel.graph.model.TypeNameAndConstructionInfo; import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidAgentPathException; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.utils.Language; @@ -199,9 +199,9 @@ public class Workflow extends CompositeActivity implements C2KLocalObject this.itemPath = itemPath; } - public void setItemUUID( String uuid ) + public void setItemUUID( String uuid ) throws InvalidItemPathException { - setItemPath(new ItemPath(UUID.fromString(uuid))); + setItemPath(ItemPath.fromUUIDString(uuid)); } public String getItemUUID() { diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java index 889ee80..76b6adf 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java @@ -13,7 +13,6 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays; -import java.util.UUID; import com.c2kernel.collection.Dependency; import com.c2kernel.collection.MembershipException; @@ -65,7 +64,7 @@ public class AddMemberToCollection extends PredefinedStep if (Logger.doLog(3)) Logger.msg(3, "AddMemberToCollection: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); try { collName = params[0]; - newChild = new ItemPath(UUID.fromString(params[1])); + newChild = ItemPath.fromUUIDString(params[1]); if (params.length > 2) props = (CastorHashMap)Gateway.getMarshaller().unmarshall(params[2]); diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java index 257c644..58b1263 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java @@ -13,7 +13,6 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays; -import java.util.UUID; import com.c2kernel.collection.Aggregation; import com.c2kernel.common.InvalidDataException; @@ -67,7 +66,7 @@ public class AddNewSlot extends PredefinedStep try { collName = params[0]; - if (params.length > 1 && params[1].length() > 0) descKey = new ItemPath(UUID.fromString(params[1])); + if (params.length > 1 && params[1].length() > 0) descKey = ItemPath.fromUUIDString(params[1]); } catch (Exception e) { throw new InvalidDataException("AddNewSlot: Invalid parameters "+Arrays.toString(params), ""); } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java index 724e974..20ad473 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java @@ -13,7 +13,6 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays; -import java.util.UUID; import com.c2kernel.collection.Aggregation; import com.c2kernel.collection.AggregationMember; @@ -66,7 +65,7 @@ public class AssignItemToSlot extends PredefinedStep try { collName = params[0]; slotNo = Integer.parseInt(params[1]); - childItem = new ItemPath(UUID.fromString(params[2])); + childItem = ItemPath.fromUUIDString(params[2]); } catch (Exception e) { throw new InvalidDataException("AssignItemToSlot: Invalid parameters "+Arrays.toString(params), ""); } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java index 7caad61..26bf104 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java @@ -13,7 +13,6 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays; -import java.util.UUID; import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionMember; @@ -65,7 +64,7 @@ public class RemoveSlotFromCollection extends PredefinedStep try { collName = params[0]; if (params.length>1 && params[1].length()>0) slotNo = Integer.parseInt(params[1]); - if (params.length>2 && params[2].length()>0) currentChild = new ItemPath(UUID.fromString(params[2])); + if (params.length>2 && params[2].length()>0) currentChild = ItemPath.fromUUIDString(params[2]); } catch (Exception e) { throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters "+Arrays.toString(params), ""); } diff --git a/src/main/java/com/c2kernel/lifecycle/routingHelpers/ViewpointDataHelper.java b/src/main/java/com/c2kernel/lifecycle/routingHelpers/ViewpointDataHelper.java index 2250a82..26b2faa 100644 --- a/src/main/java/com/c2kernel/lifecycle/routingHelpers/ViewpointDataHelper.java +++ b/src/main/java/com/c2kernel/lifecycle/routingHelpers/ViewpointDataHelper.java @@ -1,7 +1,5 @@ package com.c2kernel.lifecycle.routingHelpers; -import java.util.UUID; - import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.lookup.ItemPath; @@ -48,7 +46,7 @@ public class ViewpointDataHelper ItemPath sourcePath; try { - sourcePath = new ItemPath(UUID.fromString(entityPath)); + sourcePath = ItemPath.fromUUIDString(entityPath); } catch (Exception e) { sourcePath = new ItemPath(entityPath); } diff --git a/src/main/java/com/c2kernel/lookup/AgentPath.java b/src/main/java/com/c2kernel/lookup/AgentPath.java index fb4ce0e..f6d6ca4 100644 --- a/src/main/java/com/c2kernel/lookup/AgentPath.java +++ b/src/main/java/com/c2kernel/lookup/AgentPath.java @@ -33,7 +33,7 @@ public class AgentPath extends ItemPath private String mAgentName=null; private String mPassword=null; - public AgentPath(SystemKey syskey) throws InvalidAgentPathException { + public AgentPath(SystemKey syskey) throws InvalidAgentPathException, InvalidItemPathException { super(syskey); try { findAgentName(); @@ -41,7 +41,7 @@ public class AgentPath extends ItemPath throw new InvalidAgentPathException(); } } - public AgentPath(UUID uuid) throws InvalidAgentPathException { + protected AgentPath(UUID uuid) throws InvalidAgentPathException, InvalidItemPathException { super(uuid); try { findAgentName(); @@ -132,6 +132,14 @@ public class AgentPath extends ItemPath digest.append(Base64.encode(hash)); return digest.toString(); } + + public static AgentPath fromUUIDString(String uuid) throws InvalidAgentPathException { + try { + return new AgentPath(ItemPath.fromUUIDString(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 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); + } + } } diff --git a/src/main/java/com/c2kernel/lookup/Lookup.java b/src/main/java/com/c2kernel/lookup/Lookup.java index 6627ea4..1b362f7 100644 --- a/src/main/java/com/c2kernel/lookup/Lookup.java +++ b/src/main/java/com/c2kernel/lookup/Lookup.java @@ -1,7 +1,6 @@ package com.c2kernel.lookup; import java.util.Iterator; -import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.process.auth.Authenticator; @@ -36,7 +35,7 @@ public interface Lookup { * @throws InvalidItemPathException When the system key is invalid/out-of-range * @throws ObjectNotFoundException When the Item does not exist in the directory. */ - public ItemPath getItemPath(UUID sysKey) throws InvalidItemPathException, ObjectNotFoundException; + public ItemPath getItemPath(String sysKey) throws InvalidItemPathException, ObjectNotFoundException; /** * Find the ItemPath for which a DomainPath is an alias. diff --git a/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java b/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java index db7e8d7..fd2004b 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java +++ b/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java @@ -1,11 +1,10 @@ package com.c2kernel.persistency.outcome; -import java.util.UUID; - import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.events.Event; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.persistency.ClusterStorageException; @@ -161,9 +160,9 @@ public class Viewpoint implements C2KLocalObject { this.itemPath = itemPath; } - public void setItemUUID( String uuid ) + public void setItemUUID( String uuid ) throws InvalidItemPathException { - setItemPath(new ItemPath(UUID.fromString(uuid))); + setItemPath(ItemPath.fromUUIDString(uuid)); } public String getItemUUID() { diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index e269e09..d5fcaa0 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -23,6 +23,7 @@ import com.c2kernel.lifecycle.instance.predefined.server.ServerPredefinedStepCon import com.c2kernel.lifecycle.instance.stateMachine.Transition; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.lookup.LookupManager; import com.c2kernel.lookup.Path; @@ -98,14 +99,14 @@ public class Bootstrap Logger.msg(1, "Boot data items complete"); } - private static void verifyBootDataItems(String bootList, String ns, boolean reset) { + private static void verifyBootDataItems(String bootList, String ns, boolean reset) throws InvalidItemPathException { StringTokenizer str = new StringTokenizer(bootList, "\n\r"); while (str.hasMoreTokens()) { String thisItem = str.nextToken(); ItemPath itemPath = null; String[] itemParts = thisItem.split("/"); if (itemParts.length == 3) { // includes UUID - itemPath = new ItemPath(UUID.fromString(itemParts[2])); + itemPath = ItemPath.fromUUIDString(itemParts[2]); } String itemType = itemParts[0]; String itemName = itemParts[1]; @@ -281,7 +282,7 @@ public class Bootstrap /************************************************************************** * Checks for the existence of the admin users so you can use Cristal **************************************************************************/ - private static void checkAgent(String name, String pass, RolePath rolePath, UUID uuid) throws Exception { + private static void checkAgent(String name, String pass, RolePath rolePath, String uuid) throws Exception { Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user."); LookupManager lookup = Gateway.getLookupManager(); @@ -294,7 +295,7 @@ public class Bootstrap Logger.msg("Bootstrap.checkAgent() - User '"+name+"' not found. Creating."); try { - AgentPath agentPath = new AgentPath(new ItemPath(uuid), name); + AgentPath agentPath = new AgentPath(ItemPath.fromUUIDString(uuid), name); agentPath.setPassword(pass); Gateway.getCorbaServer().createAgent(agentPath); lookup.add(agentPath); @@ -324,14 +325,14 @@ public class Bootstrap if (!adminRole.exists()) Gateway.getLookupManager().createRole(adminRole); // check for import user - checkAgent("system", adminPassword, adminRole, new UUID(0, 0)); + checkAgent("system", adminPassword, adminRole, new UUID(0, 0).toString()); - checkAgent("admin", adminPassword, adminRole, new UUID(0, 1)); + checkAgent("admin", adminPassword, adminRole, new UUID(0, 1).toString()); // check for local usercode user & role RolePath usercodeRole = new RolePath(rootRole, "UserCode", true); if (!usercodeRole.exists()) Gateway.getLookupManager().createRole(usercodeRole); - checkAgent(InetAddress.getLocalHost().getHostName(), "uc", usercodeRole, UUID.randomUUID()); + checkAgent(InetAddress.getLocalHost().getHostName(), "uc", usercodeRole, UUID.randomUUID().toString()); } public static void createServerItem() throws Exception { diff --git a/src/main/java/com/c2kernel/process/ItemHTTPBridge.java b/src/main/java/com/c2kernel/process/ItemHTTPBridge.java index 86e3659..8e4329c 100644 --- a/src/main/java/com/c2kernel/process/ItemHTTPBridge.java +++ b/src/main/java/com/c2kernel/process/ItemHTTPBridge.java @@ -1,11 +1,11 @@ package com.c2kernel.process; import java.util.StringTokenizer; -import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.utils.server.HTTPRequestHandler; @@ -33,8 +33,8 @@ public class ItemHTTPBridge extends HTTPRequestHandler { String query = tok.nextToken(); ItemPath itemPath; try { - itemPath = new ItemPath(UUID.fromString(path)); - } catch (IllegalArgumentException ex) { + itemPath = ItemPath.fromUUIDString(path); + } catch (InvalidItemPathException ex) { DomainPath domPath = new DomainPath(path); if (!domPath.exists()) return error("404 Not Found", "The path "+path+" you requested was not found."); diff --git a/src/main/java/com/c2kernel/process/module/ModuleImport.java b/src/main/java/com/c2kernel/process/module/ModuleImport.java index f54b47d..346488b 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleImport.java +++ b/src/main/java/com/c2kernel/process/module/ModuleImport.java @@ -1,13 +1,12 @@ package com.c2kernel.process.module; -import java.util.UUID; - import com.c2kernel.common.CannotManageException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; public abstract class ModuleImport { @@ -23,9 +22,9 @@ public abstract class ModuleImport { public abstract void create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException; - public void setID( String uuid ) + public void setID( String uuid ) throws InvalidItemPathException { - if (uuid != null) itemPath = new ItemPath(UUID.fromString(uuid)); + if (uuid != null) itemPath = ItemPath.fromUUIDString(uuid); } public String getID() { -- cgit v1.2.3