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

java.lang.Object
  extended by org.inria.ns.reflex.processor.xcl.xml.XMLContext
      extended by org.inria.ns.reflex.xml.sax.SAXContext
All Implemented Interfaces:
Iterable, Collection, List, XMLListener

public class SAXContext
extends XMLContext
implements XMLListener

A SAXContext maintains a single DOM branch and sometimes few other nodes ; when a terminal event is fired, its counterpart node is pruned from the branch.

Events are fired as soon as a content is added to an element, except if the content is a whitespace. This allow elements to add/update/remove attributes.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from class org.inria.ns.reflex.processor.xcl.xml.XMLContext
XMLContext.Guard
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.xml.XMLListener
DUMMY_LISTENER
 
Constructor Summary
SAXContext(XMLContext.Guard guard, SAXFilter filter, DataSet dataSet)
          Create a new SAX context.
 
Method Summary
 void addXML(Object xml)
          Add an XML object to this context (the current node or a list of node).
 boolean convertSAXToDOM(XMLReader reader)
          Fire SAX events from the given reader.
static void generateEvent(Object item, SAXFilter filter, DataSet dataSet)
          Generate events while processing an item of the content.
 void nodeAppended(Node childNode)
          Flush some previously stored events according to the node type.
 void setNode(Node node)
          Set the current node of this context.
 void textUpdated(Text text)
          Flush the events if the text is not blank.
 
Methods inherited from class org.inria.ns.reflex.processor.xcl.xml.XMLContext
add, add, addAll, addAll, attributeAdded, attributeValueUpdated, clear, commentUpdated, contains, containsAll, equals, get, getNode, getRootNode, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, newXMLContext, processingInstructionUpdated, remove, remove, removeAll, retainAll, set, setAttributeAsContext, setContainerAsContext, size, subList, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.inria.ns.reflex.xml.XMLListener
attributeAdded, attributeValueUpdated, commentUpdated, processingInstructionUpdated
 

Constructor Detail

SAXContext

public SAXContext(XMLContext.Guard guard,
                  SAXFilter filter,
                  DataSet dataSet)
Create a new SAX context.

Parameters:
guard - A guard that protects the creation of this context.
filter - The target filter
dataSet - The data set to use.
See Also:
XMLContext.newXMLContext(DataSet)
Method Detail

addXML

public void addXML(Object xml)
Add an XML object to this context (the current node or a list of node).

If it is a DOM node, it is also set as the current node of this context.

Parameters:
xml - The content to add (attribute, element, etc).
See Also:
XMLContext.addXML(java.lang.Object)

setNode

public void setNode(Node node)
Set the current node of this context.

Overrides:
setNode in class XMLContext
Parameters:
node - The node.

generateEvent

public static void generateEvent(Object item,
                                 SAXFilter filter,
                                 DataSet dataSet)
                          throws SAXException,
                                 ExecutionException
Generate events while processing an item of the content.

Parameters:
item - The item to process.
  • a list
  • a node
  • a sax event
  • an XML reader
  • a string
filter - The consumer of the events.
dataSet - The data set in use when running the content.
Throws:
SAXException - When a SAX error occurs.
ExecutionException - When the content can't be performed.

nodeAppended

public void nodeAppended(Node childNode)
Flush some previously stored events according to the node type.

Specified by:
nodeAppended in interface XMLListener
Parameters:
childNode - The child node appended.
See Also:
XMLListener.nodeAppended(org.w3c.dom.Node)

convertSAXToDOM

public boolean convertSAXToDOM(XMLReader reader)
                        throws ExecutionException,
                               SAXException
Fire SAX events from the given reader.

Specified by:
convertSAXToDOM in interface XMLListener
Parameters:
reader - The XML source.
Returns:
false : the caller must not convert SAX events to DOM nodes.
Throws:
SAXException
ExecutionException
See Also:
XMLListener.convertSAXToDOM(org.xml.sax.XMLReader)

textUpdated

public void textUpdated(Text text)
Flush the events if the text is not blank.

Specified by:
textUpdated in interface XMLListener
Parameters:
text - The text to flush.
See Also:
XMLListener.textUpdated(org.w3c.dom.Text)