org.hyphenType.optionsextractor
Class OptionsExtractor<T extends Options<?>>

java.lang.Object
  extended by org.hyphenType.optionsextractor.OptionsExtractor<T>
Type Parameters:
T - The options interface type.
Direct Known Subclasses:
UnitTestingOptionExtractor

public class OptionsExtractor<T extends Options<?>>
extends Object

A factory for option objects, and the easiest way to get started with this tool. This class provides the easiest (although not the most flexible, nor the most automated) way to obtain an instance of an option object programmatically. For a non-programmatical and automated method to obtain an option object (i.e. if you do not want to call any API), please utilize the StandAloneAppWrapper class instead.
Here is (possibly the simplest and least invasive) example on how to use this class:

 public static void main(String[] arguments) {
     OptionsExtractor soe = new OptionsExtractor(MyOptionInterface.class);
     MyOptionInterface options = soe.options(arguments);
 }
 
In the source code above, the OptionsExtractor constructor will perform a deep analysis on the options interface MyOptionInterface All arguments received by the main method will be parsed according to the rules declared in the options interface MyOptionInterface .

Author:
Aurelio Akira M. Matsui

Constructor Summary
OptionsExtractor(Class<T> optionInterfaceClass)
          Creates an OptionsExtractor object based on an options interface class.
 
Method Summary
protected  InvocationHandler buildInvocationHandler(OptionValues<T> values, Class<? extends Options<?>> optionsInterface, Class<? extends StatusCode> exitCodeEnumClass, String[] rawArguments)
          Prepared to be replaced by a subclass.
 T options(String... arguments)
           
 T options(UserInput userInput, String... arguments)
          Factory method that creates an instance of the options interface specified in the constructor OptionsExtractor(Class).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptionsExtractor

public OptionsExtractor(Class<T> optionInterfaceClass)
                 throws InvalidOptionsInterfaceException
Creates an OptionsExtractor object based on an options interface class. Exceptions thrown by this constructor means that there is a problem with the structure of the options interface. If you are sure your options interface does not have any inconsistency (which can be tested simply by calling this method before wrapping your application), you do not have any reason to expect any exception being thrown from this method.

The user input option allows the caller to chose which interactive user input to utilize. If you do not want to bother about interactive user inputs (either because your application does not use interactive user input or because you are satisfied with the standard user input), simply call the OptionsExtractor(Class) constructor instead.

Parameters:
optionInterfaceClass -
userInput - The user input to utilize.
Throws:
InvalidOptionsInterfaceException
InvalidOptionException
Method Detail

options

public T options(String... arguments)
                             throws StringParsingErrorException,
                                    MandatoryValueNotFoundException,
                                    RegexMismatchException,
                                    StringParseException,
                                    MandatoryMapValueNotFoundException,
                                    MandatorySimpleArgumentNotFoundException,
                                    OptionsExtractorException
Throws:
StringParsingErrorException
MandatoryValueNotFoundException
RegexMismatchException
StringParseException
MandatoryMapValueNotFoundException
MandatorySimpleArgumentNotFoundException
OptionsExtractorException

options

public T options(UserInput userInput,
                 String... arguments)
                             throws OptionsExtractorException,
                                    StringParsingErrorException,
                                    MandatoryValueNotFoundException,
                                    RegexMismatchException,
                                    StringParseException,
                                    MandatoryMapValueNotFoundException,
                                    MandatorySimpleArgumentNotFoundException
Factory method that creates an instance of the options interface specified in the constructor OptionsExtractor(Class).

Parameters:
userInput - The input from the user.
arguments - The arguments to be parsed.
Returns:
A new instance of the option interface, containing all arguments parsed.
Throws:
OptionsExtractorException
MandatorySimpleArgumentNotFoundException
MandatoryMapValueNotFoundException
StringParseException
RegexMismatchException
MandatoryValueNotFoundException
StringParsingErrorException
InvalidOptionException

buildInvocationHandler

protected InvocationHandler buildInvocationHandler(OptionValues<T> values,
                                                   Class<? extends Options<?>> optionsInterface,
                                                   Class<? extends StatusCode> exitCodeEnumClass,
                                                   String[] rawArguments)
Prepared to be replaced by a subclass. Extending OptionsExtractor is useful to replace the composition of objects that will process the arguments.

Parameters:
values -
formatter -
exitCodeEnumClass -
rawArguments -
Returns:


Copyright © 2013. All Rights Reserved.