diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-06 13:26:21 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-06 13:26:21 +0000 |
commit | fe58d5b5ddfcecca984c57f9c8b2ae8a2e1eead2 (patch) | |
tree | c12a203f9cd7c234eac2e05a4befc06ea908343b /sca-java-2.x/trunk | |
parent | 069744ba06cca232eee0f0784f1721816d343343 (diff) |
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
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r-- | sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java | 57 |
1 files changed, 21 insertions, 36 deletions
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<KEY> implements ScopeContainer<KEY> 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<KEY> implements ScopeContainer<KEY> 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<KEY> implements ScopeContainer<KEY> 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<KEY> implements ScopeContainer<KEY> 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<KEY> implements ScopeContainer<KEY> @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() { |