예제 #1
0
  /**
   * Stores the rule dictionary from the specified dictionaryPath
   *
   * @param A rule dictionary object
   * @param dictionaryLocation The full path to the .rules file.
   * @see See writeDictionary http://docs.oracle.com/cd/E23943_01/apirefs.1111/e10663/toc.htm
   */
  public static void storeRuleDictionary(RuleDictionary dictionary, String dictionaryLocation)
      throws Exception {

    List<SDKWarning> warnings = new ArrayList<SDKWarning>();
    List<SDKException> errors = new ArrayList<SDKException>();

    dictionary.validate(errors, warnings);

    if (warnings.size() > 0) {
      System.err.println("Validation warnings: " + warnings);
    }

    if (errors.size() > 0) {

      System.err.println("Validation errors: " + errors);
      System.out.println("Skipping write of rule dictionary");

    } else {

      StringWriter swriter = new StringWriter();
      dictionary.writeDictionary(swriter);
      Writer writer = null;
      try {
        writer =
            new OutputStreamWriter(new FileOutputStream(new File(dictionaryLocation)), "UTF-8");
        writer.write(swriter.toString());
      } finally {
        if (writer != null)
          try {
            writer.close();
          } catch (IOException e) {
            System.out.println("Warning: Unable to close dictionary writer.");
          }
      }
    }
  }