FileDocCategorySizeDatePackage
PropLoader.javaAPI DocphoneME MR2 API (J2ME)3639Wed May 02 18:00:32 BST 2007com.sun.tck.wma

PropLoader

public class PropLoader extends Object
Tool for load properties from environment or property object.

Fields Summary
Constructors Summary
Methods Summary
protected intgetIntProp(int valDefault, java.lang.String envVar, java.lang.String propsName, java.lang.String propVar)
Load integer property value from environment or from connections.prop. When environment setting is defined, variable receives the value from it. Else it is initialized from connections.prop.

param
valDefault the default value is assigned when neither environment variable nor property is defined
param
envVar the name of environment variable
param
propsName the properties file name
param
propVar the name of property variable
return
string property value

        int retValue;
        String strVal = getProp("D", envVar, propsName, propVar);
        try {
            retValue = Integer.parseInt(strVal);
        } catch (NumberFormatException nfe) { // save default value
            retValue = valDefault;
        }
        return retValue;
    
protected java.lang.StringgetProp(java.lang.String valDefault, java.lang.String envVar, java.lang.String propsName, java.lang.String propVar)
Load string property value from environment or from connections.prop. When environment setting is defined, variable receives the value from it. Else it is initialized from connections.prop.

param
valDefault the default value is assigned when neither environment variable nor property is defined
param
envVar the name of environment variable
param
propsName the properties file name
param
propVar the name of property variable
return
string property value

        String retValue = System.getProperty(envVar);
        if (retValue == null) { // get from properties
            try {
                Properties props = new Properties();
                props.load(new FileInputStream(propsName));
                retValue = props.getProperty(propVar);
                if (retValue == null) { // get default value
                    retValue = valDefault;
                }
            } catch (IOException ioe) { // no properties
                retValue = valDefault;
            }
        }
        return retValue;