From fe58d5b5ddfcecca984c57f9c8b2ae8a2e1eead2 Mon Sep 17 00:00:00 2001 From: slaws Date: Mon, 6 Jun 2011 13:26:21 +0000 Subject: Tidy toString and add strings to exceptions rather than numbers. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1132629 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/core/scope/AbstractScopeContainer.java | 57 ++++++++-------------- 1 file changed, 21 insertions(+), 36 deletions(-) (limited to 'sca-java-2.x/trunk/modules/core/src') diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java index 4674456925..a1bb91faec 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java @@ -36,8 +36,17 @@ public abstract class AbstractScopeContainer implements ScopeContainer protected RuntimeComponent component; protected volatile int lifecycleState = UNINITIALIZED; - - + + private static String scopeStateStrings[] = {"CONFIG_ERROR", + "UNINITIALIZED", + "INITIALIZING", + "INITIALIZED", + "NOT USED", + "RUNNING", + "STOPPING", + "STOPPED", + "ERROR"}; + public AbstractScopeContainer(Scope scope, RuntimeComponent component) { this.scope = scope; this.component = component; @@ -45,7 +54,9 @@ public abstract class AbstractScopeContainer implements ScopeContainer protected void checkInit() { if (getLifecycleState() != RUNNING) { - throw new IllegalStateException("Scope container not running [" + getLifecycleState() + "]"); + throw new IllegalStateException("Scope container not running. Current state is [" + + scopeStateStrings[getLifecycleState() + 1] + + "]"); } } @@ -110,7 +121,9 @@ public abstract class AbstractScopeContainer implements ScopeContainer public synchronized void start() { int lifecycleState = getLifecycleState(); if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { - throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state but the current state is [" + + scopeStateStrings[lifecycleState + 1] + + "]. Did you try to start the same node twice?"); } setLifecycleState(RUNNING); } @@ -128,7 +141,9 @@ public abstract class AbstractScopeContainer implements ScopeContainer public synchronized void stop() { int lifecycleState = getLifecycleState(); if (lifecycleState != RUNNING) { - throw new IllegalStateException("Scope in wrong state [" + lifecycleState + "]"); + throw new IllegalStateException("Scope in wrong state. Current state is [" + + scopeStateStrings[lifecycleState + 1] + + "]"); } setLifecycleState(STOPPED); } @@ -139,37 +154,7 @@ public abstract class AbstractScopeContainer implements ScopeContainer @Override public String toString() { - String s; - switch (lifecycleState) { - case ScopeContainer.CONFIG_ERROR: - s = "CONFIG_ERROR"; - break; - case ScopeContainer.ERROR: - s = "ERROR"; - break; - case ScopeContainer.INITIALIZING: - s = "INITIALIZING"; - break; - case ScopeContainer.INITIALIZED: - s = "INITIALIZED"; - break; - case ScopeContainer.RUNNING: - s = "RUNNING"; - break; - case ScopeContainer.STOPPING: - s = "STOPPING"; - break; - case ScopeContainer.STOPPED: - s = "STOPPED"; - break; - case ScopeContainer.UNINITIALIZED: - s = "UNINITIALIZED"; - break; - default: - s = "UNKNOWN"; - break; - } - return "In state [" + s + ']'; + return "In state [" + scopeStateStrings[lifecycleState + 1] + ']'; } public RuntimeComponent getComponent() { -- cgit v1.2.3