Пример #1
0
  /**
   * ルールセット定義を取得する。<br>
   * 指定されたルールセットIDに対応する設定ファイルが見つからない場合は、<br>
   * デフォルトのルールセット定義を取得する。
   *
   * @param id ルールセットID
   * @return ルールセット定義
   * @throws RuleCreateException ルールセット定義ファイル読み込みに失敗した場合
   */
  public RuleSetDef getRuleSetDef(final String id) throws RuleCreateException {
    RuleSetDef def = this.ruleSetMap_.get(id);
    if (def != null) {
      return def;
    }

    if (id.equals(DEFAULT_RULESET_ID)) {
      def = this.accessor_.findRuleSet(DEFAULT_RULESET_FILE);
      def.setName(this.ruleSetConfigMap_.get(id).getName());
    } else if (id.equals(DEFAULT_HP_UX_RULESET_ID)) {
      def = this.accessor_.findRuleSet(DEFAULT_HP_UX_RULESET_FILE);
      def.setName(this.ruleSetConfigMap_.get(id).getName());
    } else if (id.equals(DEFAULT_JAVA_RULESET_ID)) {
      def = this.accessor_.findRuleSet(DEFAULT_JAVA_RULESET_FILE);
      def.setName(this.ruleSetConfigMap_.get(id).getName());
    } else if (id.equals(DEFAULT_DB_RULESET_ID)) {
      def = this.accessor_.findRuleSet(DEFAULT_DB_RULESET_FILE);
      def.setName(this.ruleSetConfigMap_.get(id).getName());
    } else {
      RuleSetConfig config = this.ruleSetConfigMap_.get(id);
      if (config == null) {
        throw new RuleCreateException("InvalidRuleSetDef", new Object[] {id});
      }
      String fileName = config.getFileName();
      def = this.accessor_.findRuleSet(fileName);
    }

    this.ruleSetMap_.put(id, def);

    return def;
  }
Пример #2
0
 /**
  * ルールをコピーします。<br>
  *
  * @param orgId コピー元 ID
  * @param dstId コピー先 ID
  * @param dstName コピー先ルールセットの名前
  * @throws RuleCreateException ルールセット定義ファイル読み込みに失敗した場合
  */
 public void copyRuleSetDef(final String orgId, final String dstId, final String dstName)
     throws RuleCreateException {
   RuleSetDef orgDef = getRuleSetDef(orgId);
   RuleSetDef dstDef = new RuleSetDef(orgDef);
   dstDef.setName(dstName);
   this.ruleSetMap_.put(dstId, dstDef);
 }
Пример #3
0
  /**
   * アクティブなルールセットに含まれる、ルールインスタンスの一覧を取得する。 アクティブなルールセット中の要素中にあるルール名が不正であるために、
   * インスタンス生成に失敗した場合には、RuleCreateExceptionをスローする。
   *
   * @return ルールインスタンスの一覧
   * @throws RuleCreateException ルール定義ファイルの読み込みに失敗した場合
   */
  public List<PerformanceRule> getActiveRules() throws RuleCreateException {
    List<PerformanceRule> ruleList = new ArrayList<PerformanceRule>();
    List<String> errorMessageList = new ArrayList<String>();

    RuleSetDef ruleSetDef = getActiveRuleSetDef();

    for (RuleDef ruleDef : ruleSetDef.getRuleDefs()) {
      try {
        PerformanceRule rule = RuleInstanceUtil.createRuleInstance(ruleDef);
        if (rule != null) {
          ruleList.add(rule);
        }
      } catch (RuleCreateException ex) {
        errorMessageList.add(ex.getMessage());
      }
    }

    if (errorMessageList.size() > 0) {
      String[] messages = errorMessageList.toArray(new String[errorMessageList.size()]);
      throw new RuleCreateException(RULE_CREATE_ERROR, null, messages);
    }

    return ruleList;
  }
Пример #4
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>());
  }