Class StatefulWriter
java.lang.Object
com.thoughtworks.xstream.io.WriterWrapper
com.thoughtworks.xstream.io.StatefulWriter
- All Implemented Interfaces:
ExtendedHierarchicalStreamWriter, HierarchicalStreamWriter
An wrapper for all
HierarchicalStreamWriter implementations, that keeps the state.
Writing in a wrong state will throw a StreamException, that wraps either an
IOException (writing to a closed writer) or an IllegalStateException. The
implementation will also track unbalanced nodes or multiple attributes with the same name.- Since:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FastStackprivate intprivate intstatic intSTATE_CLOSEDis the state if the writer has been closed.static intSTATE_NODE_ENDis the state if a node has endedstatic intSTATE_NODE_STARTis the state of a new node has been started.static intSTATE_OPENis the initial value of the writer.static intSTATE_VALUEis the state if the value of a node has been written.Fields inherited from class WriterWrapper
wrapped -
Constructor Summary
ConstructorsConstructorDescriptionStatefulWriter(HierarchicalStreamWriter wrapped) Constructs a StatefulWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(String name, String value) private voidvoidclose()Close the writer, if necessary.voidendNode()voidflush()Flush the writer, if necessary.private ObjectvoidWrite the value (text content) of the current node.voidvoidprivate voidintstate()Retrieve the state of the writer.Methods inherited from class WriterWrapper
underlyingWriter
-
Field Details
-
STATE_OPEN
public static int STATE_OPENSTATE_OPENis the initial value of the writer.- Since:
- 1.2
-
STATE_NODE_START
public static int STATE_NODE_STARTSTATE_NODE_STARTis the state of a new node has been started.- Since:
- 1.2
-
STATE_VALUE
public static int STATE_VALUESTATE_VALUEis the state if the value of a node has been written.- Since:
- 1.2
-
STATE_NODE_END
public static int STATE_NODE_ENDSTATE_NODE_ENDis the state if a node has ended- Since:
- 1.2
-
STATE_CLOSED
public static int STATE_CLOSEDSTATE_CLOSEDis the state if the writer has been closed.- Since:
- 1.2
-
state
private transient int state -
balance
private transient int balance -
attributes
-
-
Constructor Details
-
StatefulWriter
Constructs a StatefulWriter.- Parameters:
wrapped- the wrapped writer- Since:
- 1.2
-
-
Method Details
-
startNode
- Specified by:
startNodein interfaceHierarchicalStreamWriter- Overrides:
startNodein classWriterWrapper
-
startNode
- Specified by:
startNodein interfaceExtendedHierarchicalStreamWriter- Overrides:
startNodein classWriterWrapper
-
startNodeCommon
private void startNodeCommon() -
addAttribute
- Specified by:
addAttributein interfaceHierarchicalStreamWriter- Overrides:
addAttributein classWriterWrapper
-
setValue
Description copied from interface:HierarchicalStreamWriterWrite the value (text content) of the current node.- Specified by:
setValuein interfaceHierarchicalStreamWriter- Overrides:
setValuein classWriterWrapper
-
endNode
public void endNode()- Specified by:
endNodein interfaceHierarchicalStreamWriter- Overrides:
endNodein classWriterWrapper
-
flush
public void flush()Description copied from interface:HierarchicalStreamWriterFlush the writer, if necessary.- Specified by:
flushin interfaceHierarchicalStreamWriter- Overrides:
flushin classWriterWrapper
-
close
public void close()Description copied from interface:HierarchicalStreamWriterClose the writer, if necessary.- Specified by:
closein interfaceHierarchicalStreamWriter- Overrides:
closein 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:
-
readResolve
-