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 allHierarchicalStreamWriterimplementations, 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
- Author:
- Jörg Schaible
-
-
Field Summary
Fields Modifier and Type Field Description static intSTATE_CLOSEDSTATE_CLOSEDis the state if the writer has been closed.static intSTATE_NODE_ENDSTATE_NODE_ENDis the state if a node has endedstatic intSTATE_NODE_STARTSTATE_NODE_STARTis the state of a new node has been started.static intSTATE_OPENSTATE_OPENis the initial value of the writer.static intSTATE_VALUESTATE_VALUEis 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 voidaddAttribute(java.lang.String name, java.lang.String value)voidclose()Close the writer, if necessary.voidendNode()voidflush()Flush the writer, if necessary.voidsetValue(java.lang.String text)Write the value (text content) of the current node.voidstartNode(java.lang.String name)voidstartNode(java.lang.String name, java.lang.Class clazz)intstate()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_OPENis the initial value of the writer.- Since:
- 1.2
-
STATE_NODE_START
public static int STATE_NODE_START
STATE_NODE_STARTis the state of a new node has been started.- Since:
- 1.2
-
STATE_VALUE
public static int STATE_VALUE
STATE_VALUEis 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_ENDis the state if a node has ended- Since:
- 1.2
-
STATE_CLOSED
public static int STATE_CLOSED
STATE_CLOSEDis the state if the writer has been closed.- Since:
- 1.2
-
-
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:
startNodein interfaceHierarchicalStreamWriter- Overrides:
startNodein classWriterWrapper
-
startNode
public void startNode(java.lang.String name, java.lang.Class clazz)- Specified by:
startNodein interfaceExtendedHierarchicalStreamWriter- Overrides:
startNodein classWriterWrapper
-
addAttribute
public void addAttribute(java.lang.String name, java.lang.String value)- Specified by:
addAttributein interfaceHierarchicalStreamWriter- Overrides:
addAttributein classWriterWrapper
-
setValue
public void setValue(java.lang.String text)
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
-
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
-
-