org.fhcrc.cpl.toolbox.commandline
Class BaseCommandLineModuleImpl

java.lang.Object
  extended by org.fhcrc.cpl.toolbox.commandline.BaseCommandLineModuleImpl
All Implemented Interfaces:
CommandLineModule
Direct Known Subclasses:
BaseViewerCommandLineModuleImpl, DemoCommandModule

public abstract class BaseCommandLineModuleImpl
extends java.lang.Object
implements CommandLineModule

Base class for command line modules. Command line modules do not have to extend this class (they only need to implement CommandLineModule), but it's highly recommended, because this class provides dozens of highly useful convenience methods for argument management


Field Summary
protected  java.util.Map<java.lang.String,CommandLineArgumentDefinition> mArgumentDefs
           
protected  java.util.Map<java.lang.String,java.lang.Object> mArgumentValues
           
protected  java.util.Map<java.lang.String,java.lang.String> mArgumentValueStrings
           
protected  java.lang.String mCommandName
           
protected  java.lang.String mHelpMessage
           
protected  java.lang.String mShortDescription
           
protected  java.lang.String mUsageMessage
           
 
Fields inherited from interface org.fhcrc.cpl.toolbox.commandline.CommandLineModule
MODULE_HELP_AUTOMATIC, MODULE_USAGE_AUTOMATIC, UNNAMED_ARG_SERIES_SEPARATOR
 
Constructor Summary
BaseCommandLineModuleImpl()
           
 
Method Summary
protected  void addArgumentDefinition(CommandLineArgumentDefinition def)
          Add an argument definition
protected  void addArgumentDefinitions(CommandLineArgumentDefinition[] defArray)
          Add argument definitions
protected  void addArgumentDefinitions(CommandLineArgumentDefinition[] defArray, boolean advanced)
          Add a argument definitions, setting the "advanced" state appropriately
protected  void assertArgumentAbsent(java.lang.String argumentName)
          Asserts the absence of an argument.
protected  void assertArgumentAbsent(java.lang.String argumentName, java.lang.String requiredAbsentByArgument)
          Asserts the absence of an argument.
protected  void assertArgumentPresent(java.lang.String argumentName)
          Asserts the presence of an argument.
protected  void assertArgumentPresent(java.lang.String requiredArgumentName, java.lang.String requiredByArgumentName)
          Asserts the presence of an argument.
protected  java.lang.String createArgsTableHTML(CommandLineArgumentDefinition[] argDefs)
           
protected  FileToReadArgumentDefinition createUnnamedFileArgumentDefinition(boolean required, java.lang.String helpText)
           
protected  FileToReadArgumentDefinition createUnnamedSeriesFileArgumentDefinition(boolean required, java.lang.String helpText)
          Cover method for ArgumentDefinitionFactory method
 void digestArguments(java.util.Map<java.lang.String,java.lang.String> argumentValueMap)
          Digest raw string argument values.
 CommandLineArgumentDefinition[] getAdvancedArgumentDefinitions()
          Implements a method in CommandLineModule
 CommandLineArgumentDefinition getArgumentDefinition(java.lang.String argumentName)
          Implements a method in CommandLineModule
 CommandLineArgumentDefinition[] getArgumentDefinitions()
          Implements a method in CommandLineModule
 CommandLineArgumentDefinition[] getArgumentDefinitionsSortedForDisplay()
          Return the array of argument definitions in the proper display order
protected  java.lang.Object getArgumentValue(java.lang.String argumentName)
           
protected  java.util.Map<java.lang.String,java.lang.Object> getArgumentValues()
           
 java.util.Map<java.lang.String,java.lang.String> getArgumentValueStrings()
          Return the original argument name-value pairs that were passed into this module via digestArguments()
 CommandLineArgumentDefinition[] getBasicArgumentDefinitions()
          Implements a method in CommandLineModule
protected  boolean getBooleanArgumentValue(java.lang.String argumentName)
           
 java.lang.String getCommandName()
           
protected  DeltaMassArgumentDefinition.DeltaMassWithType getDeltaMassArgumentValue(java.lang.String argumentName)
           
protected  double getDoubleArgumentValue(java.lang.String argumentName)
           
protected  double[] getDoubleArrayArgumentValue(java.lang.String argumentName)
           
protected  Protein[] getFastaFileArgumentValue(java.lang.String argumentName)
           
protected  java.io.File getFileArgumentValue(java.lang.String argumentName)
           
protected  java.io.File[] getFileArrayArgumentValue(java.lang.String argumentName)
           
protected  float getFloatArgumentValue(java.lang.String argumentName)
           
 java.lang.String getFullHelp()
          Returns the full help message to be displayed by --help
 java.lang.String getHelpMessage()
          a String giving the user detailed help on invoking this command
 java.lang.String getHtmlHelpFragment()
          Returns an HTML fragment containing full help information for this module
protected  int getIntegerArgumentValue(java.lang.String argumentName)
           
protected  MS2Modification[] getModificationListArgumentValue(java.lang.String argumentName)
           
protected static java.io.PrintWriter getPrintWriter(java.io.File outFile)
           
 java.lang.String getShortDescription()
           
protected  java.lang.String getStringArgumentValue(java.lang.String argumentName)
           
protected  java.lang.Object getUnnamedArgumentValue()
          process an arguments from the unnamed definition, converting it to a given argument type
protected  java.io.File getUnnamedFileArgumentValue()
           
protected  java.lang.Object[] getUnnamedSeriesArgumentValues()
          process a bunch of arguments from the unnamed series definition, converting them to a given argument type
protected  java.io.File[] getUnnamedSeriesFileArgumentValues()
          Convenience method for getting an array of files specified in an unnamed series, since files are the things most commonly specified that way.
 java.lang.String getUsage()
           
 boolean hasAdvancedArguments()
          Does this module have any 'advanced' arguments?
protected  boolean hasArgumentValue(java.lang.String argumentName)
          Convenience method to tell whether an argument map contains an argument
protected  boolean hasUnnamedArgumentValue()
           
protected  boolean hasUnnamedSeriesArgumentValue()
           
 void invoke(java.util.Map<java.lang.String,java.lang.String> argumentValues)
          Invoke the CommandLineModule, using the argument values specified in the argumentValues array.
protected  java.lang.String makeHtmlSafe(java.lang.String plainString)
           
protected  CommandLineArgumentDefinition[] sortArgDefsForDisplay(java.util.Map<java.lang.String,CommandLineArgumentDefinition> defMap)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.fhcrc.cpl.toolbox.commandline.CommandLineModule
assignArgumentValues, execute
 

Field Detail

mCommandName

protected java.lang.String mCommandName

mUsageMessage

protected java.lang.String mUsageMessage

mHelpMessage

protected java.lang.String mHelpMessage

mShortDescription

protected java.lang.String mShortDescription

mArgumentDefs

protected java.util.Map<java.lang.String,CommandLineArgumentDefinition> mArgumentDefs

mArgumentValues

protected java.util.Map<java.lang.String,java.lang.Object> mArgumentValues

mArgumentValueStrings

protected java.util.Map<java.lang.String,java.lang.String> mArgumentValueStrings
Constructor Detail

BaseCommandLineModuleImpl

public BaseCommandLineModuleImpl()
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

makeHtmlSafe

protected java.lang.String makeHtmlSafe(java.lang.String plainString)

getUsage

public java.lang.String getUsage()
Specified by:
getUsage in interface CommandLineModule
Returns:
a String telling the user how to invoke this command

getFullHelp

public java.lang.String getFullHelp()
Returns the full help message to be displayed by --help

Specified by:
getFullHelp in interface CommandLineModule
Returns:

hasAdvancedArguments

public boolean hasAdvancedArguments()
Does this module have any 'advanced' arguments?

Returns:

getHtmlHelpFragment

public java.lang.String getHtmlHelpFragment()
Returns an HTML fragment containing full help information for this module

Specified by:
getHtmlHelpFragment in interface CommandLineModule
Returns:

createArgsTableHTML

protected java.lang.String createArgsTableHTML(CommandLineArgumentDefinition[] argDefs)

getHelpMessage

public java.lang.String getHelpMessage()
Description copied from interface: CommandLineModule
a String giving the user detailed help on invoking this command

Specified by:
getHelpMessage in interface CommandLineModule
Returns:
a String telling the user how to invoke this command; can be detailed

getShortDescription

public java.lang.String getShortDescription()
Specified by:
getShortDescription in interface CommandLineModule
Returns:
a String with a quick description of the feature

getCommandName

public java.lang.String getCommandName()
Specified by:
getCommandName in interface CommandLineModule
Returns:
a String that tells Application to invoke this commandlinemodule and not another one. Had better not collide with another one

addArgumentDefinition

protected void addArgumentDefinition(CommandLineArgumentDefinition def)
Add an argument definition

Parameters:
def -

addArgumentDefinitions

protected void addArgumentDefinitions(CommandLineArgumentDefinition[] defArray)
Add argument definitions

Parameters:
defArray -

addArgumentDefinitions

protected void addArgumentDefinitions(CommandLineArgumentDefinition[] defArray,
                                      boolean advanced)
Add a argument definitions, setting the "advanced" state appropriately

Parameters:
defArray -

getBasicArgumentDefinitions

public CommandLineArgumentDefinition[] getBasicArgumentDefinitions()
Implements a method in CommandLineModule

Specified by:
getBasicArgumentDefinitions in interface CommandLineModule
Returns:
an array of argument definitions

getAdvancedArgumentDefinitions

public CommandLineArgumentDefinition[] getAdvancedArgumentDefinitions()
Implements a method in CommandLineModule

Specified by:
getAdvancedArgumentDefinitions in interface CommandLineModule
Returns:
an array of argument definitions

getArgumentDefinitions

public CommandLineArgumentDefinition[] getArgumentDefinitions()
Implements a method in CommandLineModule

Specified by:
getArgumentDefinitions in interface CommandLineModule
Returns:
an array of argument definitions

sortArgDefsForDisplay

protected CommandLineArgumentDefinition[] sortArgDefsForDisplay(java.util.Map<java.lang.String,CommandLineArgumentDefinition> defMap)

getArgumentDefinitionsSortedForDisplay

public CommandLineArgumentDefinition[] getArgumentDefinitionsSortedForDisplay()
Return the array of argument definitions in the proper display order

Specified by:
getArgumentDefinitionsSortedForDisplay in interface CommandLineModule
Returns:

getArgumentDefinition

public CommandLineArgumentDefinition getArgumentDefinition(java.lang.String argumentName)
Implements a method in CommandLineModule

Specified by:
getArgumentDefinition in interface CommandLineModule
Parameters:
argumentName -
Returns:
an argument matching the specified name, or null if not found

getUnnamedSeriesArgumentValues

protected java.lang.Object[] getUnnamedSeriesArgumentValues()
                                                     throws ArgumentValidationException
process a bunch of arguments from the unnamed series definition, converting them to a given argument type

Returns:
Throws:
ArgumentValidationException

getUnnamedArgumentValue

protected java.lang.Object getUnnamedArgumentValue()
                                            throws ArgumentValidationException
process an arguments from the unnamed definition, converting it to a given argument type

Returns:
Throws:
ArgumentValidationException

getUnnamedSeriesFileArgumentValues

protected java.io.File[] getUnnamedSeriesFileArgumentValues()
                                                     throws ArgumentValidationException
Convenience method for getting an array of files specified in an unnamed series, since files are the things most commonly specified that way. I do NOT recommend creating separate convenience methods for each type -- that'd be bloat

Returns:
Throws:
ArgumentValidationException

digestArguments

public void digestArguments(java.util.Map<java.lang.String,java.lang.String> argumentValueMap)
                     throws ArgumentValidationException
Digest raw string argument values. Make sure they're all there and convert properly

Specified by:
digestArguments in interface CommandLineModule
Parameters:
argumentValueMap -
Throws:
ArgumentValidationException

invoke

public void invoke(java.util.Map<java.lang.String,java.lang.String> argumentValues)
            throws ArgumentValidationException,
                   CommandLineModuleExecutionException
Invoke the CommandLineModule, using the argument values specified in the argumentValues array. Essentially this should just call digestArguments() and then execute()

Specified by:
invoke in interface CommandLineModule
Parameters:
argumentValues -
Throws:
ArgumentValidationException
CommandLineModuleExecutionException

assertArgumentPresent

protected void assertArgumentPresent(java.lang.String argumentName)
                              throws ArgumentValidationException
Asserts the presence of an argument. If absent, throws AVException. This is for situations in which the presence of certain arguments makes other 'optional' arguments mandatory

Parameters:
argumentName -
Throws:
ArgumentValidationException

assertArgumentPresent

protected void assertArgumentPresent(java.lang.String requiredArgumentName,
                                     java.lang.String requiredByArgumentName)
                              throws ArgumentValidationException
Asserts the presence of an argument. If absent, throws AVException. This is for situations in which the presence of certain arguments makes other 'optional' arguments mandatory. This version allows the user to specify which argument requires the other one

Throws:
ArgumentValidationException

assertArgumentAbsent

protected void assertArgumentAbsent(java.lang.String argumentName)
                             throws ArgumentValidationException
Asserts the absence of an argument. If presence, throws AVException. This is for situations in which the presence of certain arguments makes other 'optional' arguments meaningless

Parameters:
argumentName -
Throws:
ArgumentValidationException

assertArgumentAbsent

protected void assertArgumentAbsent(java.lang.String argumentName,
                                    java.lang.String requiredAbsentByArgument)
                             throws ArgumentValidationException
Asserts the absence of an argument. If presence, throws AVException. This is for situations in which the presence of certain arguments makes other 'optional' arguments meaningless. This version allows the user to specify which argument made the arg problematic

Parameters:
argumentName -
Throws:
ArgumentValidationException

hasArgumentValue

protected boolean hasArgumentValue(java.lang.String argumentName)
Convenience method to tell whether an argument map contains an argument

Parameters:
argumentName -
Returns:

hasUnnamedSeriesArgumentValue

protected boolean hasUnnamedSeriesArgumentValue()

hasUnnamedArgumentValue

protected boolean hasUnnamedArgumentValue()

getStringArgumentValue

protected java.lang.String getStringArgumentValue(java.lang.String argumentName)

getDoubleArgumentValue

protected double getDoubleArgumentValue(java.lang.String argumentName)

getDoubleArrayArgumentValue

protected double[] getDoubleArrayArgumentValue(java.lang.String argumentName)

getFloatArgumentValue

protected float getFloatArgumentValue(java.lang.String argumentName)

getIntegerArgumentValue

protected int getIntegerArgumentValue(java.lang.String argumentName)

getBooleanArgumentValue

protected boolean getBooleanArgumentValue(java.lang.String argumentName)

getFileArgumentValue

protected java.io.File getFileArgumentValue(java.lang.String argumentName)

getFileArrayArgumentValue

protected java.io.File[] getFileArrayArgumentValue(java.lang.String argumentName)

getUnnamedFileArgumentValue

protected java.io.File getUnnamedFileArgumentValue()

getFastaFileArgumentValue

protected Protein[] getFastaFileArgumentValue(java.lang.String argumentName)

getDeltaMassArgumentValue

protected DeltaMassArgumentDefinition.DeltaMassWithType getDeltaMassArgumentValue(java.lang.String argumentName)

getModificationListArgumentValue

protected MS2Modification[] getModificationListArgumentValue(java.lang.String argumentName)

getArgumentValues

protected java.util.Map<java.lang.String,java.lang.Object> getArgumentValues()

getArgumentValue

protected java.lang.Object getArgumentValue(java.lang.String argumentName)

createUnnamedFileArgumentDefinition

protected FileToReadArgumentDefinition createUnnamedFileArgumentDefinition(boolean required,
                                                                           java.lang.String helpText)

createUnnamedSeriesFileArgumentDefinition

protected FileToReadArgumentDefinition createUnnamedSeriesFileArgumentDefinition(boolean required,
                                                                                 java.lang.String helpText)
Cover method for ArgumentDefinitionFactory method

Parameters:
required -
helpText -
Returns:

getPrintWriter

protected static java.io.PrintWriter getPrintWriter(java.io.File outFile)
                                             throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

getArgumentValueStrings

public java.util.Map<java.lang.String,java.lang.String> getArgumentValueStrings()
Return the original argument name-value pairs that were passed into this module via digestArguments()

Specified by:
getArgumentValueStrings in interface CommandLineModule
Returns:


Fred Hutchinson Cancer Research Center