com.softwareag.tamino.db.api.objectModel.stream
Class TStreamAdapter

java.lang.Object
  extended by com.softwareag.tamino.db.api.objectModel.TDataObject
      extended by com.softwareag.tamino.db.api.objectModel.TXMLObject
          extended by com.softwareag.tamino.db.api.objectModel.stream.TStreamAdapter
All Implemented Interfaces:
TStreamable, TXMLStreamable, java.io.Serializable

public class TStreamAdapter
extends TXMLObject
implements java.io.Serializable

TStreamAdapter is the adaption of a stream based object model to the TXMLObject class. It extends the TXMLObject class. XML data is internally represented only be byte or character input streams.

Version:
$Revision: 1.20 $
Author:
Marcus Schreyer
See Also:
Serialized Form

Constructor Summary
TStreamAdapter()
          Default Constructor.
TStreamAdapter(org.xml.sax.InputSource inputSource)
          Initializes the adapter with the given input source.
TStreamAdapter(org.xml.sax.InputSource inputSource, java.util.Locale locale)
          Initializes the adapter with the given input source.
TStreamAdapter(org.xml.sax.InputSource inputSource, java.lang.String systemId)
          Initializes the adapter with the given input source.
TStreamAdapter(org.xml.sax.InputSource inputSource, java.lang.String systemId, java.util.Locale locale)
          Initializes the adapter with the given input source.
TStreamAdapter(java.io.InputStream inputStream)
          Initializes the adapter with the given byte stream.
TStreamAdapter(java.io.InputStream inputStream, java.util.Locale locale)
          Initializes the adapter with the given byte stream.
TStreamAdapter(java.io.InputStream inputStream, java.lang.String systemId)
          Initializes the adapter with the given byte stream.
TStreamAdapter(java.io.InputStream inputStream, java.lang.String systemId, java.util.Locale locale)
          Initializes the adapter with the given byte stream.
TStreamAdapter(java.util.Locale locale)
          Default Constructor.
TStreamAdapter(java.io.Reader reader)
          Initializes the adapter with the given character stream.
TStreamAdapter(java.io.Reader reader, java.util.Locale locale)
          Initializes the adapter with the given character stream.
TStreamAdapter(java.io.Reader reader, java.lang.String systemId)
          Initializes the adapter with the given character stream.
TStreamAdapter(java.io.Reader reader, java.lang.String systemId, java.util.Locale locale)
          Initializes the adapter with the given character stream.
 
Method Summary
protected  boolean canWriteToOutputStream()
          Indicates if this instance can be currently written to an output stream.
 java.lang.String getDocname()
          Gets the ino:docname from this Tamino data object.
 java.lang.String getDoctype()
          Gets the doctype for this Tamino data object.
 java.lang.Object getDocument()
          Gets the document instance of the underlying object model.
 java.lang.Object getElement()
          Gets element instance of the underlying object model.
 java.lang.String getId()
          Gets the ino:id attribute for the underlying XML data.
protected  void readDocumentStateFrom(java.io.ObjectInputStream in)
          This abstract method serves as a plugin method for readStateFrom.
 void readFrom(java.io.InputStream inputStream)
          Reads data from inputStream and initializes the concrete object.
 void readFrom(java.io.InputStream inputStream, java.lang.String systemId)
          Reads data from inputStream and initializes the concrete object.
 void readFrom(java.io.Reader reader)
          Reads data from reader and initializes the concrete object.
 void readFrom(java.io.Reader reader, java.lang.String systemId)
          Reads data from reader and initializes the concrete object.
 void setDocname(java.lang.String docname)
          Sets the ino:docname.
 void setId(java.lang.String id)
          Sets the ino:id for the XML instance.
protected  void writeDocumentStateTo(java.io.ObjectOutputStream out)
          This abstract method serves as a plugin method for writeStateTo.
 void writeTo(java.io.OutputStream outputStream, java.lang.String encoding)
          Writes the XML document represented by this TXMLObject instance to the outputStream passed as parameter.
 void writeTo(java.io.Writer writer, java.lang.String encoding)
          Writes the XML document represented by this TXMLObject instance to the Writer passed as parameter.
 
Methods inherited from class com.softwareag.tamino.db.api.objectModel.TXMLObject
getEncoding, getSystemId, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, setContentType, setEncoding, setProperty, setSystemId, writeTo, writeTo
 
Methods inherited from class com.softwareag.tamino.db.api.objectModel.TDataObject
getCollection, getContentType, getLastModified, getLocale, hasCollection, hasDocname, hasDoctype, hasId, readStateFrom, setCollection, setDoctype, setLastModified, setLocale, writeStateTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.softwareag.tamino.db.api.io.TStreamable
getContentType
 

Constructor Detail

TStreamAdapter

public TStreamAdapter()
Default Constructor. Initializes the adapter with no content.


TStreamAdapter

public TStreamAdapter(org.xml.sax.InputSource inputSource)
Initializes the adapter with the given input source.


TStreamAdapter

public TStreamAdapter(org.xml.sax.InputSource inputSource,
                      java.lang.String systemId)
Initializes the adapter with the given input source.


TStreamAdapter

public TStreamAdapter(java.io.Reader reader)
Initializes the adapter with the given character stream.


TStreamAdapter

public TStreamAdapter(java.io.Reader reader,
                      java.lang.String systemId)
Initializes the adapter with the given character stream.


TStreamAdapter

public TStreamAdapter(java.io.InputStream inputStream)
Initializes the adapter with the given byte stream.


TStreamAdapter

public TStreamAdapter(java.io.InputStream inputStream,
                      java.lang.String systemId)
Initializes the adapter with the given byte stream.


TStreamAdapter

public TStreamAdapter(java.util.Locale locale)
Default Constructor. Initializes the adapter with no content.


TStreamAdapter

public TStreamAdapter(org.xml.sax.InputSource inputSource,
                      java.util.Locale locale)
Initializes the adapter with the given input source.


TStreamAdapter

public TStreamAdapter(org.xml.sax.InputSource inputSource,
                      java.lang.String systemId,
                      java.util.Locale locale)
Initializes the adapter with the given input source.


TStreamAdapter

public TStreamAdapter(java.io.Reader reader,
                      java.util.Locale locale)
Initializes the adapter with the given character stream.


TStreamAdapter

public TStreamAdapter(java.io.Reader reader,
                      java.lang.String systemId,
                      java.util.Locale locale)
Initializes the adapter with the given character stream.


TStreamAdapter

public TStreamAdapter(java.io.InputStream inputStream,
                      java.util.Locale locale)
Initializes the adapter with the given byte stream.


TStreamAdapter

public TStreamAdapter(java.io.InputStream inputStream,
                      java.lang.String systemId,
                      java.util.Locale locale)
Initializes the adapter with the given byte stream.

Method Detail

setDocname

public void setDocname(java.lang.String docname)
Sets the ino:docname.

Overrides:
setDocname in class TXMLObject
Parameters:
docname - is the ino:docname attribute of the data object.

setId

public void setId(java.lang.String id)
Sets the ino:id for the XML instance.

Overrides:
setId in class TXMLObject
Parameters:
id - denoted the ino:id that should be set on an underlying element instance.

getDocname

public java.lang.String getDocname()
Gets the ino:docname from this Tamino data object.

Overrides:
getDocname in class TXMLObject
Returns:
the ino:docname attribute if available, otherwise an empty string.

getId

public java.lang.String getId()
Gets the ino:id attribute for the underlying XML data.

Overrides:
getId in class TXMLObject
Returns:
the ino:id if an element instance or an underlying stream with an id is given.

getDoctype

public java.lang.String getDoctype()
Gets the doctype for this Tamino data object. If the doctype has not been explicitly set the name of the root element is assumed as the doctype.

Overrides:
getDoctype in class TDataObject
Returns:
the name of the doctype of this TDataObject instance.

getDocument

public java.lang.Object getDocument()
Gets the document instance of the underlying object model. Here the document referrs to the input stream that is currently given. Since this input stream can be a byte or character input stream an org.xml.sax.InputSource instance is handed back that wrapps the concrete input stream. Please note, that getDocument and getElement deliver the same result.

Specified by:
getDocument in class TXMLObject
Returns:
The org.xml.sax.InputSource instance of the underlying object model, null if none is given.

getElement

public java.lang.Object getElement()
Gets element instance of the underlying object model. Here the element referrs to the input stream that is currently given. Since this input stream can be a byte or character input stream an org.xml.sax.InputSource instance is handed back that wrapps the concrete input stream. Please note, that getDocument and getElement deliver the same result.

Specified by:
getElement in class TXMLObject
Returns:
The org.xml.sax.InputSource instance of the underlying object model, null if none is given.

readFrom

public void readFrom(java.io.InputStream inputStream)
              throws TStreamReadException
Reads data from inputStream and initializes the concrete object.

Specified by:
readFrom in interface TStreamable
Parameters:
inputStream - denotes the byte stream from which the object is newly initialized.
Throws:
TStreamReadException - due to any problems when reading the stream.

readFrom

public void readFrom(java.io.InputStream inputStream,
                     java.lang.String systemId)
              throws TStreamReadException
Reads data from inputStream and initializes the concrete object.

Specified by:
readFrom in interface TXMLStreamable
Parameters:
inputStream - denotes the byte stream from which the object is newly initialized.
systemId - the base URI of the data to resolve relative references.
Throws:
TStreamReadException - due to any problems when reading the stream.

readFrom

public void readFrom(java.io.Reader reader)
              throws TStreamReadException
Reads data from reader and initializes the concrete object.

Specified by:
readFrom in interface TStreamable
Parameters:
reader - denotes the character stream from which the object is newly initialized.
Throws:
TStreamReadException - due to any problems when reading the stream.

readFrom

public void readFrom(java.io.Reader reader,
                     java.lang.String systemId)
              throws TStreamReadException
Reads data from reader and initializes the concrete object.

Specified by:
readFrom in interface TXMLStreamable
Parameters:
reader - denotes the character stream from which the object is newly initialized.
systemId - the base URI to resolve relative references.
Throws:
TStreamReadException - due to any problems when reading the stream.

writeTo

public void writeTo(java.io.OutputStream outputStream,
                    java.lang.String encoding)
             throws TStreamWriteException
Writes the XML document represented by this TXMLObject instance to the outputStream passed as parameter.

This method uses the given encoding. The given encoding is always set in the prologue of the stream, i.e. the prologue always looks like this: <?xml ... encoding="..." ...?> and the byte stream representing the XML document is always encoded with the given encoding.

Specified by:
writeTo in interface TXMLStreamable
Overrides:
writeTo in class TXMLObject
Parameters:
outputStream - the byte output stream.
encoding - the encoding used for serializing the XML document.
Throws:
TStreamWriteException - signals an error while attempting to write the stream.

writeTo

public void writeTo(java.io.Writer writer,
                    java.lang.String encoding)
             throws TStreamWriteException
Writes the XML document represented by this TXMLObject instance to the Writer passed as parameter.

This method uses the given encoding. The given encoding is always set in the prologue of the stream, i.e. the prologue always looks like this: <?xml ... encoding="..." ...?>. The character stream representing the XML document is normally not concerned with a particular encoding, unless an OutputStreamWriter is used. An OutputStreamWriter is a converter between a character stream and a byte stream. That conversion is done based on a specific encoding. If an OutputStreamWriter is used with any other encoding than given encoding, there will be a mismatch between the encoding set in the prologue and the encoding of the byte stream. It is therefore recommended to only use an OutputStreamWriter in conjunction with given encoding.

Specified by:
writeTo in interface TXMLStreamable
Overrides:
writeTo in class TXMLObject
Parameters:
writer - the character output stream writer.
encoding - the encoding used for serializing the XML document.
Throws:
TStreamWriteException - signals an error while attempting to write the stream.

canWriteToOutputStream

protected boolean canWriteToOutputStream()
Indicates if this instance can be currently written to an output stream.

Specified by:
canWriteToOutputStream in class TDataObject
Returns:
true if invocation of writeTo is possible, false otherwise.

writeDocumentStateTo

protected void writeDocumentStateTo(java.io.ObjectOutputStream out)
                             throws java.io.IOException
This abstract method serves as a plugin method for writeStateTo. Each time writeStateTo is called with the writeDocument parameter set to true, this method is invoked at the end of the operation. This method is needed for the implementation of serialization.

Overrides:
writeDocumentStateTo in class TDataObject
Parameters:
out - the ObjectOutputStream needed for serialization.
Throws:
java.io.IOException

readDocumentStateFrom

protected void readDocumentStateFrom(java.io.ObjectInputStream in)
                              throws java.io.IOException,
                                     java.lang.ClassNotFoundException
This abstract method serves as a plugin method for readStateFrom. Each time readStateFrom is called this method is invoked at the end of the operation. It is needed for the implementation of deserialization.

Overrides:
readDocumentStateFrom in class TDataObject
Parameters:
out - the ObjectOutputStream needed for serialization.
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright (c) 2013 Software AG. All Rights Reserved.