com.softwareag.tamino.db.api.io
Class TInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.softwareag.tamino.db.api.io.TInputStream
All Implemented Interfaces:
java.io.Closeable

public class TInputStream
extends java.io.FilterInputStream

TInputStream represents a Tamino specific InputStream. This stream class extends FilterInputStream. It decorates a given InputStream and contains a TStreamHeader. A TStreamHeader can contain further information about the stream content, such as collection and schema information.
In some rare cases it is neccessary to carry a exception with instead of an non-existing input stream. This cheating allows to postpone throwing of an exception while still processing the TSreamHeader!

Version:
$Revision: 1.19 $
Author:
Marcus Schreyer

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
TInputStream(java.lang.Exception failureException, TStreamHeader header)
          Special Constructor.
TInputStream(java.io.InputStream inputStream, TStreamHeader header)
          Special Constructor.
 
Method Summary
 void addCloseListener(TInputStreamCloseListener closeListener)
          Adds a close listener to this input stream.
 void close()
          Closes this input stream and releases any system resources associated with the stream.
 TException createTException()
          Constructs a TException with the returnvalue, code, messageline and messagetext from this TInputStream.
protected  void finalize()
          Try to close the inputStream.
 TCommandStatement getCommandStatement()
          Get the command statement which created this input stream.
 java.lang.String getCursorHandle()
          Returns the cursor handle from the TInputStream returned by openCursor() method of accessor, returns null otherwise
 java.lang.Exception getFailureException()
          Gets the failure exception as a Exception instance.
 java.lang.String getFirstObjectId()
          Get the Tamino object id.
 TStreamHeader getHeader()
          Gets the streams meta data as a TStreamHeader instance.
 java.lang.String getPreparedHandle()
          Returns the prepared query's handle from the TInputStream returned by _prepare, returns null otherwise.
 java.lang.String getReturnValue()
          Get the Tamino return value.
 boolean hasCommandStatement()
          Check whether this input stream contains a command statement.
 boolean hasFailureException()
          Checks whether this TInputStream instance contains an failure exception instance.
 boolean hasFirstObjectId()
          Checks whether this TInputStream instance contains an Tamino object id.
 boolean hasObjectContent()
          Checks whether this TInputStreams header instance contains an Tamino object content information, i.e.
 boolean hasReturnValue()
          Checks whether this TInputStream instance contains an Tamino return value.
 boolean isGiven()
          Checks whether this TInputStream instance contains an InputStream instance.
 void setCommandStatement(TCommandStatement commandStatement)
          Give this stream the commend statement.
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TInputStream

public TInputStream(java.io.InputStream inputStream,
                    TStreamHeader header)
Special Constructor. Initializes the stream with the decorated InputStream and the given TStreamHeader instance.

Parameters:
inputStream - the InputStream instance decorated by this TInputStream instance.
header - the TStreamHeader instance to contain meta information.

TInputStream

public TInputStream(java.lang.Exception failureException,
                    TStreamHeader header)
Special Constructor. Initializes the stream with a exception in the case of an communication error and the given TStreamHeader instance. The decorated input stream is set to null.

Parameters:
failureException - the exception instance that caused a problem.
header - the TStreamHeader instance to contain meta information.
Method Detail

getHeader

public TStreamHeader getHeader()
Gets the streams meta data as a TStreamHeader instance.

Returns:
the TStreamHeader instance if present, otherwise null.

getFailureException

public java.lang.Exception getFailureException()
Gets the failure exception as a Exception instance.

Returns:
the Exception instance if present, otherwise null.

isGiven

public boolean isGiven()
Checks whether this TInputStream instance contains an InputStream instance.

Returns:
true if this TInputStream instance contains an InputStream instance, otherwise false.

hasReturnValue

public boolean hasReturnValue()
Checks whether this TInputStream instance contains an Tamino return value. Under certain circumstances it is possible that Tamino gives as the ino:returnValue of the response within the TStreamHeader. In such a case it might be possible to avoid parsing the input stream.

Returns:
true if this TInputStream instance contains an Tamino return value.

getReturnValue

public java.lang.String getReturnValue()
Get the Tamino return value. Under certain circumstances it is possible that Tamino gives as the ino:returnValue of the response within the TStreamHeader. In such a case it might be possible to avoid parsing the input stream.

Returns:
the return value or null if not exisitent.

hasFirstObjectId

public boolean hasFirstObjectId()
Checks whether this TInputStream instance contains an Tamino object id. Under certain circumstances it is possible that Tamino gives us the first ino:id of the response within the TStreamHeader. In such a case it might be possible to avoid parsing the input stream.

Returns:
true if this TInputStream instance contains an Tamino object id.

getFirstObjectId

public java.lang.String getFirstObjectId()
Get the Tamino object id. Under certain circumstances it is possible that Tamino gives as the first ino:id of the response within the TStreamHeader. In such a case it might be possible to avoid parsing the input stream.

Returns:
the object id or null if not exisitent.

hasObjectContent

public boolean hasObjectContent()
Checks whether this TInputStreams header instance contains an Tamino object content information, i.e. ino:id, ino:collection, ino:id and ino:doctype. Under certain circumstances it is possible that Tamino gives us the first object content of the response within the TStreamHeader. In such a case it might be possible to avoid parsing the input stream.

Returns:
true if this TInputStream instance contains an Tamino object content.

getCommandStatement

public TCommandStatement getCommandStatement()
Get the command statement which created this input stream.

Returns:
the command statement for this input stream

setCommandStatement

public void setCommandStatement(TCommandStatement commandStatement)
Give this stream the commend statement.

Parameters:
commandStatement - the command statement for this input stream

hasCommandStatement

public boolean hasCommandStatement()
Check whether this input stream contains a command statement.

Returns:
command statement available?

hasFailureException

public boolean hasFailureException()
Checks whether this TInputStream instance contains an failure exception instance.

Returns:
true if this TInputStream instance contains an failure exception instance, otherwise false.

close

public void close()
           throws java.io.IOException
Closes this input stream and releases any system resources associated with the stream. Additionally the registered TInputStreamCloseListener will be notified. The notification will only be executed once per stream regardless of how often close() will be called.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException - rethrows the original IOException.

addCloseListener

public void addCloseListener(TInputStreamCloseListener closeListener)
Adds a close listener to this input stream. The added close listener will be called when this stream has been closed(). The notification will only be executed once per stream regardless of how often close() will be called.

Note: This can only be set once!

Parameters:
closeListener - the close listener.

finalize

protected void finalize()
                 throws java.lang.Throwable
Try to close the inputStream. This may sooth the 8285 problem.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getCursorHandle

public java.lang.String getCursorHandle()
                                 throws TException
Returns the cursor handle from the TInputStream returned by openCursor() method of accessor, returns null otherwise

Returns:
handle if present, null otherwise.
Throws:
TException

getPreparedHandle

public java.lang.String getPreparedHandle()
                                   throws TException
Returns the prepared query's handle from the TInputStream returned by _prepare, returns null otherwise. Only for internal use

Returns:
handle if present, null otherwise.
Throws:
TException

createTException

public TException createTException()
Constructs a TException with the returnvalue, code, messageline and messagetext from this TInputStream. Only for Internal use

Returns:
TException


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