1 24 25 package org.objectweb.cjdbc.console.text.commands; 26 27 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 28 import org.objectweb.cjdbc.console.jmx.RmiJmxClient; 29 import org.objectweb.cjdbc.console.text.Console; 30 import org.objectweb.cjdbc.console.text.ConsoleException; 31 import org.objectweb.cjdbc.console.text.module.AbstractConsoleModule; 32 33 40 public abstract class ConsoleCommand implements Comparable 41 { 42 protected Console console; 43 protected RmiJmxClient jmxClient; 44 protected AbstractConsoleModule module; 45 46 51 public ConsoleCommand(AbstractConsoleModule module) 52 { 53 this.console = module.getConsole(); 54 this.module = module; 55 jmxClient = console.getJmxClient(); 56 } 57 58 61 public int compareTo(Object o) 62 { 63 if (o instanceof ConsoleCommand) 64 { 65 ConsoleCommand c = (ConsoleCommand) o; 66 return getCommandName().compareTo(c.getCommandName()); 67 } 68 else 69 { 70 throw new IllegalArgumentException (); 71 } 72 } 73 74 81 public abstract void parse(String commandText) throws Exception ; 82 83 89 public void execute(String commandText) throws Exception 90 { 91 if (!jmxClient.isValidConnection()) 92 { 93 try 94 { 95 jmxClient.reconnect(); 96 } 97 catch (Exception e) 98 { 99 throw new ConsoleException(ConsoleTranslate 100 .get("jmx.server.connection.lost")); 101 } 102 } 103 parse(commandText); 104 } 105 106 111 public abstract String getCommandName(); 112 113 119 public String getCommandParameters() 120 { 121 return ""; 122 } 123 124 129 public abstract String getCommandDescription(); 130 131 136 public String getUsage() 137 { 138 String usage = ConsoleTranslate.get("command.usage", new String [] {getCommandName(), getCommandParameters()}); 139 usage += "\n " + getCommandDescription(); 140 return usage; 141 } 142 } 143 144 | Popular Tags |