Author: slaws
Date: Mon Jun  6 13:26:21 2011
New Revision: 1132629

URL: http://svn.apache.org/viewvc?rev=1132629&view=rev
Log:
Tidy toString and add strings to exceptions rather than numbers. 

Modified:
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java?rev=1132629&r1=1132628&r2=1132629&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java
 Mon Jun  6 13:26:21 2011
@@ -36,8 +36,17 @@ public abstract class AbstractScopeConta
 
     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 AbstractScopeConta
 
     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 AbstractScopeConta
     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 AbstractScopeConta
     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 AbstractScopeConta
 
     @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() {


Reply via email to