korat.config
Class ConfigLoader

java.lang.Object
  extended by korat.config.ConfigLoader

public class ConfigLoader
extends Object

Class that should be used only by CodeManager for command line options loading/parsing purposes.

Author:
Aleksandar Milicevic

Field Summary
static MyOption ARGS
           
static MyOption CLZ
           
private  CommandLine cmdLine
           
static MyOption CONFIG_FILE
           
static MyOption CV_DELTA
           
static MyOption CV_END
           
static MyOption CV_EXPECTED
           
static MyOption CV_FILE
           
static MyOption CV_FULL_FORMAT_RATIO
           
static MyOption CV_START
           
static MyOption CV_WRITE
           
static MyOption CV_WRITE_NUM
           
static MyOption DUMP_BYTECODES
           
static MyOption EXCLUDE_PACKAGES
           
static MyOption FINITIZATION
           
private  CommandLine fromFileCmdLine
           
static MyOption HELP
           
private  Options koratOptions
          This contains all defined options and will be initialized dynamically, through the java reflection mechanism.
static MyOption LISTENERS
           
static MyOption MAX_STRUCT
           
static MyOption PREDICATE
           
static MyOption PRINT
           
static MyOption PRINT_CAND_VECTS
           
static MyOption PROGRESS
           
static char SEP
           
static String SEP_STR
           
static MyOption SERIALIZE
           
static MyOption VISUALIZE
           
 
Constructor Summary
ConfigLoader()
           
 
Method Summary
private  void checkRequiredOptions()
          Checks for the presence of the required options.
private  boolean getFlagOption(MyOption opt)
           
private  int getIntOptionValue(MyOption opt)
           
private  long getLongOptionValue(MyOption opt)
           
private  String getOptionValue(MyOption opt)
           
private  String[] getStringArrayOptionValue(MyOption opt)
           
private  void initKoratOptions()
          initialize koratOptions with all declared options
private  void initStuffFromOptions()
          Initializes stuff from the previously parsed options.
 void loadDefaults()
           
private  String[] loadFromFile(String fileName)
          Loads options from the config file and returns them as a string array.
private  void parseArgs(String[] args, boolean fromFile)
          Parses options from the given string array.
(package private)  void parseCmdLine(String[] args)
           
(package private)  void printUsage(Options options)
           
(package private)  void printUsage(PrintWriter pw, Options options)
           
private static String[] processConfigFile(InputStream is)
          Loads options from the config file and returns them as a string array.
private  void storeOptions()
          Stores the previously parsed options to ConfigManager instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEP

public static final char SEP
See Also:
Constant Field Values

SEP_STR

public static final String SEP_STR

ARGS

public static final MyOption ARGS

CLZ

public static final MyOption CLZ

CONFIG_FILE

public static final MyOption CONFIG_FILE

CV_DELTA

public static final MyOption CV_DELTA

CV_END

public static final MyOption CV_END

CV_EXPECTED

public static final MyOption CV_EXPECTED

CV_FILE

public static final MyOption CV_FILE

CV_FULL_FORMAT_RATIO

public static final MyOption CV_FULL_FORMAT_RATIO

CV_START

public static final MyOption CV_START

CV_WRITE

public static final MyOption CV_WRITE

CV_WRITE_NUM

public static final MyOption CV_WRITE_NUM

DUMP_BYTECODES

public static final MyOption DUMP_BYTECODES

EXCLUDE_PACKAGES

public static final MyOption EXCLUDE_PACKAGES

FINITIZATION

public static final MyOption FINITIZATION

HELP

public static final MyOption HELP

LISTENERS

public static final MyOption LISTENERS

MAX_STRUCT

public static final MyOption MAX_STRUCT

PREDICATE

public static final MyOption PREDICATE

PRINT

public static final MyOption PRINT

PRINT_CAND_VECTS

public static final MyOption PRINT_CAND_VECTS

PROGRESS

public static final MyOption PROGRESS

SERIALIZE

public static final MyOption SERIALIZE

VISUALIZE

public static final MyOption VISUALIZE

koratOptions

private Options koratOptions
This contains all defined options and will be initialized dynamically, through the java reflection mechanism.


cmdLine

private CommandLine cmdLine

fromFileCmdLine

private CommandLine fromFileCmdLine
Constructor Detail

ConfigLoader

ConfigLoader()
Method Detail

initKoratOptions

private void initKoratOptions()
initialize koratOptions with all declared options


printUsage

void printUsage(Options options)

printUsage

void printUsage(PrintWriter pw,
                Options options)

parseCmdLine

void parseCmdLine(String[] args)

parseArgs

private void parseArgs(String[] args,
                       boolean fromFile)

Parses options from the given string array.

The algorithm for handling options is as follows:
  1. if HELP options is found - prints usage and exists
  2. if the given options are cmd line options (not from config file) and if the CONFIG_FILE option is found, then first loads options from the file specified through the CONFIG_FILE option.
  3. loads options from cmd line
  4. stores options to ConfigManger instance
  5. checks for required options
  6. initializes stuff according to the previously parsed options

Parameters:
args - options to parse
fromFile - whether the given options are from file or from cmd line.
See Also:
loadFromFile(String), processConfigFile(InputStream), storeOptions(), checkRequiredOptions(), initStuffFromOptions()

loadFromFile

private String[] loadFromFile(String fileName)
                       throws IOException

Loads options from the config file and returns them as a string array.

This method only searches for the file with the given name and then calls processConfigFile which does the conversion from the file format to string array

Parameters:
fileName - name of the config file
Returns:
options from file represented as string array (just like they were specified through the cmd line).
Throws:
IOException - if an I/O exception occurs.
See Also:
processConfigFile(InputStream)

processConfigFile

private static String[] processConfigFile(InputStream is)
                                   throws IOException

Loads options from the config file and returns them as a string array.

Format of the config file should be like the format of the cmd line with a couple of additional possibilities:
  1. line breaks are allowed
  2. all lines starting with "#" are ignored (considered as comments)

Parameters:
is - input stream of the config file
Returns:
options from file represented as string array (just like they were specified through the cmd line).
Throws:
IOException - if an I/O exception occurs.

checkRequiredOptions

private void checkRequiredOptions()
                           throws MissingOptionException
Checks for the presence of the required options.

Throws:
MissingOptionException - if a required options is not provided.

initStuffFromOptions

private void initStuffFromOptions()
Initializes stuff from the previously parsed options.


storeOptions

private void storeOptions()
Stores the previously parsed options to ConfigManager instance. Since it uses java reflection to automatically store all declared options, it relies on the "naming rule" of the MyOption options and option fields in ConfigManager class: each of MyOptions options (except for HELP) must have its corresponding field in the ConfigManager class which is named exactly as the longOpt property of that option.


loadDefaults

public void loadDefaults()

getStringArrayOptionValue

private String[] getStringArrayOptionValue(MyOption opt)

getOptionValue

private String getOptionValue(MyOption opt)

getFlagOption

private boolean getFlagOption(MyOption opt)

getIntOptionValue

private int getIntOptionValue(MyOption opt)

getLongOptionValue

private long getLongOptionValue(MyOption opt)