net.sf.mmm.util.cli.base
Class AbstractCliParser

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractLoggableObject
      extended by net.sf.mmm.util.cli.base.AbstractCliParser
All Implemented Interfaces:
CliParser
Direct Known Subclasses:
DefaultCliParser

public abstract class AbstractCliParser
extends AbstractLoggableObject
implements CliParser

This is the abstract base-implementation of the CliParser interface.

Since:
2.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Nested Class Summary
static class AbstractCliParser.CliArgumentHelpInfo
          This inner class holds the help information for a single CliArgument.
static class AbstractCliParser.CliHelpWriter
          This inner class is a helper to simplify writing the help-usage.
protected static class AbstractCliParser.CliOptionHelpInfo
          This inner class holds the help information for a single CliOption.
protected static class AbstractCliParser.CliParserState
          This inner class holds the state of the argument parsing.
 
Field Summary
private  CliState cliState
           
private  CliParserDependencies dependencies
           
private static Pattern PATTERN_MIXED_SHORT_OPTIONS
          The Pattern for a mix of multiple short-options.
private  Object state
           
private  CliValueMap valueMap
          The CliValueMap.
 
Fields inherited from interface net.sf.mmm.util.cli.api.CliParser
CHAR_OPTION, END_OPTIONS, PREFIX_LONG_OPTION, PREFIX_SHORT_OPTION
 
Constructor Summary
AbstractCliParser(Object state, CliState cliState, CliParserDependencies dependencies)
          The constructor.
 
Method Summary
protected  void checkOption(CliOptionContainer optionContainer)
          This method checks a CliOption for correctness.
protected  void checkOptionName(String name, CliOptionContainer optionContainer)
          This method checks the given name of the given option.
protected  void checkRequiredParameters(AbstractCliParser.CliParserState parserState)
          This method checks that all required options are present if they are triggered by the current mode.
protected  CliState getCliState()
          This method gets the CliState.
protected  CliParserDependencies getDependencies()
           
 Object getState()
          This method gets the instance of the state where the command-line arguments should be applied to.
protected  void handleUndefinedMode(CliOptionContainer option)
          This method handles a CliOption with an undefined CliOption.mode().
protected  void parseArgument(AbstractCliParser.CliParserState parserState, String argument, CliArgumentContainer argumentContainer, CliParameterConsumer parameterConsumer)
          This method parses the value of a CliOption.
protected  void parseOption(AbstractCliParser.CliParserState parserState, String option, CliOptionContainer optionContainer, CliParameterConsumer parameterConsumer)
          This method parses the value of a CliOption.
protected  void parseParameter(String argument, AbstractCliParser.CliParserState parserState, CliParameterConsumer parameterConsumer)
          This method parses a single command-line argument.
 CliModeObject parseParameters(String... parameters)
          This method parses the given command-line parameters and applies the parsed options and arguments to the Pojo that was supplied when building this parser.
 void printHelp(Appendable target)
          This method prints the help (program usage) generated from the annotations to the given Appendable using default settings.
 void printHelp(Appendable appendable, CliOutputSettings settings)
          This method prints the help (program usage) generated from the annotations to the given Appendable using the given settings.
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN_MIXED_SHORT_OPTIONS

private static final Pattern PATTERN_MIXED_SHORT_OPTIONS
The Pattern for a mix of multiple short-options. E.g. "-vpa" instead of "-v", "-p" and "-a".


cliState

private final CliState cliState
See Also:
getCliState()

dependencies

private final CliParserDependencies dependencies
See Also:
getDependencies()

valueMap

private final CliValueMap valueMap
The CliValueMap.


state

private final Object state
See Also:
getState()
Constructor Detail

AbstractCliParser

public AbstractCliParser(Object state,
                         CliState cliState,
                         CliParserDependencies dependencies)
The constructor.

Parameters:
state - is the state.
cliState - is the CliState.
dependencies - are the dependencies with the required components.
Method Detail

checkOption

protected void checkOption(CliOptionContainer optionContainer)
This method checks a CliOption for correctness.

Parameters:
optionContainer - is the CliOptionContainer.

checkOptionName

protected void checkOptionName(String name,
                               CliOptionContainer optionContainer)
This method checks the given name of the given option.

Parameters:
name - is the name or alias.
optionContainer - is the CliOptionContainer.

handleUndefinedMode

protected void handleUndefinedMode(CliOptionContainer option)
This method handles a CliOption with an undefined CliOption.mode().

Parameters:
option - is the CliOptionContainer.

getCliState

protected CliState getCliState()
This method gets the CliState.

Returns:
the CliState.

getState

public Object getState()
This method gets the instance of the state where the command-line arguments should be applied to. The class of this object should be properly annotated.

Returns:
the state.
See Also:
CliClass

parseOption

protected void parseOption(AbstractCliParser.CliParserState parserState,
                           String option,
                           CliOptionContainer optionContainer,
                           CliParameterConsumer parameterConsumer)
This method parses the value of a CliOption.

Parameters:
parserState - is the AbstractCliParser.CliParserState.
option - is the command-line parameter that triggered the given optionContainer.
optionContainer - is the CliOptionContainer for the current option that has already been detected.
parameterConsumer - is the CliParameterConsumer.

parseArgument

protected void parseArgument(AbstractCliParser.CliParserState parserState,
                             String argument,
                             CliArgumentContainer argumentContainer,
                             CliParameterConsumer parameterConsumer)
This method parses the value of a CliOption.

Parameters:
parserState - is the AbstractCliParser.CliParserState.
argument - is the commandline parameter.
argumentContainer - is the CliArgumentContainer for the current argument.
parameterConsumer - is the CliParameterConsumer.

parseParameters

public CliModeObject parseParameters(String... parameters)
                              throws CliException
This method parses the given command-line parameters and applies the parsed options and arguments to the Pojo that was supplied when building this parser.

Specified by:
parseParameters in interface CliParser
Parameters:
parameters - are the command-line arguments of the main-program.
Returns:
the mode that was triggered.
Throws:
CliException - if the given arguments are invalid.

checkRequiredParameters

protected void checkRequiredParameters(AbstractCliParser.CliParserState parserState)
This method checks that all required options are present if they are triggered by the current mode.

Parameters:
parserState - is the current AbstractCliParser.CliParserState.

parseParameter

protected void parseParameter(String argument,
                              AbstractCliParser.CliParserState parserState,
                              CliParameterConsumer parameterConsumer)
This method parses a single command-line argument.

Parameters:
argument - is the command-line argument.
parserState - is the AbstractCliParser.CliParserState.
parameterConsumer - is the CliParameterConsumer.

printHelp

public void printHelp(Appendable target)
This method prints the help (program usage) generated from the annotations to the given Appendable using default settings.

Specified by:
printHelp in interface CliParser
Parameters:
target - is the Appendable where to print to.
See Also:
CliParser.printHelp(Appendable, CliOutputSettings)

printHelp

public void printHelp(Appendable appendable,
                      CliOutputSettings settings)
This method prints the help (program usage) generated from the annotations to the given Appendable using the given settings.

Specified by:
printHelp in interface CliParser
Parameters:
appendable - is the Appendable where to print to.
settings - are the CliOutputSettings used to configure the output.

getDependencies

protected CliParserDependencies getDependencies()
Returns:
the dependencies for this parser.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.