return new StringValue(getStringValue());
case Type.UNTYPED_ATOMIC:
return new UntypedAtomicValue(getStringValue());
case Type.YEAR_MONTH_DURATION:
if (days!=0 || hours!=0 || minutes!=0 || seconds!=0 || milliseconds!=0) {
DynamicError err = new DynamicError(
"Cannot convert to yearMonthDuration because some components are non-zero");
err.setXPathContext(context);
err.setErrorCode("FORG0001");
throw err;
} else {
return MonthDurationValue.fromMonths((years*12 + months) * (negative ? -1 : +1));
}
case Type.DAY_TIME_DURATION:
if (years!=0 || months!=0) {
DynamicError err = new DynamicError(
"Cannot convert to dayTimeDuration because some components are non-zero");
err.setXPathContext(context);
err.setErrorCode("FORG0001");
throw err;
} else {
return SecondsDurationValue.fromSeconds(getLengthInSeconds());
}
default:
DynamicError err = new DynamicError("Cannot convert duration to " +
StandardNames.getDisplayName(requiredType));
err.setXPathContext(context);
err.setErrorCode("FORG0001");
throw err;
}
}