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); }
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; } }
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; } }