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

java.lang.Object
  extended by net.sf.mmm.util.cli.base.CliClassContainer
      extended by net.sf.mmm.util.cli.base.CliState

public class CliState
extends CliClassContainer

This is a container for the state-class. It determines and holds the CLI-informations of that state-class. In advance to CliClassContainer it also handles the CLI specific property annotations.

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

Nested Class Summary
protected static class CliState.CliArgumentFormatter
          This inner class converts a CliArgumentContainer to a String.
 
Nested classes/interfaces inherited from class net.sf.mmm.util.cli.base.CliClassContainer
CliClassContainer.CliModeFormatter
 
Field Summary
private  AnnotationUtil annotationUtil
           
private  List<CliArgumentContainer> arguments
           
private  Map<String,CliOptionContainer> name2OptionMap
           
private  List<CliOptionContainer> optionList
           
private  ReflectionUtil reflectionUtil
           
 
Constructor Summary
CliState(Class<?> stateClass, PojoDescriptorBuilderFactory descriptorBuilderFactory, org.slf4j.Logger logger, ReflectionUtil reflectionUtil, AnnotationUtil annotationUtil)
          The constructor.
 
Method Summary
private  void addArgument(CliArgumentContainer argumentContainer)
          This method registers the given argument.
private  void addOption(CliOptionContainer optionContainer)
          This method registers the given option.
private  void addOption(String nameOrAlias, CliOptionContainer option)
          This method registers the given option with the given name.
protected  boolean findPropertyAnnotations(PojoDescriptorBuilder descriptorBuilder)
          This method finds the properties annotated with CliOption or CliArgument.
protected  AnnotationUtil getAnnotationUtil()
           
 Collection<CliArgumentContainer> getArguments()
          This method gets the List of all CLI-arguments.
 List<CliArgumentContainer> getArguments(CliModeObject mode)
          This method gets the List of CLI-arguments for the given mode.
 CliOptionContainer getOption(String nameOrAlias)
          This method gets the option associated with the given nameOrAlias.
 List<CliOptionContainer> getOptions()
          This method gets the List of CLI-options .
 Collection<CliOptionContainer> getOptions(CliModeObject mode)
          This method gets the options for the given mode.
protected  ReflectionUtil getReflectionUtil()
           
protected  NodeCycle<CliArgumentContainer> initializeArgumentRecursive(BasicDoubleLinkedNode<CliArgumentContainer> node, Map<String,BasicDoubleLinkedNode<CliArgumentContainer>> argumentMap)
          This method initializes the node containing an CliArgumentContainer in order to determine the appropriate order of the CliArguments.
protected  void initializeArguments()
          This method initializes the arguments.
protected  CliModeObject requireMode(String id, Object annotationContainer)
          This method is like CliClassContainer.getMode(String) but also handles the case that a CliMode may be undefined.
 
Methods inherited from class net.sf.mmm.util.cli.base.CliClassContainer
addMode, getCliClass, getCliStyle, getLogger, getMode, getModeIds, getName, getStateClass, initializeModeRecursive
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reflectionUtil

private final ReflectionUtil reflectionUtil
See Also:
getReflectionUtil()

annotationUtil

private final AnnotationUtil annotationUtil
See Also:
getAnnotationUtil()

name2OptionMap

private final Map<String,CliOptionContainer> name2OptionMap
See Also:
getOption(String)

optionList

private final List<CliOptionContainer> optionList
See Also:
getOptions()

arguments

private final List<CliArgumentContainer> arguments
See Also:
getArguments()
Constructor Detail

CliState

public CliState(Class<?> stateClass,
                PojoDescriptorBuilderFactory descriptorBuilderFactory,
                org.slf4j.Logger logger,
                ReflectionUtil reflectionUtil,
                AnnotationUtil annotationUtil)
The constructor.

Parameters:
stateClass - is the state-class.
descriptorBuilderFactory - is the PojoDescriptorBuilderFactory used to introspect the properties of the stateClass.
logger - is the Logger to use (e.g. for CliStyleHandling).
reflectionUtil - is the ReflectionUtil instance to use.
annotationUtil - is the AnnotationUtil instance to use.
Method Detail

getAnnotationUtil

protected AnnotationUtil getAnnotationUtil()
Returns:
the annotationUtil

getReflectionUtil

protected ReflectionUtil getReflectionUtil()
Returns:
the reflectionUtil

initializeArguments

protected void initializeArguments()
This method initializes the arguments. This means that the arguments are ordered properly.

See Also:
CliArgument.addCloseTo(), CliArgument.addAfter()

initializeArgumentRecursive

protected NodeCycle<CliArgumentContainer> initializeArgumentRecursive(BasicDoubleLinkedNode<CliArgumentContainer> node,
                                                                      Map<String,BasicDoubleLinkedNode<CliArgumentContainer>> argumentMap)
                                                               throws NodeCycleException
This method initializes the node containing an CliArgumentContainer in order to determine the appropriate order of the CliArguments.

Parameters:
node - is the node to initialize (link into the node-list).
argumentMap - maps the id to the according argument-node.
Returns:
a NodeCycle if a cyclic dependency has been detected but is NOT yet complete or null if the initialization was successful.
Throws:
NodeCycleException - if a cyclic dependency was detected and completed.

findPropertyAnnotations

protected boolean findPropertyAnnotations(PojoDescriptorBuilder descriptorBuilder)
This method finds the properties annotated with CliOption or CliArgument.

Parameters:
descriptorBuilder - is the PojoDescriptorBuilder to use (determines if fields or setters are used).
Returns:
true if at least one annotated property has been found, false otherwise.

requireMode

protected CliModeObject requireMode(String id,
                                    Object annotationContainer)
This method is like CliClassContainer.getMode(String) but also handles the case that a CliMode may be undefined.

Parameters:
id - is the ID of the requested CliMode.
annotationContainer - is the CliArgumentContainer or CliOptionContainer.
Returns:
the requested CliModeObject.

addArgument

private void addArgument(CliArgumentContainer argumentContainer)
This method registers the given argument.

Parameters:
argumentContainer - is the argument to register.

addOption

private void addOption(CliOptionContainer optionContainer)
This method registers the given option.

Parameters:
optionContainer - is the option to register.

addOption

private void addOption(String nameOrAlias,
                       CliOptionContainer option)
This method registers the given option with the given name.

Parameters:
nameOrAlias - is the CliOption.name() or alias of the option.
option - is the option to register.

getOption

public CliOptionContainer getOption(String nameOrAlias)
This method gets the option associated with the given nameOrAlias.

Parameters:
nameOrAlias - is the CliOption.name() or alias of the requested option.
Returns:
the requested option or null if no such option exists.

getOptions

public List<CliOptionContainer> getOptions()
This method gets the List of CLI-options .

Returns:
the options

getArguments

public Collection<CliArgumentContainer> getArguments()
This method gets the List of all CLI-arguments.

Returns:
the arguments

getArguments

public List<CliArgumentContainer> getArguments(CliModeObject mode)
This method gets the List of CLI-arguments for the given mode.

Parameters:
mode - is the according mode.
Returns:
the arguments.

getOptions

public Collection<CliOptionContainer> getOptions(CliModeObject mode)
This method gets the options for the given mode.

Parameters:
mode - is the CliModeObject for which the options are required.
Returns:
a Collection with all options that are compatible with the given mode.


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