Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ConsoleCommand.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): Mathieu Peltier.
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  * This class defines a ConsoleCommand
00035  * 
00036  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00037  * @author <a href="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
00038  * @version 1.0
00039  */
00040 public abstract class ConsoleCommand implements Comparable
00041 {
00042   protected Console               console;
00043   protected RmiJmxClient          jmxClient;
00044   protected AbstractConsoleModule module;
00045 
00046   /**
00047    * Creates a new <code>ConsoleCommand.java</code> object
00048    * 
00049    * @param module module that owns this commands
00050    */
00051   public ConsoleCommand(AbstractConsoleModule module)
00052   {
00053     this.console = module.getConsole();
00054     this.module = module;
00055     jmxClient = console.getJmxClient();
00056   }
00057 
00058   /**
00059    * @see java.lang.Comparable#compareTo(java.lang.Object)
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    * Parse the text of the command
00076    * 
00077    * @param commandText the command text
00078    * @throws Exception if connection with the mbean server is lost or command
00079    *           does not have the proper format
00080    */
00081   public abstract void parse(String commandText) throws Exception;
00082 
00083   /**
00084    * Check if the JMX connection is still valid. Otherwise reconnect.
00085    * 
00086    * @param commandText the parameters to execute the command with
00087    * @throws Exception if fails
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    * Get the name of the command
00108    * 
00109    * @return <code>String</code> of the command name
00110    */
00111   public abstract String getCommandName();
00112 
00113   /**
00114    * Return a <code>String</code> description of the parameters of this
00115    * command.
00116    * 
00117    * @return <code>String</code> like &lt;driverPathName&gt;
00118    */
00119   public String getCommandParameters()
00120   {
00121     return "";
00122   }
00123 
00124   /**
00125    * Get the description of the command
00126    * 
00127    * @return <code>String</code> of the command description
00128    */
00129   public abstract String getCommandDescription();
00130 }

Generated on Mon Apr 11 22:01:30 2005 for C-JDBC by  doxygen 1.3.9.1