org.inria.ns.reflex.xml.dom
Class DOMFragment

java.lang.Object
  extended by org.inria.ns.reflex.xml.dom.DOMFragment
All Implemented Interfaces:
Iterable, Collection, List, Unwrappable, DocumentFragment, Node

public class DOMFragment
extends Object
implements Node, DocumentFragment, List, Unwrappable

A DocumentFragment must behave like a list ; this implementation is a wrapper.

It can also store attributes, namespaces, QNameSets, and DocTypes. It can track ID : imported elements that have an ID attribute are still reachable by their ID.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Unwrappable
Unwrappable.Unwrapper
 
Field Summary
 ImportStrategy importStrategy
          The import strategy.
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Fields inherited from interface org.inria.ns.reflex.structures.Unwrappable
UNWRAPPER
 
Constructor Summary
DOMFragment()
          Create a new document fragment and wrap it in this DOMFragment.
DOMFragment(DocumentFragment fragment)
          Wrap a document fragment in a DOMFragment that can be view like a List.
 
Method Summary
 void add(int index, Object element)
           
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 boolean addAll(int index, Collection c)
           
 void addDoc(Document document)
           
 void addDoc(DOMFragment fragment)
           
 Node appendChild(Node newChild)
           
 void clear()
           
 Node cloneNode(boolean deep)
           
 short compareDocumentPosition(Node other)
           
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 Object get(int index)
           
 NamedNodeMap getAttributes()
          Return a non-null map of attributes.
 String getBaseURI()
           
 NodeList getChildNodes()
           
 Element getElementById(String elementId)
          Get the element with the ID given.
 Object getFeature(String feature, String version)
           
 Node getFirstChild()
           
 Node getLastChild()
           
 String getLocalName()
           
 String getNamespaceURI()
           
 Node getNextSibling()
           
 String getNodeName()
           
 short getNodeType()
           
 String getNodeValue()
           
 Document getOwnerDocument()
           
 Node getParentNode()
           
 String getPrefix()
           
 Node getPreviousSibling()
           
 String getTextContent()
           
 Object getUserData(String key)
           
 boolean hasAttributes()
           
 boolean hasChildNodes()
           
 int indexOf(Object o)
           
 Node insertBefore(Node newChild, Node refChild)
           
 boolean isDefaultNamespace(String namespaceURI)
           
 boolean isEmpty()
           
 boolean isEqualNode(Node arg)
           
 boolean isSameNode(Node other)
           
 boolean isSupported(String feature, String version)
           
 Iterator iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 String lookupNamespaceURI(String prefix)
           
 String lookupPrefix(String namespaceURI)
           
 void normalize()
           
 Object remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 Node removeChild(Node oldChild)
           
 Node replaceChild(Node newChild, Node oldChild)
           
 boolean retainAll(Collection c)
           
 Object set(int index, Object element)
           
 void setElementId(Element element, String elementId)
          Set an ID to an element in this document.
 void setNodeValue(String nodeValue)
           
 void setPrefix(String prefix)
           
 void setTextContent(String textContent)
           
 Object setUserData(String key, Object data, UserDataHandler handler)
           
 int size()
           
 List subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 Object unwrap()
          Return the object wrapped.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Field Detail

importStrategy

public ImportStrategy importStrategy
The import strategy.

Constructor Detail

DOMFragment

public DOMFragment(DocumentFragment fragment)
Wrap a document fragment in a DOMFragment that can be view like a List.

Parameters:
fragment - The non-null fragment to wrap.
See Also:
unwrap()

DOMFragment

public DOMFragment()
Create a new document fragment and wrap it in this DOMFragment.

See Also:
unwrap()
Method Detail

getNodeName

public String getNodeName()
Specified by:
getNodeName in interface Node
See Also:
Node.getNodeName()

getNodeValue

public String getNodeValue()
                    throws DOMException
Specified by:
getNodeValue in interface Node
Throws:
DOMException
See Also:
Node.getNodeValue()

setNodeValue

public void setNodeValue(String nodeValue)
                  throws DOMException
Specified by:
setNodeValue in interface Node
Throws:
DOMException
See Also:
Node.setNodeValue(java.lang.String)

getNodeType

public short getNodeType()
Specified by:
getNodeType in interface Node
See Also:
Node.getNodeType()

getParentNode

public Node getParentNode()
Specified by:
getParentNode in interface Node
See Also:
Node.getParentNode()

getChildNodes

public NodeList getChildNodes()
Specified by:
getChildNodes in interface Node
See Also:
Node.getChildNodes()

getFirstChild

public Node getFirstChild()
Specified by:
getFirstChild in interface Node
See Also:
Node.getFirstChild()

getLastChild

public Node getLastChild()
Specified by:
getLastChild in interface Node
See Also:
Node.getLastChild()

getPreviousSibling

public Node getPreviousSibling()
Specified by:
getPreviousSibling in interface Node
See Also:
Node.getPreviousSibling()

getNextSibling

public Node getNextSibling()
Specified by:
getNextSibling in interface Node
See Also:
Node.getNextSibling()

getAttributes

public NamedNodeMap getAttributes()
Return a non-null map of attributes.

Specified by:
getAttributes in interface Node
Returns:
The map of attributes of this fragment.
See Also:
Node.getAttributes()

getOwnerDocument

public Document getOwnerDocument()
Specified by:
getOwnerDocument in interface Node
See Also:
Node.getOwnerDocument()

insertBefore

public Node insertBefore(Node newChild,
                         Node refChild)
                  throws DOMException
Specified by:
insertBefore in interface Node
Throws:
DOMException
See Also:
Node.insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)

replaceChild

public Node replaceChild(Node newChild,
                         Node oldChild)
                  throws DOMException
Specified by:
replaceChild in interface Node
Throws:
DOMException
See Also:
Node.replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)

removeChild

public Node removeChild(Node oldChild)
                 throws DOMException
Specified by:
removeChild in interface Node
Throws:
DOMException
See Also:
Node.removeChild(org.w3c.dom.Node)

appendChild

public Node appendChild(Node newChild)
                 throws DOMException
Specified by:
appendChild in interface Node
Throws:
DOMException
See Also:
Node.appendChild(org.w3c.dom.Node)

hasChildNodes

public boolean hasChildNodes()
Specified by:
hasChildNodes in interface Node
See Also:
Node.hasChildNodes()

cloneNode

public Node cloneNode(boolean deep)
Specified by:
cloneNode in interface Node
See Also:
Node.cloneNode(boolean)

normalize

public void normalize()
Specified by:
normalize in interface Node
See Also:
Node.normalize()

isSupported

public boolean isSupported(String feature,
                           String version)
Specified by:
isSupported in interface Node
See Also:
Node.isSupported(java.lang.String, java.lang.String)

getNamespaceURI

public String getNamespaceURI()
Specified by:
getNamespaceURI in interface Node
See Also:
Node.getNamespaceURI()

getPrefix

public String getPrefix()
Specified by:
getPrefix in interface Node
See Also:
Node.getPrefix()

setPrefix

public void setPrefix(String prefix)
               throws DOMException
Specified by:
setPrefix in interface Node
Throws:
DOMException
See Also:
Node.setPrefix(java.lang.String)

getLocalName

public String getLocalName()
Specified by:
getLocalName in interface Node
See Also:
Node.getLocalName()

hasAttributes

public boolean hasAttributes()
Specified by:
hasAttributes in interface Node
See Also:
Node.hasAttributes()

unwrap

public Object unwrap()
Description copied from interface: Unwrappable
Return the object wrapped. The object wrapped must be of the same type of the wrapper.

Specified by:
unwrap in interface Unwrappable
See Also:
Unwrappable.unwrap()

get

public Object get(int index)
Specified by:
get in interface List
See Also:
AbstractList.get(int)

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in interface List
See Also:
AbstractCollection.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface List
See Also:
List.isEmpty()

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection
Specified by:
contains in interface List
See Also:
List.contains(java.lang.Object)

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List
See Also:
List.iterator()

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
See Also:
List.toArray()

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
See Also:
List.toArray(java.lang.Object[])

add

public boolean add(Object o)
Specified by:
add in interface Collection
Specified by:
add in interface List
See Also:
List.add(java.lang.Object)

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface List
See Also:
List.remove(java.lang.Object)

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface List
See Also:
List.containsAll(java.util.Collection)

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
See Also:
List.addAll(java.util.Collection)

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List
See Also:
List.addAll(int, java.util.Collection)

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List
See Also:
List.removeAll(java.util.Collection)

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface List
See Also:
List.retainAll(java.util.Collection)

clear

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

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List
See Also:
List.set(int, java.lang.Object)

add

public void add(int index,
                Object element)
Specified by:
add in interface List
See Also:
List.add(int, java.lang.Object)

remove

public Object remove(int index)
Specified by:
remove in interface List
See Also:
List.remove(int)

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List
See Also:
List.indexOf(java.lang.Object)

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List
See Also:
List.lastIndexOf(java.lang.Object)

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List
See Also:
List.listIterator()

listIterator

public ListIterator listIterator(int index)
Specified by:
listIterator in interface List
See Also:
List.listIterator(int)

subList

public List subList(int fromIndex,
                    int toIndex)
Specified by:
subList in interface List
See Also:
List.subList(int, int)

getElementById

public Element getElementById(String elementId)
Get the element with the ID given.

Parameters:
elementId - The ID to look for.
Returns:
The element that has the ID given, or null.

setElementId

public void setElementId(Element element,
                         String elementId)
Set an ID to an element in this document.

Parameters:
element - The element.
elementId - Its ID.
See Also:
getElementById(String)

addDoc

public void addDoc(Document document)
Parameters:
document -

addDoc

public void addDoc(DOMFragment fragment)
Parameters:
fragment -

compareDocumentPosition

public short compareDocumentPosition(Node other)
                              throws DOMException
Specified by:
compareDocumentPosition in interface Node
Parameters:
other -
Returns:
Throws:
DOMException
See Also:
Node.compareDocumentPosition(org.w3c.dom.Node)

getBaseURI

public String getBaseURI()
Specified by:
getBaseURI in interface Node
Returns:
See Also:
Node.getBaseURI()

getFeature

public Object getFeature(String feature,
                         String version)
Specified by:
getFeature in interface Node
Parameters:
feature -
version -
Returns:
See Also:
Node.getFeature(java.lang.String, java.lang.String)

getTextContent

public String getTextContent()
                      throws DOMException
Specified by:
getTextContent in interface Node
Returns:
Throws:
DOMException
See Also:
Node.getTextContent()

getUserData

public Object getUserData(String key)
Specified by:
getUserData in interface Node
Parameters:
key -
Returns:
See Also:
Node.getUserData(java.lang.String)

isDefaultNamespace

public boolean isDefaultNamespace(String namespaceURI)
Specified by:
isDefaultNamespace in interface Node
Parameters:
namespaceURI -
Returns:
See Also:
Node.isDefaultNamespace(java.lang.String)

isEqualNode

public boolean isEqualNode(Node arg)
Specified by:
isEqualNode in interface Node
Parameters:
arg -
Returns:
See Also:
Node.isEqualNode(org.w3c.dom.Node)

isSameNode

public boolean isSameNode(Node other)
Specified by:
isSameNode in interface Node
Parameters:
other -
Returns:
See Also:
Node.isSameNode(org.w3c.dom.Node)

lookupNamespaceURI

public String lookupNamespaceURI(String prefix)
Specified by:
lookupNamespaceURI in interface Node
Parameters:
prefix -
Returns:
See Also:
Node.lookupNamespaceURI(java.lang.String)

lookupPrefix

public String lookupPrefix(String namespaceURI)
Specified by:
lookupPrefix in interface Node
Parameters:
namespaceURI -
Returns:
See Also:
Node.lookupPrefix(java.lang.String)

setTextContent

public void setTextContent(String textContent)
                    throws DOMException
Specified by:
setTextContent in interface Node
Parameters:
textContent -
Throws:
DOMException
See Also:
Node.setTextContent(java.lang.String)

setUserData

public Object setUserData(String key,
                          Object data,
                          UserDataHandler handler)
Specified by:
setUserData in interface Node
Parameters:
key -
data -
handler -
Returns:
See Also:
Node.setUserData(java.lang.String, java.lang.Object, org.w3c.dom.UserDataHandler)