/** * Factory method to construct an "external object". This is an XDM value that wraps a Java * object. Such values can be passed as parameters to stylesheets or queries, for use in conjunction * with external (extension) functions. * <p>Changed in Saxon 9.5 to return XdmItem rather than XdmAtomicValue, since wrapped * external objects are now modelled as a separate type of item, rather than as an atomic value.</p> * * @param object the value to be wrapped as an external object. Must not be null. * @return the object, wrapped as an XdmItem */ public XdmItem getExternalObject(Object object) { return (XdmItem) XdmItem.wrap(new ObjectValue<>(object)); }
/** * Factory method to construct an "external object". This is an XDM value that wraps a Java * object. Such values can be passed as parameters to stylesheets or queries, for use in conjunction * with external (extension) functions. * <p>Changed in Saxon 9.5 to return XdmItem rather than XdmAtomicValue, since wrapped * external objects are now modelled as a separate type of item, rather than as an atomic value.</p> * * @param object the value to be wrapped as an external object. Must not be null. * @return the object, wrapped as an XdmItem */ public XdmItem getExternalObject(Object object) { return (XdmItem) XdmItem.wrap(new ObjectValue<>(object)); }
/** * Get the n'th item in the value, counting from zero. * * @param n the item that is required, counting the first item in the sequence as item zero * @return the n'th item in the sequence making up the value, counting from zero * @throws IndexOutOfBoundsException if n is less than zero or greater than or equal to the number * of items in the value * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public XdmItem itemAt(int n) throws IndexOutOfBoundsException, SaxonApiUncheckedException { if (n < 0 || n >= size()) { throw new IndexOutOfBoundsException("" + n); } try { Item<?> item = SequenceTool.itemAt(value, n); return (XdmItem)XdmItem.wrap(item); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } }
/** * Get the n'th item in the value, counting from zero. * * @param n the item that is required, counting the first item in the sequence as item zero * @return the n'th item in the sequence making up the value, counting from zero * @throws IndexOutOfBoundsException if n is less than zero or greater than or equal to the number * of items in the value * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public XdmItem itemAt(int n) throws IndexOutOfBoundsException, SaxonApiUncheckedException { if (n < 0 || n >= size()) { throw new IndexOutOfBoundsException("" + n); } try { Item<?> item = SequenceTool.itemAt(value, n); return (XdmItem)XdmItem.wrap(item); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } }
/** * Get the n'th item in the value, counting from zero. * @param n the item that is required, counting the first item in the sequence as item zero * @return the n'th item in the sequence making up the value, counting from zero * @throws IndexOutOfBoundsException if n is less than zero or greater than or equal to the number * of items in the value * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public XdmItem itemAt(int n) throws IndexOutOfBoundsException, SaxonApiUncheckedException { if (n < 0 || n >= size()) { throw new IndexOutOfBoundsException(""+n); } if (value instanceof Value) { try { return (XdmItem)XdmItem.wrap(((Value)value).itemAt(n)); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } } else { return (XdmNode)XdmNode.wrap((NodeInfo)value); } }
/** * Factory method to construct an atomic value given its lexical representation and the * required item type * @param value the lexical representation of the required value * @param type the item type of the required value * @return the constructed item * @throws SaxonApiException if the supplied string is not in the lexical space of the target type, or * if the target type is not atomic */ public static XdmItem newAtomicValue(String value, ItemType type) throws SaxonApiException { net.sf.saxon.type.ItemType it = type.getUnderlyingItemType(); if (!it.isAtomicType()) { throw new SaxonApiException("Requested type is not atomic"); } Configuration config = type.getProcessor().getUnderlyingConfiguration(); ConversionResult result = new StringValue(value).convert((AtomicType)it, true, config.getConversionContext()); try { return (XdmItem)wrap(result.asAtomic()); } catch (ValidationException e) { throw new SaxonApiException(e); } }