org.inria.ns.reflex.processor.xcl.xml
Class XMLContext

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

public abstract class XMLContext
extends Object
implements List, XMLListener

A context specific for handling XML objects.

This context is live : when an item is added, it is processed immediately.

For SAX elements, an event is kept as long as no content has been yet encountered or until it ends. This strategy allow elements to be updated (for example by adding or removing an attribute) as long as no operation that consist on appending child nodes has been processed : this context will fire the event when necessary.

Author:
Philippe Poulard

Nested Class Summary
static class XMLContext.Guard
          A guard that protect the creation of a SAX or DOM context.
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.xml.XMLListener
DUMMY_LISTENER
 
Constructor Summary
XMLContext(XMLContext.Guard guard)
          Default constructor.
 
Method Summary
 void add(int index, Object element)
           
 boolean add(Object o)
          Add an object to this context.
 boolean addAll(Collection c)
           
 boolean addAll(int index, Collection c)
           
 void attributeAdded(Attr attr)
          Set an attribute as the context if it is set by <xcl:attribute> or <xcl:namespace-declaration>.
 void attributeValueUpdated(Attr attr)
          Do nothing.
 void clear()
           
 void commentUpdated(Comment comment)
          Do nothing.
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 boolean equals(Object obj)
           
 Object get(int index)
           
 Node getNode()
          Get the current node of this context.
 DOMFragment getRootNode()
          Get the root node of this context.
 int hashCode()
           
 int indexOf(Object o)
           
 boolean isEmpty()
           
 Iterator iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
static XMLContext newXMLContext(DataSet dataSet)
          Create a new XML context.
 void processingInstructionUpdated(ProcessingInstruction processingInstruction)
          Do nothing.
 Object remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 boolean retainAll(Collection c)
           
 Object set(int index, Object element)
           
 void setAttributeAsContext(boolean b)
          Indicates whether an attribute can become the context or not.
 void setContainerAsContext(boolean b)
          Indicates whether an XML container can become the context or not.
 void setNode(Node node)
          Set the current node of this context.
 int size()
           
 List subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 String toString()
          Full dump of the tree of this context
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.inria.ns.reflex.xml.XMLListener
convertSAXToDOM, nodeAppended, textUpdated
 

Constructor Detail

XMLContext

public XMLContext(XMLContext.Guard guard)
Default constructor.

Parameters:
guard - The guard that protect the construction of this context.
See Also:
XMLContext.Guard.protect()
Method Detail

newXMLContext

public static XMLContext newXMLContext(DataSet dataSet)
                                throws ExecutionException
Create a new XML context.

If a SAX feeder is present in the given data set, a SAXContext will be created, otherwise a DOMContext will be created.

Parameters:
dataSet - The data set to look into.
Returns:
A DOM context or a SAX context.
Throws:
ExecutionException

setAttributeAsContext

public void setAttributeAsContext(boolean b)
Indicates whether an attribute can become the context or not.

Parameters:
b - true if this context is used by <xcl:attribute> or <xcl:namespace-declaration>, false otherwise.

setContainerAsContext

public void setContainerAsContext(boolean b)
Indicates whether an XML container can become the context or not.

Parameters:
b - true if this context is used by <xcl:element> or <xcl:document>, false otherwise.

attributeAdded

public void attributeAdded(Attr attr)
Set an attribute as the context if it is set by <xcl:attribute> or <xcl:namespace-declaration>.

Specified by:
attributeAdded in interface XMLListener
Parameters:
attr - The candidate context.
See Also:
XMLListener.attributeAdded(org.w3c.dom.Attr)

attributeValueUpdated

public void attributeValueUpdated(Attr attr)
Do nothing.

Specified by:
attributeValueUpdated in interface XMLListener
Parameters:
attr - The attribute which value has changed.
See Also:
XMLListener.attributeValueUpdated(org.w3c.dom.Attr)

commentUpdated

public void commentUpdated(Comment comment)
Do nothing.

Specified by:
commentUpdated in interface XMLListener
Parameters:
comment - The comment which value has changed.
See Also:
XMLListener.commentUpdated(org.w3c.dom.Comment)

processingInstructionUpdated

public void processingInstructionUpdated(ProcessingInstruction processingInstruction)
Do nothing.

Specified by:
processingInstructionUpdated in interface XMLListener
Parameters:
processingInstruction - The processing instruction which value has changed.
See Also:
XMLListener.processingInstructionUpdated(org.w3c.dom.ProcessingInstruction)

getNode

public Node getNode()
Get the current node of this context.

Returns:
The node.

setNode

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

Used only to restore the previous context node.

Parameters:
node - The node.

getRootNode

public DOMFragment getRootNode()
Get the root node of this context.

Returns:
The root.

add

public boolean add(Object o)
Add an object to this context.

Specified by:
add in interface Collection
Specified by:
add in interface List
Parameters:
o - The object to add.
Returns:
true

add

public void add(int index,
                Object element)
Specified by:
add in interface List
Parameters:
index -
element -

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List
Parameters:
index -
c -
Returns:

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
Parameters:
c -
Returns:

clear

public void clear()
Specified by:
clear in interface Collection
Specified by:
clear in interface List

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection
Specified by:
contains in interface List
Parameters:
o -
Returns:

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface List
Parameters:
c -
Returns:

equals

public boolean equals(Object obj)
Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

get

public Object get(int index)
Specified by:
get in interface List
Parameters:
index -
Returns:

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List
Parameters:
o -
Returns:

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface List
Returns:

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List
Returns:

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List
Parameters:
o -
Returns:

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List
Returns:

listIterator

public ListIterator listIterator(int index)
Specified by:
listIterator in interface List
Parameters:
index -
Returns:

remove

public Object remove(int index)
Specified by:
remove in interface List
Parameters:
index -
Returns:

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface List
Parameters:
o -
Returns:

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List
Parameters:
c -
Returns:

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface List
Parameters:
c -
Returns:

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List
Parameters:
index -
element -
Returns:

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in interface List
Returns:

subList

public List subList(int fromIndex,
                    int toIndex)
Specified by:
subList in interface List
Parameters:
fromIndex -
toIndex -
Returns:

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
Returns:

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
Parameters:
a -
Returns:

toString

public String toString()
Full dump of the tree of this context

Overrides:
toString in class Object
See Also:
toString()