com.thoughtworks.xstream.io
Class AbstractWriter

java.lang.Object
  extended by com.thoughtworks.xstream.io.AbstractWriter
All Implemented Interfaces:
ExtendedHierarchicalStreamWriter, HierarchicalStreamWriter
Direct Known Subclasses:
AbstractJsonWriter, AbstractXmlWriter

public abstract class AbstractWriter
extends Object
implements ExtendedHierarchicalStreamWriter

Abstract base class for all HierarchicalStreamWriter implementations. Implementations of HierarchicalStreamWriter should rather be derived from this class then implementing the interface directly.

Since:
1.4
Author:
Jörg Schaible

Constructor Summary
protected AbstractWriter()
          Creates an AbstractWriter with a NameCoder that does nothing.
protected AbstractWriter(NameCoder nameCoder)
          Creates an AbstractWriter with a provided NameCoder.
 
Method Summary
 String encodeAttribute(String name)
          Encode the attribute name into the name of the target format.
 String encodeNode(String name)
          Encode the node name into the name of the target format.
 void startNode(String name, Class clazz)
          
 HierarchicalStreamWriter underlyingWriter()
          Return the underlying HierarchicalStreamWriter implementation.
 
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, close, endNode, flush, setValue, startNode
 

Constructor Detail

AbstractWriter

protected AbstractWriter()
Creates an AbstractWriter with a NameCoder that does nothing.

Since:
1.4

AbstractWriter

protected AbstractWriter(NameCoder nameCoder)
Creates an AbstractWriter with a provided NameCoder.

Parameters:
nameCoder - the name coder used to write names in the target format
Since:
1.4
Method Detail

startNode

public void startNode(String name,
                      Class clazz)

Specified by:
startNode in interface ExtendedHierarchicalStreamWriter

underlyingWriter

public HierarchicalStreamWriter underlyingWriter()
Return the underlying HierarchicalStreamWriter implementation.

If a Converter needs to access methods of a specific HierarchicalStreamWriter implementation that are not defined in the HierarchicalStreamWriter interface, it should call this method before casting. This is because the writer passed to the Converter is often wrapped/decorated by another implementation to provide additional functionality (such as XPath tracking).

For example:

MySpecificWriter mySpecificWriter = (MySpecificWriter)writer; // INCORRECT!
 mySpecificWriter.doSomethingSpecific();
MySpecificWriter mySpecificWriter = (MySpecificWriter)writer.underlyingWriter();  // CORRECT!
 mySpecificWriter.doSomethingSpecific();

Implementations of HierarchicalStreamWriter should return 'this', unless they are a decorator, in which case they should delegate to whatever they are wrapping.

Specified by:
underlyingWriter in interface HierarchicalStreamWriter

encodeNode

public String encodeNode(String name)
Encode the node name into the name of the target format.

Parameters:
name - the original name
Returns:
the name in the target format
Since:
1.4

encodeAttribute

public String encodeAttribute(String name)
Encode the attribute name into the name of the target format.

Parameters:
name - the original name
Returns:
the name in the target format
Since:
1.4


Copyright © 2004-2014 XStream. All Rights Reserved.