com.ibm.di.util
Class ParamUtils

java.lang.Object
  extended by com.ibm.di.util.ParamUtils

public class ParamUtils
extends Object

Utility class for work with command-line parameters.

Since:
7.0

Constructor Summary
ParamUtils()
           
 
Method Summary
static String getOptionalParam(Map params, String paramName, String defaultValue)
          Retrieves the value of an optional parameter.
static String getRequiredParam(Map params, String paramName)
          Retrieves the value of a required parameter.
static String getRequiredProperty(String prop)
          Retrieves the value of a required system property.
static Map parseCommandLine(String[] args)
          Builds a collection of parameters (name-value) from a given command-line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParamUtils

public ParamUtils()
Method Detail

getRequiredParam

public static String getRequiredParam(Map params,
                                      String paramName)
                               throws Exception
Retrieves the value of a required parameter.

Parameters:
params - collection of parameters
paramName - parameter to retrieve
Returns:
the value of the parameter
Throws:
Exception - if the parameter is not found in the given collection

getOptionalParam

public static String getOptionalParam(Map params,
                                      String paramName,
                                      String defaultValue)
Retrieves the value of an optional parameter. If the parameter is not set, a default value is returned.

Parameters:
params - collection of parameters
paramName - parameter to retrieve
defaultValue - default value
Returns:
the value of the parameter or the default, if the parameter is not set

parseCommandLine

public static Map parseCommandLine(String[] args)
                            throws Exception
Builds a collection of parameters (name-value) from a given command-line. If a command-line token starts with "-" it is considered to be a parameter name, otherwise it is deemed a parameter value. It is allowed to have parameters without a value - in this case an empty string is used to represent the value. An example for a valid command-line is: "-flagA -param1 value1 -param2 value2 -flagB".

Parameters:
args - command-line arguments
Returns:
parameter name to parameter value mapping
Throws:
Exception - if a value without corresponding parameter name is encountered

getRequiredProperty

public static String getRequiredProperty(String prop)
                                  throws Exception
Retrieves the value of a required system property.

Parameters:
prop - system property name
Returns:
the system property value
Throws:
Exception - if the property is not set