opennlp.tools.cmdline
Class ArgumentParser

java.lang.Object
  extended by opennlp.tools.cmdline.ArgumentParser

public class ArgumentParser
extends Object

Parser for command line arguments. The parser creates a dynamic proxy which can be access via a command line argument interface.

The command line argument proxy interface must follow these conventions:
- Methods do not define arguments
- Method names must start with get
- Allowed return types are Integer, Boolean, String, File and Charset.

Note: Do not use this class, internal use only!


Nested Class Summary
static interface ArgumentParser.OptionalParameter
           
static interface ArgumentParser.ParameterDescription
           
 
Method Summary
static
<T> String
createUsage(Class<T>... argProxyInterfaces)
          Creates a usage string which can be printed in case the user did specify the arguments incorrectly.
static
<T> String
createUsage(Class<T> argProxyInterface)
          Creates a usage string which can be printed in case the user did specify the arguments incorrectly.
static
<T> String[]
filter(String[] args, Class<T> argProxyInterface)
          Filters arguments leaving only those pertaining to argProxyInterface.
static
<T> T
parse(String[] args, Class<T> argProxyInterface)
          Parses the passed arguments and creates an instance of the proxy interface.
static
<T> boolean
validateArguments(String[] args, Class<T>... argProxyInterfaces)
          Tests if the argument are correct or incorrect.
static
<T> boolean
validateArguments(String[] args, Class<T> argProxyInterface)
          Tests if the argument are correct or incorrect.
static
<T> String
validateArgumentsLoudly(String[] args, Class<T>... argProxyInterfaces)
          Tests if the arguments are correct or incorrect.
static
<T> String
validateArgumentsLoudly(String[] args, Class<T> argProxyInterface)
          Tests if the arguments are correct or incorrect.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createUsage

public static <T> String createUsage(Class<T> argProxyInterface)
Creates a usage string which can be printed in case the user did specify the arguments incorrectly. Incorrectly is defined as validateArguments(String[], Class) returns false.

Parameters:
argProxyInterface - interface with parameter descriptions
Returns:
the help message usage string

createUsage

public static <T> String createUsage(Class<T>... argProxyInterfaces)
Creates a usage string which can be printed in case the user did specify the arguments incorrectly. Incorrectly is defined as validateArguments(String[], Class[]) returns false.

Parameters:
argProxyInterfaces - interfaces with parameter descriptions
Returns:
the help message usage string

validateArguments

public static <T> boolean validateArguments(String[] args,
                                            Class<T> argProxyInterface)
Tests if the argument are correct or incorrect. Incorrect means, that mandatory arguments are missing or there are unknown arguments. The argument value itself can also be incorrect, but this is checked by the parse(String[], Class) method and reported accordingly.

Parameters:
args - command line arguments
argProxyInterface - interface with parameters description
Returns:
true, if arguments are valid

validateArguments

public static <T> boolean validateArguments(String[] args,
                                            Class<T>... argProxyInterfaces)
Tests if the argument are correct or incorrect. Incorrect means, that mandatory arguments are missing or there are unknown arguments. The argument value itself can also be incorrect, but this is checked by the parse(String[], Class) method and reported accordingly.

Parameters:
args - command line arguments
argProxyInterfaces - interfaces with parameters description
Returns:
true, if arguments are valid

validateArgumentsLoudly

public static <T> String validateArgumentsLoudly(String[] args,
                                                 Class<T> argProxyInterface)
Tests if the arguments are correct or incorrect.

Parameters:
args - command line arguments
argProxyInterface - interface with parameters description
Returns:
null, if arguments are valid or error message otherwise

validateArgumentsLoudly

public static <T> String validateArgumentsLoudly(String[] args,
                                                 Class<T>... argProxyInterfaces)
Tests if the arguments are correct or incorrect.

Parameters:
args - command line arguments
argProxyInterfaces - interfaces with parameters description
Returns:
null, if arguments are valid or error message otherwise

parse

public static <T> T parse(String[] args,
                          Class<T> argProxyInterface)
Parses the passed arguments and creates an instance of the proxy interface.

In case an argument value cannot be parsed a TerminateToolException is thrown which contains an error message which explains the problems.

Parameters:
args - arguments
argProxyInterface - interface with parameters description
Returns:
parsed parameters
Throws:
TerminateToolException - if an argument value cannot be parsed.
IllegalArgumentException - if validateArguments returns false, if the proxy interface is not compatible.

filter

public static <T> String[] filter(String[] args,
                                  Class<T> argProxyInterface)
Filters arguments leaving only those pertaining to argProxyInterface.

Type Parameters:
T - T
Parameters:
args - arguments
argProxyInterface - interface with parameters description
Returns:
arguments pertaining to argProxyInterface


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.