Example #1
0
  public static Boolean toBoolean(Attribute attr, int line, Boolean defaultValue) {
    if (attr == null) return defaultValue;

    if (attr.getValue() instanceof Literal) {
      Boolean b = ((Literal) attr.getValue()).getBoolean(null);
      if (b != null) return b;
    }
    return defaultValue;
  }
Example #2
0
  public static Boolean toBoolean(Attribute attr, Position start) throws BytecodeException {
    if (attr == null) throw new BytecodeException("attribute does not exist", start);

    if (attr.getValue() instanceof Literal) {
      Boolean b = ((Literal) attr.getValue()).getBoolean(null);
      if (b != null) return b;
    }
    throw new BytecodeException(
        "attribute [" + attr.getName() + "] must be a constant boolean value", start);
  }
Example #3
0
  public static boolean isLiteralAttribute(
      Tag tag, Attribute attr, short type, boolean required, boolean throwWhenNot)
      throws EvaluatorException {
    String strType = "/constant";
    if (attr != null && !isNull(attr.getValue())) {

      switch (type) {
        case TYPE_ALL:
          if (attr.getValue() instanceof Literal) return true;
          break;
        case TYPE_BOOLEAN:
          if (CastBoolean.toExprBoolean(attr.getValue()) instanceof LitBoolean) return true;
          strType = " boolean";
          break;
        case TYPE_NUMERIC:
          if (CastDouble.toExprDouble(attr.getValue()) instanceof LitDouble) return true;
          strType = " numeric";
          break;
        case TYPE_STRING:
          if (CastString.toExprString(attr.getValue()) instanceof LitString) return true;
          strType = " string";
          break;
      }
      if (!throwWhenNot) return false;
      throw new EvaluatorException(
          "Attribute ["
              + attr.getName()
              + "] of the Tag ["
              + tag.getFullname()
              + "] must be a literal"
              + strType
              + " value. "
              + "attributes java class type "
              + attr.getValue().getClass().getName());
    }
    if (required) {
      if (!throwWhenNot) return false;
      throw new EvaluatorException(
          "Attribute [" + attr.getName() + "] of the Tag [" + tag.getFullname() + "] is required");
    }
    return false;
  }
Example #4
0
 /**
  * extract the content of a attribut
  *
  * @param cfxdTag
  * @param attrName
  * @return attribute value
  * @throws EvaluatorException
  */
 public static Literal getAttributeLiteral(Tag tag, String attrName, Literal defaultValue) {
   Attribute attr = tag.getAttribute(attrName);
   if (attr != null && attr.getValue() instanceof Literal) return ((Literal) attr.getValue());
   return defaultValue;
 }
Example #5
0
 /**
  * extract the content of a attribut
  *
  * @param cfxdTag
  * @param attrName
  * @return attribute value
  * @throws EvaluatorException
  */
 public static Literal getAttributeLiteral(Tag tag, String attrName) throws EvaluatorException {
   Attribute attr = tag.getAttribute(attrName);
   if (attr != null && attr.getValue() instanceof Literal) return ((Literal) attr.getValue());
   throw new EvaluatorException("attribute [" + attrName + "] must be a constant value");
 }