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. --- .../predefined/server/RemoveDomainContext.java | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java index d90f163..2d78e69 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java @@ -20,10 +20,12 @@ */ package com.c2kernel.lifecycle.instance.predefined.server; -import com.c2kernel.common.CannotManageException; -import com.c2kernel.common.InvalidDataException; +import java.util.Arrays; + +import com.c2kernel.common.CannotManage; +import com.c2kernel.common.InvalidData; import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; import com.c2kernel.lifecycle.instance.predefined.PredefinedStep; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; @@ -38,28 +40,25 @@ public class RemoveDomainContext extends PredefinedStep { @Override protected String runActivityLogic(AgentPath agent, ItemPath item, - int transitionID, String requestData) throws InvalidDataException { + int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage { - Logger.msg(1, "RemoveDomainContext::request() - Starting."); - - DomainPath pathToDelete = new DomainPath(getDataList(requestData)[0]); + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveDomainContext: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidData("RemoveDomainContext: Invalid parameters "+Arrays.toString(params)); + + DomainPath pathToDelete = new DomainPath(params[0]); if (!pathToDelete.exists()) - throw new InvalidDataException("Context "+pathToDelete+" does not exist", ""); + throw new ObjectNotFound("Context "+pathToDelete+" does not exist"); + try { pathToDelete.getItemPath(); - throw new InvalidDataException("Path "+pathToDelete+" is an Entity. Use its own Erase step instead, or RemoveAgent.", ""); - } catch (ObjectNotFoundException ex) { } + throw new InvalidData("Path "+pathToDelete+" is an Entity. Use its own Erase step instead, or RemoveAgent."); + } catch (ObjectNotFound ex) { } + if (Gateway.getLookup().getChildren(pathToDelete).hasNext()) - throw new InvalidDataException("Context "+pathToDelete+" is not empty. Cannot delete.", ""); + throw new ObjectCannotBeUpdated("Context "+pathToDelete+" is not empty. Cannot delete."); - try { - Gateway.getLookupManager().delete(pathToDelete); - } catch (ObjectCannotBeUpdated e) { - Logger.error(e); - throw new InvalidDataException("Exception deleting path"+pathToDelete+": "+e.getMessage(), ""); - } catch (CannotManageException e) { - throw new InvalidDataException("Cannot alter directory in a non-server process", ""); - } + Gateway.getLookupManager().delete(pathToDelete); return requestData; } } -- cgit v1.2.3