You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/14 10:05:20 UTC

svn commit: r695139 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command: CommandContainerImpl.java CommandDocumenterImpl.java

Author: jdillon
Date: Sun Sep 14 01:05:20 2008
New Revision: 695139

URL: http://svn.apache.org/viewvc?rev=695139&view=rev
Log:
Hook up MessageSource

Modified:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java?rev=695139&r1=695138&r2=695139&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java Sun Sep 14 01:05:20 2008
@@ -33,6 +33,8 @@
 import org.apache.geronimo.gshell.command.CommandContainerAware;
 import org.apache.geronimo.gshell.notification.Notification;
 import org.apache.geronimo.gshell.prefs.PreferencesProcessor;
+import org.apache.geronimo.gshell.i18n.MessageSource;
+import org.apache.geronimo.gshell.i18n.ResourceBundleMessageSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
@@ -61,7 +63,7 @@
 
     private CommandCompleter completer;
 
-    // TODO: MessageSource
+    private MessageSource messages;
 
     public String getId() {
         return id;
@@ -103,6 +105,16 @@
         this.completer = completer;
     }
 
+    public MessageSource getMessages() {
+        return messages;
+    }
+
+    public void setMessages(final MessageSource messages) {
+        assert messages != null;
+
+        this.messages = messages;
+    }
+
     @PostConstruct
     public void init() {
         // Validate properties
@@ -117,14 +129,16 @@
         if (completer == null) {
             setCompleter(new CommandCompleterImpl());
         }
-
-        // TODO: Setup MessageSource
+        if (messages == null) {
+            setMessages(new ResourceBundleMessageSource(action.getClass()));
+        }
         
         // Inject ourself into CommandContainerAware instances
         Object[] children = {
             action,
             documenter,
             completer,
+            messages,
         };
 
         for (Object child : children) {
@@ -164,11 +178,14 @@
                 */
             }
             catch (Exception e) {
-                new CommandResult(e);
+                return new CommandResult(e);
             }
 
             try {
-                final Object value = action.execute(context);
+                log.trace("Executing action: {}", action);
+
+                Object value = action.execute(context);
+
                 log.trace("Result: {}", value);
 
                 result = new CommandResult(value);
@@ -185,7 +202,7 @@
             }
         }
         finally {
-            MDC.remove("commandId");
+            MDC.remove("command-id");
         }
 
         return result;
@@ -206,22 +223,27 @@
         assert action != null;
         assert args != null;
 
+        if (log.isTraceEnabled()) {
+            log.trace("Processing arguments: {}", Arguments.toStringArray(args));
+        }
+
         CommandLineProcessor clp = new CommandLineProcessor();
         clp.addBean(action);
 
         // Attach some help context
         CommandDocumenter documenter = getDocumenter();
-        assert documenter != null;
+        clp.addBean(documenter);
 
         HelpSupport help = new HelpSupport();
         clp.addBean(help);
-        clp.addBean(documenter);
 
         // Process the arguments
         clp.process(Arguments.toStringArray(args));
 
         // Render command-line usage
         if (help.displayHelp) {
+            log.trace("Render command-line usage");
+            
             documenter.renderUsage(context.getInfo(), context.getIo().out);
             return true;
         }
@@ -230,7 +252,7 @@
     }
 
     /**
-     * Helper to inject <tt>--help<tt> support.  Package access to allow DefaultCommandDocumentor access.
+     * Helper to inject <tt>--help<tt> support.  Package access to allow CommandDocumentorImpl access.
      */
     static class HelpSupport
     {

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java?rev=695139&r1=695138&r2=695139&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java Sun Sep 14 01:05:20 2008
@@ -24,8 +24,8 @@
 import org.apache.geronimo.gshell.command.CommandAction;
 import org.apache.geronimo.gshell.command.CommandDocumenter;
 import org.apache.geronimo.gshell.command.CommandInfo;
+import org.apache.geronimo.gshell.i18n.MessageSource;
 
-import javax.annotation.PostConstruct;
 import java.io.PrintWriter;
 
 /**
@@ -37,15 +37,14 @@
     extends CommandContainerComponentSupport
     implements CommandDocumenter
 {
-    //
-    // TODO: Need to provide i18n keys to lookup the values for name & description
-    //
-    
     private String name;
 
     private String description;
 
     public String getName() {
+        if (name == null) {
+            name = getMessage("command.name");
+        }
         return name;
     }
 
@@ -54,6 +53,9 @@
     }
 
     public String getDescription() {
+        if (description == null) {
+            description = getMessage("command.description");
+        }
         return description;
     }
 
@@ -61,17 +63,23 @@
         this.description = description;
     }
 
-    @PostConstruct
-    public void init() {
-        // TODO: Validate
+    private String getMessage(final String code) {
+        assert code != null;
+
+        MessageSource messages = getContainer().getMessages();
+        assert messages != null;
+        
+        return messages.getMessage(code);
     }
-    
+
     // CommandDocumenter
 
     public void renderUsage(final CommandInfo info, final PrintWriter out) {
         assert info != null;
         assert out != null;
 
+        log.debug("Rendering command usage");
+        
         CommandLineProcessor clp = new CommandLineProcessor();
 
         // Attach our helper to inject --help
@@ -95,8 +103,8 @@
         out.println();
 
         Printer printer = new Printer(clp);
-
         printer.printUsage(out, name);
+        
         out.println();
     }
 
@@ -104,8 +112,11 @@
         assert info != null;
         assert out != null;
 
+        log.debug("Rendering command manual");
+        
         out.println(info.getName());
         out.println();
+        
         out.println("TODO: Full docs");
     }
 }
\ No newline at end of file