org.inria.ns.reflex.xml.sax
Class SAXNode

java.lang.Object
  extended by org.inria.ns.reflex.xml.sax.SAXNode
All Implemented Interfaces:
NamedType, Unwrappable, XOperable, NamedNode

public class SAXNode
extends Object
implements XOperable, Unwrappable, NamedNode

A SAXNode belongs to the sole branch held while reading an XML tree.

In fact, when the cache is active, new branches may grow, but branches will be pruned as long as the cache will be fetched.

A map is used to store the position and the size of each sibling by type and/or name : text(), comment(), processing-instruction(), processing-instruction(target), *, prefix:*, prefix:name.

Detailed strategy

Read the article.

Author:
Philippe Poulard
See Also:
XPathFilter

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Unwrappable
Unwrappable.Unwrapper
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.structures.Unwrappable
UNWRAPPER
 
Constructor Summary
SAXNode(Anticipable filter, NamedEvent event)
          Create a SAX node backed by a SAX event.
 
Method Summary
 Node asDOMNode()
          Return a DOM node twin of this SAXNode.
 Node asDOMNode(Document owner)
          Return a DOM node twin of this SAXNode.
 Node asDOMNode(Node cousin)
          Return a DOM node twin of this SAXNode.
 void endEvent(ContentHandler handler)
          Fire the underlying event.
 QName getDOMName()
          Return the name of this node.
 QName getTypeName()
          Return the type name of the underlying event.
 XOperator getXOperator()
          Return the XOperator for this type.
 QName getXPathName()
          Return the name of this node.
 boolean isDetached()
          Indicates whether this node is still in the tree.
 void normalize()
          Merge adjacent text nodes.
 void startEvent(ContentHandler handler)
          Fire the underlying event.
 String toString()
          Return this key and its counters.
 Object unwrap()
          Unwrap the underlying SAX event.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SAXNode

public SAXNode(Anticipable filter,
               NamedEvent event)
Create a SAX node backed by a SAX event.

Parameters:
filter - The SAX filter that can read forward on demand.
event - The underlying event.
Method Detail

getXOperator

public XOperator getXOperator()
Return the XOperator for this type.

Specified by:
getXOperator in interface XOperable
Returns:
The non null X-operator of this object.
See Also:
XOperable.getXOperator()

isDetached

public boolean isDetached()
Indicates whether this node is still in the tree.

A node that fire its end event is automatically detached from its tree. The underlying event can't be fired again.

Returns:
true if this node is no longer in the tree, false otherwise.

normalize

public void normalize()
Merge adjacent text nodes.

*** This method DOESN'T update size-related counters which might became them inconsistent, because some of them might already have been used. The best way to normalize safely, is to avoid reading forward BEFORE the normalization is asked. ***


startEvent

public void startEvent(ContentHandler handler)
                throws SAXException
Fire the underlying event.

Parameters:
handler - The handler that receives the event.
Throws:
SAXException

endEvent

public void endEvent(ContentHandler handler)
              throws SAXException
Fire the underlying event.

Nodes that are container (document, element) may have content. Other nodes can't.

Parameters:
handler - The handler that receives the event.
Throws:
SAXException

getDOMName

public QName getDOMName()
Return the name of this node.

Specified by:
getDOMName in interface NamedNode
Returns:
The name of this node.
See Also:
NamedNode.getDOMName()

getXPathName

public QName getXPathName()
Return the name of this node.

Specified by:
getXPathName in interface NamedNode
Returns:
The name of this node.
See Also:
NamedNode.getXPathName()

unwrap

public Object unwrap()
Unwrap the underlying SAX event.

Specified by:
unwrap in interface Unwrappable
Returns:
The SAX event, safely castable.
See Also:
Unwrappable.unwrap(), NamedEvent

toString

public String toString()
Return this key and its counters.

Overrides:
toString in class Object
Returns:
This name and its counters.

asDOMNode

public Node asDOMNode()
               throws ParserConfigurationException
Return a DOM node twin of this SAXNode.

The node will have its content -if any- and attributes.

Returns:
A new DOM node.
Throws:
ParserConfigurationException

asDOMNode

public Node asDOMNode(Node cousin)
Return a DOM node twin of this SAXNode.

The node will have its content -if any- and attributes.

Parameters:
cousin - A cousin node, that is to say the node created will have the same owner document than its cousin.
Returns:
A new DOM node.

asDOMNode

public Node asDOMNode(Document owner)
Return a DOM node twin of this SAXNode.

The node will have its content -if any- and attributes.

Parameters:
owner - The document that own this node.
Returns:
A new DOM node.
See Also:
SAXEvent#asDOMNode(Document)

getTypeName

public QName getTypeName()
Return the type name of the underlying event.

Specified by:
getTypeName in interface NamedType
Returns:
The type name of the event.