org.cdlib.xtf.lazyTree
Class ProxyElement

Object
  extended by NodeImpl
      extended by ProxyElement
All Implemented Interfaces:
Source, SourceLocator, FingerprintedNode, Item, NodeInfo, ValueRepresentation, SearchElement, SearchNode

public final class ProxyElement
extends NodeImpl
implements NodeInfo, FingerprintedNode, SourceLocator, SearchElement

A very lazy element. It assumes the attributes of the element can be known in advance without actually loading that element. If that assumption proves incorrect (i.e. by accessing anything else), the real element is loaded and its actual attributes are used. This class is used by SearchTree for many of its synthetic nodes.

Author:
Martin Haye

Field Summary
(package private)  int[] attrNames
          Pre-computed attribute names
(package private)  String[] attrValues
          Pre-computed attribute values
(package private)  LazyDocument document
          Document to use for loading
(package private)  ElementImpl element
          The actual element (null until loaded)
(package private)  int nodeNum
          Node number represented by this element
 
Fields inherited from class NodeImpl
nameCode, nextSibNum, NODE_LETTER, parentNum, prevSibNum
 
Fields inherited from interface NodeInfo
ALL_NAMESPACES, EMPTY_NAMESPACE_LIST, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACES
 
Fields inherited from interface ValueRepresentation
EMPTY_VALUE_ARRAY
 
Constructor Summary
ProxyElement(LazyDocument realDocument)
          General constructor, attaches to a given lazy-loading document
 
Method Summary
 void allocateAttributes(int nAttrs)
          Allocate the attribute array.
 Value atomize()
          Get the typed value.
 int compareOrder(NodeInfo other)
          Loads the real node and defers to it
 void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId)
          Loads the real node and defers to it
 void generateId(FastStringBuffer buffer)
          Loads the real node and defers to it
 String getAttributeValue(int fingerprint)
          Loads the real node and defers to it
 String getBaseURI()
          Loads the real node and defers to it
 int getColumnNumber()
          Loads the real node and defers to it
 Configuration getConfiguration()
          Get the configuration
 int[] getDeclaredNamespaces(int[] buffer)
          Loads the real node and defers to it
 String getDisplayName()
          Loads the real node and defers to it
 int getDocumentNumber()
          Loads the real node and defers to it
 DocumentInfo getDocumentRoot()
          Loads the real node and defers to it
 int getFingerprint()
          Loads the real node and defers to it
 int getLineNumber()
          Loads the real node and defers to it
 String getLocalPart()
          Loads the real node and defers to it
 int getNameCode()
          Loads the real node and defers to it
 NamePool getNamePool()
          Loads the real node and defers to it
 int getNodeKind()
          Loads the real node and defers to it
 NodeInfo getParent()
          Loads the real node and defers to it
 String getPrefix()
          Loads the real node and defers to it
 String getPublicId()
          Loads the real node and defers to it
 NodeInfo getRoot()
          Loads the real node and defers to it
 long getSequenceNumber()
          Loads the real node and defers to it
 String getStringValue()
          Loads the real node and defers to it
 CharSequence getStringValueCS()
          Loads the real node and defers to it
 String getSystemId()
          Loads the real node and defers to it
 int getTypeAnnotation()
          Loads the real node and defers to it
 SequenceIterator getTypedValue()
          Loads the real node and defers to it
 String getURI()
          Loads the real node and defers to it
 boolean hasChildNodes()
          Loads the real node and defers to it
 boolean isSameNodeInfo(NodeInfo other)
          Loads the real node and defers to it
 AxisIterator iterateAxis(byte axisNumber)
          Loads the real node and defers to it
 AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest)
          If only the attributes are accessed, uses ProxyAttributeEnumeration to serve up the pre-computed attributes.
private  ElementImpl real()
          Obtain the real underlying ElementImpl.
 void sendNamespaceDeclarations(Receiver out, boolean includeAncestors)
          Loads the real node and defers to it
 void setAttribute(int attrNum, int nameCode, String value)
          Set an attribute
 void setChildNum(int num)
          Establish the child node number
 void setNameCode(int code)
          Establish a name for this node
 void setNextSibNum(int num)
          Establish the next sibling node number
 void setNodeNum(int nodeNum)
          Set the node number for this node.
 void setParentNum(int newParentNum)
          Establish the parent node number
 void setPrevSibNum(int num)
          Establish the previous sibling node number
 void setSystemId(String systemId)
          Loads the real node and defers to it
 
Methods inherited from class NodeImpl
equals, getFirstChild, getLastChild, getNextInDocument, getNextSibling, getPreviousInDocument, getPreviousSibling, hashCode, init
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface NodeInfo
equals, hashCode
 

Field Detail

element

ElementImpl element
The actual element (null until loaded)


document

LazyDocument document
Document to use for loading


nodeNum

int nodeNum
Node number represented by this element


attrNames

int[] attrNames
Pre-computed attribute names


attrValues

String[] attrValues
Pre-computed attribute values

Constructor Detail

ProxyElement

public ProxyElement(LazyDocument realDocument)
General constructor, attaches to a given lazy-loading document

Method Detail

setNodeNum

public void setNodeNum(int nodeNum)
Set the node number for this node.

Specified by:
setNodeNum in interface SearchNode

allocateAttributes

public void allocateAttributes(int nAttrs)
Allocate the attribute array.

Specified by:
allocateAttributes in interface SearchElement

setAttribute

public void setAttribute(int attrNum,
                         int nameCode,
                         String value)
Set an attribute

Specified by:
setAttribute in interface SearchElement

setParentNum

public void setParentNum(int newParentNum)
Establish the parent node number

Specified by:
setParentNum in interface SearchNode

setChildNum

public void setChildNum(int num)
Establish the child node number

Specified by:
setChildNum in interface SearchElement

setNextSibNum

public void setNextSibNum(int num)
Establish the next sibling node number

Specified by:
setNextSibNum in interface SearchNode

setPrevSibNum

public void setPrevSibNum(int num)
Establish the previous sibling node number

Specified by:
setPrevSibNum in interface SearchNode

setNameCode

public void setNameCode(int code)
Establish a name for this node

Specified by:
setNameCode in interface SearchElement

real

private final ElementImpl real()
Obtain the real underlying ElementImpl. If not loaded, load it now.


getSequenceNumber

public long getSequenceNumber()
Loads the real node and defers to it

Overrides:
getSequenceNumber in class NodeImpl

compareOrder

public int compareOrder(NodeInfo other)
Loads the real node and defers to it

Specified by:
compareOrder in interface NodeInfo
Overrides:
compareOrder in class NodeImpl
Parameters:
other - The other node, whose position is to be compared with this node
Returns:
-1 if this node precedes the other node, +1 if it follows the other node, or 0 if they are the same node. (In this case, isSameNode() will always return true, and the two nodes will produce the same result for generateId())

getConfiguration

public Configuration getConfiguration()
Description copied from class: NodeImpl
Get the configuration

Specified by:
getConfiguration in interface NodeInfo
Overrides:
getConfiguration in class NodeImpl

generateId

public void generateId(FastStringBuffer buffer)
Loads the real node and defers to it

Specified by:
generateId in interface NodeInfo
Overrides:
generateId in class NodeImpl

getAttributeValue

public String getAttributeValue(int fingerprint)
Loads the real node and defers to it

Specified by:
getAttributeValue in interface NodeInfo
Overrides:
getAttributeValue in class NodeImpl
Parameters:
fingerprint - The fingerprint of the attribute name
Returns:
the attribute value if it exists or null if not

getBaseURI

public String getBaseURI()
Loads the real node and defers to it

Specified by:
getBaseURI in interface NodeInfo
Overrides:
getBaseURI in class NodeImpl

getFingerprint

public int getFingerprint()
Loads the real node and defers to it

Specified by:
getFingerprint in interface NodeInfo
Overrides:
getFingerprint in class NodeImpl

getLocalPart

public String getLocalPart()
Loads the real node and defers to it

Specified by:
getLocalPart in interface NodeInfo
Overrides:
getLocalPart in class NodeImpl
Returns:
The local name of this node. For a node with no name, return "",.

getNameCode

public int getNameCode()
Loads the real node and defers to it

Specified by:
getNameCode in interface NodeInfo
Overrides:
getNameCode in class NodeImpl

getParent

public NodeInfo getParent()
Loads the real node and defers to it

Specified by:
getParent in interface NodeInfo
Overrides:
getParent in class NodeImpl
Returns:
The Node object describing the containing element or root node.

getStringValue

public String getStringValue()
Loads the real node and defers to it

Specified by:
getStringValue in interface Item
Specified by:
getStringValue in interface NodeInfo
Specified by:
getStringValue in interface ValueRepresentation

getSystemId

public String getSystemId()
Loads the real node and defers to it

Specified by:
getSystemId in interface Source
Specified by:
getSystemId in interface SourceLocator
Specified by:
getSystemId in interface NodeInfo
Overrides:
getSystemId in class NodeImpl

getURI

public String getURI()
Loads the real node and defers to it

Specified by:
getURI in interface NodeInfo
Overrides:
getURI in class NodeImpl
Returns:
The URI of the namespace of this node. For the default namespace, return an empty string. For an unnamed node, return the empty string.

hasChildNodes

public boolean hasChildNodes()
Loads the real node and defers to it

Specified by:
hasChildNodes in interface NodeInfo
Overrides:
hasChildNodes in class NodeImpl
Returns:
true if the node has any children, false if the node has no children.

isSameNodeInfo

public boolean isSameNodeInfo(NodeInfo other)
Loads the real node and defers to it

Specified by:
isSameNodeInfo in interface NodeInfo
Overrides:
isSameNodeInfo in class NodeImpl
Returns:
true if this Node object and the supplied Node object represent the same node in the tree.

iterateAxis

public AxisIterator iterateAxis(byte axisNumber,
                                NodeTest nodeTest)
If only the attributes are accessed, uses ProxyAttributeEnumeration to serve up the pre-computed attributes. Otherwise, we load the real element and defer to it.

Specified by:
iterateAxis in interface NodeInfo
Overrides:
iterateAxis in class NodeImpl
Parameters:
axisNumber - The axis to be iterated over
nodeTest - A pattern to be matched by the returned nodes
Returns:
an AxisIterator that scans the nodes reached by the axis in turn.

getPrefix

public String getPrefix()
Loads the real node and defers to it

Specified by:
getPrefix in interface NodeInfo
Overrides:
getPrefix in class NodeImpl
Returns:
the prefix part of the name. For an unnamed node, return an empty string.

copy

public void copy(Receiver out,
                 int whichNamespaces,
                 boolean copyAnnotations,
                 int locationId)
          throws XPathException
Loads the real node and defers to it

Specified by:
copy in interface NodeInfo
Throws:
XPathException

getNamePool

public NamePool getNamePool()
Loads the real node and defers to it

Specified by:
getNamePool in interface NodeInfo
Overrides:
getNamePool in class NodeImpl

getNodeKind

public int getNodeKind()
Loads the real node and defers to it

Specified by:
getNodeKind in interface NodeInfo

iterateAxis

public AxisIterator iterateAxis(byte axisNumber)
Loads the real node and defers to it

Specified by:
iterateAxis in interface NodeInfo
Overrides:
iterateAxis in class NodeImpl
Parameters:
axisNumber - The axis to be iterated over
Returns:
an AxisIterator that scans the nodes reached by the axis in turn.

setSystemId

public void setSystemId(String systemId)
Loads the real node and defers to it

Specified by:
setSystemId in interface Source
Overrides:
setSystemId in class NodeImpl

getDisplayName

public String getDisplayName()
Loads the real node and defers to it

Specified by:
getDisplayName in interface NodeInfo
Overrides:
getDisplayName in class NodeImpl
Returns:
The display name of this node. For a node with no name, return an empty string.

getDocumentNumber

public int getDocumentNumber()
Loads the real node and defers to it

Specified by:
getDocumentNumber in interface NodeInfo
Overrides:
getDocumentNumber in class NodeImpl

getDocumentRoot

public DocumentInfo getDocumentRoot()
Loads the real node and defers to it

Specified by:
getDocumentRoot in interface NodeInfo
Overrides:
getDocumentRoot in class NodeImpl
Returns:
the DocumentInfo representing the containing document

getRoot

public NodeInfo getRoot()
Loads the real node and defers to it

Specified by:
getRoot in interface NodeInfo
Overrides:
getRoot in class NodeImpl
Returns:
the NodeInfo representing the containing document

getTypeAnnotation

public int getTypeAnnotation()
Loads the real node and defers to it

Specified by:
getTypeAnnotation in interface NodeInfo
Overrides:
getTypeAnnotation in class NodeImpl

sendNamespaceDeclarations

public void sendNamespaceDeclarations(Receiver out,
                                      boolean includeAncestors)
                               throws XPathException
Loads the real node and defers to it

Specified by:
sendNamespaceDeclarations in interface NodeInfo
Overrides:
sendNamespaceDeclarations in class NodeImpl
Parameters:
out - The relevant outputter
includeAncestors - True if namespaces declared on ancestor elements must
Throws:
XPathException

getColumnNumber

public int getColumnNumber()
Loads the real node and defers to it

Specified by:
getColumnNumber in interface SourceLocator
Overrides:
getColumnNumber in class NodeImpl

getDeclaredNamespaces

public int[] getDeclaredNamespaces(int[] buffer)
Loads the real node and defers to it

Specified by:
getDeclaredNamespaces in interface NodeInfo
Overrides:
getDeclaredNamespaces in class NodeImpl
Parameters:
buffer - If this is non-null, and the result array fits in this buffer, then the result may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
Returns:
An array of integers representing the namespace declarations and undeclarations present on this element. For a node other than an element, return null. Otherwise, the returned array is a sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The top half word of each namespace code represents the prefix, the bottom half represents the URI. If the bottom half is zero, then this is a namespace undeclaration rather than a declaration. The XML namespace is never included in the list. If the supplied array is larger than required, then the first unused entry will be set to -1.

For a node other than an element, the method returns null.


getLineNumber

public int getLineNumber()
Loads the real node and defers to it

Specified by:
getLineNumber in interface SourceLocator
Specified by:
getLineNumber in interface NodeInfo
Overrides:
getLineNumber in class NodeImpl

getPublicId

public String getPublicId()
Loads the real node and defers to it

Specified by:
getPublicId in interface SourceLocator
Overrides:
getPublicId in class NodeImpl

getStringValueCS

public CharSequence getStringValueCS()
Loads the real node and defers to it

Specified by:
getStringValueCS in interface Item
Specified by:
getStringValueCS in interface ValueRepresentation
Overrides:
getStringValueCS in class NodeImpl

getTypedValue

public SequenceIterator getTypedValue()
                               throws XPathException
Loads the real node and defers to it

Specified by:
getTypedValue in interface Item
Overrides:
getTypedValue in class NodeImpl
Throws:
XPathException

atomize

public Value atomize()
              throws XPathException
Description copied from class: NodeImpl
Get the typed value. The result of this method will always be consistent with the method Item.getTypedValue(). However, this method is often more convenient and may be more efficient, especially in the common case where the value is expected to be a singleton.

Specified by:
atomize in interface NodeInfo
Overrides:
atomize in class NodeImpl
Returns:
the typed value. If requireSingleton is set to true, the result will always be an AtomicValue. In other cases it may be a Value representing a sequence whose items are atomic values.
Throws:
XPathException