activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r652598 - in /activemq/trunk/activemq-console: ./ src/main/java/org/apache/activemq/console/ src/main/java/org/apache/activemq/console/command/ src/main/java/org/apache/activemq/console/filter/ src/main/java/org/apache/activemq/console/form...
Date Thu, 01 May 2008 18:13:31 GMT
Author: chirino
Date: Thu May  1 11:13:29 2008
New Revision: 652598

URL: http://svn.apache.org/viewvc?rev=652598&view=rev
Log:
Fix for AMQ-1707

Added:
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/CommandContext.java   (with props)
Removed:
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/GlobalWriter.java
Modified:
    activemq/trunk/activemq-console/pom.xml
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractAmqCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/OutputFormatter.java

Modified: activemq/trunk/activemq-console/pom.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/pom.xml?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/pom.xml (original)
+++ activemq/trunk/activemq-console/pom.xml Thu May  1 11:13:29 2008
@@ -26,9 +26,21 @@
   </parent>
 
   <artifactId>activemq-console</artifactId>
+  <packaging>bundle</packaging>
   <name>ActiveMQ :: Console</name>
   <description>ActiveMQ Management Console</description>
 
+  <properties>
+    <activemq.osgi.import.pkg>
+      org.apache.activemq*;resolution:=optional,
+      org.springframework*;resolution:=optional,
+      *
+    </activemq.osgi.import.pkg>
+    <activemq.osgi.export>
+      org.apache.activemq.console*;version=${project.version},
+    </activemq.osgi.export>
+  </properties>
+  
   <dependencies>
     <!-- activemq related dependencies -->
     <dependency>

Added: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/CommandContext.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/CommandContext.java?rev=652598&view=auto
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/CommandContext.java (added)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/CommandContext.java Thu May  1 11:13:29 2008
@@ -0,0 +1,244 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.activemq.console;
+
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Map;
+
+import javax.jms.Message;
+import javax.management.AttributeList;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.apache.activemq.console.formatter.OutputFormatter;
+
+public final class CommandContext {
+    private OutputFormatter formatter;
+
+    /**
+     * Retrieve the output stream being used by the global formatter
+     * 
+     * @return
+     */
+    public OutputStream getOutputStream() {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        return formatter.getOutputStream();
+    }
+
+    /**
+     * Print an ObjectInstance format of an mbean
+     * 
+     * @param mbean - mbean to print
+     */
+    public void printMBean(ObjectInstance mbean) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMBean(mbean);
+    }
+
+    /**
+     * Print an ObjectName format of an mbean
+     * 
+     * @param mbean - mbean to print
+     */
+    public void printMBean(ObjectName mbean) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMBean(mbean);
+    }
+
+    /**
+     * Print an AttributeList format of an mbean
+     * 
+     * @param mbean - mbean to print
+     */
+    public void printMBean(AttributeList mbean) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMBean(mbean);
+    }
+
+    /**
+     * Print a Map format of an mbean
+     * 
+     * @param mbean
+     */
+    public void printMBean(Map mbean) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMBean(mbean);
+    }
+
+    /**
+     * Print a Collection format of mbeans
+     * 
+     * @param mbean - collection of mbeans
+     */
+    public void printMBean(Collection mbean) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMBean(mbean);
+    }
+
+    /**
+     * Print a Map format of a JMS message
+     * 
+     * @param msg
+     */
+    public void printMessage(Map msg) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMessage(msg);
+    }
+
+    /**
+     * Print a Message format of a JMS message
+     * 
+     * @param msg - JMS message to print
+     */
+    public void printMessage(Message msg) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMessage(msg);
+    }
+
+    /**
+     * Print a collection of JMS messages
+     * 
+     * @param msg - collection of JMS messages
+     */
+    public void printMessage(Collection msg) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printMessage(msg);
+    }
+
+    /**
+     * Print help messages
+     * 
+     * @param helpMsgs - help messages to print
+     */
+    public void printHelp(String[] helpMsgs) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printHelp(helpMsgs);
+    }
+
+    /**
+     * Print an information message
+     * 
+     * @param info - information message to print
+     */
+    public void printInfo(String info) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printInfo(info);
+    }
+
+    /**
+     * Print an exception message
+     * 
+     * @param e - exception to print
+     */
+    public void printException(Exception e) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printException(e);
+    }
+
+    /**
+     * Print a version information
+     * 
+     * @param version - version info to print
+     */
+    public void printVersion(String version) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.printVersion(version);
+    }
+
+    /**
+     * Print a generic key value mapping
+     * 
+     * @param map to print
+     */
+    public void print(Map map) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.print(map);
+    }
+
+    /**
+     * Print a generic array of strings
+     * 
+     * @param strings - string array to print
+     */
+    public void print(String[] strings) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.print(strings);
+    }
+
+    /**
+     * Print a collection of objects
+     * 
+     * @param collection - collection to print
+     */
+    public void print(Collection collection) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.print(collection);
+    }
+
+    /**
+     * Print a java string
+     * 
+     * @param string - string to print
+     */
+    public void print(String string) {
+        if (formatter == null) {
+            throw new IllegalStateException("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
+        }
+        formatter.print(string);
+    }
+
+    public OutputFormatter getFormatter() {
+        return formatter;
+    }
+
+    public void setFormatter(OutputFormatter formatter) {
+        this.formatter = formatter;
+    }
+}

Propchange: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/CommandContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/CommandContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java Thu May  1 11:13:29 2008
@@ -26,7 +26,6 @@
 import org.apache.activemq.broker.util.CommandHandler;
 import org.apache.activemq.console.command.ShellCommand;
 import org.apache.activemq.console.formatter.CommandShellOutputFormatter;
-import org.apache.activemq.console.formatter.GlobalWriter;
 
 /**
  * A default implementation of the @{link CommandHandler} interface
@@ -40,12 +39,14 @@
     public void processCommand(TextMessage request, TextMessage response) throws Exception {
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        GlobalWriter.instantiate(new CommandShellOutputFormatter(out));
+        CommandContext ctx = new CommandContext();
+        ctx.setFormatter(new CommandShellOutputFormatter(out));
 
         // lets turn the text into a list of arguments
         String requestText = request.getText();
 
         List<String> tokens = tokenize(requestText);
+        command.setCommandContext(ctx);
         command.execute(tokens);
 
         out.flush();

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractAmqCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractAmqCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractAmqCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractAmqCommand.java Thu May  1 11:13:29 2008
@@ -27,7 +27,6 @@
 import javax.jms.JMSException;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.console.formatter.GlobalWriter;
 
 public abstract class AbstractAmqCommand extends AbstractCommand {
     private URI brokerUrl;
@@ -43,7 +42,7 @@
      */
     protected Connection createConnection() throws JMSException {
         if (getBrokerUrl() == null) {
-            GlobalWriter
+            context
                 .printException(new IllegalStateException("You must specify a broker "
                                                           + "URL to connect to using the --amqurl option."));
             return null;
@@ -70,7 +69,7 @@
      */
     protected Connection createConnection(String username, String password) throws JMSException {
         if (getBrokerUrl() == null) {
-            GlobalWriter
+            context
                 .printException(new IllegalStateException(
                                                           "You must specify a broker URL to connect to using the --amqurl option."));
             return null;
@@ -113,14 +112,14 @@
         if (token.equals("--amqurl")) {
             // If no broker url specified, or next token is a new option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Broker URL not specified."));
+                context.printException(new IllegalArgumentException("Broker URL not specified."));
                 tokens.clear();
                 return;
             }
 
             // If broker url already specified
             if (getBrokerUrl() != null) {
-                GlobalWriter
+                context
                     .printException(new IllegalArgumentException("Multiple broker URL cannot be specified."));
                 tokens.clear();
                 return;
@@ -131,7 +130,7 @@
             try {
                 setBrokerUrl(new URI(strBrokerUrl));
             } catch (URISyntaxException e) {
-                GlobalWriter.printException(e);
+                context.printException(e);
                 tokens.clear();
                 return;
             }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractCommand.java Thu May  1 11:13:29 2008
@@ -19,7 +19,7 @@
 import java.util.List;
 
 import org.apache.activemq.ActiveMQConnectionMetaData;
-import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.CommandContext;
 
 public abstract class AbstractCommand implements Command {
     public static final String COMMAND_OPTION_DELIMETER = ",";
@@ -27,6 +27,12 @@
     private boolean isPrintHelp;
     private boolean isPrintVersion;
 
+    protected CommandContext context;
+
+    public void setCommandContext(CommandContext context) {
+        this.context = context;
+    }
+    
     /**
      * Execute a generic command, which includes parsing the options for the
      * command and running the specific task.
@@ -44,7 +50,7 @@
 
             // Print the AMQ version
         } else if (isPrintVersion) {
-            GlobalWriter.printVersion(ActiveMQConnectionMetaData.PROVIDER_VERSION);
+            context.printVersion(ActiveMQConnectionMetaData.PROVIDER_VERSION);
 
             // Run the specified task
         } else {
@@ -103,7 +109,7 @@
             System.setProperty(key, value);
         } else {
             // Token is unrecognized
-            GlobalWriter.printInfo("Unrecognized option: " + token);
+            context.printInfo("Unrecognized option: " + token);
             isPrintHelp = true;
         }
     }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java Thu May  1 11:13:29 2008
@@ -24,8 +24,6 @@
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
-import org.apache.activemq.console.formatter.GlobalWriter;
-
 public abstract class AbstractJmxCommand extends AbstractCommand {
     public static final String DEFAULT_JMX_URL    = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
 
@@ -112,12 +110,12 @@
         if (token.equals("--jmxurl")) {
             // If no jmx url specified, or next token is a new option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("JMX URL not specified."));
+                context.printException(new IllegalArgumentException("JMX URL not specified."));
             }
 
             // If jmx url already specified
             if (getJmxServiceUrl() != null) {
-                GlobalWriter.printException(new IllegalArgumentException("Multiple JMX URL cannot be specified."));
+                context.printException(new IllegalArgumentException("Multiple JMX URL cannot be specified."));
                 tokens.clear();
             }
 
@@ -125,7 +123,7 @@
             try {
                 this.setJmxServiceUrl(new JMXServiceURL(strJmxUrl));
             } catch (MalformedURLException e) {
-                GlobalWriter.printException(e);
+                context.printException(e);
                 tokens.clear();
             }
         } else {

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java Thu May  1 11:13:29 2008
@@ -27,7 +27,6 @@
 
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.command.ActiveMQTopic;
-import org.apache.activemq.console.formatter.GlobalWriter;
 import org.apache.activemq.console.util.AmqMessagesUtil;
 
 public class AmqBrowseCommand extends AbstractAmqCommand {
@@ -86,13 +85,13 @@
         try {
             // If no destination specified
             if (tokens.isEmpty()) {
-                GlobalWriter.printException(new IllegalArgumentException("No JMS destination specified."));
+                context.printException(new IllegalArgumentException("No JMS destination specified."));
                 return;
             }
 
             // If no broker url specified
             if (getBrokerUrl() == null) {
-                GlobalWriter.printException(new IllegalStateException("No broker url specified. Use the --amqurl option to specify a broker url."));
+                context.printException(new IllegalStateException("No broker url specified. Use the --amqurl option to specify a broker url."));
                 return;
             }
 
@@ -124,11 +123,11 @@
                 }
 
                 // Display the messages
-                GlobalWriter.printMessage(AmqMessagesUtil.filterMessagesView(addMsgs, groupViews, queryViews));
+                context.printMessage(AmqMessagesUtil.filterMessagesView(addMsgs, groupViews, queryViews));
             }
 
         } catch (Exception e) {
-            GlobalWriter.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
+            context.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
             throw new Exception(e);
         }
     }
@@ -148,7 +147,7 @@
             // If no message selector is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+                context.printException(new IllegalArgumentException("Message selector not specified"));
                 return;
             }
 
@@ -162,7 +161,7 @@
             // If no message selector is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+                context.printException(new IllegalArgumentException("Message selector not specified"));
                 return;
             }
 
@@ -176,7 +175,7 @@
 
             // If no view specified, or next token is a new option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Attributes to view not specified"));
+                context.printException(new IllegalArgumentException("Attributes to view not specified"));
                 return;
             }
 
@@ -223,7 +222,7 @@
 
                 // Unknown group view
             } else {
-                GlobalWriter.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
+                context.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
             }
         } else {
             // Let super class handle unknown option
@@ -235,7 +234,7 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java Thu May  1 11:13:29 2008
@@ -25,7 +25,6 @@
 
 import javax.management.ObjectInstance;
 
-import org.apache.activemq.console.formatter.GlobalWriter;
 import org.apache.activemq.console.util.AmqMessagesUtil;
 import org.apache.activemq.console.util.JmxMBeansUtil;
 
@@ -95,11 +94,11 @@
                 // Iterate through the queue result
                 for (Iterator j = queueList.iterator(); j.hasNext();) {
                     List messages = JmxMBeansUtil.createMessageQueryFilter(useJmxServiceUrl(), ((ObjectInstance)j.next()).getObjectName()).query(queryAddObjects);
-                    GlobalWriter.printMessage(JmxMBeansUtil.filterMessagesView(messages, groupViews, queryViews));
+                    context.printMessage(JmxMBeansUtil.filterMessagesView(messages, groupViews, queryViews));
                 }
             }
         } catch (Exception e) {
-            GlobalWriter.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
+            context.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
             throw new Exception(e);
         }
     }
@@ -119,7 +118,7 @@
             // If no message selector is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+                context.printException(new IllegalArgumentException("Message selector not specified"));
                 return;
             }
 
@@ -133,7 +132,7 @@
             // If no message selector is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+                context.printException(new IllegalArgumentException("Message selector not specified"));
                 return;
             }
 
@@ -147,7 +146,7 @@
 
             // If no view specified, or next token is a new option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Attributes to view not specified"));
+                context.printException(new IllegalArgumentException("Attributes to view not specified"));
                 return;
             }
 
@@ -194,7 +193,7 @@
 
                 // Unknown group view
             } else {
-                GlobalWriter.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
+                context.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
             }
         } else {
             // Let super class handle unknown option
@@ -206,7 +205,7 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java Thu May  1 11:13:29 2008
@@ -19,7 +19,12 @@
 
 import java.util.List;
 
+import org.apache.activemq.console.CommandContext;
+
 public interface Command {
+    
+    void setCommandContext( CommandContext context );
+    
     /**
      * Execute the specified command
      * @param tokens - arguments to the command

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java Thu May  1 11:13:29 2008
@@ -20,7 +20,6 @@
 import java.util.List;
 import java.util.Set;
 
-import org.apache.activemq.console.formatter.GlobalWriter;
 import org.apache.activemq.console.util.JmxMBeansUtil;
 
 public class ListCommand extends AbstractJmxCommand {
@@ -45,9 +44,9 @@
         try {
             Set<String> propsView = new HashSet<String>();
             propsView.add("BrokerName");
-            GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(useJmxServiceUrl()), propsView));
+            context.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(useJmxServiceUrl()), propsView));
         } catch (Exception e) {
-            GlobalWriter.printException(new RuntimeException("Failed to execute list task. Reason: " + e));
+            context.printException(new RuntimeException("Failed to execute list task. Reason: " + e));
             throw new Exception(e);
         }
     }
@@ -56,7 +55,7 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java Thu May  1 11:13:29 2008
@@ -27,7 +27,6 @@
 import javax.management.openmbean.CompositeData;
 import javax.management.remote.JMXConnector;
 
-import org.apache.activemq.console.formatter.GlobalWriter;
 import org.apache.activemq.console.util.JmxMBeansUtil;
 
 public class PurgeCommand extends AbstractJmxCommand {
@@ -87,7 +86,7 @@
                 }
             }
         } catch (Exception e) {
-            GlobalWriter.printException(new RuntimeException("Failed to execute purge task. Reason: " + e));
+            context.printException(new RuntimeException("Failed to execute purge task. Reason: " + e));
             throw new Exception(e);
         }
     }
@@ -101,7 +100,7 @@
     public void purgeQueue(ObjectName queue) throws Exception {
         JMXConnector conn = createJmxConnector();
         MBeanServerConnection server = conn.getMBeanServerConnection();
-        GlobalWriter.printInfo("Purging all messages in queue: " + queue.getKeyProperty("Destination"));
+        context.printInfo("Purging all messages in queue: " + queue.getKeyProperty("Destination"));
         server.invoke(queue, "purge", new Object[] {}, new String[] {});
         conn.close();
     }
@@ -121,7 +120,7 @@
         for (Iterator i = messages.iterator(); i.hasNext();) {
             CompositeData msg = (CompositeData)i.next();
             param[0] = "" + msg.get("JMSMessageID");
-            GlobalWriter.printInfo("Removing message: " + param[0] + " from queue: " + queue.getKeyProperty("Destination"));
+            context.printInfo("Removing message: " + param[0] + " from queue: " + queue.getKeyProperty("Destination"));
             server.invoke(queue, "removeMessage", param, new String[] {
                 "java.lang.String"
             });
@@ -144,7 +143,7 @@
             // If no message selector is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+                context.printException(new IllegalArgumentException("Message selector not specified"));
                 return;
             }
 
@@ -158,7 +157,7 @@
             // If no message selector is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+                context.printException(new IllegalArgumentException("Message selector not specified"));
                 return;
             }
 
@@ -177,7 +176,7 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java Thu May  1 11:13:29 2008
@@ -24,7 +24,6 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import org.apache.activemq.console.formatter.GlobalWriter;
 import org.apache.activemq.console.util.JmxMBeansUtil;
 
 public class QueryCommand extends AbstractJmxCommand {
@@ -112,10 +111,10 @@
                 addMBeans.removeAll(subMBeans);
             }
 
-            GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(addMBeans, queryViews));
+            context.printMBean(JmxMBeansUtil.filterMBeansView(addMBeans, queryViews));
 
         } catch (Exception e) {
-            GlobalWriter.printException(new RuntimeException("Failed to execute query task. Reason: " + e));
+            context.printException(new RuntimeException("Failed to execute query task. Reason: " + e));
             throw new Exception(e);
         }
     }
@@ -141,7 +140,7 @@
             // If additive query
             String predefQuery = PREDEFINED_OBJNAME_QUERY.getProperty(key);
             if (predefQuery == null) {
-                GlobalWriter.printException(new IllegalArgumentException("Unknown query object type: " + key));
+                context.printException(new IllegalArgumentException("Unknown query object type: " + key));
                 return;
             }
             String queryStr = JmxMBeansUtil.createQueryString(predefQuery, value);
@@ -162,7 +161,7 @@
             // If subtractive query
             String predefQuery = PREDEFINED_OBJNAME_QUERY.getProperty(key);
             if (predefQuery == null) {
-                GlobalWriter.printException(new IllegalArgumentException("Unknown query object type: " + key));
+                context.printException(new IllegalArgumentException("Unknown query object type: " + key));
                 return;
             }
             String queryStr = JmxMBeansUtil.createQueryString(predefQuery, value);
@@ -176,7 +175,7 @@
             // If no object name query is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Object name query not specified"));
+                context.printException(new IllegalArgumentException("Object name query not specified"));
                 return;
             }
 
@@ -190,7 +189,7 @@
             // If no object name query is specified, or next token is a new
             // option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Object name query not specified"));
+                context.printException(new IllegalArgumentException("Object name query not specified"));
                 return;
             }
 
@@ -203,7 +202,7 @@
 
             // If no view specified, or next token is a new option
             if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
-                GlobalWriter.printException(new IllegalArgumentException("Attributes to view not specified"));
+                context.printException(new IllegalArgumentException("Attributes to view not specified"));
                 return;
             }
 
@@ -222,7 +221,7 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java Thu May  1 11:13:29 2008
@@ -22,8 +22,8 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.activemq.console.CommandContext;
 import org.apache.activemq.console.formatter.CommandShellOutputFormatter;
-import org.apache.activemq.console.formatter.GlobalWriter;
 
 public class ShellCommand extends AbstractCommand {
 
@@ -66,17 +66,20 @@
      * @return 0 for a successful run, -1 if there are any exception
      */
     public static int main(String[] args, InputStream in, PrintStream out) {
-        GlobalWriter.instantiate(new CommandShellOutputFormatter(out));
+        
+        CommandContext context = new CommandContext();
+        context.setFormatter(new CommandShellOutputFormatter(out));
 
         // Convert arguments to list for easier management
         List<String> tokens = new ArrayList<String>(Arrays.asList(args));
 
         ShellCommand main = new ShellCommand();
         try {
+            main.setCommandContext(context);
             main.execute(tokens);
             return 0;
         } catch (Exception e) {
-            GlobalWriter.printException(e);
+            context.printException(e);
             return -1;
         }
     }
@@ -99,26 +102,32 @@
 
         // Process task token
         if (tokens.size() > 0) {
+            Command command=null;
             String taskToken = (String)tokens.remove(0);
             if (taskToken.equals("start")) {
-                new StartCommand().execute(tokens);
+                command = new StartCommand();
             } else if (taskToken.equals("stop")) {
-                new ShutdownCommand().execute(tokens);
+                command = new ShutdownCommand();
             } else if (taskToken.equals("list")) {
-                new ListCommand().execute(tokens);
+                command = new ListCommand();
             } else if (taskToken.equals("query")) {
-                new QueryCommand().execute(tokens);
+                command = new QueryCommand();
             } else if (taskToken.equals("bstat")) {
-                new BstatCommand().execute(tokens);
+                command = new BstatCommand();
             } else if (taskToken.equals("browse")) {
-                new AmqBrowseCommand().execute(tokens);
+                command = new AmqBrowseCommand();
             } else if (taskToken.equals("purge")) {
-                new PurgeCommand().execute(tokens);
+                command = new PurgeCommand();
             } else if (taskToken.equals("help")) {
                 printHelp();
             } else {
                 printHelp();
             }
+            
+            if( command!=null ) {
+                command.setCommandContext(context);
+                command.execute(tokens);
+            }
         } else {
             printHelp();
         }
@@ -129,6 +138,6 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java Thu May  1 11:13:29 2008
@@ -26,7 +26,6 @@
 import javax.management.ObjectName;
 import javax.management.remote.JMXServiceURL;
 
-import org.apache.activemq.console.formatter.GlobalWriter;
 import org.apache.activemq.console.util.JmxMBeansUtil;
 
 public class ShutdownCommand extends AbstractJmxCommand {
@@ -70,12 +69,12 @@
 
                 // If there is no broker to stop
                 if (mbeans.isEmpty()) {
-                    GlobalWriter.printInfo("There are no brokers to stop.");
+                    context.printInfo("There are no brokers to stop.");
                     return;
 
                     // There should only be one broker to stop
                 } else if (mbeans.size() > 1) {
-                    GlobalWriter.printInfo("There are multiple brokers to stop. Please select the broker(s) to stop or use --all to stop all brokers.");
+                    context.printInfo("There are multiple brokers to stop. Please select the broker(s) to stop or use --all to stop all brokers.");
                     return;
 
                     // Get the first broker only
@@ -92,7 +91,7 @@
                     brokerName = (String)brokerNames.remove(0);
                     Collection matchedBrokers = JmxMBeansUtil.getBrokersByName(useJmxServiceUrl(), brokerName);
                     if (matchedBrokers.isEmpty()) {
-                        GlobalWriter.printInfo(brokerName + " did not match any running brokers.");
+                        context.printInfo(brokerName + " did not match any running brokers.");
                     } else {
                         mbeans.addAll(matchedBrokers);
                     }
@@ -102,7 +101,7 @@
             // Stop all brokers in set
             stopBrokers(useJmxServiceUrl(), mbeans);
         } catch (Exception e) {
-            GlobalWriter.printException(new RuntimeException("Failed to execute stop task. Reason: " + e));
+            context.printException(new RuntimeException("Failed to execute stop task. Reason: " + e));
             throw new Exception(e);
         }
     }
@@ -122,7 +121,7 @@
             brokerObjName = ((ObjectInstance)i.next()).getObjectName();
 
             String brokerName = brokerObjName.getKeyProperty("BrokerName");
-            GlobalWriter.print("Stopping broker: " + brokerName);
+            context.print("Stopping broker: " + brokerName);
 
             try {
                 server.invoke(brokerObjName, "terminateJVM", new Object[] {
@@ -130,7 +129,7 @@
                 }, new String[] {
                     "int"
                 });
-                GlobalWriter.print("Succesfully stopped broker: " + brokerName);
+                context.print("Succesfully stopped broker: " + brokerName);
             } catch (Exception e) {
                 // TODO: Check exceptions throwned
                 // System.out.println("Failed to stop broker: [ " + brokerName +
@@ -162,7 +161,7 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java Thu May  1 11:13:29 2008
@@ -25,7 +25,6 @@
 
 import org.apache.activemq.broker.BrokerFactory;
 import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.console.formatter.GlobalWriter;
 
 public class StartCommand extends AbstractCommand {
 
@@ -84,7 +83,7 @@
                     try {
                         setConfigUri(new URI(strConfigURI));
                     } catch (URISyntaxException e) {
-                        GlobalWriter.printException(e);
+                        context.printException(e);
                         return;
                     }
 
@@ -96,7 +95,7 @@
             // elsewhere
             waitForShutdown();
         } catch (Exception e) {
-            GlobalWriter.printException(new RuntimeException("Failed to execute start task. Reason: " + e, e));
+            context.printException(new RuntimeException("Failed to execute start task. Reason: " + e, e));
             throw new Exception(e);
         }
     }
@@ -171,7 +170,7 @@
      * Print the help messages for the browse command
      */
     protected void printHelp() {
-        GlobalWriter.printHelp(helpFile);
+        context.printHelp(helpFile);
     }
 
 }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java Thu May  1 11:13:29 2008
@@ -38,7 +38,6 @@
 import org.apache.activemq.command.ActiveMQObjectMessage;
 import org.apache.activemq.command.ActiveMQStreamMessage;
 import org.apache.activemq.command.ActiveMQTextMessage;
-import org.apache.activemq.console.formatter.GlobalWriter;
 import org.apache.activemq.console.util.AmqMessagesUtil;
 
 public class MapTransformFilter extends ResultTransformFilter {
@@ -68,7 +67,7 @@
                 object
             });
         } catch (NoSuchMethodException e) {
-            GlobalWriter.print("Unable to transform mbean of type: " + object.getClass().getName() + ". No corresponding transformToMap method found.");
+//            CommandContext.print("Unable to transform mbean of type: " + object.getClass().getName() + ". No corresponding transformToMap method found.");
             return null;
         }
     }

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/OutputFormatter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/OutputFormatter.java?rev=652598&r1=652597&r2=652598&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/OutputFormatter.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/OutputFormatter.java Thu May  1 11:13:29 2008
@@ -25,7 +25,7 @@
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
 
-interface OutputFormatter {
+public interface OutputFormatter {
 
     /**
      * Retrieve the output stream being used by the formatter



Mime
View raw message