Ejemplo n.º 1
0
 public void addCellValue(int row, int column, String value) {
   this.hasValues = true;
   Integer key = new Integer(column);
   String content = (String) this.constraints.get(key);
   if (content == null) {
     throw new DecisionTableParseException(
         "No code snippet for CONDITION in cell "
             + RuleSheetParserUtil.rc2name(this.headerRow + 2, this.headerCol));
   }
   SnippetBuilder snip = new SnippetBuilder(content);
   String result = snip.build(fixValue(value));
   this.values.add(result);
 }
Ejemplo n.º 2
0
 /**
  * Work out the type of "field" that is being specified, as in : age age < age == $param age == $1
  * || age == $2 forall{age < $}{,}
  *
  * <p>etc. as we treat them all differently.
  */
 public FieldType calcFieldType(String content) {
   if (!SnippetBuilder.getType(content).equals(SnippetBuilder.SnippetType.SINGLE)) {
     return FieldType.NORMAL_FIELD;
   }
   for (String op : operators) {
     if (content.endsWith(op)) {
       return FieldType.OPERATOR_FIELD;
     }
   }
   return FieldType.SINGLE_FIELD;
 }
  private ParameterizedValueBuilder getValueBuilder(final String content) {

    // Work out the type of "template":-
    // age                     ---> SnippetType.SINGLE
    // age ==                  ---> SnippetType.SINGLE
    // age == $param           ---> SnippetType.PARAM
    // age == $1 || age == $2  ---> SnippetType.INDEXED
    // forall{age < $}{,}      ---> SnippetType.FORALL
    String template = content.trim();
    SnippetType type = SnippetBuilder.getType(template);
    if (type == SnippetType.SINGLE) {
      type = SnippetType.PARAM;
      boolean hasExplicitOperator = false;
      for (String op : operators) {
        if (template.endsWith(op)) {
          hasExplicitOperator = true;
          break;
        }
      }
      if (!hasExplicitOperator) {
        template = template + " ==";
      }
      template = template + " \"";
      template = template + SnippetBuilder.PARAM_STRING + "\"";
    }

    // Make a ValueBuilder for the template
    switch (type) {
      case INDEXED:
        return new IndexedParametersValueBuilder(
            template, parameterUtilities, ParameterizedValueBuilder.Part.LHS);
      case PARAM:
        return new SingleParameterValueBuilder(
            template, parameterUtilities, ParameterizedValueBuilder.Part.LHS);
      case SINGLE:
        return new LiteralValueBuilder(template);
    }
    throw new DecisionTableParseException(
        "SnippetBuilder.SnippetType '"
            + type.toString()
            + "' is not supported. The column will not be added.");
  }