示例#1
0
  public XQValue cast(XQItem value, EvalContext context) throws EvaluationException {
    XQItemType type = value.getItemType();
    Duration result = null;
    try {
      if (type instanceof StringType) result = Duration.parseDuration(value.getString().trim());
      else if (type instanceof DurationType) result = value.getDuration();
      else invalidCast(type);
    } catch (DateTimeException e) {
      castException(e);
    }

    return new SingleDuration(result, XQType.DURATION);
  }
示例#2
0
  public XQValue cast(XQItem value, EvalContext context) throws EvaluationException {
    XQItemType type = value.getItemType();

    switch (type.quickCode()) {
      case XQType.QT_STRING:
      case XQType.QT_UNTYPED:
        return new SingleBoolean(Conversion.toBoolean(value.getString().trim()));
      case XQType.QT_DEC:
      case XQType.QT_INT:
      case XQType.QT_FLOAT:
      case XQType.QT_DOUBLE: // extension
      case XQType.QT_BOOL:
        return new SingleBoolean(value.getBoolean());

      default:
        invalidCast(type);
        return null;
    }
  }