biz.c24.io.api.presentation
Class XMLSink

java.lang.Object
  extended by biz.c24.io.api.presentation.Sink
      extended by biz.c24.io.api.presentation.XMLSink
All Implemented Interfaces:
Serializable, Cloneable

public class XMLSink
extends Sink

A sink for generating XML from data objects. A common usage of this class would be:

 FileOutputStream out = new FileOutputStream("myfile.xml"); // note: stream clean up code has been ommited for clarity
 XMLSink snk = new XMLSink(out);
 snk.writeObject(myObj); // where my element is the root complex data object holding the data hierarchy to be formatted.
 
Note that this implementation is not synchronized. If multiple threads use an instance concurrently, it must be synchronized externally.

See Also:
Sink, Serialized Form

Constructor Summary
XMLSink()
          Constructs a new instance.
XMLSink(OutputStream stream)
          Constructs a new instance which will write to stream.
XMLSink(Writer writer)
          Constructs a new instance which will write to wrtier.
XMLSink(XMLSink clone)
          Constructs a new instance cloned from clone.
 
Method Summary
 void clearBatchIterators()
          Clears all batch iterators registered with this Sink.
 Object clone()
           
 org.apache.xml.serialize.OutputFormat getFormat()
          Returns the output format.
 SAXSink getWrappedSink()
          Returns the wrapped SAX sink on which this sink is based.
 boolean isHumanReadable()
          Deprecated. Use getFormat().getIndenting() instead.
 boolean isWriteOptionalDefaultValues()
          Deprecated. Use getWrappedSink().isWriteOptionalDefaultValues() instead.
 boolean isWriteOptionalFixedValues()
          Deprecated. Use getWrappedSink().isWriteOptionalFixedValues() instead.
 boolean isWriteXMLHeader()
          Deprecated. Use !getFormat().getOmitXMLDeclaration() instead.
 void registerBatchIterator(Class batchEntry, Iterator batchIterator)
          Register a batch iterator against a particular class of batch entry.
 void setFormat(org.apache.xml.serialize.OutputFormat format)
          Sets the output format.
 void setHumanReadable(boolean humanReadable)
          Deprecated. Use getFormat().setIndenting(boolean) instead.
 void setWriteOptionalDefaultValues(boolean writeOptionalDefaultValues)
          Deprecated. Use getWrappedSink().setWriteOptionalDefaultValues(boolean) instead.
 void setWriteOptionalFixedValues(boolean writeOptionalFixedValues)
          Deprecated. Use getWrappedSink().setWriteOptionalFixedValues(boolean) instead.
 void setWriteXMLHeader(boolean writeXMLHeader)
          Deprecated. Use getFormat().setOmitXMLDeclaration(!boolean) instead.
 void unregisterBatchIterator(Class batchEntry)
          Unregisters an iterator from a particular class of batch entry.
 void writeObject(ComplexDataObject obj)
          Writes an object to the writer or output stream that has been set.
 
Methods inherited from class biz.c24.io.api.presentation.Sink
checkInit, getEncoding, getOutputStream, getWriter, setEncoding, setOutputStream, setWriter, stream, writer
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLSink

public XMLSink()
Constructs a new instance.


XMLSink

public XMLSink(XMLSink clone)
Constructs a new instance cloned from clone.

Parameters:
clone - The instance to clone.

XMLSink

public XMLSink(OutputStream stream)
Constructs a new instance which will write to stream.

Parameters:
stream - The stream to write the XML data to.

XMLSink

public XMLSink(Writer writer)
Constructs a new instance which will write to wrtier.

Parameters:
writer - The writer to write the XML data to.
Method Detail

getWrappedSink

public SAXSink getWrappedSink()
Returns the wrapped SAX sink on which this sink is based.

The wrapped sink provides access to additional configuration properties.

Returns:
The sink.

getFormat

public org.apache.xml.serialize.OutputFormat getFormat()
Returns the output format.

The format object can be configured to control the style of the resulting XML.

Returns:
The format.

setFormat

public void setFormat(org.apache.xml.serialize.OutputFormat format)
Sets the output format.

Parameters:
format - The new format.

writeObject

public void writeObject(ComplexDataObject obj)
                 throws IOException
Description copied from class: Sink
Writes an object to the writer or output stream that has been set.

Specified by:
writeObject in class Sink
Parameters:
obj - The object to be written.
Throws:
IOException - If the complete object could not be written for any reason.

isWriteOptionalDefaultValues

public boolean isWriteOptionalDefaultValues()
Deprecated. Use getWrappedSink().isWriteOptionalDefaultValues() instead.

Returns whether optional default element and attribute values will be produced. The default value is false.

Returns:
Whether optional default values be produced.

setWriteOptionalDefaultValues

public void setWriteOptionalDefaultValues(boolean writeOptionalDefaultValues)
Deprecated. Use getWrappedSink().setWriteOptionalDefaultValues(boolean) instead.

Sets whether optional default element and attribute values will be produced.

Parameters:
writeOptionalDefaultValues - The new value.

isWriteOptionalFixedValues

public boolean isWriteOptionalFixedValues()
Deprecated. Use getWrappedSink().isWriteOptionalFixedValues() instead.

Returns whether optional fixed element and attribute values will be produced. The default value is false.

Returns:
Whether optional fixed values be produced.

setWriteOptionalFixedValues

public void setWriteOptionalFixedValues(boolean writeOptionalFixedValues)
Deprecated. Use getWrappedSink().setWriteOptionalFixedValues(boolean) instead.

Sets whether optional fixed element and attribute values will be produced.

Parameters:
writeOptionalFixedValues - The new value.

isHumanReadable

public boolean isHumanReadable()
Deprecated. Use getFormat().getIndenting() instead.

Returns whether human readable output will be produced, i.e. with newlines and indentations. The default value is true.

Returns:
Whether human readable output will be produced.

setHumanReadable

public void setHumanReadable(boolean humanReadable)
Deprecated. Use getFormat().setIndenting(boolean) instead.

Sets whether human readable output will be produced.

Parameters:
humanReadable - The new value.

isWriteXMLHeader

public boolean isWriteXMLHeader()
Deprecated. Use !getFormat().getOmitXMLDeclaration() instead.

Returns whether an XML header will be produced at the top of XML documents. The default value is true.

Returns:
Whether an XML header will be produced.

setWriteXMLHeader

public void setWriteXMLHeader(boolean writeXMLHeader)
Deprecated. Use getFormat().setOmitXMLDeclaration(!boolean) instead.

Sets whether an XML header will be produced at the top of XML documents.

Parameters:
writeXMLHeader - The new value.

registerBatchIterator

public void registerBatchIterator(Class batchEntry,
                                  Iterator batchIterator)
Description copied from class: Sink
Register a batch iterator against a particular class of batch entry.
Batch iterators provide a hook by which any number of instances can returned from the iterator and therefore appear in the output even though they are not referenced by the object supplied to the Sink.writeObject(biz.c24.io.api.data.ComplexDataObject) method.

Overrides:
registerBatchIterator in class Sink
Parameters:
batchEntry - The class of the generated Element, DataType, or ComplexDataObject to register the iterator against.
batchIterator - The iterator which will return the instances.

unregisterBatchIterator

public void unregisterBatchIterator(Class batchEntry)
Description copied from class: Sink
Unregisters an iterator from a particular class of batch entry.

Overrides:
unregisterBatchIterator in class Sink
Parameters:
batchEntry - The class which should be cleared from the map.
See Also:
Sink.registerBatchIterator(Class, java.util.Iterator)

clearBatchIterators

public void clearBatchIterators()
Description copied from class: Sink
Clears all batch iterators registered with this Sink.

Overrides:
clearBatchIterators in class Sink

clone

public Object clone()
Specified by:
clone in class Sink


C24 Technologies © 2002-2012: All Rights Reserved.