Пример #1
0
  /** ルールセット定義などをプリファレンスストア、xmlファイルに保存する。 */
  @SuppressWarnings("deprecation")
  public synchronized void commit() {
    // アクティブなルールセットIDの保存。
    RulePreferenceUtil.saveActiveRuleSetId(this.activeRuleSetId_);

    // ルールセット詳細一覧の保存。
    List<String> ruleSetIdList = new ArrayList<String>();
    Collection<RuleSetConfig> ruleSetConfigs = this.ruleSetConfigMap_.values();

    for (RuleSetConfig config : ruleSetConfigs) {
      String id = config.getId();
      if (isDefaultRuleSet(id)) {
        continue;
      }

      RulePreferenceUtil.saveRuleSet(config);

      //
      ruleSetIdList.add(id);
    }

    // ルールセットID一覧の保存。
    String[] ruleSetIds = ruleSetIdList.toArray(new String[ruleSetIdList.size()]);
    RulePreferenceUtil.saveRuleSetIds(ruleSetIds);

    // ルールセットの保存。
    // 変更があったルールセットのみ保存する。
    for (String ruleId : this.dirtyRuleSetIds_) {
      if (isDefaultRuleSet(ruleId)) {
        continue;
      }

      RuleSetConfig config = this.ruleSetConfigMap_.get(ruleId);
      if (config == null) {
        continue;
      }
      RuleSetDef def = this.ruleSetMap_.get(ruleId);
      this.accessor_.updateRuleSet(def, config.getFileName());
    }

    // ルールセットの保存。
    // ファイルが存在しないルールセットについて、
    // デフォルトのルールを元にファイルを作成する。
    for (RuleSetConfig config : ruleSetConfigs) {
      String id = config.getId();
      if (isDefaultRuleSet(id)) {
        continue;
      }

      File file = new File(config.getFileName());
      if (file.exists() && file.isFile()) {
        continue;
      }

      File parentFile = file.getParentFile();

      if (parentFile != null && parentFile.exists() == false) {
        try {
          parentFile.mkdirs();
        } catch (SecurityException ex) {
          LOGGER.error(ex.getMessage(), ex);
        }
      }

      // デフォルトのルールをコピーして保存する
      try {
        RuleSetDef defaultRuleSetClone = new RuleSetDef(getRuleSetDef(DEFAULT_RULESET_ID));
        defaultRuleSetClone.setName(config.getName());
        this.accessor_.updateRuleSet(defaultRuleSetClone, config.getFileName());
      } catch (RuleCreateException ex) {
        LOGGER.error(ex.getMessage(), ex);
      }
    }

    // ルールファイルを削除する。
    for (RuleSetConfig config : this.removeList_) {
      File file = new File(config.getFileName());
      if (file.exists()) {
        try {
          file.delete();
        } catch (SecurityException ex) {
          LOGGER.error(ex.getMessage(), ex);
        }
      }
    }
    this.removeList_ = Collections.synchronizedList(new ArrayList<RuleSetConfig>());
  }