org.exist.fluent
Class Item

java.lang.Object
  extended by org.exist.fluent.Resource
      extended by org.exist.fluent.Item
Direct Known Subclasses:
Node

public class Item
extends Resource

An XML item in the database. While most often used to represent XML elements, it can also stand in for any DOM node or an atomic value. However, it is not used to represent entire XML documents (see XMLDocument). Not all operations are valid in all cases.

Version:
$Revision: 1.13 $ ($Date: 2006/04/14 04:12:04 $)
Author:
Piotr Kaminski

Method Summary
 boolean booleanValue()
          Return the converted boolean value following XQuery / XPath conversion rules.
 Comparable<Object> comparableValue()
          Return the comparable value of this item, if available.
 XMLGregorianCalendar dateTimeValue()
          Return the XML date/time value of this item by parsing its string representation.
 double doubleValue()
          Return the double value of this item.
 Duration durationValue()
          Return the duration value of this item by parsing its string representation as a duration.
 boolean equals(Object o)
           
 boolean extant()
          Return whether this item really exists.
 int hashCode()
          The hash code computation can be expensive, and the hash codes may not be very well distributed.
 Date instantValue()
          Return the java.util.Date value of this item by parsing its string representation as an XML date/time value, then converting to a Java date.
 int intValue()
          Return the int value of this item.
 long longValue()
          Return the long value of this item.
 Node node()
          Return this item cast as a node.
 Item toAtomicItem()
          Atomize this item and return the result.
 ItemList toItemList()
          Return a singleton item list consisting of this item.
 String toString()
          Return the string representation of this item.
 String type()
          Return the type of this item, e.g.
 String value()
           
 String valueWithDefault(String defaultValue)
           
 
Methods inherited from class org.exist.fluent.Resource
database, namespaceBindings, query
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

node

public Node node()
Return this item cast as a node.

Returns:
this item cast as a node
Throws:
DatabaseException - if this item is not a node

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
The hash code computation can be expensive, and the hash codes may not be very well distributed. You probably shouldn't use items in situations where they might get hashed.

Overrides:
hashCode in class Object

type

public String type()
Return the type of this item, e.g. element() or xs:string.

Returns:
the type of this item

extant

public boolean extant()
Return whether this item really exists. Examples of items that don't exist even though they have an object representing them include virtual placeholders returned for an optional query that didn't select an item, and items that were deleted from the database after being selected.

Returns:
true if the item exists, false otherwise

toItemList

public ItemList toItemList()
Return a singleton item list consisting of this item.

Returns:
an item list that contains only this item

toAtomicItem

public Item toAtomicItem()
Atomize this item and return the result. This is useful if you don't know if you're holding a node or an atomic item, and want to ensure it's an atomic value without potentially losing its type by converting it to a string.

Returns:
the atomized value of this item; may be this item itself if it's already atomic

value

public String value()
Returns:
the string value of this item if atomic, or the concatenation of its text content if a node

valueWithDefault

public String valueWithDefault(String defaultValue)
Parameters:
defaultValue - the default value to return if the item is null (unbound)
Returns:
the string value of this item if atomic, or the concatenation of its text content if a node, or the given default value if this is a null item

booleanValue

public boolean booleanValue()
Return the converted boolean value following XQuery / XPath conversion rules. For numeric values, return false iff the value is 0. For strings, return true if the value is 'true' or '1' and false if the value is 'false' or '0', fail otherwise. For nodes, return the conversion of the effective string value.

Returns:
the boolean value of the item
Throws:
DatabaseException - if the conversion failed

intValue

public int intValue()
Return the int value of this item. For numeric atomic values, truncate to an int; for other values, request a conversion of the effective string value (which may fail). If the value is out of range for ints, return the smallest or largest int, as appropriate. If you think overflow may be a problem, check for these values.

Returns:
the int value of this item
Throws:
DatabaseException - if the conversion failed

longValue

public long longValue()
Return the long value of this item. For numeric atomic values, truncate to a long; for other values, request a conversion of the effective string value (which may fail). If the value is out of range for longs, return the smallest or largest long, as appropriate. If you think overflow may be a problem, check for these values.

Returns:
the long value of this item
Throws:
DatabaseException - if the conversion failed

doubleValue

public double doubleValue()
Return the double value of this item. For numeric atomic values, truncate to a double; for other values, request a conversion of the effective string value (which may fail). If the value is out of range for doubles, return positive or negative infinity, as appropriate. If you think overflow may be a problem, check for these values.

Returns:
the double value of this item
Throws:
DatabaseException - if the conversion failed

durationValue

public Duration durationValue()
Return the duration value of this item by parsing its string representation as a duration.

Returns:
the duration value of this item
Throws:
DatabaseException - if the conversion failed

dateTimeValue

public XMLGregorianCalendar dateTimeValue()
Return the XML date/time value of this item by parsing its string representation.

Returns:
the XML date/time value of this item
Throws:
DatabaseException - if the conversion failed

instantValue

public Date instantValue()
Return the java.util.Date value of this item by parsing its string representation as an XML date/time value, then converting to a Java date.

Returns:
the Java time instant value of this item
Throws:
DatabaseException - if the conversion failed

comparableValue

public Comparable<Object> comparableValue()
Return the comparable value of this item, if available. The resulting object will directly compare the XQuery value without converting to a string first, unless the item is untyped and atomic, in which case it will be cast to a string. Items of different types will compare in an arbitrary but stable order. Nodes are never comparable.

Returns:
the comparable value of this item
Throws:
DatabaseException - if this item is not comparable

toString

public String toString()
Return the string representation of this item. If the item is atomic, return its string value. If it is a node, serialize it to a string.

Overrides:
toString in class Object
Returns:
the string representation of this item


Copyright (C) All rights reserved.