geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r702413 - /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
Date Tue, 07 Oct 2008 09:45:18 GMT
Author: jdillon
Date: Tue Oct  7 02:45:18 2008
New Revision: 702413

URL: http://svn.apache.org/viewvc?rev=702413&view=rev
Log:
Add ensureOpened() checks and update state when init() and close() are called

Modified:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java?rev=702413&r1=702412&r2=702413&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
Tue Oct  7 02:45:18 2008
@@ -79,37 +79,48 @@
 
     private ErrorHandler errorHandler;
 
-    public void setCompleters(final List<Completor> completers) {
-        assert completers != null;
+    private boolean opened;
 
-        this.completers = completers;
+    private synchronized void ensureOpened() {
+        if (!opened) {
+            throw new IllegalStateException("Shell has not been opened or has been closed");
+        }
+    }
+
+    public synchronized boolean isOpened() {
+        return true;
+    }
+
+    public synchronized void close() {
+        log.debug("Closing");
+        opened = false;
     }
 
     public ShellContext getContext() {
+        ensureOpened();
+
         if (context == null) {
             throw new IllegalStateException("Shell context has not been initialized");
         }
         return context;
     }
 
-    //
-    // TODO: Add ensureOpened() and add checks
-    //
-    
-    public boolean isOpened() {
-        return true;
-    }
+    public void setCompleters(final List<Completor> completers) {
+        assert completers != null;
 
-    public void close() {
-        log.debug("Closing");
+        this.completers = completers;
     }
-
+    
     public boolean isInteractive() {
         return true;
     }
 
     @PostConstruct
     public void init() throws Exception {
+        if (opened) {
+            throw new IllegalStateException("Shell is already opened");
+        }
+
         assert application != null;
 
         // Dereference some bits from the applciation context
@@ -134,6 +145,8 @@
 
         branding = application.getModel().getBranding();
 
+        opened = true;
+
         //
         // TODO: Populate variables with some defaults, like the username/hostname/etc.
         //
@@ -142,21 +155,29 @@
     }
 
     public Object execute(final String line) throws Exception {
+        ensureOpened();
+
         assert executor != null;
         return executor.execute(getContext(), line);
     }
 
     public Object execute(final String command, final Object[] args) throws Exception {
+        ensureOpened();
+
         assert executor != null;
         return executor.execute(getContext(), command, args);
     }
 
     public Object execute(final Object... args) throws Exception {
+        ensureOpened();
+
         assert executor != null;
         return executor.execute(getContext(), args);
     }
 
     public Object execute(final Object[][] commands) throws Exception {
+        ensureOpened();
+
         assert executor != null;
         return executor.execute(getContext(), commands);
     }
@@ -164,6 +185,8 @@
     public void run(final Object... args) throws Exception {
         assert args != null;
 
+        ensureOpened();
+
         log.debug("Starting interactive console; args: {}", args);
 
         assert branding != null;



Mime
View raw message