LiveGraph
data visualisation and analysis framework

org.LiveGraph.bootstrap
Class CommandLineProcessor

java.lang.Object
  extended by org.LiveGraph.bootstrap.CommandLineProcessor

public class CommandLineProcessor
extends java.lang.Object

This class represents a parser for command line arguments for a LiveGraph application.

LiveGraph (http://www.live-graph.org).

Copyright (c) 2007-2008 by G. Paperin.

File: CommandLineProcessor.java

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:

1. Redistributions of source code must retain the above acknowledgement of the LiveGraph project and its web-site, the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the LiveGraph project and its web-site, the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived software must display the following acknowledgement:
This product includes software developed by the LiveGraph project and its contributors.
(http://www.live-graph.org)

4. All advertising materials distributed in form of HTML pages or any other technology permitting active hyper-links that mention features or use of this software or any derived software must display the acknowledgment specified in condition 3 of this agreement, and in addition, include a visible and working hyper-link to the LiveGraph homepage (http://www.live-graph.org).

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version:
"2.0.beta01"
Author:
Greg Paperin (http://www.paperin.org)

Field Summary
private  java.lang.String[] args
          Command line arguments to parse.
static java.lang.String correctPromptMsg
          Message specifying the correct usage of command line argumnts.
private  java.util.List<java.lang.String> errMessages
          Holds any error messages occured during parsing.
private  java.io.File file_Data
          The data file if such was parsed.
private  java.io.File file_DataFileSettings
          The data file settings file if such was parsed.
private  java.io.File file_DataSeriesSettings
          The data series settings file if such was parsed.
private  java.io.File file_GraphSettings
          The graph settings file if such was parsed.
private  boolean hasError
          Flag set when any errors during argument parsing or validation occur.
static java.lang.String newLine
          System specific new-line string.
 
Constructor Summary
CommandLineProcessor()
          Initialises the parser for an empty command line.
CommandLineProcessor(java.lang.String[] args)
          Initialises the parser for the specified command line arguments.
 
Method Summary
private  void error(int argIndex, java.lang.String argStr, java.lang.String... messages)
          Logs an error message.
 java.lang.String getErrorMessages()
          Constructs a String from all error messages that occured during parsing or validation.
 java.io.File getFile_Data()
          Data file - parsed from the command line.
 java.io.File getFile_DataFileSettings()
          File for data file settings - either parsed from the command line or the default session file.
 java.io.File getFile_DataSeriesSettings()
          File for data series settings - either parsed from the command line or the default session file.
 java.io.File getFile_GraphSettings()
          File for graph settings - either parsed from the command line or the default session file.
 boolean hasErrors()
          Checks whether any errors have occured.
private  java.io.File parseArgFile2(int parseIndex, java.lang.String argDesc, java.io.File currValue)
          Validates a pair of command line arguments, where the first is a flag and the second is a file path.
private  void parseArgs()
          Parses the command line arguments for legal settings values.
private  void processArgs()
          Used internally to process the arguments.
private  void setFile_Data(java.io.File f)
          Sets the data file -parsed from the command line.
private  void setFile_DataFileSettings(java.io.File f)
          Sets the file for data file settings - either parsed from the command line or the default session file.
private  void setFile_DataSeriesSettings(java.io.File f)
          Sets the file for data series settings - either parsed from the command line or the default session file.
private  void setFile_GraphSettings(java.io.File f)
          Sets the file for graph settings - either parsed from the command line or the default session file.
private  void supplementWithDefaults()
          If data file, graph or data series settings are not set, checks whether the apropriate session.lgdfs, session.lggs and session.lgdss files are available and, if so, sets the argument values appropriately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newLine

public static final java.lang.String newLine
System specific new-line string.


correctPromptMsg

public static final java.lang.String correctPromptMsg
Message specifying the correct usage of command line argumnts.


errMessages

private java.util.List<java.lang.String> errMessages
Holds any error messages occured during parsing.


hasError

private boolean hasError
Flag set when any errors during argument parsing or validation occur.


args

private java.lang.String[] args
Command line arguments to parse.


file_DataFileSettings

private java.io.File file_DataFileSettings
The data file settings file if such was parsed.


file_GraphSettings

private java.io.File file_GraphSettings
The graph settings file if such was parsed.


file_DataSeriesSettings

private java.io.File file_DataSeriesSettings
The data series settings file if such was parsed.


file_Data

private java.io.File file_Data
The data file if such was parsed.

Constructor Detail

CommandLineProcessor

public CommandLineProcessor()
Initialises the parser for an empty command line.


CommandLineProcessor

public CommandLineProcessor(java.lang.String[] args)
Initialises the parser for the specified command line arguments.

Parameters:
args - Command line arguments.
Method Detail

processArgs

private void processArgs()
Used internally to process the arguments. First, parses the command line. Then, tries to apply default settings for arguments not specified on the command line.


supplementWithDefaults

private void supplementWithDefaults()
If data file, graph or data series settings are not set, checks whether the apropriate session.lgdfs, session.lggs and session.lgdss files are available and, if so, sets the argument values appropriately.


parseArgs

private void parseArgs()
Parses the command line arguments for legal settings values.


parseArgFile2

private java.io.File parseArgFile2(int parseIndex,
                                   java.lang.String argDesc,
                                   java.io.File currValue)
Validates a pair of command line arguments, where the first is a flag and the second is a file path.

Parameters:
parseIndex - The argument index of the flag, i.e. the first argument of the pair.
argDesc - A textual description of the current flag (for megsages).
currValue - The current value for the setting corresponding to the flag.
Returns:
A validated File object that stands for the path described by the second argument.

error

private void error(int argIndex,
                   java.lang.String argStr,
                   java.lang.String... messages)
Logs an error message.

Parameters:
argIndex - Index of the argument to which the error relates.
argStr - The argument to which the error relates.
messages - Error messages.

hasErrors

public boolean hasErrors()
Checks whether any errors have occured.

Returns:
true if at least one error occured during parsing or validation, false otherwise.

getErrorMessages

public java.lang.String getErrorMessages()
Constructs a String from all error messages that occured during parsing or validation.

Returns:
A verbose message resarding all errors that occured during parsing or validation, or null if no errors have occured.

getFile_DataFileSettings

public java.io.File getFile_DataFileSettings()
File for data file settings - either parsed from the command line or the default session file.

Returns:
Validated File from which LiveGraph should load the data file settings or null if no file was set or if the file is not present or cannot be accessed.

setFile_DataFileSettings

private void setFile_DataFileSettings(java.io.File f)
Sets the file for data file settings - either parsed from the command line or the default session file.

Parameters:
f - Validated File from which LiveGraph should load the data file settings.

getFile_GraphSettings

public java.io.File getFile_GraphSettings()
File for graph settings - either parsed from the command line or the default session file.

Returns:
Validated File from which LiveGraph should load the graph settings or null if no file was set or if the file is not present or cannot be accessed.

setFile_GraphSettings

private void setFile_GraphSettings(java.io.File f)
Sets the file for graph settings - either parsed from the command line or the default session file.

Parameters:
f - Validated File from which LiveGraph should load the graph settings.

getFile_DataSeriesSettings

public java.io.File getFile_DataSeriesSettings()
File for data series settings - either parsed from the command line or the default session file.

Returns:
Validated File from which LiveGraph should load the data series settings or null if no file was set or if the file is not present or cannot be accessed.

setFile_DataSeriesSettings

private void setFile_DataSeriesSettings(java.io.File f)
Sets the file for data series settings - either parsed from the command line or the default session file.

Parameters:
f - Validated File from which LiveGraph should load the data series settings.

getFile_Data

public java.io.File getFile_Data()
Data file - parsed from the command line.

Returns:
Validated File from which LiveGraph should load the data or null if no file was set or if the file is not present or cannot be accessed.

setFile_Data

private void setFile_Data(java.io.File f)
Sets the data file -parsed from the command line.

Parameters:
f - Validated File from which LiveGraph should load the data.

LiveGraph
data visualisation and analysis framework