com.ptc.wgmecad
Class ArgumentMap

java.lang.Object
  extended bycom.ptc.wgmecad.ArgumentMap

public class ArgumentMap
extends Object

This class is the repository for all command line options and for all data entered in the GUI. It acts as the data transfer mechanism to the code that actually performs the operations.


Field Summary
static String hookDebugSettingsFileName
           
static String hookSettingsFileName
           
private static ArgumentMap instance
           
(package private) static org.apache.log4j.Logger logger
           
private  HashMap map
           
private  HashMap mapPersistance
           
private static Boolean mustPersist
           
private  File persistDebugHookFile
           
private  File persistFile
           
private  File persistHookFile
           
static String persistSeparator
           
static Object[] persistSortArray
           
static String settingsFileName
           
 
Constructor Summary
private ArgumentMap()
           
 
Method Summary
 boolean defaultParameter(String name, String defaultValue)
          returns true if the parameter was already set.
 Argument getArgument(String name)
           
static ArgumentMap getInstance()
           
static int getIntValueFromArgMapKey(String resourceKey, int defaultValue)
          First default the argument map to have the value of defaultValue, then retrieve the value back from the map.
 int getNextAvailableArgumentNumber(String prefix)
           
 boolean getParameterExists(String name)
           
 boolean getParameterHasValue(String name)
           
 String[] getParametersWithPrefix(String prefix)
          returns an array of Strings of all the parameters which have the designated prefix.
 String getParameterValue(String name)
           
 String getParameterValue(String name, String defaultValue)
          Return value for name parameter if it exists, defaultValue if it doesn't.
 File getPersistDebugHookFile(File _tempDir)
           
 File getPersistFile(boolean forWrite)
           
 File getPersistHookFile(File _tempDir)
           
 boolean isParameterValueEqualTrue(String name)
          Check on the state of a boolean parameter, the existance of which is uncertain.
 boolean isParameterValueEqualTrue(String name, boolean defaultValue)
          Check on the state of a boolean parameter, the existance of which is uncertain.
 boolean isPersistant(String name)
           
 boolean loadPersistedArguments()
           
 boolean loadPersistedArguments(BufferedReader file)
           
 boolean loadPersistedArguments(File file)
           
 void removeAllParameter(String _prefix)
           
 int removeHolesFromNumberedArguments(String prefix)
          This function consolidates the numbering of numbered args.
 boolean removeParameter(String name, boolean savePersistance)
          Remove a parameter from the map.
 boolean renameParameter(String oldName, String newName)
          Remove one parameter and rename it to another Returns true if a parameter is overwritten in the process.
 boolean savePersistedArguments(boolean isExit)
           
 boolean savePersistedArguments(File file, boolean isExit)
           
 boolean savePersistedArguments(PrintStream file, boolean isExit)
           
 boolean savePersistedHookArguments_orig(PrintStream file)
           
 boolean savePersistedHookArguments(boolean debug, File _tempDir)
           
 boolean savePersistedHookArguments(File file)
           
 boolean savePersistedHookArguments(PrintStream file)
           
 boolean setArgument(Argument arg, boolean persist)
          returns true if the parameter was previously set
 boolean setParameter(String name, boolean persist)
           
 boolean setParameter(String name, String value, boolean persist)
          returns true if the parameter was previously set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private HashMap map

mapPersistance

private HashMap mapPersistance

mustPersist

private static Boolean mustPersist

persistSeparator

public static final String persistSeparator

settingsFileName

public static final String settingsFileName

hookSettingsFileName

public static final String hookSettingsFileName

hookDebugSettingsFileName

public static final String hookDebugSettingsFileName

persistSortArray

public static Object[] persistSortArray

logger

static org.apache.log4j.Logger logger

instance

private static ArgumentMap instance

persistDebugHookFile

private File persistDebugHookFile

persistHookFile

private File persistHookFile

persistFile

private File persistFile
Constructor Detail

ArgumentMap

private ArgumentMap()
Method Detail

getInstance

public static ArgumentMap getInstance()

removeHolesFromNumberedArguments

public int removeHolesFromNumberedArguments(String prefix)
This function consolidates the numbering of numbered args. It takes any args with this prefix and treats them as thought they should be numbered - so be careful.

Returns:
returns the number of args in the numbered args list list

getNextAvailableArgumentNumber

public int getNextAvailableArgumentNumber(String prefix)
Parameters:
prefix - - the arguments concidered will all start with this string
Returns:
- the next available number for an argument with this prefix

renameParameter

public boolean renameParameter(String oldName,
                               String newName)
Remove one parameter and rename it to another Returns true if a parameter is overwritten in the process.


removeParameter

public boolean removeParameter(String name,
                               boolean savePersistance)
Remove a parameter from the map. If savePersistance is also set to true, then remove any persistance data. returns true if there was a parameter there to be removed, false it the parameter was not there.


removeAllParameter

public void removeAllParameter(String _prefix)

getPersistDebugHookFile

public File getPersistDebugHookFile(File _tempDir)

getPersistHookFile

public File getPersistHookFile(File _tempDir)

savePersistedHookArguments

public boolean savePersistedHookArguments(boolean debug,
                                          File _tempDir)

savePersistedHookArguments_orig

public boolean savePersistedHookArguments_orig(PrintStream file)

savePersistedHookArguments

public boolean savePersistedHookArguments(PrintStream file)

savePersistedHookArguments

public boolean savePersistedHookArguments(File file)

getPersistFile

public File getPersistFile(boolean forWrite)

savePersistedArguments

public boolean savePersistedArguments(boolean isExit)

savePersistedArguments

public boolean savePersistedArguments(PrintStream file,
                                      boolean isExit)

savePersistedArguments

public boolean savePersistedArguments(File file,
                                      boolean isExit)

loadPersistedArguments

public boolean loadPersistedArguments()

loadPersistedArguments

public boolean loadPersistedArguments(File file)

loadPersistedArguments

public boolean loadPersistedArguments(BufferedReader file)
                               throws IOException
Throws:
IOException

isPersistant

public boolean isPersistant(String name)

defaultParameter

public boolean defaultParameter(String name,
                                String defaultValue)
returns true if the parameter was already set. Only sets the parameter if it does not yet exist. Also has the side effect of causing the parameter to persist


setParameter

public boolean setParameter(String name,
                            String value,
                            boolean persist)
returns true if the parameter was previously set


setArgument

public boolean setArgument(Argument arg,
                           boolean persist)
returns true if the parameter was previously set


setParameter

public boolean setParameter(String name,
                            boolean persist)

getArgument

public Argument getArgument(String name)

getParameterExists

public boolean getParameterExists(String name)

getParameterValue

public String getParameterValue(String name)

getParameterValue

public String getParameterValue(String name,
                                String defaultValue)
Return value for name parameter if it exists, defaultValue if it doesn't.

Parameters:
name -
defaultValue -
Returns:

getParameterHasValue

public boolean getParameterHasValue(String name)

getParametersWithPrefix

public String[] getParametersWithPrefix(String prefix)
returns an array of Strings of all the parameters which have the designated prefix. The prefix is evaluated in a case-insensitive manner.


isParameterValueEqualTrue

public boolean isParameterValueEqualTrue(String name)
Check on the state of a boolean parameter, the existance of which is uncertain.

Parameters:
name - - param name to check
Returns:
- true if it exists and the value equals "true", ignoring case.

isParameterValueEqualTrue

public boolean isParameterValueEqualTrue(String name,
                                         boolean defaultValue)
Check on the state of a boolean parameter, the existance of which is uncertain.

Parameters:
name - - param name to check
Returns:
- true if it exists and the value equals "true", ignoring case.

getIntValueFromArgMapKey

public static int getIntValueFromArgMapKey(String resourceKey,
                                           int defaultValue)
First default the argument map to have the value of defaultValue, then retrieve the value back from the map. If there is any problem (such as a formating error) then revert to the default value and set that back into the map.

Parameters:
resourceKey - - the key for the argument which specifies this number.
defaultValue -
Returns: