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. --- .../lifecycle/instance/predefined/ClearSlot.java | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java index acba2cb..a15b98f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java @@ -25,12 +25,13 @@ import java.util.Arrays; import com.c2kernel.collection.Aggregation; import com.c2kernel.collection.AggregationMember; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; @@ -54,10 +55,13 @@ public class ClearSlot extends PredefinedStep * Params: * 0 - collection name * 1 - slot number + * @throws ObjectNotFound + * @throws PersistencyException + * @throws ObjectCannotBeUpdated */ @Override protected String runActivityLogic(AgentPath agent, ItemPath item, - int transitionID, String requestData) throws InvalidDataException { + int transitionID, String requestData) throws InvalidData, ObjectNotFound, PersistencyException, ObjectCannotBeUpdated { String collName; int slotNo; @@ -71,17 +75,15 @@ public class ClearSlot extends PredefinedStep collName = params[0]; slotNo = Integer.parseInt(params[1]); } catch (Exception e) { - throw new InvalidDataException("ClearSlot: Invalid parameters "+Arrays.toString(params), ""); + throw new InvalidData("ClearSlot: Invalid parameters "+Arrays.toString(params)); } // load collection try { agg = (Aggregation)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); - } catch (ObjectNotFoundException ex) { - throw new InvalidDataException("ClearSlot: Collection '"+collName+"' not found in this Item", ""); - } catch (ClusterStorageException ex) { + } catch (PersistencyException ex) { Logger.error(ex); - throw new InvalidDataException("ClearSlot: Error loading collection '"+collName+"': "+ex.getMessage(), ""); + throw new PersistencyException("ClearSlot: Error loading collection '"+collName+"': "+ex.getMessage()); } // find member and clear @@ -89,22 +91,22 @@ public class ClearSlot extends PredefinedStep for (AggregationMember member : agg.getMembers().list) { if (member.getID() == slotNo) { if (member.getItemPath() != null) - throw new InvalidDataException("ClearSlot: Member slot "+slotNo+" already empty", ""); + throw new ObjectCannotBeUpdated("ClearSlot: Member slot "+slotNo+" already empty"); member.clearItem(); stored = true; break; } } if (!stored) { - throw new InvalidDataException("Member slot "+slotNo+" not found.", ""); + throw new ObjectNotFound("ClearSlot: Member slot "+slotNo+" not found."); } try { Gateway.getStorage().put(item, agg, null); - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.error(e); - throw new InvalidDataException("Error storing collection", ""); + throw new PersistencyException("ClearSlot: Error storing collection"); } return requestData; } -- cgit v1.2.3