/** * A step equivalent to the XPath "cast as" operator: the supplied item is atomized * if necessary, and the resulting atomic values are cast to the required type */ public static Step<XdmAtomicValue> castAs(ItemType type) { if (!ItemType.ANY_ATOMIC_VALUE.subsumes(type)) { throw new IllegalArgumentException("Target of castAs must be an atomic type"); } final net.sf.saxon.type.ItemType tType = type.getUnderlyingItemType().getPrimitiveItemType(); final ConversionRules rules = type.getConversionRules(); return atomize().then(new Step<XdmAtomicValue>() { public Stream<? extends XdmAtomicValue> apply(XdmItem xdmItem) { try { AtomicValue source = ((XdmAtomicValue)xdmItem).getUnderlyingValue(); Converter converter = rules.getConverter(source.getItemType(), (AtomicType)tType); AtomicValue result = converter.convert(source).asAtomic(); return Stream.of((XdmAtomicValue) XdmValue.wrap(result)); } catch (ValidationException e) { throw new SaxonApiUncheckedException(new SaxonApiException(e)); } } }); }
/** * A step equivalent to the XPath "cast as" operator: the supplied item is atomized * if necessary, and the resulting atomic values are cast to the required type */ public static Step<XdmAtomicValue> castAs(ItemType type) { if (!ItemType.ANY_ATOMIC_VALUE.subsumes(type)) { throw new IllegalArgumentException("Target of castAs must be an atomic type"); } final net.sf.saxon.type.ItemType tType = type.getUnderlyingItemType().getPrimitiveItemType(); final ConversionRules rules = type.getConversionRules(); return atomize().then(new Step<XdmAtomicValue>() { public Stream<? extends XdmAtomicValue> apply(XdmItem xdmItem) { try { AtomicValue source = ((XdmAtomicValue)xdmItem).getUnderlyingValue(); Converter converter = rules.getConverter(source.getItemType(), (AtomicType)tType); AtomicValue result = converter.convert(source).asAtomic(); return Stream.of((XdmAtomicValue) XdmValue.wrap(result)); } catch (ValidationException e) { throw new SaxonApiUncheckedException(new SaxonApiException(e)); } } }); }
StringConverter converter = ((AtomicType)it).getStringConverter(type.getConversionRules()); setValue(converter.convertString(lexicalForm).asAtomic()); } catch (ValidationException e) {
StringConverter converter = ((AtomicType)it).getStringConverter(type.getConversionRules()); setValue(converter.convertString(lexicalForm).asAtomic()); } catch (ValidationException e) {