1 24 25 package org.objectweb.cjdbc.console.text.commands.controller; 26 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.io.FileNotFoundException ; 30 import java.io.IOException ; 31 32 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 33 import org.objectweb.cjdbc.console.text.ConsoleException; 34 import org.objectweb.cjdbc.console.text.commands.ConsoleCommand; 35 import org.objectweb.cjdbc.console.text.module.AbstractConsoleModule; 36 37 43 public class AddDriver extends ConsoleCommand 44 { 45 46 51 public AddDriver(AbstractConsoleModule module) 52 { 53 super(module); 54 } 55 56 59 public void parse(String commandText) throws IOException , ConsoleException 60 { 61 String filename = null; 62 if (commandText == null || commandText.trim().equals("")) 64 { 65 try 66 { 67 filename = console.readLine(ConsoleTranslate 68 .get("controller.command.add.driver.input.filename")); 69 } 70 catch (Exception che) 71 { 72 } 73 } 74 else 75 filename = commandText.trim(); 76 77 if (filename == null || filename.equals("")) 78 throw new ConsoleException(ConsoleTranslate 79 .get("controller.command.add.driver.null.filename")); 80 81 try 82 { 83 jmxClient.getControllerProxy().addDriver(readDriver(filename)); 85 console.println(ConsoleTranslate.get( 86 "controller.command.add.driver.file.sent", filename)); 87 } 88 catch (FileNotFoundException fnf) 89 { 90 throw new ConsoleException(ConsoleTranslate.get( 91 "controller.command.add.driver.file.not.found", filename)); 92 } 93 catch (Exception ioe) 94 { 95 throw new ConsoleException(ConsoleTranslate.get( 96 "controller.command.add.driver.sent.failed", ioe)); 97 } 98 } 99 100 private byte[] readDriver(String filename) throws FileNotFoundException , 101 IOException 102 { 103 File file; 104 FileInputStream fileInput = null; 105 file = new File (filename); 106 fileInput = new FileInputStream (file); 107 108 long size = file.length(); 110 if (size > Integer.MAX_VALUE) 111 throw new IOException (ConsoleTranslate 112 .get("controller.command.add.driver.file.too.big")); 113 byte[] bytes = new byte[(int) size]; 114 int nb = fileInput.read(bytes); 115 fileInput.close(); 116 if (nb != size) 117 throw new IOException (ConsoleTranslate 118 .get("controller.command.add.driver.file.not.read")); 119 return bytes; 120 } 121 122 125 public String getCommandName() 126 { 127 return "upload driver"; 128 } 129 130 133 public String getCommandDescription() 134 { 135 return ConsoleTranslate.get("controller.command.add.driver.description"); 136 } 137 138 141 public String getCommandParameters() 142 { 143 return ConsoleTranslate.get("controller.command.add.driver.params"); 144 } 145 146 } 147 | Popular Tags |