laser.util.commandline
Class CommandLineUtils

java.lang.Object
  extended by laser.util.commandline.CommandLineUtils

public class CommandLineUtils
extends java.lang.Object

The CommandLineUtils class provides the functionality to retrieve an artifact from persistent store.

Author:
Heather M. Conboy (laser-software@cs.umass.edu)

Field Summary
static java.lang.String COPYRIGHT_NOTICE_PREFIX
          The copyright notice prefix
static java.lang.String COPYRIGHT_NOTICE_SUFFIX
          The copyright notice suffix
static java.lang.String HELP_KEY
          The key for help
static java.lang.String HELP_NAME
          The name for help
static java.lang.String HELP_USAGE
          The usage for help
static java.lang.String HELP_WHERE
          The where for help
static java.lang.String KEY_PREFIX
          The key prefix
static java.lang.String LEFTOVER_KEY
          The key for the leftovers (i.e.
static java.lang.String LS
          The platform specific line separator used within the help message
static java.lang.String PROPERTY_PREFIX
          The property prefix
static java.lang.String PROPERTY_USAGE_SUFFIX
          The property usage suffix
static java.lang.String PROPERTY_WHERE_PREFIX
          The property where prefix
static java.lang.String PROPERTY_WHERE_SUFFIX
          The property where suffix
static java.lang.String USAGE_HEADER
          The help message usage header
static java.lang.String USAGE_SEPARATOR
          The help message usage separator
static java.lang.String WHERE_HEADER
          The help message where header
static java.lang.String WHERE_SEPARATOR
          The help message where separator
 
Constructor Summary
CommandLineUtils()
           
 
Method Summary
static boolean checkFlag(java.lang.String name, java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs)
          Checks that the given flag is specified correctly.
static java.util.List<java.lang.String> checkMultiValuedArgument(java.lang.String name, java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs)
          Checks that the given argument is specified correctly.
static java.util.List<java.lang.String> checkMultiValuedArgument(java.lang.String name, java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs, boolean optional)
          Checks that the given argument is specified correctly.
static java.lang.String checkProperty(java.lang.String name)
          Checks that that given property is specified correctly.
static java.lang.String checkProperty(java.lang.String name, java.lang.String value)
          Checks that that given property is specified correctly.
static java.lang.String checkSingleValuedArgument(java.lang.String name, java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs)
          Checks that the given argument is specified correctly.
static java.lang.String checkSingleValuedArgument(java.lang.String name, java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs, boolean optional)
          Checks that the given argument is specified correctly.
static java.lang.String getBaseName(java.lang.String fullName)
          Gets the base name of the given fully-qualified name.
static java.lang.String getCopyrightNotice(java.lang.String years)
          Gets the appropriate copyright notice.
static java.lang.String getKey(java.lang.String name)
          Gets the key from the given name.
static java.lang.String getName(java.lang.String key)
          Gets the name from the given key.
static java.lang.String getPropertyKey(java.lang.String name)
          Gets the key for the given property.
static java.lang.String getPropertyUsage(java.lang.String name)
          Gets the help usage for the given property.
static java.lang.String getPropertyWhere(java.lang.String name)
          Gets the help where for the given property.
static boolean isKey(java.lang.String aString)
          Determines if a String is a key in the command line.
static void printHelp(java.lang.String years, java.lang.String usage, java.lang.String where)
          Prints out the help message to STDOUT.
static java.lang.Object readPersistent(java.lang.String artifactClassname, java.lang.String filename)
          Retrieves an artifact of the specified class from the given file that contains the persistent form of the artifact.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LS

public static final java.lang.String LS
The platform specific line separator used within the help message


COPYRIGHT_NOTICE_PREFIX

public static final java.lang.String COPYRIGHT_NOTICE_PREFIX
The copyright notice prefix

See Also:
Constant Field Values

COPYRIGHT_NOTICE_SUFFIX

public static final java.lang.String COPYRIGHT_NOTICE_SUFFIX
The copyright notice suffix


USAGE_HEADER

public static final java.lang.String USAGE_HEADER
The help message usage header

See Also:
Constant Field Values

USAGE_SEPARATOR

public static final java.lang.String USAGE_SEPARATOR
The help message usage separator

See Also:
Constant Field Values

WHERE_HEADER

public static final java.lang.String WHERE_HEADER
The help message where header

See Also:
Constant Field Values

WHERE_SEPARATOR

public static final java.lang.String WHERE_SEPARATOR
The help message where separator


KEY_PREFIX

public static final java.lang.String KEY_PREFIX
The key prefix

See Also:
Constant Field Values

HELP_NAME

public static final java.lang.String HELP_NAME
The name for help

See Also:
Constant Field Values

HELP_KEY

public static final java.lang.String HELP_KEY
The key for help


HELP_USAGE

public static final java.lang.String HELP_USAGE
The usage for help


HELP_WHERE

public static final java.lang.String HELP_WHERE
The where for help


LEFTOVER_KEY

public static final java.lang.String LEFTOVER_KEY
The key for the leftovers (i.e. unparsed values)

See Also:
Constant Field Values

PROPERTY_PREFIX

public static final java.lang.String PROPERTY_PREFIX
The property prefix

See Also:
Constant Field Values

PROPERTY_USAGE_SUFFIX

public static final java.lang.String PROPERTY_USAGE_SUFFIX
The property usage suffix

See Also:
Constant Field Values

PROPERTY_WHERE_PREFIX

public static final java.lang.String PROPERTY_WHERE_PREFIX
The property where prefix

See Also:
Constant Field Values

PROPERTY_WHERE_SUFFIX

public static final java.lang.String PROPERTY_WHERE_SUFFIX
The property where suffix

See Also:
Constant Field Values
Constructor Detail

CommandLineUtils

public CommandLineUtils()
Method Detail

getCopyrightNotice

public static final java.lang.String getCopyrightNotice(java.lang.String years)
Gets the appropriate copyright notice.

Parameters:
years - The years to be included

getKey

public static final java.lang.String getKey(java.lang.String name)
Gets the key from the given name.

Parameters:
name - The name
Returns:
The key

isKey

public static final boolean isKey(java.lang.String aString)
Determines if a String is a key in the command line. A key is considered to be anything that starts with KEY_PREFIX and whose "name" does not start with a digit.

"-foo", "-bar0", and "-f0o" are all keys while "-", "foo", and "-0foo" are not.

Parameters:
aString - String to check for being a key
Returns:
true if aString is a key, false otherwise

getBaseName

public static final java.lang.String getBaseName(java.lang.String fullName)
Gets the base name of the given fully-qualified name.

Parameters:
fullName - The fully-qualfied name
Returns:
The base name

getName

public static final java.lang.String getName(java.lang.String key)
Gets the name from the given key.

Parameters:
key - The key
Returns:
The name

getPropertyKey

public static final java.lang.String getPropertyKey(java.lang.String name)
Gets the key for the given property.

Parameters:
name - The name
Returns:
The key

getPropertyUsage

public static final java.lang.String getPropertyUsage(java.lang.String name)
Gets the help usage for the given property.

Parameters:
name - The name
Returns:
The help usage

getPropertyWhere

public static final java.lang.String getPropertyWhere(java.lang.String name)
Gets the help where for the given property.

Parameters:
name - The name
Returns:
The help where

printHelp

public static final void printHelp(java.lang.String years,
                                   java.lang.String usage,
                                   java.lang.String where)
Prints out the help message to STDOUT.

NOTE: The program is terminated. The help flag is already included.

Parameters:
years - The years to include in the copyright notice
usage - The usage description
where - The where description

checkProperty

public static final java.lang.String checkProperty(java.lang.String name)
Checks that that given property is specified correctly. This means that a single value was specified.

NOTE: The program is terminated if the property is specified incorrectly. Any error messages are reported to STDERR.

Parameters:
name - The property name
value - The property value
Returns:
The property's single value as a String

checkProperty

public static final java.lang.String checkProperty(java.lang.String name,
                                                   java.lang.String value)
Checks that that given property is specified correctly. This means that a single value was specified.

NOTE: The program is terminated if the property is specified incorrectly. Any error messages are reported to STDERR.

Parameters:
name - The property name
value - The property value
Returns:
The property's single value as a String

checkFlag

public static final boolean checkFlag(java.lang.String name,
                                      java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs)
Checks that the given flag is specified correctly. This means that no values were given to the flag.

NOTE: The program is terminated if the argument is specified incorrectly. Any error messages are reported to STDERR.

Parameters:
name - The flag name
commandLineArgs - The command line arguments
Returns:
The flag's value as a boolean

checkSingleValuedArgument

public static final java.lang.String checkSingleValuedArgument(java.lang.String name,
                                                               java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs)
Checks that the given argument is specified correctly. This means that a one value was specified.

NOTE: The program is terminated if the argument is specified incorrectly. Any error messages are reported to STDERR.

Parameters:
name - The argument name
commandLineArgs - The command line arguments
Returns:
The argument's value as a String

checkSingleValuedArgument

public static java.lang.String checkSingleValuedArgument(java.lang.String name,
                                                         java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs,
                                                         boolean optional)
Checks that the given argument is specified correctly. If optional is true, then either zero or one value is specified, else one value is specified.

NOTE: The program is terminated if the argument is specified incorrectly. Any error messages are reported to STDERR.

Parameters:
name - The argument name
commandLineArgs - The command line arguments
optional - True if the argument is optional and false otherwise
Returns:
The argument's value as a String

checkMultiValuedArgument

public static final java.util.List<java.lang.String> checkMultiValuedArgument(java.lang.String name,
                                                                              java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs)
Checks that the given argument is specified correctly. This means that one or more values are specified. NOTE: The program is terminated if the argument is specified incorrectly. Any error messages are reported to STDERR.

Parameters:
name - The argument name
commandLineArgs - The command line arguments
Returns:
The argument's values as a List

checkMultiValuedArgument

public static final java.util.List<java.lang.String> checkMultiValuedArgument(java.lang.String name,
                                                                              java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandLineArgs,
                                                                              boolean optional)
Checks that the given argument is specified correctly. If optional is true, then zero or more values are specified, else one or more values are specified.

NOTE: The program is terminated if the argument is specified incorrectly. Any error messages are reported to STDERR.

Parameters:
name - The argument name
commandLineArgs - The command line arguments
optional - True if the argument is optional and false otherwise
Returns:
The argument's values as a List

readPersistent

public static final java.lang.Object readPersistent(java.lang.String artifactClassname,
                                                    java.lang.String filename)
                                             throws java.io.IOException,
                                                    PersistentException
Retrieves an artifact of the specified class from the given file that contains the persistent form of the artifact.

PRECONDITION: The artifact class must implement Persistent.

Parameters:
artifactClassname - The fully-qualified classname of the artifact class
filename - The input file that contains the persistent form of the artifact
Returns:
The retrieved artifact
Throws:
java.io.IOException - if there is an I/O error
PersistentException - if there is an error reading in the persistent form of the artifact