From 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 Mon Sep 17 00:00:00 2001 From: abranson Date: Thu, 4 Aug 2011 00:42:34 +0200 Subject: More code cleanup: Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class --- source/com/c2kernel/entity/TraceableEntity.java | 86 +++++++++++++------------ 1 file changed, 46 insertions(+), 40 deletions(-) mode change 100755 => 100644 source/com/c2kernel/entity/TraceableEntity.java (limited to 'source/com/c2kernel/entity/TraceableEntity.java') diff --git a/source/com/c2kernel/entity/TraceableEntity.java b/source/com/c2kernel/entity/TraceableEntity.java old mode 100755 new mode 100644 index 49bbe47..c7aff82 --- a/source/com/c2kernel/entity/TraceableEntity.java +++ b/source/com/c2kernel/entity/TraceableEntity.java @@ -11,7 +11,6 @@ package com.c2kernel.entity; -import java.util.Iterator; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; @@ -87,7 +86,8 @@ public class TraceableEntity extends ItemPOA /************************************************************************** * **************************************************************************/ - public org.omg.PortableServer.POA _default_POA() + @Override + public org.omg.PortableServer.POA _default_POA() { if(mPoa != null) return mPoa; @@ -99,7 +99,8 @@ public class TraceableEntity extends ItemPOA /************************************************************************** * **************************************************************************/ - public int getSystemKey() + @Override + public int getSystemKey() { Logger.msg(8, "TraceableEntity::getSystemKey() - " + mSystemKey); return mSystemKey; @@ -108,7 +109,8 @@ public class TraceableEntity extends ItemPOA /************************************************************************** * **************************************************************************/ - public void initialise( int agentId, + @Override + public void initialise( int agentId, String propString, String initWfString ) @@ -120,22 +122,22 @@ public class TraceableEntity extends ItemPOA synchronized (this) { Workflow lc = null; PropertyArrayList props = null; - + AgentPath agentPath; try { agentPath = new AgentPath(agentId); } catch (InvalidEntityPathException e) { throw new AccessRightsException("Invalid Agent Id:" + agentId); } - + //unmarshalling checks the validity of the received strings - + // create properties if (!propString.equals("")) { try { props = (PropertyArrayList)CastorXMLUtility.unmarshall(propString); - for (Iterator i = props.list.iterator(); i.hasNext();) { - Property thisProp = (Property)i.next(); + for (Object name : props.list) { + Property thisProp = (Property)name; mStorage.put(mSystemKey, thisProp, props); } } catch (Throwable ex) { @@ -145,10 +147,10 @@ public class TraceableEntity extends ItemPOA } mStorage.commit(props); } - + // create wf try { - if (initWfString == null || initWfString.equals("")) + if (initWfString == null || initWfString.equals("")) lc = new Workflow(new CompositeActivity()); else lc = new Workflow((CompositeActivity)CastorXMLUtility.unmarshall(initWfString)); @@ -158,14 +160,15 @@ public class TraceableEntity extends ItemPOA Logger.msg(8, "TraceableEntity::initialise("+mSystemKey+") - Workflow was invalid: "+initWfString); Logger.error(ex); } - } + } } /************************************************************************** * **************************************************************************/ //requestdata is xmlstring - public void requestAction( int agentId, + @Override + public void requestAction( int agentId, String stepPath, int transitionID, String requestData @@ -180,31 +183,31 @@ public class TraceableEntity extends ItemPOA synchronized (this) { try { - Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " + + Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " + Transitions.getTransitionName(transitionID) + " "+stepPath + " by " +agentId ); - AgentPath agent = new AgentPath(agentId); + AgentPath agent = new AgentPath(agentId); Workflow lifeCycle = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null); - + lifeCycle.requestAction( agent, stepPath, transitionID, requestData ); - + // store the workflow if we've changed the state of the domain wf - if (!(stepPath.startsWith("workflow/predefined"))) + if (!(stepPath.startsWith("workflow/predefined"))) mStorage.put(mSystemKey, lifeCycle, null); - + // Normal operation exceptions } catch (AccessRightsException ex) { - Logger.msg("Propagating AccessRightsException back to the calling agent"); + Logger.msg("Propagating AccessRightsException back to the calling agent"); throw ex; } catch (InvalidTransitionException ex) { - Logger.msg("Propagating InvalidTransitionException back to the calling agent"); + Logger.msg("Propagating InvalidTransitionException back to the calling agent"); throw ex; } catch (ObjectNotFoundException ex) { - Logger.msg("Propagating ObjectNotFoundException back to the calling agent"); - throw ex; + Logger.msg("Propagating ObjectNotFoundException back to the calling agent"); + throw ex; // errors } catch (ClusterStorageException ex) { Logger.error(ex); @@ -212,13 +215,13 @@ public class TraceableEntity extends ItemPOA } catch (InvalidEntityPathException ex) { Logger.error(ex); throw new AccessRightsException("Invalid Agent Id: "+agentId, ""); - } catch (InvalidDataException ex) { + } catch (InvalidDataException ex) { Logger.error(ex); - Logger.msg("Propagating InvalidDataException back to the calling agent"); + Logger.msg("Propagating InvalidDataException back to the calling agent"); throw ex; - } catch (ObjectAlreadyExistsException ex) { + } catch (ObjectAlreadyExistsException ex) { Logger.error(ex); - Logger.msg("Propagating ObjectAlreadyExistsException back to the calling agent"); + Logger.msg("Propagating ObjectAlreadyExistsException back to the calling agent"); throw ex; // non-CORBA exception hasn't been caught! } catch (Throwable ex) { @@ -226,13 +229,14 @@ public class TraceableEntity extends ItemPOA Logger.error(ex); throw new InvalidDataException("Extraordinary Exception during execution:"+ex.getClass().getName()+" - "+ex.getMessage(), ""); } - } + } } /************************************************************************** * **************************************************************************/ - public String queryLifeCycle( int agentId, + @Override + public String queryLifeCycle( int agentId, boolean filter ) throws AccessRightsException, @@ -241,7 +245,7 @@ public class TraceableEntity extends ItemPOA { synchronized (this) { Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - agent: " + agentId); - + try { AgentPath agent = new AgentPath(agentId); @@ -266,21 +270,22 @@ public class TraceableEntity extends ItemPOA * @param path - the path to the object required * the suffix 'all' retrieves a listing of all keys on that level * - * @return The result string in xml format + * @return The result string in xml format * except 'all' which returns a comma sep list * * @exception ObjectNotFoundException * ************************************************************************/ - public String queryData(String path) + @Override + public String queryData(String path) throws AccessRightsException, ObjectNotFoundException, PersistencyException { synchronized (this) { String result = ""; - + Logger.msg(1, "TraceableEntity::queryData("+mSystemKey+") - " + path ); - + try { // check for cluster contents query @@ -289,11 +294,11 @@ public class TraceableEntity extends ItemPOA int allPos = path.lastIndexOf("all"); String query = path.substring(0,allPos); String[] ids = mStorage.getClusterContents( mSystemKey, query ); - + for( int i=0; i