From 275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 3 Oct 2014 17:30:41 +0200 Subject: Huge exception overhaul: Merged ClusterStorageException with PersistencyException. Replaced MembershipException with InvalidCollectionModification CORBA Exception. Made all predef steps throw more accurate exceptions when they go wrong, and let more exceptions bubble through from underneath. --- .../java/com/c2kernel/entity/proxy/ItemProxy.java | 81 +++++++++++----------- 1 file changed, 42 insertions(+), 39 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/proxy/ItemProxy.java') diff --git a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java index 503e408..f5b0be7 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java @@ -32,10 +32,11 @@ import org.exolab.castor.xml.ValidationException; import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionArrayList; import com.c2kernel.common.AccessRightsException; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.InvalidTransitionException; -import com.c2kernel.common.ObjectAlreadyExistsException; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.InvalidCollectionModification; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.InvalidTransition; +import com.c2kernel.common.ObjectAlreadyExists; +import com.c2kernel.common.ObjectNotFound; import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.Item; @@ -47,7 +48,6 @@ import com.c2kernel.lifecycle.instance.Workflow; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.outcome.Viewpoint; import com.c2kernel.process.Gateway; import com.c2kernel.property.Property; @@ -89,18 +89,18 @@ public class ItemProxy return mItemPath; } - protected Item getItem() throws ObjectNotFoundException { + protected Item getItem() throws ObjectNotFound { if (mItem == null) mItem = narrow(); return mItem; } - public Item narrow() throws ObjectNotFoundException + public Item narrow() throws ObjectNotFound { try { return ItemHelper.narrow(mIOR); } catch (org.omg.CORBA.BAD_PARAM ex) { } - throw new ObjectNotFoundException("CORBA Object was not an Item, or the server is down."); + throw new ObjectNotFound("CORBA Object was not an Item, or the server is down."); } public void initialise( AgentPath agentId, @@ -108,11 +108,11 @@ public class ItemProxy CompositeActivity workflow, CollectionArrayList colls ) - throws AccessRightsException, InvalidDataException, PersistencyException, ObjectNotFoundException, MarshalException, ValidationException, IOException, MappingException + throws AccessRightsException, InvalidData, PersistencyException, ObjectNotFound, MarshalException, ValidationException, IOException, MappingException, InvalidCollectionModification { Logger.msg(7, "ItemProxy::initialise - started"); CastorXMLUtility xml = Gateway.getMarshaller(); - if (itemProps == null) throw new InvalidDataException("No initial properties supplied"); + if (itemProps == null) throw new InvalidData("No initial properties supplied"); String propString = xml.marshall(itemProps); String wfString = ""; if (workflow != null) wfString = xml.marshall(workflow); @@ -124,7 +124,7 @@ public class ItemProxy public void setProperty(AgentProxy agent, String name, String value) throws AccessRightsException, - PersistencyException, InvalidDataException + PersistencyException, InvalidData { String[] params = new String[2]; params[0] = name; @@ -135,34 +135,37 @@ public class ItemProxy throw (e); } catch (PersistencyException e) { throw (e); - } catch (InvalidDataException e) { + } catch (InvalidData e) { throw (e); } catch (Exception e) { Logger.error(e); - throw new PersistencyException("Could not store property", ""); + throw new PersistencyException("Could not store property"); } } - /************************************************************************** + + /** + * @throws InvalidCollectionModification * **************************************************************************/ public String requestAction( Job thisJob ) throws AccessRightsException, - InvalidTransitionException, - ObjectNotFoundException, - InvalidDataException, + InvalidTransition, + ObjectNotFound, + InvalidData, PersistencyException, - ObjectAlreadyExistsException + ObjectAlreadyExists, + InvalidCollectionModification { String outcome = thisJob.getOutcomeString(); // check fields that should have been filled in if (outcome==null) if (thisJob.isOutcomeRequired()) - throw new InvalidDataException("Outcome is required.", ""); + throw new InvalidData("Outcome is required."); else outcome=""; if (thisJob.getAgentPath() == null) - throw new InvalidDataException("No Agent specified.", ""); + throw new InvalidData("No Agent specified."); Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName()); return getItem().requestAction (thisJob.getAgentPath().getSystemKey(), thisJob.getStepPath(), @@ -174,7 +177,7 @@ public class ItemProxy **************************************************************************/ private ArrayList getJobList(AgentPath agentPath, boolean filter) throws AccessRightsException, - ObjectNotFoundException, + ObjectNotFound, PersistencyException { JobArrayList thisJobList; @@ -184,14 +187,14 @@ public class ItemProxy } catch (Exception e) { Logger.error(e); - throw new PersistencyException("Exception::ItemProxy::getJobList() - Cannot unmarshall the jobs", null); + throw new PersistencyException("Exception::ItemProxy::getJobList() - Cannot unmarshall the jobs"); } return thisJobList.list; } public ArrayList getJobList(AgentProxy agent) throws AccessRightsException, - ObjectNotFoundException, + ObjectNotFound, PersistencyException { return getJobList(agent.getPath(), true); @@ -199,7 +202,7 @@ public class ItemProxy private Job getJobByName(String actName, AgentPath agent) throws AccessRightsException, - ObjectNotFoundException, + ObjectNotFound, PersistencyException { ArrayList jobList = getJobList(agent, true); @@ -211,21 +214,21 @@ public class ItemProxy } - public Collection getCollection(String collName) throws ObjectNotFoundException { + public Collection getCollection(String collName) throws ObjectNotFound { return (Collection)getObject(ClusterStorage.COLLECTION+"/"+collName+"/last"); } - public Workflow getWorkflow() throws ObjectNotFoundException { + public Workflow getWorkflow() throws ObjectNotFound { return (Workflow)getObject(ClusterStorage.LIFECYCLE+"/workflow"); } - public Viewpoint getViewpoint(String schemaName, String viewName) throws ObjectNotFoundException { + public Viewpoint getViewpoint(String schemaName, String viewName) throws ObjectNotFound { return (Viewpoint)getObject(ClusterStorage.VIEWPOINT+"/"+schemaName+"/"+viewName); } public Job getJobByName(String actName, AgentProxy agent) throws AccessRightsException, - ObjectNotFoundException, + ObjectNotFound, PersistencyException { return getJobByName(actName, agent.getPath()); } @@ -245,7 +248,7 @@ public class ItemProxy * **************************************************************************/ public String queryData( String path ) - throws ObjectNotFoundException + throws ObjectNotFound { try { @@ -263,7 +266,7 @@ public class ItemProxy } C2KLocalObject target = Gateway.getStorage().get(mItemPath, path, null); return Gateway.getMarshaller().marshall(target); - } catch (ObjectNotFoundException e) { + } catch (ObjectNotFound e) { throw e; } catch (Exception e) { Logger.error(e); @@ -271,11 +274,11 @@ public class ItemProxy } } - public String[] getContents( String path ) throws ObjectNotFoundException { + public String[] getContents( String path ) throws ObjectNotFound { try { return Gateway.getStorage().getClusterContents(mItemPath, path.substring(0, path.length())); - } catch (ClusterStorageException e) { - throw new ObjectNotFoundException(e.toString()); + } catch (PersistencyException e) { + throw new ObjectNotFound(e.toString()); } } @@ -284,24 +287,24 @@ public class ItemProxy * **************************************************************************/ public C2KLocalObject getObject( String xpath ) - throws ObjectNotFoundException + throws ObjectNotFound { // load from storage, falling back to proxy loader if not found in others try { return Gateway.getStorage().get( mItemPath, xpath , null); } - catch( ClusterStorageException ex ) + catch( PersistencyException ex ) { Logger.msg(4, "Exception loading object :"+mItemPath+"/"+xpath); - throw new ObjectNotFoundException( ex.toString() ); + throw new ObjectNotFound( ex.toString() ); } } public String getProperty( String name ) - throws ObjectNotFoundException + throws ObjectNotFound { Logger.msg(5, "Get property "+name+" from item "+mItemPath); Property prop = (Property)getObject("Property/"+name); @@ -311,7 +314,7 @@ public class ItemProxy } catch (NullPointerException ex) { - throw new ObjectNotFoundException(); + throw new ObjectNotFound(); } } @@ -319,7 +322,7 @@ public class ItemProxy { try { return getProperty("Name"); - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { return null; } } -- cgit v1.2.3