geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r417102 - in /geronimo/sandbox/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/ gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-core/src/main/java/org/apache/geronimo/gshell/ gshell-core/src/main/java/o...
Date Mon, 26 Jun 2006 01:40:40 GMT
Author: jdillon
Date: Sun Jun 25 18:40:39 2006
New Revision: 417102

URL: http://svn.apache.org/viewvc?rev=417102&view=rev
Log:
Added Notification, which is a generalized support for non-error states thrown as Error's
(like ExitNotification)
Added ExitNotification and ErrorNotification which are used to pass state from command to
the interp via throwing

Added:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
  (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/package.html
Modified:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java

Modified: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=417102&r1=417101&r2=417102&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Sun Jun 25 18:40:39 2006
@@ -27,7 +27,6 @@
 import org.apache.commons.cli.CommandLine;
 import org.apache.geronimo.gshell.console.IO;
 import org.apache.geronimo.gshell.util.Arguments;
-import org.apache.geronimo.gshell.ExitNotification;
 
 import java.util.Iterator;
 
@@ -116,7 +115,7 @@
             log.error("Initialization failed", e);
 
             //
-            // HACK:
+            // HACK: Need to handle or descide to ignore this exception
             //
 
             throw new RuntimeException("Command initialization failed", e);
@@ -153,7 +152,7 @@
             log.error("Destruction failed", e);
 
             //
-            // HACK:
+            // HACK: Need to handle or descide to ignore this exception
             //
 
             throw new RuntimeException("Command destruction failed", e);
@@ -241,15 +240,15 @@
 
             result = Command.FAILURE;
         }
-        catch (ExitNotification n) {
+        catch (Notification n) {
             //
-            // HACK: Propagate the notifciation
+            // Always rethrow notifications
             //
-
             throw n;
         }
         catch (Error e) {
             log.error(e.getMessage());
+
             if (log.isDebugEnabled()) {
                 log.debug("Error details", e);
             }

Added: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java?rev=417102&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java
Sun Jun 25 18:40:39 2006
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.command;
+
+//
+// TODO: May want to move to util, not command-specific
+//
+
+/**
+ * Thrown to indicate a notification state.
+ *
+ * @version $Id$
+ */
+public abstract class Notification
+    extends Error
+{
+    ///CLOVER:OFF
+
+    public Notification(String msg) {
+        super(msg);
+    }
+
+    public Notification(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+    public Notification(Throwable cause) {
+        super(cause);
+    }
+
+    public Notification() {
+        super();
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Notification.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java?rev=417102&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java
Sun Jun 25 18:40:39 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell;
+
+import org.apache.geronimo.gshell.command.Notification;
+
+/**
+ * Thrown to indicate an error notification state.
+ *
+ * @version $Id$
+ */
+public class ErrorNotification
+    extends Notification
+{
+    ///CLOVER:OFF
+
+    public ErrorNotification(String msg) {
+        super(msg);
+    }
+
+    public ErrorNotification(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+    public ErrorNotification(Throwable cause) {
+        super(cause);
+    }
+
+    public ErrorNotification() {
+        super();
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ErrorNotification.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java?rev=417102&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
Sun Jun 25 18:40:39 2006
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell;
+
+import org.apache.geronimo.gshell.command.Notification;
+
+/**
+ * Thrown to indicate that the current shell should exit.
+ *
+ * <p>
+ * Commands should use this instead of {@link System#exit}.
+ *
+ * @version $Id$
+ */
+public class ExitNotification
+    extends Notification
+{
+    ///CLOVER:OFF
+    
+    private final int code;
+
+    public ExitNotification(final int code) {
+        this.code = code;
+    }
+
+    public ExitNotification() {
+        this(0);
+    }
+
+    public int getCode() {
+        return code;
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java?rev=417102&r1=417101&r2=417102&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
Sun Jun 25 18:40:39 2006
@@ -55,6 +55,10 @@
                             shell.execute(line);
                         }
                         catch (ExitNotification n) {
+                            //
+                            // TODO: Propagate the exit status ?
+                            //
+
                             return Result.STOP;
                         }
                     }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java?rev=417102&r1=417101&r2=417102&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
Sun Jun 25 18:40:39 2006
@@ -54,7 +54,6 @@
         assert input != null;
 
         Reader reader = new StringReader(input);
-        CommandLineParser parser = new CommandLineParser();
         ASTCommandLine cl = parser.parse(reader);
 
         // If debug is enabled, the log the parse tree
@@ -79,6 +78,11 @@
 
         return new CommandLine() {
             public void execute() throws Exception {
+
+                //
+                // TODO: Handle ErrorNotification
+                //
+
                 root.jjtAccept(visitor, null);
             }
         };

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java?rev=417102&r1=417101&r2=417102&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
Sun Jun 25 18:40:39 2006
@@ -25,6 +25,7 @@
 import org.apache.geronimo.gshell.commandline.parser.ASTPlainString;
 import org.apache.geronimo.gshell.util.Arguments;
 import org.apache.geronimo.gshell.Shell;
+import org.apache.geronimo.gshell.ErrorNotification;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -55,20 +56,16 @@
 
     public Object visit(final SimpleNode node, final Object data) {
         assert node != null;
-        // assert data != null;
-
-        log.error("Unhandled node type: " + node.getClass().getName());
 
         //
-        // TODO: Exception?  Means impl node does not accept
+        // It is an error if we forgot to implement a node handler
         //
 
-        return null;
+        throw new Error("Unhandled node type: " + node.getClass().getName());
     }
 
     public Object visit(final ASTCommandLine node, final Object data) {
         assert node != null;
-        // assert data != null;
 
         //
         // NOTE: Visiting children will execute seperate commands in serial
@@ -79,7 +76,6 @@
 
     public Object visit(final ASTExpression node, final Object data) {
         assert node != null;
-        // assert data != null;
 
         // Create the argument list (cmd name + args)
         List<Object> list = new ArrayList<Object>(node.jjtGetNumChildren());
@@ -97,13 +93,7 @@
             result = shell.execute(commandName, args);
         }
         catch (Exception e) {
-            //
-            // FIXME: Need to resolve how to pass back this exception to the calling code
-            //        Maybe a custom RuntimeException or Error that can be caust by upper
layer
-            //        and then decoded and rethrown?
-            //
-
-            throw new RuntimeException(e);
+            throw new ErrorNotification(e);
         }
 
         return result;



Mime
View raw message