io::zorba::api::xqj::ZorbaXQItemThis class represents an item in the XDM. This class also implements the common interface XQItemAccessor for accessing the values of an XQuery item. All the get functions raise an exception if the underlying sequence object is not positioned on an item (e.g. if the sequence is positioned before the first item or after the last item).Example -{.java} XQPreparedExpression expr = conn.prepareExpression("for $i .."); XQSequence result = expr.executeQuery(); // create the ItemTypes for string and integer ZorbaXQItemType strType = conn.createAtomicType(ZorbaXQItemType.XQBASETYPE_STRING); ZorbaXQItemType intType = conn.createAtomicType(ZorbaXQItemType.XQBASETYPE_INTEGER); // posititioned before the first item while (result.next()) { // If string or any of its subtypes, then get the string value out if (result.instanceOf(strType)) String str = result.getAtomicValue(); else if (result.instanceOf(intType)) // if it is exactly an int int intval = result.getInt(); ... // Alternatively, you can get the exact type out. ZorbaXQItemType type = result.getItemType(); // Now perform the comparison.. if (type.equals(intType)) { ... }; }See also: Table 6 - XQuery Atomic Types and Corresponding Java Object Types, XQuery API for Java (XQJ) 1.0, for mapping of XQuery atomic types to Java object types. For example, if the XQuery value returned is of type xs:unsignedByte, then calling the getObject() method will return a Java object of type java.lang.Short. Table 7 - XQuery Node Types and Corresponding Java Object Types XQuery API for Java (XQJ) 1.0, for the mapping of XQuery node types to the corresponding Java object types. For example, if the XQuery value returned is an element node, then calling the getObject() or getNode() method will return a Java object of type org.w3.dom.Element. Protected Functions
Public Functions
Private Functions
Private Attributesclosedboolean closed
itemItem item
itemTypeXQItemType itemType
Protected FunctionsgetZorbaItemItem getZorbaItem()
Public Functionsclosevoid close() Close the item and release all the resources associated with this item. No method other than the isClosed or close method may be called once the item is closed. Calling close on an ZorbaXQItem object that is already closed has no effect. Parameters
getAtomicValueString getAtomicValue() Gets the current item as a Java String. The current item must be an atomic value. This function casts the current item to an xs:string value according to the casting rules defined in 17.1.2 Casting to xs:string and xs:untypedAtomic, XQuery 1.0 and XPath 2.0 Functions and Operators, and then returns the value as a Java String. Returnsthe string representation of the itemParameters
getBooleanboolean getBoolean() Gets the current item as a boolean. The current item must be an atomic value of type xs:boolean or a subtype. Returnsa boolean representing the current itemParameters
getBytebyte getByte() Gets the current item as a byte. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of byte. Returnsa byte representing the current itemParameters
getDoubledouble getDouble() Gets the current item as a double. The current item must be an atomic value of type xs:double or a subtype. Returnsa double representing the current itemParameters
getFloatfloat getFloat() Gets the current item as a float. The current item must be an atomic value of type xs:float or a subtype. Returnsa float representing the current itemParameters
getIntint getInt() Gets the current item as an int. Gets the current item as an int. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of int. Returnsan int representing the current itemParameters
getItemAsStreamXMLStreamReader getItemAsStream() Read the current item as an XMLStreamReader object. Read the current item as an XMLStreamReader object, 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 XQException is thrown. While the stream is being read, the application MUST NOT do any other concurrent operations on the underlying item or sequence. The operation on the stream is undefined if the underlying sequence is repositioned or the state of the underlying item or sequence is changed by concurrent operations. Returnsan XML reader object as XMLStreamReaderParameters
getItemAsStringString getItemAsString(Properties prprts) Serializes the current item 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. Parameters
Returnsthe serialized representation of the itemParameters
getItemTypeXQItemType getItemType() Gets the type of the item. On a forward only sequence this method can be called independent of any other get or write method. It will not raise an error if such method has been called already, nor will it affect subsequent invocations of any other get or write method. Returnsthe type of the itemParameters
getLonglong getLong() Gets the current item as a long. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of long. Returnsa long representing the current itemParameters
getNodeNode getNode() Gets the item as a DOM node. The current item must be a node. The type of the returned DOM node is governed by Table 7 - XQuery Node Types and Corresponding Java Object Types XQuery API for Java (XQJ) 1.0 The instance of the returned node is implementation dependent. The node may be a reference or a copy of the internal state of the item. It is advisable to make a copy of the node if the application plans to modify it. Returnsa DOM node representing the current itemParameters
getNodeUriURI getNodeUri() Returns the URI for this item. If the item is a document node, then this method returns the absolute URI of the resource from which the document node was constructed. If the document URI is not available, then the empty string is returned. If the document URI is available, the returned value is the same as if fn:document-uri were evaluated on this document node. If the item is of a node kind other than document node, then the returned URI is implementation-defined. On a forward only sequence this method can be called independent of any other get or write method. It will not raise an error if such method has been called already, nor will it affect subsequent invocations of any other get or write method on the current item. Returnsthe document URI for this document node or the empty string if not available. For other node kinds, the result is implementation-definedParameters
getObjectObject getObject() Gets the current item as an Object. The data type of the returned object will be the Java Object type as specified in 14.4 Mapping an XQuery Atomic Value to a Java Object Type and 14.5 Mapping an XQuery Node to a Java Object Type, XQuery API for Java (XQJ) 1.0. Returnsan object representing the current itemParameters
getShortshort getShort() Gets the current item as a short. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of short. Returnsa short representing the current itemParameters
instanceOfboolean instanceOf(XQItemType xqit) Checks if the item "matches" an item type. Checks if the item "matches" an item type, as defined in 2.5.4.2 Matching an Item Type and an Item, XQuery 1.0: An XML Query Language. You can use this method to first check the type of the result before calling the specific get methods.Example - {.java} ... ZorbaXQItemType strType = conn.createAtomicType(ZorbaXQItemType.XQBASETYPE_STRING); ZorbaXQItemType nodeType = conn.createNodeType(); XQSequence result = preparedExpr.executeQuery(); while (result.next()) { // Generic check for node.. if (result.instanceOf(nodeType)) org.w3.dom.Node node = result.getNode(); else if (result.instanceOf(strType)) String str = result.getAtomicValue(); } If either the type of the XQItemAccessor or the input ZorbaXQItemType is not a built-in type, then this method is allowed to raise exception if it can NOT determine the instanceOf relationship due to the lack of the access of the XML schema that defines the user defined schema types if the XQMetaData.isUserDefinedXMLSchemaTypeSupported() method returns false. Otherwise, this method must determine if the type of the XQItemAccessor is an instance of the input ZorbaXQItemType. Note even if isUserDefinedXMLSchemaTypeSupported() returns false, an XQJ implementation may still be able to determine the instanceOf relationship for certain cases involving user defined schema type. For example, if the type of an XQItemAccessor is of mySchema:hatSize sequence type and the input parameter ZorbaXQItemType is of item() sequence type, the return value for instanceOf relationship should always be true even though the XQJ implementation does not know the precise type information of mySchema:hatSize type defined in XML schema 'mySchema'. Parameters
Returnstrue if this item matches the input item type as defined in 2.5.4.2 Matching an Item Type and an Item, XQuery 1.0: An XML Query Language, and false if it does notParameters
isClosedboolean isClosed() Checks if the item is closed.
Returnsboolean true if the item is in a closed state, false otherwisewriteItemvoid writeItem(OutputStream out, Properties prprts) Serializes the current item to a Writer. Serializes the current item to a Writer according to 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. Parameters
Parameters
writeItemvoid writeItem(Writer writer, Properties prprts) Serializes the current item to a Writer. Serializes the current item to a Writer according to 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 a Writer, make sure the writer's encoding matches the encoding parameter if specified as a property or the default encoding. Parameters
Parameters
writeItemToResultvoid writeItemToResult(Result result) Writes the current item to a Result. First the item is normalized as described in XSLT 2.0 and XQuery 1.0 serialization. Subsequently it is serialized to the Result object. Note that the normalization process can fail, in which case an XQException is thrown. An XQJ implementation must at least support the following implementations:
Parameters
Parameters
writeItemToSAXvoid writeItemToSAX(ContentHandler ch) Writes the current item to a SAX handler. Writes the current item to a SAX handler, as described in 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 XQException is thrown. The specified org.xml.sax.ContentHandler can optionally implement the org.xml.sax.LexicalHandler interface. An implementation must check if the specified ContentHandler implements LexicalHandler. If the handler is a LexicalHandler comment nodes are reported, otherwise they will be silently ignored. Parameters
Parameters
ZorbaXQItem ZorbaXQItem(XQItemType itemType)
ZorbaXQItem ZorbaXQItem(Item item)
ZorbaXQItem ZorbaXQItem(Item item, XQItemType itemType)
ZorbaXQItem ZorbaXQItem(javax.xml.xquery.XQItem item)
Private FunctionsisClosedXQExceptionvoid isClosedXQException()
isDecimalXQExceptionvoid isDecimalXQException()
isFloatXQExceptionvoid isFloatXQException()
isNullXQExceptionvoid isNullXQException(Object value)
|