geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r697475 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandResult.java gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandImpl.java
Date Sun, 21 Sep 2008 11:14:59 GMT
Author: jdillon
Date: Sun Sep 21 04:14:58 2008
New Revision: 697475

URL: http://svn.apache.org/viewvc?rev=697475&view=rev
Log:
Refactored CommandResult to avoid undesired value confusion when initializing

Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandResult.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandImpl.java

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandResult.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandResult.java?rev=697475&r1=697474&r2=697475&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandResult.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandResult.java
Sun Sep 21 04:14:58 2008
@@ -42,26 +42,6 @@
         this.notification = notification;
     }
 
-    public CommandResult(final Object value) {
-        this(value, null, null);
-
-        assert value != null;
-        assert !(value instanceof Throwable);
-    }
-
-    public CommandResult(final Throwable failure) {
-        this(null, failure, null);
-
-        assert failure != null;
-        assert !(failure instanceof Notification);
-    }
-
-    public CommandResult(final Notification notification) {
-        this(null, null, notification);
-
-        assert notification != null;
-    }
-
     /**
      * The result value of a command execution.
      *
@@ -114,4 +94,37 @@
     public String toString() {
         return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
+
+    /**
+     * Command execution resulting in a normal value.
+     */
+    public static class ValueResult
+        extends CommandResult
+    {
+        public ValueResult(final Object value) {
+            super(value, null, null);
+        }
+    }
+
+    /**
+     * Command execution resulting in a failure.
+     */
+    public static class FailureResult
+        extends CommandResult
+    {
+        public FailureResult(final Throwable failure) {
+            super(null, failure, null);
+        }
+    }
+
+    /**
+     * Command execution resulting in a notification.
+     */
+    public static class NotificationResult
+        extends CommandResult
+    {
+        public NotificationResult(final Notification notification) {
+            super(null, null, notification);
+        }
+    }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandImpl.java?rev=697475&r1=697474&r2=697475&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandImpl.java
Sun Sep 21 04:14:58 2008
@@ -102,18 +102,17 @@
                 // Process command line options/arguments
                 if (processArguments(io, action, args)) {
                     // return if we have been asked to display --help
-                    return new CommandResult(CommandAction.Result.SUCCESS);
+                    return new CommandResult.ValueResult(CommandAction.Result.SUCCESS);
                 }
 
                 // TODO: Add preferences processor
             }
             catch (Exception e) {
-                return new CommandResult(e);
+                return new CommandResult.FailureResult(e);
             }
 
             // Setup the command context
-            CommandContext context = new CommandContext()
-            {
+            CommandContext context = new CommandContext() {
                 public Object[] getArguments() {
                     return args;
                 }
@@ -139,17 +138,17 @@
 
                 log.trace("Result: {}", value);
 
-                result = new CommandResult(value);
+                result = new CommandResult.ValueResult(value);
             }
             catch (final Notification n) {
                 log.trace("Notified: {}, n");
 
-                result = new CommandResult(n);
+                result = new CommandResult.NotificationResult(n);
             }
             catch (final Throwable t) {
                 log.trace("Caught: {}", t);
 
-                result = new CommandResult(t);
+                result = new CommandResult.FailureResult(t);
             }
         }
         finally {



Mime
View raw message