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

org.objectweb.cjdbc.console.text.ConsoleLauncher Class Reference

List of all members.

Static Public Member Functions

void main (String args[]) throws Exception
void startGuiConsole (CommandLine commandLine) throws Exception
void startTextConsole (CommandLine commandLine) throws Exception

Detailed Description

This class defines a ConsoleLauncher

Author:
Nicolas Modrzyk

Mathieu Peltier

Version:
1.0

Definition at line 57 of file ConsoleLauncher.java.


Member Function Documentation

void org.objectweb.cjdbc.console.text.ConsoleLauncher.main String  args[]  )  throws Exception [static]
 

Launchs the C-JDBC console. The available options are: <il> -d or --debug: show stack trace when error occurs. -f or --file: use a given file as the source of commands instead of reading commands interactively. -h or --help: displays usage information. -i or --ip: IP address of the host name where the JMX Server hosting the controller is running (the default is '0.0.0.0'). -p or --port: JMX/RMI Port number of (the default is org.objectweb.cjdbc.common.jmx.JmxConstants#DEFAULT_JMX_RMI_PORT). -s or --secret: password for JMX connection. -u or --username: username for JMX connection. -v or --version: displays version information.

Parameters:
args command line arguments (see above)
Exceptions:
Exception if fails

Definition at line 91 of file ConsoleLauncher.java.

00092   {
00093     // Create options object
00094     Options options = createOptions();
00095 
00096     // Parse command line
00097     CommandLineParser parser = new GnuParser();
00098     CommandLine commandLine = null;
00099     try
00100     {
00101       commandLine = parser.parse(options, args);
00102     }
00103     catch (ParseException e)
00104     {
00105       System.err.println("Syntax error (" + e + ")");
00106       printUsage(options);
00107       System.exit(1);
00108     }
00109 
00110     // Non-recognized options
00111     int n = commandLine.getArgs().length;
00112     for (int i = 0; i < n; i++)
00113     {
00114       System.err.println("Syntax error (unrecognized option: "
00115           + commandLine.getArgs()[i] + ")");
00116       printUsage(options);
00117       System.exit(1);
00118     }
00119 
00120     // Handle --help option
00121     if (commandLine.hasOption('h'))
00122     {
00123       if (commandLine.getOptions().length > 1)
00124         System.err.println("Syntax error");
00125 
00126       printUsage(options);
00127       System.exit(1);
00128     }
00129 
00130     // Handle --version option
00131     if (commandLine.hasOption('v'))
00132     {
00133       if (commandLine.getOptions().length > 1)
00134       {
00135         System.err.println("Syntax error");
00136         printUsage(options);
00137       }
00138       else
00139         System.out.println("C-JDBC controller console version "
00140             + Constants.VERSION);
00141 
00142       System.exit(1);
00143     }
00144 
00145     // Handle text/gui console start
00146     if (commandLine.hasOption('t'))
00147     {
00148       startTextConsole(commandLine);
00149     }
00150     else
00151     {
00152       try
00153       {
00154         startGuiConsole(commandLine);
00155       }
00156       catch (Throwable t)
00157       {
00158         System.out
00159             .println("Cannot initiate graphic mode. Loading text console instead.");
00160         startTextConsole(commandLine);
00161       }
00162     }
00163 
00164   }

void org.objectweb.cjdbc.console.text.ConsoleLauncher.startGuiConsole CommandLine  commandLine  )  throws Exception [static]
 

Starts the gui

Parameters:
commandLine parameters to start the gui
Exceptions:
Exception if cannot load gui(probably no graphics)

Definition at line 172 of file ConsoleLauncher.java.

00173   {
00174     // Set look and feel: Kunstoff not supported in Mac os X
00175     // so revert to default one
00176     String system = System.getProperty("os.name");
00177     if (system.indexOf("Mac OS") != -1)
00178     {
00179       try
00180       {
00181         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
00182       }
00183       catch (Exception e)
00184       {
00185       }
00186     }
00187 
00188     // set default encoding to UTF so we support japanese
00189     Properties pi = System.getProperties();
00190     pi.put("file.encoding", "UTF-8"); // To add a new
00191     // one
00192     System.setProperties(pi);
00193     new CjdbcGui();
00194   }

void org.objectweb.cjdbc.console.text.ConsoleLauncher.startTextConsole CommandLine  commandLine  )  throws Exception [static]
 

Starts the text console with the given commandline

Parameters:
commandLine parameters for the text console
Exceptions:
Exception if fails

Definition at line 202 of file ConsoleLauncher.java.

References org.objectweb.cjdbc.console.text.Console.handlePrompt(), and org.objectweb.cjdbc.console.text.Console.setDebug().

00203   {
00204     // Handle --ip option
00205     String ip;
00206     try
00207     {
00208       ip = InetAddress.getLocalHost().getHostName();
00209     }
00210     catch (UnknownHostException e1)
00211     {
00212       ip = "127.0.0.1";
00213     }
00214     if (commandLine.hasOption('i'))
00215     {
00216       String tmp = commandLine.getOptionValue('i');
00217       if (tmp != null)
00218       {
00219         ip = tmp;
00220       }
00221     }
00222 
00223     // Handle --port option
00224     int port;
00225     if (commandLine.hasOption('p'))
00226     {
00227       String s = commandLine.getOptionValue('p');
00228       if (s == null)
00229       {
00230         port = JmxConstants.DEFAULT_JMX_RMI_PORT;
00231       }
00232       else
00233         try
00234         {
00235           port = Integer.parseInt(s);
00236           System.out.println("Using specified " + port + " port number");
00237         }
00238         catch (NumberFormatException e)
00239         {
00240           System.out.println("Bad port number (" + e + "), using default "
00241               + JmxConstants.DEFAULT_JMX_RMI_PORT + " port number");
00242           port = JmxConstants.DEFAULT_JMX_RMI_PORT;
00243         }
00244     }
00245     else
00246     {
00247       port = JmxConstants.DEFAULT_JMX_RMI_PORT;
00248     }
00249 
00250     RmiJmxClient jmxClient = null;
00251     if (commandLine.hasOption('u') && commandLine.hasOption('s'))
00252     {
00253       String username = commandLine.getOptionValue('u');
00254       String password = commandLine.getOptionValue('s');
00255       jmxClient = new RmiJmxClient("" + port, ip, username, password);
00256     }
00257     else
00258     {
00259       try
00260       {
00261         jmxClient = new RmiJmxClient("" + port, ip, null);
00262       }
00263       catch (Exception e)
00264       {
00265         System.out.println("Cannot connect to the jmx server");
00266         System.exit(1);
00267       }
00268     }
00269 
00270     // Launch the console (handle --text and --file options )
00271     System.out.println("Launching the C-JDBC controller console");
00272 
00273     Console console;
00274     if (commandLine.hasOption('f'))
00275     {
00276       File file = new File(commandLine.getOptionValue('f'));
00277       FileInputStream in = null;
00278       try
00279       {
00280         in = new FileInputStream(file);
00281       }
00282       catch (FileNotFoundException e)
00283       {
00284         System.err.println("Failed to open file '" + file.toString() + "' ("
00285             + e + ")");
00286         System.exit(1);
00287       }
00288       console = new Console(jmxClient, in, false);
00289       console.setDebug(commandLine.hasOption('d'));
00290       console.handlePrompt();
00291       System.exit(0);
00292     }
00293     else
00294     {
00295       console = new Console(jmxClient, System.in, true);
00296       console.setDebug(commandLine.hasOption('d'));
00297       console.handlePrompt();
00298     }
00299   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:40 2005 for C-JDBC by  doxygen 1.3.9.1