de.fhg.igd.logging
Class CommandLineInterface

java.lang.Object
  extended byde.fhg.igd.logging.CommandLineInterface

public class CommandLineInterface
extends Object

This class is a simple parser for command line arguments. It provides a command line interface for the LoggingConfiguration by defining and "publishing" a set of public methods (whose parameters need to be exclusively of type String).

Published methods are defined by descriptors (which are simple String objects). The syntax is:

"<method-name>,<number-of-parameters>['*']"

where

Version:
"$Id: CommandLineInterface.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Matthias Pressfreund

Field Summary
protected static CommandLineInterface instance_
          The singleton instance
protected static String[] OPTION_DESCR_
          The option descriptors
protected  Map options_
          The map of available options; Method objects are used as keys, Boolean objects (representing the repeatable flag) as values
 
Constructor Summary
private CommandLineInterface()
          Create a CommandLineInterface.
 
Method Summary
protected  Object call(Method method, String[] params)
          Invoke the given method on the current configuration.
static CommandLineInterface getInstance()
          Get the singleton instance.
 void process(String[] args)
          Parse the given command line arguments and process the detected options.
protected  void process(String option, List params)
          Create one or more calls from an option.
 String toString()
           
static String usage()
          Get usage information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OPTION_DESCR_

protected static final String[] OPTION_DESCR_
The option descriptors


options_

protected Map options_
The map of available options; Method objects are used as keys, Boolean objects (representing the repeatable flag) as values


instance_

protected static CommandLineInterface instance_
The singleton instance

Constructor Detail

CommandLineInterface

private CommandLineInterface()
Create a CommandLineInterface. Since this class is a singleton, getInstance() should be used.

Throws:
IllegalArgumentException - if the option descriptor is invalid
Method Detail

getInstance

public static CommandLineInterface getInstance()
Get the singleton instance.

Returns:
The CommandLineInterface

process

public void process(String[] args)
Parse the given command line arguments and process the detected options.

Parameters:
args - The command line arguments
Throws:
LoggingException - if parsing the command line arguments or processing an option failed

process

protected void process(String option,
                       List params)
Create one or more calls from an option.

Parameters:
option - The option to process
params - The parameters of the given option
Throws:
LoggingException - if the option could not be processed

call

protected Object call(Method method,
                      String[] params)
Invoke the given method on the current configuration.

Parameters:
method - The method to be invoked
params - The parameters to be passed to the method
Returns:
The return value of the method call
Throws:
LoggingException - if an exception was thrown by the called method
UnsupportedOperationException - if calling the requested method failed

usage

public static String usage()
Get usage information.

Returns:
The help printout

toString

public String toString()


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.