コード例 #1
0
ファイル: Settings.java プロジェクト: KhMassri/ONENC
  /**
   * Returns a String-valued setting. Setting is first looked from the namespace that is set (if
   * any) and then from the secondary namespace (if any). All other getters use this method as their
   * first step too (so all getters may throw SettingsError and look from both namespaces).
   *
   * @param name Name of the setting to get
   * @return The contents of the setting in a String
   * @throws SettingsError if the setting is not found from either one of the namespaces
   */
  public String getSetting(String name) {
    String fullPropName;
    if (props == null) {
      init(null);
    }
    fullPropName = getFullPropertyName(name, false);
    String value = props.getProperty(fullPropName);

    if (value != null) { // found value, check if run setting can be parsed
      value = parseRunSetting(value.trim());
    }

    if ((value == null || value.length() == 0) && this.secondaryNamespace != null) {
      // try secondary namespace if the value wasn't found from primary
      fullPropName = getFullPropertyName(name, true);
      value = props.getProperty(fullPropName);

      if (value != null) {
        value = parseRunSetting(value.trim());
      }
    }

    if (value == null || value.length() == 0) {
      throw new SettingsError("Can't find setting " + getPropertyNamesString(name));
    }

    outputSetting(fullPropName + " = " + value);
    return value;
  }