|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
This interface represents a common interface 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 -
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_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.
XQItemType type = result.getItemType();
// Now perform the comparison..
if (type.isOfType(intType))
{ ... };
}
See also:
xs:unsignedByte, then calling the getObject() method
will return a Java object of type java.lang.Short.
getObject() or
getNode() method will return a Java object of type
org.w3.dom.Element.
| Method Summary | |
String |
getAtomicValue()
Gets the current item as a Java String. |
boolean |
getBoolean()
Gets the current item as a boolean.
|
byte |
getByte()
Gets the current item as a byte.
|
double |
getDouble()
Gets the current item as a double.
|
float |
getFloat()
Gets the current item as a float.
|
int |
getInt()
Gets the current item as an int.
|
XMLStreamReader |
getItemAsStream()
Read the current item as an XMLStreamReader object, as described
in Section 4.4.4 Serializing an XDM instance into a StAX event stream
(XMLStreamReader), XQuery API for Java (XQJ) 1.0.
|
String |
getItemAsString(Properties props)
Serializes the current item according to the XSLT 2.0 and XQuery 1.0 serialization. |
XQItemType |
getItemType()
Gets the type of the item. |
long |
getLong()
Gets the current item as a long.
|
Node |
getNode()
Gets the item as a DOM node. |
URI |
getNodeUri()
Returns the URI for this item. |
Object |
getObject()
Gets the current item as an Object.
|
Object |
getObject(XQCommonHandler hdlr)
Returns a Java Object corresponding to the XQuery type using the
XQCommonHandler passed in. |
short |
getShort()
Gets the current item as a short.
|
boolean |
instanceOf(XQItemType 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. |
void |
writeItem(OutputStream os,
Properties props)
Serializes the current item. |
void |
writeItem(Writer ow,
Properties props)
Serializes the current item according to a Writer according to
XSLT 2.0 and XQuery 1.0 serialization.
|
void |
writeItemToResult(Result result)
Writes the current item to a Result. |
void |
writeItemToSAX(ContentHandler saxhdlr)
Writes the current item to a SAX handler, as described in in Section 4.4.5 Serializing an XDM instance into a StAX event stream, XQuery API for Java (XQJ) 1.0. |
| Method Detail |
public boolean getBoolean()
throws XQException
boolean.
The current item must be an atomic value of type xs:boolean
or a subtype.
boolean representing the current item
XQException - if (1) the conversion of the current item to a
boolean fails, (2) if there are
errors accessing the current item, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public byte getByte()
throws XQException
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.
byte representing the current item
XQException - if (1) the conversion of the current item to a
byte fails, (2) if there are
errors accessing the current item, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public double getDouble()
throws XQException
double.
The current item must be an atomic value of type xs:double
or a subtype.
double representing the current item
XQException - if (1) the conversion of the current item to a
double fails, (2) if there are
errors accessing the current item, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public float getFloat()
throws XQException
float.
The current item must be an atomic value of type xs:float
or a subtype.
float representing the current item
XQException - if (1) the conversion of the current item to a
float fails, (2) if there are
errors accessing the current item, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public int getInt()
throws XQException
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.
int representing the current item
XQException - if (1) the conversion of the current item to a
int fails, (2) if there are
errors accessing the current item, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public XQItemType getItemType()
throws XQException
XQException - if (1) there are errors accessing the type of the item,
or (2) the underlying sequence or item is in a closed state
public String getAtomicValue()
throws XQException
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.
XQException - if (1) there are errors accessing the item's value,
(2) the item is not an atomic value,
(3) there is an error when casting the
item to a string representation,
(4) the underlying sequence or item is in a
closed state, or (5) in the case of forward only
sequences, a get or write method was already
invoked on the current item
public long getLong()
throws XQException
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.
long representing the current item
XQException - if (1) the conversion of the current item to a
long fails, (2) if there are
errors accessing the current item, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public Node getNode()
throws XQException
XQException - if (1) if there are errors accessing the current item,
(2) the current item is not a node, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public URI getNodeUri()
throws XQException
XQException - if (1) if there are errors accessing the current item,
(2) the current item is not a node, or (3) if the
underlying sequence or item is in a closed state.
public Object getObject()
throws XQException
Object.
The data type of the returned object will be the Java Object
type as specified in 6.3 Mapping an XQuery Atomic Value to a
Java Object Type and 6.4 Mapping an XQuery Node to a Java Object Type,
XQuery API for Java (XQJ) 1.0.
If a XQCommonHandler is set at the XQConnection,
then that handler will be used to return the relevant object.
XQException - if (1) if there are errors accessing the current item,
(2) if the underlying sequence or item is in a closed state,
or (3) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public Object getObject(XQCommonHandler hdlr)
throws XQException
Object corresponding to the XQuery type using the
XQCommonHandler passed in.
hdlr - an XQCommonHandler to use for generating
the object. If the hdlr is null,
then the data type of the returned object will be the Java
Object type as specified in 6.3 Mapping an
XQuery Atomic Value to a Java Object Type and 6.4 Mapping
an XQuery Node to a Java Object Type, XQuery API for Java
(XQJ) 1.0.
Object
XQException - if (1) if there are errors accessing the current item,
(2) if the underlying sequence or item is in a closed state,
or (3) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public XMLStreamReader getItemAsStream()
throws XQException
XMLStreamReader object, as described
in Section 4.4.4 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.
XMLStreamReader
XQException - if (1) there are errors accessing the current item
or the underlying sequence, (2) the underlying sequence
or item 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 current item into a StAX event
stream as defined in Section 4.4.4 Serializing an XDM
instance into a StAX event stream (XMLStreamReader), XQuery
API for Java (XQJ) 1.0
public String getItemAsString(Properties props)
throws XQException
props - specifies the serialization parameters, null
is considered equivalent to an empty Properties
object.
XQException - if (1) there are errors accessing the current
item or the underlying sequence, (2) the underlying
sequence or item 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) if there are errors during serialization
public short getShort()
throws XQException
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.
short representing the current item
XQException - if (1) the conversion of the current item to a
short fails, (2) if there are
errors accessing the current item, (3) if the
underlying sequence or item is in a closed state,
or (4) in the case of forward only sequences, a
get or write method was already invoked on the
current item
public boolean instanceOf(XQItemType type)
throws XQException
...
XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING);
XQItemType 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();
}
XQItemAccessor or the input
XQItemType 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 schmea types if the
XQMetaData.isUserDefinedXMLSchemaTypeSupported() method
returns false.
XQItemAccessor is an instance of the input
XQItemType. Note even if
isUserDefinedXMLScheamTypeSupported() 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
XQItemType is of 'item()' sequence type,
the return value for instanceOf relationship should always be false
even though the XQJ implementation does not know the precise type
information of mySchema:hatSize type defined in XML
schema 'mySchema'.
type - item type to match
true 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 not.
XQException - if (1) there are errors accessing the item's
type, or (2) if the underlying sequence or item
is in a closed state, or (3) if the implementation is
unable to determine the schema definition of a user
defined schema type.
public void writeItem(OutputStream os,
Properties props)
throws XQException
os - the output stream into which the current item is
to be serializedprops - specifies the serialization parameters, null
is considered equivalent to an empty Properties
object.
XQException - if (1) there are errors accessing the current
item or the underlying sequence, (2) the underlying
sequence or item 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) if there are errors during serialization
public void writeItem(Writer ow,
Properties props)
throws XQException
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 4.4.3.2 Serializing an XQSequence, XQuery
API for Java (XQJ) 1.0 for more information.
Writer, make sure the writer's encoding
matches the encoding parameter if specified as a property or the default
encoding.
ow - the writer object into which the current item is to be
serializedprops - specifies the serialization parameters, null
is considered equivalent to an empty Properties
object.
XQException - if (1) there are errors accessing the current
item or the underlying sequence, (2) the underlying
sequence or item 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) if there are errors during
serialization
public void writeItemToSAX(ContentHandler saxhdlr)
throws XQException
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.
saxhdlr - the SAX content handler, optionally a lexical handler
XQException - if (1) there are errors accessing the current
item or the underlying sequence, (2) the underlying
sequence or item 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 while serializing the XDM instance
into a SAX event stream.
public void writeItemToResult(Result result)
throws XQException
Result. First the item is
normalized as described in [XQuery Serialization]. Note that the
normalization process can fail, in which case an XQException is thrown.
Subsequently it is serialized to the Result object.javax.xml.transform.dom.DOMResult
javax.xml.transform.sax.SAXResult
javax.xml.transform.stream.StreamResult
result - the result object into which the item is to be serialized
XQException - if (1) there are errors accessing the current item or the
underlying sequence, (2) the underlying sequence or item 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 while serializing the current
item into the Result object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||