src/org/objectweb/cjdbc/console/text/Console.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.console.text; 00026 00027 import java.io.BufferedReader; 00028 import java.io.IOException; 00029 import java.io.InputStream; 00030 import java.io.InputStreamReader; 00031 00032 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 00033 import org.objectweb.cjdbc.console.jmx.RmiJmxClient; 00034 import org.objectweb.cjdbc.console.text.module.ControllerConsole; 00035 import org.objectweb.cjdbc.console.text.module.MonitorConsole; 00036 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin; 00037 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole; 00038 import org.objectweb.cjdbc.console.views.InfoViewer; 00039 00049 public class Console 00050 { 00051 00053 private BufferedReader inbuf; 00054 00056 private boolean interactive; 00057 00058 private RmiJmxClient jmxClient; 00059 00061 private VirtualDatabaseAdmin adminModule; 00062 00064 private MonitorConsole monitorModule; 00065 00067 private VirtualDatabaseConsole consoleModule; 00068 00070 private ControllerConsole controllerModule; 00071 00073 private boolean debug = false; 00074 00075 private boolean printColor = true; 00076 00082 public void setDebug(boolean debug) 00083 { 00084 this.debug = debug; 00085 } 00086 00094 public Console(RmiJmxClient jmxClient, InputStream in, boolean interactive) 00095 { 00096 inbuf = new BufferedReader(new InputStreamReader(in)); 00097 this.interactive = interactive; 00098 this.jmxClient = jmxClient; 00099 00100 controllerModule = new ControllerConsole(this); 00101 adminModule = new VirtualDatabaseAdmin(this); 00102 monitorModule = new MonitorConsole(this); 00103 consoleModule = new VirtualDatabaseConsole(this); 00104 setSupportColors(); 00105 } 00106 00107 private void setSupportColors() 00108 { 00109 String os = System.getProperty("os.name"); 00110 boolean windows = os.indexOf("nt") > -1 || os.indexOf("windows") > -1; 00111 if (windows) 00112 printColor = false; 00113 else 00114 printColor = true; 00115 } 00116 00122 public boolean isInteractive() 00123 { 00124 return interactive; 00125 } 00126 00130 public void handlePrompt() 00131 { 00132 controllerModule.handlePrompt(); 00133 } 00134 00138 public String readLine(String prompt) throws ConsoleException 00139 { 00140 if (interactive) 00141 printPrompt(prompt + " > "); 00142 String line = ""; 00143 try 00144 { 00145 line = inbuf.readLine(); 00146 } 00147 catch (IOException e) 00148 { 00149 throw new ConsoleException(ConsoleTranslate.get( 00150 "console.read.command.failed", e)); 00151 } 00152 if (line != null) 00153 line = line.trim(); 00154 return line; 00155 } 00156 00162 private void printPrompt(String string) 00163 { 00164 if (printColor) 00165 ColorPrinter.printMessage(string, System.out, ColorPrinter.PROMPT, false); 00166 } 00167 00171 public String readPassword(String prompt) throws ConsoleException 00172 { 00173 if (interactive) 00174 printPrompt(prompt + " > "); 00175 String password; 00176 try 00177 { 00178 password = inbuf.readLine(); 00179 } 00180 catch (IOException e) 00181 { 00182 throw new ConsoleException(ConsoleTranslate.get( 00183 "console.read.password.failed", e)); 00184 } 00185 return password; 00186 } 00187 00191 public void print(String s) 00192 { 00193 System.out.print(s); 00194 } 00195 00199 public void println(String s) 00200 { 00201 System.out.println(s); 00202 } 00203 00210 public void println(String s, int color) 00211 { 00212 if (printColor) 00213 ColorPrinter.printMessage(s, System.out, color); 00214 else 00215 System.out.println(s); 00216 } 00217 00221 public void println() 00222 { 00223 System.out.println(); 00224 } 00225 00229 public void printError(String message) 00230 { 00231 if (printColor) 00232 ColorPrinter.printMessage(message, System.err, ColorPrinter.ERROR); 00233 else 00234 System.err.println(message); 00235 } 00236 00243 public void printError(String message, Exception e) 00244 { 00245 if (debug) 00246 e.printStackTrace(); 00247 printError(message); 00248 } 00249 00257 public void showInfo(String[][] info, InfoViewer viewer) 00258 { 00259 if (printColor) 00260 println(viewer.displayText(info), ColorPrinter.STATUS); 00261 else 00262 System.out.println(viewer.displayText(info)); 00263 } 00264 00270 public RmiJmxClient getJmxClient() 00271 { 00272 return jmxClient; 00273 } 00274 00280 public VirtualDatabaseAdmin getAdminModule() 00281 { 00282 return adminModule; 00283 } 00284 00290 public VirtualDatabaseConsole getConsoleModule() 00291 { 00292 return consoleModule; 00293 } 00294 00300 public ControllerConsole getControllerModule() 00301 { 00302 return controllerModule; 00303 } 00304 00310 public MonitorConsole getMonitorModule() 00311 { 00312 return monitorModule; 00313 } 00314 }

CJDBCversion1.0.4に対してTue Oct 12 15:15:59 2004に生成されました。 doxygen 1.3.8