From cbe61e1d6f0a4a0628a192ae860b7db61becaa63 Mon Sep 17 00:00:00 2001 From: abhishek Date: Tue, 29 May 2012 14:25:37 +0530 Subject: [PATCH] SHL-32 - Sub-classes of AbstractShell should be able to handle results of execution as required. Added a protected method handleExecutionResult() which is called from executeCommand() to handle the result if the result is not of a type 'ExitShellRequest'. handleExecutionResult() can be over-ridden by sub-classes if a different behavior is desired. --- .../roo/shell/AbstractShell.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/roo/shell/AbstractShell.java b/src/main/java/org/springframework/roo/shell/AbstractShell.java index 28f4eac0..6551d2e9 100644 --- a/src/main/java/org/springframework/roo/shell/AbstractShell.java +++ b/src/main/java/org/springframework/roo/shell/AbstractShell.java @@ -209,12 +209,8 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme exitShellRequest = (ExitShellRequest) result; // Give ProcessManager a chance to close down its threads before the overall OSGi framework is terminated (ROO-1938) executionStrategy.terminate(); - } else if (result instanceof Iterable) { - for (Object o : (Iterable) result) { - logger.info(o.toString()); - } } else { - logger.info(result.toString()); + handleExecutionResult(result); } } @@ -446,4 +442,24 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme logger.log(level, message); } } + + /** + * Handles the result of execution of a command. Given result is + * expected to be not null. If result is a + * {@link java.lang.Iterable} object, it will be iterated through to print + * the output of toString. For other type of objects, simply output + * of toString is shown. Subclasses can alter this implementation + * to handle the result differently. + * + * @param result not null result of execution of a command. + */ + protected void handleExecutionResult(Object result) { + if (result instanceof Iterable) { + for (Object o : (Iterable) result) { + logger.info(o.toString()); + } + } else { + logger.info(result.toString()); + } + } }