Berkeley DB XML
version 2.5.16

com.sleepycat.dbxml
Class XmlValue

java.lang.Object
  extended by com.sleepycat.dbxml.XmlValue

public class XmlValue
extends Object

The XmlValue class encapsulates the value of a node in an XML document. The type of the value may be any one of the class constants. There are convenience operators for specially handling the types of STRING, DOUBLE, and BOOLEAN, as well as a constructor to make an XmlValue from XmlDocument.

The XmlValue class provides several constructors, each of which maps a Java type or Berkeley DB XML class onto an appropriate XmlValue type. The following table lists the constructor parameter mappings.

This object is not thread-safe, and can only be safely used by one thread at a time in an application.


Field Summary
static int ANY_SIMPLE_TYPE
           
static int ANY_URI
           
static int ATTRIBUTE_NODE
          Node type returned by getNodeType().
static int BASE_64_BINARY
           
static int BOOLEAN
           
static int CDATA_SECTION_NODE
          Node type returned by getNodeType().
static int COMMENT_NODE
          Node type returned by getNodeType().
static int DATE
           
static int DATE_TIME
           
static int DAY_TIME_DURATION
           
static int DECIMAL
           
static int DOCUMENT_FRAGMENT_NODE
          Node type returned by getNodeType().
static int DOCUMENT_NODE
          Node type returned by getNodeType().
static int DOCUMENT_TYPE_NODE
          Node type returned by getNodeType().
static int DOUBLE
           
static int DURATION
           
static int ELEMENT_NODE
          Node type returned by getNodeType().
static int ENTITY_NODE
          Node type returned by getNodeType().
static int ENTITY_REFERENCE_NODE
          Node type returned by getNodeType().
static int FLOAT
           
static int G_DAY
           
static int G_MONTH
           
static int G_MONTH_DAY
           
static int G_YEAR
           
static int G_YEAR_MONTH
           
static int HEX_BINARY
           
static int NODE
           
static int NONE
           
static int NOTATION
           
static int NOTATION_NODE
          Node type returned by getNodeType().
static int PROCESSING_INSTRUCTION_NODE
          Node type returned by getNodeType().
static int QNAME
           
static int STRING
           
static int TEXT_NODE
          Node type returned by getNodeType().
static int TIME
           
static int UNTYPED_ATOMIC
           
static int YEAR_MONTH_DURATION
           
 
Constructor Summary
XmlValue()
          Public constructor.
XmlValue(boolean v)
          Construct a value from a boolean.
XmlValue(double v)
          Construct a value from a double.
XmlValue(int type, byte[] dbt)
          Construct a typed value from a byte array.
XmlValue(int type, String v)
          Construct a typed value from a string.
XmlValue(String v)
          Construct a value from a string.
XmlValue(String typeURI, String typeName, String v)
          Construct a typed value, where the type is defined by a URI and name, from a string.
XmlValue(XmlDocument document)
          Construct a value from a document.
XmlValue(XmlValue other)
          Copy constructor.
 
Method Summary
 byte[] asBinary()
          Returns the value as a byte array.
 boolean asBoolean()
          Returns the value as a BOOLEAN.
 XmlDocument asDocument()
          Returns the value as an XmlDocument.
 XmlEventReader asEventReader()
          Returns the value as an XmlEventReader.
 double asNumber()
          Returns the value as a DOUBLE.
 String asString()
          Returns the value as a STRING.
 boolean equals(XmlValue value)
          Determines if two XmlValue objects represent the same value.
 XmlResults getAttributes()
          Returns returns a XmlResults that contains all of the attributes appearing on this node.
 XmlValue getFirstChild()
          Returns current node's first child node.
 XmlValue getLastChild()
          Returns current node's last child node.
 String getLocalName()
          Returns the node's local name.
 String getNamespaceURI()
          Returns the URI used for the node's namespace.
 XmlValue getNextSibling()
          Returns the sibling node immediately following this node in the document.
 String getNodeHandle()
          Returns a String handle that can be used to directly reference nodes within a document by using XmlContainer.getNode(java.lang.String)
 String getNodeName()
          Returns the name of the node contained in this XmlValue.
 short getNodeType()
          Returns the short value for this node's node type (e.g.
 String getNodeValue()
          Returns the node's value.
 XmlValue getOwnerElement()
          If the current node is an attribute node, returns the document element node that contains this attribute node.
 XmlValue getParentNode()
          Returns current node's parent.
 String getPrefix()
          Returns the prefix set for the node's namespace.
 XmlValue getPreviousSibling()
          Returns the sibling node immediately preceding this node in the document.
 XmlResults getResults()
          Returns the XmlResults that is associated with this XmlValue, or null if there is none.
 int getType()
          Returns the type of the XmlValue, which will be one of the XmlValue class constants.
 String getTypeName()
          Returns the type name of the XmlValue
 String getTypeURI()
          Returns the type URI of the XmlValue
 boolean isBoolean()
          Returns true if the XmlValue is one of type BOOLEAN.
 boolean isNode()
          Returns true if the XmlValue is of type NODE.
 boolean isNull()
          Returns true if the XmlValue has no value (type NONE).
 boolean isNumber()
          Returns true if the XmlValue is one of the numeric types, such as DOUBLE, FLOAT, etc.
 boolean isString()
          Returns true if the XmlValue is one of type STRING.
 boolean isType(int type)
          Indicates whether the XmlValue is of the specified type.
static void setValue(XmlValue to, XmlValue from)
          Assigns a new value to an existing one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ELEMENT_NODE

public static final int ELEMENT_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

ATTRIBUTE_NODE

public static final int ATTRIBUTE_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

TEXT_NODE

public static final int TEXT_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

CDATA_SECTION_NODE

public static final int CDATA_SECTION_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

ENTITY_REFERENCE_NODE

public static final int ENTITY_REFERENCE_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

ENTITY_NODE

public static final int ENTITY_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

PROCESSING_INSTRUCTION_NODE

public static final int PROCESSING_INSTRUCTION_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

COMMENT_NODE

public static final int COMMENT_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

DOCUMENT_NODE

public static final int DOCUMENT_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

DOCUMENT_TYPE_NODE

public static final int DOCUMENT_TYPE_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

DOCUMENT_FRAGMENT_NODE

public static final int DOCUMENT_FRAGMENT_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

NOTATION_NODE

public static final int NOTATION_NODE
Node type returned by getNodeType().

See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values

NODE

public static final int NODE
See Also:
Constant Field Values

ANY_SIMPLE_TYPE

public static final int ANY_SIMPLE_TYPE
See Also:
Constant Field Values

ANY_URI

public static final int ANY_URI
See Also:
Constant Field Values

BASE_64_BINARY

public static final int BASE_64_BINARY
See Also:
Constant Field Values

BOOLEAN

public static final int BOOLEAN
See Also:
Constant Field Values

DATE

public static final int DATE
See Also:
Constant Field Values

DATE_TIME

public static final int DATE_TIME
See Also:
Constant Field Values

DAY_TIME_DURATION

public static final int DAY_TIME_DURATION
See Also:
Constant Field Values

DECIMAL

public static final int DECIMAL
See Also:
Constant Field Values

DOUBLE

public static final int DOUBLE
See Also:
Constant Field Values

DURATION

public static final int DURATION
See Also:
Constant Field Values

FLOAT

public static final int FLOAT
See Also:
Constant Field Values

G_DAY

public static final int G_DAY
See Also:
Constant Field Values

G_MONTH

public static final int G_MONTH
See Also:
Constant Field Values

G_MONTH_DAY

public static final int G_MONTH_DAY
See Also:
Constant Field Values

G_YEAR

public static final int G_YEAR
See Also:
Constant Field Values

G_YEAR_MONTH

public static final int G_YEAR_MONTH
See Also:
Constant Field Values

HEX_BINARY

public static final int HEX_BINARY
See Also:
Constant Field Values

NOTATION

public static final int NOTATION
See Also:
Constant Field Values

QNAME

public static final int QNAME
See Also:
Constant Field Values

STRING

public static final int STRING
See Also:
Constant Field Values

TIME

public static final int TIME
See Also:
Constant Field Values

YEAR_MONTH_DURATION

public static final int YEAR_MONTH_DURATION
See Also:
Constant Field Values

UNTYPED_ATOMIC

public static final int UNTYPED_ATOMIC
See Also:
Constant Field Values
Constructor Detail

XmlValue

public XmlValue()
         throws XmlException
Public constructor. Creates empty object.

Throws:
XmlException

XmlValue

public XmlValue(XmlValue other)
         throws XmlException
Copy constructor.

Throws:
XmlException

XmlValue

public XmlValue(String v)
         throws XmlException
Construct a value from a string.

Throws:
XmlException

XmlValue

public XmlValue(double v)
         throws XmlException
Construct a value from a double.

Throws:
XmlException

XmlValue

public XmlValue(boolean v)
         throws XmlException
Construct a value from a boolean.

Throws:
XmlException

XmlValue

public XmlValue(XmlDocument document)
         throws XmlException
Construct a value from a document.

Throws:
XmlException

XmlValue

public XmlValue(int type,
                String v)
         throws XmlException
Construct a typed value from a string.

Throws:
XmlException

XmlValue

public XmlValue(String typeURI,
                String typeName,
                String v)
         throws XmlException
Construct a typed value, where the type is defined by a URI and name, from a string.

Throws:
XmlException

XmlValue

public XmlValue(int type,
                byte[] dbt)
         throws XmlException
Construct a typed value from a byte array.

Throws:
XmlException
Method Detail

getType

public int getType()
            throws XmlException
Returns the type of the XmlValue, which will be one of the XmlValue class constants.

Throws:
XmlException

getTypeURI

public String getTypeURI()
                  throws XmlException
Returns the type URI of the XmlValue

Throws:
XmlException

getTypeName

public String getTypeName()
                   throws XmlException
Returns the type name of the XmlValue

Throws:
XmlException

getNodeHandle

public String getNodeHandle()
                     throws XmlException
Returns a String handle that can be used to directly reference nodes within a document by using XmlContainer.getNode(java.lang.String)

If the type of the XmlValue is not NODE, an exception is thrown.

Throws:
XmlException

isNull

public boolean isNull()
               throws XmlException
Returns true if the XmlValue has no value (type NONE).

Throws:
XmlException

isType

public boolean isType(int type)
               throws XmlException
Indicates whether the XmlValue is of the specified type.

Throws:
XmlException

isNumber

public boolean isNumber()
                 throws XmlException
Returns true if the XmlValue is one of the numeric types, such as DOUBLE, FLOAT, etc.

Throws:
XmlException

isString

public boolean isString()
                 throws XmlException
Returns true if the XmlValue is one of type STRING.

Throws:
XmlException

isBoolean

public boolean isBoolean()
                  throws XmlException
Returns true if the XmlValue is one of type BOOLEAN.

Throws:
XmlException

isNode

public boolean isNode()
               throws XmlException
Returns true if the XmlValue is of type NODE.

Throws:
XmlException

asBinary

public byte[] asBinary()
                throws XmlException
Returns the value as a byte array.

Throws:
XmlException

asNumber

public double asNumber()
                throws XmlException
Returns the value as a DOUBLE.

Throws:
XmlException

asString

public String asString()
                throws XmlException
Returns the value as a STRING.

Throws:
XmlException

asBoolean

public boolean asBoolean()
                  throws XmlException
Returns the value as a BOOLEAN.

Throws:
XmlException

asDocument

public XmlDocument asDocument()
                       throws XmlException
Returns the value as an XmlDocument.

Throws:
XmlException

asEventReader

public XmlEventReader asEventReader()
                             throws XmlException
Returns the value as an XmlEventReader. This operation is only valid if the XmlValue is of type NODE. The ownership of the XmlEventReader belongs to the caller, and its resources must be released using XmlEventReader.close().

Throws:
XmlException

equals

public boolean equals(XmlValue value)
               throws XmlException
Determines if two XmlValue objects represent the same value. It returns true if the two XmlValue objects represent the same value.

Throws:
XmlException

getNodeName

public String getNodeName()
                   throws XmlException
Returns the name of the node contained in this XmlValue. If the node type is not NODE, an XmlException is thrown.

Throws:
XmlException

getNodeValue

public String getNodeValue()
                    throws XmlException
Returns the node's value. If the node type is not NODE, an XmlException is thrown.

Throws:
XmlException

getNamespaceURI

public String getNamespaceURI()
                       throws XmlException
Returns the URI used for the node's namespace. If the node type is not NODE, an XmlException is thrown.

Throws:
XmlException

getPrefix

public String getPrefix()
                 throws XmlException
Returns the prefix set for the node's namespace. If the node type is not NODE, an XmlException is thrown.

Throws:
XmlException

getLocalName

public String getLocalName()
                    throws XmlException
Returns the node's local name. For example, if a node has the namespace prefix, "prefix," and its qualified name is prefix:name, then 'name' is the local name. If the node type is not NODE, an XmlException is thrown.

Throws:
XmlException

getNodeType

public short getNodeType()
                  throws XmlException
Returns the short value for this node's node type (e.g. ELEMENT_NODE) If the node type is not NODE, an XmlException is thrown.

Throws:
XmlException

getParentNode

public XmlValue getParentNode()
                       throws XmlException
Returns current node's parent. If the node has no parent, an empty node of type NONE is returned. If the node type is not NODE, an XmlException is thrown. This function cannot be used on values that were created from an XmlDocument that was created using XmlManager.createDocument() and never placed in a container, an XmlException is thrown if this happens.

Throws:
XmlException

getFirstChild

public XmlValue getFirstChild()
                       throws XmlException
Returns current node's first child node. If the node has no children, an empty node of type NONE is returned. If the node type is not NODE, an XmlException is thrown. This function cannot be used on values that were created from an XmlDocument that was created using XmlManager.createDocument() and never placed in a container, an XmlException is thrown if this happens.

Throws:
XmlException

getLastChild

public XmlValue getLastChild()
                      throws XmlException
Returns current node's last child node. If the node has no children, an empty node of type NONE is returned. If the node type is not NODE, an XmlException is thrown. This function cannot be used on values that were created from an XmlDocument that was created using XmlManager.createDocument() and never placed in a container, an XmlException is thrown if this happens.

Throws:
XmlException

getPreviousSibling

public XmlValue getPreviousSibling()
                            throws XmlException
Returns the sibling node immediately preceding this node in the document. If the current node had no siblings preceding it in the document, an empty node of type NONE is returned. If the node type is not NODE, an XmlException is thrown. This function cannot be used on values that were created from an XmlDocument that was created using XmlManager.createDocument() and never placed in a container, an XmlException is thrown if this happens.

Throws:
XmlException

getNextSibling

public XmlValue getNextSibling()
                        throws XmlException
Returns the sibling node immediately following this node in the document. If the current node had no siblings following it in the document, an empty node of type NONE is returned. If the node type is not NODE, an XmlException is thrown. This function cannot be used on values that were created from an XmlDocument that was created using XmlManager.createDocument() and never placed in a container, an XmlException is thrown if this happens.

Throws:
XmlException

getAttributes

public XmlResults getAttributes()
                         throws XmlException
Returns returns a XmlResults that contains all of the attributes appearing on this node. If the node type is not NODE, an XmlException is thrown. This function cannot be used on values that were created from an XmlDocument that was created using XmlManager.createDocument() and never placed in a container, anXmlException is thrown if this happens.

Throws:
XmlException

getOwnerElement

public XmlValue getOwnerElement()
                         throws XmlException
If the current node is an attribute node, returns the document element node that contains this attribute node. Otherwise, an XmlException is thrown. This function cannot be used on values that were created from an XmlDocument that was created using XmlManager.createDocument() and never placed in a container, an XmlException is thrown if this happens.

Throws:
XmlException

setValue

public static void setValue(XmlValue to,
                            XmlValue from)
                     throws XmlException
Assigns a new value to an existing one.

Parameters:
to - The value to be overwritten.
from - The value to copy.
Throws:
XmlException

getResults

public XmlResults getResults()
Returns the XmlResults that is associated with this XmlValue, or null if there is none. This function exists to make it easier to call XmlResults.delete() when the value is no longer needed.


Berkeley DB XML
version 2.5.16

Copyright (c) 1996,2009 Oracle. All rights reserved.