1 22 23 package org.continuent.sequoia.console.text.commands; 24 25 import org.continuent.sequoia.common.i18n.ConsoleTranslate; 26 import org.continuent.sequoia.console.jmx.RmiJmxClient; 27 import org.continuent.sequoia.console.text.Console; 28 import org.continuent.sequoia.console.text.ConsoleException; 29 import org.continuent.sequoia.console.text.module.AbstractConsoleModule; 30 31 38 public abstract class ConsoleCommand implements Comparable 39 { 40 protected Console console; 41 protected RmiJmxClient jmxClient; 42 protected AbstractConsoleModule module; 43 44 49 public ConsoleCommand(AbstractConsoleModule module) 50 { 51 this.console = module.getConsole(); 52 this.module = module; 53 jmxClient = console.getJmxClient(); 54 } 55 56 59 public int compareTo(Object o) 60 { 61 if (o instanceof ConsoleCommand) 62 { 63 ConsoleCommand c = (ConsoleCommand) o; 64 return getCommandName().compareTo(c.getCommandName()); 65 } 66 else 67 { 68 throw new IllegalArgumentException (); 69 } 70 } 71 72 79 protected void checkJmxConnectionToController() throws ConsoleException 80 { 81 jmxClient = console.getJmxClient(); 84 85 if (jmxClient == null) 86 throw new ConsoleException(ConsoleTranslate 87 .get("console.command.requires.connection")); } 89 90 97 public abstract void parse(String commandText) throws Exception ; 98 99 105 public void execute(String commandText) throws Exception 106 { 107 parse(commandText); 108 } 109 110 115 public abstract String getCommandName(); 116 117 123 public String getCommandParameters() 124 { 125 return ""; } 127 128 133 public abstract String getCommandDescription(); 134 135 140 public String getUsage() 141 { 142 String usage = ConsoleTranslate 143 .get( 144 "command.usage", new String []{getCommandName(), getCommandParameters()}); usage += "\n " + getCommandDescription(); return usage; 147 } 148 } 149 | Popular Tags |