Package com.thoughtworks.xstream.io
Class StatefulWriter
- java.lang.Object
-
- com.thoughtworks.xstream.io.WriterWrapper
-
- com.thoughtworks.xstream.io.StatefulWriter
-
- All Implemented Interfaces:
ExtendedHierarchicalStreamWriter
,HierarchicalStreamWriter
public class StatefulWriter extends WriterWrapper
An wrapper for allHierarchicalStreamWriter
implementations, that keeps the state. Writing in a wrong state will throw aStreamException
, that wraps either anIOException
(writing to a closed writer) or anIllegalStateException
. The implementation will also track unbalanced nodes or multiple attributes with the same name.- Since:
- 1.2
-
-
Field Summary
Fields Modifier and Type Field Description private FastStack
attributes
private int
balance
private int
state
static int
STATE_CLOSED
STATE_CLOSED
is the state if the writer has been closed.static int
STATE_NODE_END
STATE_NODE_END
is the state if a node has endedstatic int
STATE_NODE_START
STATE_NODE_START
is the state of a new node has been started.static int
STATE_OPEN
STATE_OPEN
is the initial value of the writer.static int
STATE_VALUE
STATE_VALUE
is the state if the value of a node has been written.-
Fields inherited from class com.thoughtworks.xstream.io.WriterWrapper
wrapped
-
-
Constructor Summary
Constructors Constructor Description StatefulWriter(HierarchicalStreamWriter wrapped)
Constructs a StatefulWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(java.lang.String name, java.lang.String value)
private void
checkClosed()
void
close()
Close the writer, if necessary.void
endNode()
void
flush()
Flush the writer, if necessary.private java.lang.Object
readResolve()
void
setValue(java.lang.String text)
Write the value (text content) of the current node.void
startNode(java.lang.String name)
void
startNode(java.lang.String name, java.lang.Class clazz)
private void
startNodeCommon()
int
state()
Retrieve the state of the writer.-
Methods inherited from class com.thoughtworks.xstream.io.WriterWrapper
underlyingWriter
-
-
-
-
Field Detail
-
STATE_OPEN
public static int STATE_OPEN
STATE_OPEN
is the initial value of the writer.- Since:
- 1.2
-
STATE_NODE_START
public static int STATE_NODE_START
STATE_NODE_START
is the state of a new node has been started.- Since:
- 1.2
-
STATE_VALUE
public static int STATE_VALUE
STATE_VALUE
is the state if the value of a node has been written.- Since:
- 1.2
-
STATE_NODE_END
public static int STATE_NODE_END
STATE_NODE_END
is the state if a node has ended- Since:
- 1.2
-
STATE_CLOSED
public static int STATE_CLOSED
STATE_CLOSED
is the state if the writer has been closed.- Since:
- 1.2
-
state
private transient int state
-
balance
private transient int balance
-
attributes
private transient FastStack attributes
-
-
Constructor Detail
-
StatefulWriter
public StatefulWriter(HierarchicalStreamWriter wrapped)
Constructs a StatefulWriter.- Parameters:
wrapped
- the wrapped writer- Since:
- 1.2
-
-
Method Detail
-
startNode
public void startNode(java.lang.String name)
- Specified by:
startNode
in interfaceHierarchicalStreamWriter
- Overrides:
startNode
in classWriterWrapper
-
startNode
public void startNode(java.lang.String name, java.lang.Class clazz)
- Specified by:
startNode
in interfaceExtendedHierarchicalStreamWriter
- Overrides:
startNode
in classWriterWrapper
-
startNodeCommon
private void startNodeCommon()
-
addAttribute
public void addAttribute(java.lang.String name, java.lang.String value)
- Specified by:
addAttribute
in interfaceHierarchicalStreamWriter
- Overrides:
addAttribute
in classWriterWrapper
-
setValue
public void setValue(java.lang.String text)
Description copied from interface:HierarchicalStreamWriter
Write the value (text content) of the current node.- Specified by:
setValue
in interfaceHierarchicalStreamWriter
- Overrides:
setValue
in classWriterWrapper
-
endNode
public void endNode()
- Specified by:
endNode
in interfaceHierarchicalStreamWriter
- Overrides:
endNode
in classWriterWrapper
-
flush
public void flush()
Description copied from interface:HierarchicalStreamWriter
Flush the writer, if necessary.- Specified by:
flush
in interfaceHierarchicalStreamWriter
- Overrides:
flush
in classWriterWrapper
-
close
public void close()
Description copied from interface:HierarchicalStreamWriter
Close the writer, if necessary.- Specified by:
close
in interfaceHierarchicalStreamWriter
- Overrides:
close
in classWriterWrapper
-
checkClosed
private void checkClosed()
-
state
public int state()
Retrieve the state of the writer.- Returns:
- one of the states
- Since:
- 1.2
- See Also:
STATE_OPEN
,STATE_NODE_START
,STATE_VALUE
,STATE_NODE_END
,STATE_CLOSED
-
readResolve
private java.lang.Object readResolve()
-
-