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

AddDriver.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): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.text.commands.controller;
00026 
00027 import java.io.File;
00028 import java.io.FileInputStream;
00029 import java.io.FileNotFoundException;
00030 import java.io.IOException;
00031 
00032 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
00033 import org.objectweb.cjdbc.console.text.ConsoleException;
00034 import org.objectweb.cjdbc.console.text.commands.ConsoleCommand;
00035 import org.objectweb.cjdbc.console.text.module.AbstractConsoleModule;
00036 
00037 /**
00038  * This class defines a AddDriver
00039  * 
00040  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00041  * @version 1.0
00042  */
00043 public class AddDriver extends ConsoleCommand
00044 {
00045 
00046   /**
00047    * Creates a new <code>AddDriver.java</code> object
00048    * 
00049    * @param module the command is attached to
00050    */
00051   public AddDriver(AbstractConsoleModule module)
00052   {
00053     super(module);
00054   }
00055 
00056   /**
00057    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#parse(java.lang.String)
00058    */
00059   public void parse(String commandText) throws IOException, ConsoleException
00060   {
00061     String filename = null;
00062     //  Get the file name if needed
00063     if (commandText == null || commandText.trim().equals(""))
00064     {
00065       try
00066       {
00067         filename = console.readLine(ConsoleTranslate
00068             .get("controller.command.adddriver.input.filename"));
00069       }
00070       catch (Exception che)
00071       {
00072       }
00073     }
00074     else
00075       filename = commandText.trim();
00076 
00077     if (filename == null || filename.equals(""))
00078       throw new ConsoleException(ConsoleTranslate
00079           .get("controller.command.adddriver.null.filename"));
00080 
00081     try
00082     {
00083       // Send the file contents to the controller
00084       jmxClient.getControllerProxy().addDriver(readDriver(filename));
00085       console.println(ConsoleTranslate.get(
00086           "controller.command.adddriver.file.sent", filename));
00087     }
00088     catch (FileNotFoundException fnf)
00089     {
00090       throw new ConsoleException(ConsoleTranslate.get(
00091           "controller.command.adddriver.file.not.found", filename));
00092     }
00093     catch (Exception ioe)
00094     {
00095       throw new ConsoleException(ConsoleTranslate.get(
00096           "controller.command.adddriver.sent.failed", ioe));
00097     }
00098   }
00099 
00100   private byte[] readDriver(String filename) throws FileNotFoundException,
00101       IOException
00102   {
00103     File file;
00104     FileInputStream fileInput = null;
00105     file = new File(filename);
00106     fileInput = new FileInputStream(file);
00107 
00108     // Read the file into an array of bytes
00109     long size = file.length();
00110     if (size > Integer.MAX_VALUE)
00111       throw new IOException(ConsoleTranslate
00112           .get("controller.command.adddriver.file.too.big"));
00113     byte[] bytes = new byte[(int) size];
00114     int nb = fileInput.read(bytes);
00115     fileInput.close();
00116     if (nb != size)
00117       throw new IOException(ConsoleTranslate
00118           .get("controller.command.adddriver.file.not.read"));
00119     return bytes;
00120   }
00121 
00122   /**
00123    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
00124    */
00125   public String getCommandName()
00126   {
00127     return "addDriver";
00128   }
00129 
00130   /**
00131    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
00132    */
00133   public String getCommandDescription()
00134   {
00135     return ConsoleTranslate.get("controller.command.adddriver");
00136   }
00137 
00138   /**
00139    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
00140    */
00141   public String getCommandParameters()
00142   {
00143     return "<driverPathName>";
00144   }
00145 
00146 }

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