Interface XQSequence
- 
- All Superinterfaces:
- XQItemAccessor
 - All Known Subinterfaces:
- XQResultSequence
 - All Known Implementing Classes:
- SaxonXQForwardSequence,- SaxonXQSequence
 
 public interface XQSequence extends XQItemAccessor This interface represents a sequence of items as defined in the XDM. The sequence may be materialized or non-materialized.The nextmethod is useful to position theXQSequenceover the next item in the sequence. If the scrollability isXQConstants.SCROLLTYPE_SCROLLABLE, then thepreviousmethod can be called to move backwards.In the case of a forward only sequence, the get methods may be only called once per item. To perform multiple gets on an item, extract the item first from the sequence using the getItemmethod and then operate on theXQItemobject.XQPreparedExpression expr = conn.prepareExpression("for $i .."); XQSequence result = expr.executeQuery(); // create the ItemTypes for string and integer XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING); XQItemType intType = conn.createAtomicType(XQItemType.XQBASETYPE_INT); // positioned before the first item while (result.next()) { XQItemType type = result.getItemType(); // If string, then get the string value out if (type.equals(strType)) String str = result.getAtomicValue(); else if (type.equals(intType)) // if it is an integer.. int intval = result.getInt(); ... }In a sequence, the cursor may be positioned on an item, after the last item or before the first item. The getPositionmethod returns the current position number. A value of 0 indicates that it is positioned before the first item, a value ofcount() + 1indicates that it is positioned after the last item, and any other value indicates that it is positioned on the item at that position.For example, a position value of 1 indicates that it is positioned on the item at position 1. The isOnItemmethod may be used to find out if the cursor is positioned on the item. When the cursor is positioned on an item, thenextmethod call will move the cursor to be on the next item.See also: Section 12 Serialization, XQuery API for Java (XQJ) 1.0, which describes some general information applicable to various XQJ serialization methods. 
- 
- 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanabsolute(int itempos)Moves theXQSequence's position to the given item number in this object.voidafterLast()Move to the position after the last item.voidbeforeFirst()Moves to the position before the first item.voidclose()Closes the sequence and frees all resources associated with this sequence.intcount()Returns a number indicating the number of items in the sequence.booleanfirst()Moves to the first item in the sequence.XQItemgetItem()Get the current item as an immutableXQItemobject.intgetPosition()Gets the current cursor position.javax.xml.stream.XMLStreamReadergetSequenceAsStream()Read the entire sequence starting from the current position as anXMLStreamReaderobject, as described in Section 12.1 Serializing an XDM instance into a StAX event stream (XMLStreamReader), XQuery API for Java (XQJ) 1.0.java.lang.StringgetSequenceAsString(java.util.Properties props)Serializes the sequence starting from the current position to a String according to the XSLT 2.0 and XQuery 1.0 serialization.booleanisAfterLast()Checks if the current position is after the last item in the sequence.booleanisBeforeFirst()Checks if the current position before the first item in the sequence.booleanisClosed()Checks if the sequence is closed.booleanisFirst()Checks if the current position at the first item in the sequence.booleanisLast()Checks if the current position at the last item in the sequence.booleanisOnItem()Check if the sequence is positioned on an item or not.booleanisScrollable()Checks if the sequence is scrollable.booleanlast()Moves to the last item in the sequence.booleannext()Moves to the next item in the sequence.booleanprevious()Moves to the previous item in the sequence.booleanrelative(int itempos)Moves the cursor a relative number of items, either positive or negative.voidwriteSequence(java.io.OutputStream os, java.util.Properties props)Serializes the sequence starting from the current position to anOutputStreamaccording to the XSLT 2.0 and XQuery 1.0 serialization.voidwriteSequence(java.io.Writer ow, java.util.Properties props)Serializes the sequence starting from the current position to a Writer according to the XSLT 2.0 and XQuery 1.0 serialization.voidwriteSequenceToResult(javax.xml.transform.Result result)Writes the entire sequence starting from the current position to aResult.voidwriteSequenceToSAX(org.xml.sax.ContentHandler saxhdlr)Writes the entire sequence starting from the current position to a SAX handler, as described in Section 12.2 Serializing an XDM instance into a SAX event stream, XQuery API for Java (XQJ) 1.0.- 
Methods inherited from interface javax.xml.xquery.XQItemAccessorgetAtomicValue, getBoolean, getByte, getDouble, getFloat, getInt, getItemAsStream, getItemAsString, getItemType, getLong, getNode, getNodeUri, getObject, getShort, instanceOf, writeItem, writeItem, writeItemToResult, writeItemToSAX
 
- 
 
- 
- 
- 
Method Detail- 
absoluteboolean absolute(int itempos) throws XQExceptionMoves theXQSequence's position to the given item number in this object. If the item number is positive, theXQSequencemoves to the given item number with respect to the beginning of theXQSequence.The first item is item 1, the second is item 2, and so on. If the given item number is negative, the XQSequencepositions itself on an absolute item position with respect to the end of the sequence.For example, calling the method absolute(-1)positions theXQSequenceon the last item; calling the methodabsolute(-2)moves theXQSequenceto the next-to-last item, and so on.absolute(0)will position the sequence before the first item.An attempt to position the sequence beyond the first/last item set leaves the current position to be before the first item or after the last item. Calling this method on an empty sequence will return false.- Parameters:
- itempos- the item position to jump to
- Returns:
- trueif the current position is within the sequence,- falseotherwise
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
afterLastvoid afterLast() throws XQExceptionMove to the position after the last item.- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
beforeFirstvoid beforeFirst() throws XQExceptionMoves to the position before the first item.- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
closevoid close() throws XQExceptionCloses the sequence and frees all resources associated with this sequence.Closing an XQSequenceobject also implicitly closes allXQItemobjects obtained from it.All methods other than the isClosedorclosemethod will raise exceptions when invoked after closing the sequence. Callingcloseon anXQSequenceobject that is already closed has no effect.- Throws:
- XQException- if there are errors during closing of the sequence
 
 - 
isClosedboolean isClosed() Checks if the sequence is closed.- Returns:
- trueif the sequence is in a closed state,- falseotherwise
 
 - 
countint count() throws XQException Returns a number indicating the number of items in the sequence.- Returns:
- the number of items in this sequence
- Throws:
- XQException- if (1) the sequence is forward-only, or (2) the sequence is closed
 
 - 
getPositionint getPosition() throws XQExceptionGets the current cursor position.0 indicates that the position is before the first item and count() + 1indicates position after the last item. A specific position indicates that the cursor is positioned on the item at that position. Use theisOnItemmethod to verify if the cursor is positioned on the item.Calling this method on an empty sequence will return 0.- Throws:
- XQException- if (1) the sequence is forward-only, or (2) the sequence is closed
 
 - 
isOnItemboolean isOnItem() throws XQExceptionCheck if the sequence is positioned on an item or not. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the sequence is currently positioned on an item,- falseif sequence is positioned before the first item, or after the last item
- Throws:
- XQException- if the sequence is in a closed state
 
 - 
isScrollableboolean isScrollable() throws XQExceptionChecks if the sequence is scrollable.- Returns:
- trueif the sequence can be scrolled backward or forward,- falseotherwise
- Throws:
- XQException- if the sequence is in a closed state
 
 - 
firstboolean first() throws XQExceptionMoves to the first item in the sequence. The method returnstrue, if it was able to move to the first item in the sequencefalse, otherwise. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the sequence was positioned on the first item,- falseotherwise
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
getItemXQItem getItem() throws XQException Get the current item as an immutableXQItemobject. In case of anXQResultSequence, the item is anXQResultItem. In the case of forward only sequences, this method or any other get or write method may only be called once on the curent item.The XQItemobject is dependent on the sequence from which it was created and is only valid for the duration ofXQSequencelifetime. Thus, theXQSequenceis closed, thisXQItemobject will be implicitly closed and it can no longer be used.- Returns:
- an XQItemobject
- Throws:
- XQException- if (1) there are errors retrieving the item, or (2) in the case of a forward only sequence, a get or write method has already been invoked on the current item.
 
 - 
getSequenceAsStreamjavax.xml.stream.XMLStreamReader getSequenceAsStream() throws XQExceptionRead the entire sequence starting from the current position as anXMLStreamReaderobject, as described in Section 12.1 Serializing an XDM instance into a StAX event stream (XMLStreamReader), XQuery API for Java (XQJ) 1.0.Note that the serialization process might fail, in which case a XQExceptionis thrown.While the stream is being read, the application MUST NOT do any other concurrent operations on the sequence. The operation on the stream is undefined if the underlying sequence position or state is changed by concurrent operations. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. - Returns:
- an XML reader object as XMLStreamReader
- Throws:
- XQException- if (1) there are errors accessing any of the items in the sequence, (2) the sequence is in a closed state, (3) in the case of a forward only sequence, a get or write method has already been invoked on the current item, or (4) in case of an error during serialization of the sequence into a StAX event stream as defined in Section 12.1 Serializing an XDM instance into a StAX event stream (XMLStreamReader), XQuery API for Java (XQJ) 1.0
 
 - 
getSequenceAsStringjava.lang.String getSequenceAsString(java.util.Properties props) throws XQExceptionSerializes the sequence starting from the current position to a String according to the XSLT 2.0 and XQuery 1.0 serialization.Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information. Reading the sequence during the serialization process performs implicit next operations to read the items. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. - Parameters:
- props- specifies the serialization parameters,- nullis considered equivalent to an empty- Propertiesobject
- Returns:
- the serialized representation of the sequence
- Throws:
- XQException- if (1) there are errors accessing the items in the sequence, (2) there are errors during serialization, (3) the sequence is in a closed state, or (4) in the case of a forward only sequence, a get or write method has already been invoked on the current item
 
 - 
isAfterLastboolean isAfterLast() throws XQExceptionChecks if the current position is after the last item in the sequence. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the current position is after the last item,- falseotherwise
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
isBeforeFirstboolean isBeforeFirst() throws XQExceptionChecks if the current position before the first item in the sequence. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the current position is before the first item,- falseotherwise
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
isFirstboolean isFirst() throws XQExceptionChecks if the current position at the first item in the sequence. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the current position is at the first item,- falseotherwise
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
isLastboolean isLast() throws XQExceptionChecks if the current position at the last item in the sequence. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the current position is at the last item,- falseotherwise
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
lastboolean last() throws XQExceptionMoves to the last item in the sequence. This method returnstrue, if it was able to move to the last item in the sequencefalse, otherwise. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the sequence was positioned on the last item,- falseotherwise
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state
 
 - 
nextboolean next() throws XQExceptionMoves to the next item in the sequence. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the new item is valid,- falseif there are no more items
- Throws:
- XQException- if the sequence is in a closed state
 
 - 
previousboolean previous() throws XQExceptionMoves to the previous item in the sequence. Calling this method on an empty sequence will returnfalse.- Returns:
- trueif the new current position is within the sequence, (i.e., not before first);- falseotherwise.
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state.
 
 - 
relativeboolean relative(int itempos) throws XQExceptionMoves the cursor a relative number of items, either positive or negative. Attempting to move beyond the first/last item in the sequence positions the sequence before/after the the first/last item. Callingrelative(0)is valid, but does not change the cursor position.Note: Calling the method relative(1)is identical to calling the methodnextand calling the methodrelative(-1)is identical to calling the methodprevious(). Calling this method on an empty sequence will returnfalse.- Parameters:
- itempos- the item position to jump to
- Returns:
- trueif the new current position is within the sequence (i.e., not before first or after last);- falseotherwise.
- Throws:
- XQException- if (1) the sequence is forward only, or (2) the sequence is in a closed state.
 
 - 
writeSequencevoid writeSequence(java.io.OutputStream os, java.util.Properties props) throws XQExceptionSerializes the sequence starting from the current position to anOutputStreamaccording to the XSLT 2.0 and XQuery 1.0 serialization.Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information. Reading the sequence during the serialization process performs implicit next operations to read the items. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. - Parameters:
- os- the output stream into which the sequence is to be serialized
- props- specifies the serialization parameters,- nullis considered equivalent to an empty- Propertiesobject
- Throws:
- XQException- if (1) there are errors accessing the items in the sequence, (2) there are errors during serialization, (3) the sequence is in a closed state, (4) in the case of a forward only sequence, a get or write method has already been invoked on the current item, or (5) the- osparameter is- null
 
 - 
writeSequencevoid writeSequence(java.io.Writer ow, java.util.Properties props) throws XQExceptionSerializes the sequence starting from the current position to a Writer according to the XSLT 2.0 and XQuery 1.0 serialization.Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information. 
 
 Warning: When outputting to aWriter, make sure the writer's encoding matches the encoding parameter if specified as a property or the default encoding.
 
 Reading the sequence during the serialization process performs implicit next operations to read the items. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. - Parameters:
- ow- the writer object into which the sequence is to be serialized
- props- specifies the serialization parameters,- nullis considered equivalent to an empty- Propertiesobject
- Throws:
- XQException- if (1) there are errors accessing the items in the sequence, (2) there are errors during serialization, (3) the sequence is in a closed state, (4) in the case of a forward only sequence, a get or write method has already been invoked on the current item, or (5) the- owparameter is- null
 
 - 
writeSequenceToSAXvoid writeSequenceToSAX(org.xml.sax.ContentHandler saxhdlr) throws XQExceptionWrites the entire sequence starting from the current position to a SAX handler, as described in Section 12.2 Serializing an XDM instance into a SAX event stream, XQuery API for Java (XQJ) 1.0.Note that the serialization process might fail, in which case a XQExceptionis thrown.After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. The specified org.xml.sax.ContentHandlercan optionally implement theorg.xml.sax.LexicalHandlerinterface. An implementation must check if the specifiedContentHandlerimplementsLexicalHandler. If the handler is aLexicalHandlercomment nodes are reported, otherwise they will be silently ignored.- Parameters:
- saxhdlr- the SAX content handler, optionally a lexical handler
- Throws:
- XQException- if (1) there are errors accessing any of the items in the sequence, (2) the sequence is in a closed state, (3) in the case of a forward only sequence, a get or write method has already been invoked on the current item, (4) in case of an error during serializing the XDM instance into a SAX event stream, or (5) the- saxhdlrparameter is- null
 
 - 
writeSequenceToResultvoid writeSequenceToResult(javax.xml.transform.Result result) throws XQExceptionWrites the entire sequence starting from the current position to aResult. First the sequence is normalized as described in XSLT 2.0 and XQuery 1.0 serialization. Subsequently it is serialized to theResultobject.
 Note that the normalization process can fail, in which case an XQExceptionis thrown.An XQJ implementation must at least support the following implementations: 
 - javax.xml.transform.dom.DOMResult
- javax.xml.transform.sax.SAXResult
- javax.xml.transform.stream.StreamResult
 - Parameters:
- result- the result object into which the sequence is to be serialized
- Throws:
- XQException- if (1) there are errors accessing any of the items in the sequence, (2) the sequence is in a closed state, (3) in the case of a forward only sequence, a get or write method has already been invoked on the current item, (4) in case of an error while serializing the sequence into the- Resultobject, or (5) the- resultparameter is- null
 
 
- 
 
-