00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.console.text.commands;
00026
00027 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
00028 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
00029 import org.objectweb.cjdbc.console.text.Console;
00030 import org.objectweb.cjdbc.console.text.ConsoleException;
00031 import org.objectweb.cjdbc.console.text.module.AbstractConsoleModule;
00032
00033
00034
00035
00036
00037
00038
00039
00040 public abstract class ConsoleCommand implements Comparable
00041 {
00042 protected Console console;
00043 protected RmiJmxClient jmxClient;
00044 protected AbstractConsoleModule module;
00045
00046
00047
00048
00049
00050
00051 public ConsoleCommand(AbstractConsoleModule module)
00052 {
00053 this.console = module.getConsole();
00054 this.module = module;
00055 jmxClient = console.getJmxClient();
00056 }
00057
00058
00059
00060
00061 public int compareTo(Object o)
00062 {
00063 if (o instanceof ConsoleCommand)
00064 {
00065 ConsoleCommand c = (ConsoleCommand) o;
00066 return getCommandName().compareTo(c.getCommandName());
00067 }
00068 else
00069 {
00070 throw new IllegalArgumentException();
00071 }
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081 public abstract void parse(String commandText) throws Exception;
00082
00083
00084
00085
00086
00087
00088
00089 public void execute(String commandText) throws Exception
00090 {
00091 if (!jmxClient.isValidConnection())
00092 {
00093 try
00094 {
00095 jmxClient.reconnect();
00096 }
00097 catch (Exception e)
00098 {
00099 throw new ConsoleException(ConsoleTranslate
00100 .get("jmx.server.connection.lost"));
00101 }
00102 }
00103 parse(commandText);
00104 }
00105
00106
00107
00108
00109
00110
00111 public abstract String getCommandName();
00112
00113
00114
00115
00116
00117
00118
00119 public String getCommandParameters()
00120 {
00121 return "";
00122 }
00123
00124
00125
00126
00127
00128
00129 public abstract String getCommandDescription();
00130 }