Example #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);
  }
Example #2
0
 public double evalAsDouble(Focus focus, EvalContext context) throws EvaluationException {
   context.at(this);
   XQItem v = args[0].evalAsOptItem(focus, context);
   if (v == null) throw EmptyException.instance();
   if (v instanceof MomentValue) {
     MomentValue mv = (MomentValue) v;
     return mv.getValue().getSecond();
   }
   try {
     DateTime dt = DateTime.parseDateTime(v.getString());
     return dt.getSecond();
   } catch (DateTimeException e) {
     context.error(Conversion.ERR_CAST, this, "cannot cast to xs:dateTime : " + e.getMessage());
     return 0;
   }
 }
Example #3
0
 public int compareTo(XQItem that, ComparisonContext context, int flags) {
   try {
     if ((flags & COMPAR_ORDER) != 0) return Comparison.ERROR;
     QName q1 = getQName(), q2 = that.getQName();
     return (q1.equals(q2)) ? Comparison.EQ : Comparison.FAIL;
   } catch (EvaluationException e) {
     return Comparison.ERROR;
   }
 }
Example #4
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;
    }
  }