Package com.thoughtworks.xstream.io.xml
Class AbstractDocumentWriter
- java.lang.Object
-
- com.thoughtworks.xstream.io.AbstractWriter
-
- com.thoughtworks.xstream.io.xml.AbstractXmlWriter
-
- com.thoughtworks.xstream.io.xml.AbstractDocumentWriter
-
- All Implemented Interfaces:
ExtendedHierarchicalStreamWriter
,HierarchicalStreamWriter
,DocumentWriter
,XmlFriendlyWriter
- Direct Known Subclasses:
DomWriter
,XppDomWriter
public abstract class AbstractDocumentWriter extends AbstractXmlWriter implements DocumentWriter
A genericHierarchicalStreamWriter
for DOM writer implementations. The implementation manages a list of top level DOM nodes. Every time the last node is closed on the node stack, the next started node is added to the list. This list can be retrieved using theDocumentWriter.getTopLevelNodes()
method.- Since:
- 1.2.1
-
-
Constructor Summary
Constructors Constructor Description AbstractDocumentWriter(java.lang.Object container, NameCoder nameCoder)
Constructs an AbstractDocumentWriter.AbstractDocumentWriter(java.lang.Object container, XmlFriendlyReplacer replacer)
Deprecated.As of 1.4 useAbstractDocumentWriter(Object, NameCoder)
instead.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Close the writer, if necessary.protected abstract java.lang.Object
createNode(java.lang.String name)
Create a node.void
endNode()
void
endNodeInternally()
Called when a node ends.void
flush()
Flush the writer, if necessary.protected java.lang.Object
getCurrent()
java.util.List
getTopLevelNodes()
Retrieve aList
with the top elements.void
startNode(java.lang.String name)
-
Methods inherited from class com.thoughtworks.xstream.io.xml.AbstractXmlWriter
escapeXmlName
-
Methods inherited from class com.thoughtworks.xstream.io.AbstractWriter
encodeAttribute, encodeNode, startNode, underlyingWriter
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.thoughtworks.xstream.io.HierarchicalStreamWriter
addAttribute, setValue, underlyingWriter
-
-
-
-
Field Detail
-
result
private final java.util.List result
-
nodeStack
private final FastStack nodeStack
-
-
Constructor Detail
-
AbstractDocumentWriter
public AbstractDocumentWriter(java.lang.Object container, NameCoder nameCoder)
Constructs an AbstractDocumentWriter.- Parameters:
container
- the top level container for the nodes to create (may benull
)nameCoder
- the object that creates XML-friendly names- Since:
- 1.4
-
AbstractDocumentWriter
public AbstractDocumentWriter(java.lang.Object container, XmlFriendlyReplacer replacer)
Deprecated.As of 1.4 useAbstractDocumentWriter(Object, NameCoder)
instead.Constructs an AbstractDocumentWriter.- Parameters:
container
- the top level container for the nodes to create (may benull
)replacer
- the object that creates XML-friendly names- Since:
- 1.2.1
-
-
Method Detail
-
startNode
public final void startNode(java.lang.String name)
- Specified by:
startNode
in interfaceHierarchicalStreamWriter
-
createNode
protected abstract java.lang.Object createNode(java.lang.String name)
Create a node. The provided node name is not yet XML friendly. IfgetCurrent()
returnsnull
the node is a top level node.- Parameters:
name
- the node name- Returns:
- the new node
- Since:
- 1.2.1
-
endNode
public final void endNode()
- Specified by:
endNode
in interfaceHierarchicalStreamWriter
-
endNodeInternally
public void endNodeInternally()
Called when a node ends. Hook for derived implementations.- Since:
- 1.2.1
-
getCurrent
protected final java.lang.Object getCurrent()
- Since:
- 1.2.1
-
getTopLevelNodes
public java.util.List getTopLevelNodes()
Description copied from interface:DocumentWriter
Retrieve aList
with the top elements. In the standard use case this list will only contain a single element. Additional elements can only occur, ifHierarchicalStreamWriter.startNode(String)
of the implementingHierarchicalStreamWriter
was called multiple times with an empty node stack. Such a situation occurs callingXStream.marshal(Object, HierarchicalStreamWriter)
multiple times directly.- Specified by:
getTopLevelNodes
in interfaceDocumentWriter
- Returns:
- a
List
with top nodes
-
flush
public void flush()
Description copied from interface:HierarchicalStreamWriter
Flush the writer, if necessary.- Specified by:
flush
in interfaceHierarchicalStreamWriter
-
close
public void close()
Description copied from interface:HierarchicalStreamWriter
Close the writer, if necessary.- Specified by:
close
in interfaceHierarchicalStreamWriter
-
-