tribble.repository
Class AbstractStorableDocument

java.lang.Object
  extended by tribble.repository.AbstractDocument
      extended by tribble.repository.AbstractStorableDocument
All Implemented Interfaces:
java.io.Closeable, Document, StorableDocument

public abstract class AbstractStorableDocument
extends AbstractDocument
implements StorableDocument

Generic storable repository document.

A repository document is composed of content data (such as an image, text, or other kind of user data) and zero or more properties.

Most of the methods in this base class that implement the Document interface do not throw any checked exceptions.

Source code:
http://david.tribble.com/src/java/tribble/repository/AbstractStorableDocument.java
Documentation:
http://david.tribble.com/docs/tribble/repository/AbstractStorableDocument.html

Since:
2008-04-10
Version:
API 2.0, $Revision: 1.1 $ $Date: 2008/04/11 03:32:39 $
Author:
David R. Tribble (david@tribble.com)
Copyright ©2008 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by the United States Department of State as a terrorist or terrorist government or agency, to use and distribute this source code provided that the original copyright notice remains present and unaltered.

Field Summary
protected  java.io.InputStream m_in
          Input stream containing the contents of this document.
 
Fields inherited from class tribble.repository.AbstractDocument
m_id, m_props, m_propVals, m_size
 
Constructor Summary
protected AbstractStorableDocument(DocumentProperty[] props)
          Constructor.
 
Method Summary
 void addProperty(DocumentProperty prop)
          Add a property to this repository document.
 void close()
          Close this repository document.
protected  void closeDataStream()
          Close the input syteam for this repository document.
 void doneReading()
          Indicate that reading of the input data stream for this repository document is complete.
 void setDataStream(java.io.InputStream in)
          Establish the input data stream containing the contents of this repository document.
 void setID(java.lang.String id)
          Establish the ID of this repository document.
 void setProperty(java.lang.String prop, java.lang.Object val)
          Set the value of a property in this repository document.
 void setSize(long len)
          Establish the data size for this repository document.
 
Methods inherited from class tribble.repository.AbstractDocument
checkOpen, finalize, getID, getProperties, getProperty, getSize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface tribble.repository.Document
getDataStream, getID, getProperties, getProperty, getSize
 

Field Detail

m_in

protected java.io.InputStream m_in
Input stream containing the contents of this document.

Constructor Detail

AbstractStorableDocument

protected AbstractStorableDocument(DocumentProperty[] props)
Constructor.

Parameters:
props - The properties which define the documents in the repository.
Since:
API 2.0, 2008-04-10
Method Detail

closeDataStream

protected void closeDataStream()
Close the input syteam for this repository document. Deallocates all resources associated with the document. Any further use of the document will result in exceptions.

Note that this method can be called multiple times with no ill effects.

Note that this method does not throw any exceptions.

Since:
API 2.0, 2008-04-10

close

public void close()
Close this repository document. Deallocates all resources associated with the document. Any further use of the document will result in exceptions.

Note that this method can be called multiple times with no ill effects.

Note that this method does not throw any exceptions.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface Document
Overrides:
close in class AbstractDocument
Since:
API 2.0, 2008-04-10

setID

public void setID(java.lang.String id)
           throws java.io.IOException,
                  java.lang.UnsupportedOperationException
Establish the ID of this repository document.

Specified by:
setID in interface StorableDocument
Parameters:
id - A name that identifies the document within the repository. Whether or not this name is unique depends on the implementation. This cannot be null.
Throws:
java.io.IOException - Thrown if an error occurred while accessing the document.
java.lang.UnsupportedOperationException - (unchecked) Thrown if this operation is not allowed by the implementation, i.e., if IDs are assigned to repository documents by some other means.
java.lang.NullPointerException - (unchecked) Thrown if id is null.
java.lang.IllegalStateException - (unchecked) Thrown if close() has been called for this object.
Since:
API 2.0, 2008-04-10

setSize

public void setSize(long len)
Establish the data size for this repository document.

Specified by:
setSize in interface StorableDocument
Parameters:
len - The size (typically in bytes) of the document data, or -1 if the size is not known.
Throws:
java.lang.IllegalStateException - (unchecked) Thrown if close() has been called for this object.
Since:
API 2.0, 2008-04-10

setProperty

public void setProperty(java.lang.String prop,
                        java.lang.Object val)
                 throws java.io.IOException
Set the value of a property in this repository document.

Specified by:
setProperty in interface StorableDocument
Parameters:
prop - The name of the document property to set.
val - The new property value.
Throws:
java.io.IOException - Thrown if an error occurred while modifying the document.
java.lang.IllegalStateException - (unchecked) Thrown if close() has been called for this object.
Since:
API 2.0, 2008-04-10

addProperty

public void addProperty(DocumentProperty prop)
                 throws java.lang.UnsupportedOperationException,
                        java.io.IOException
Add a property to this repository document.

Specified by:
addProperty in interface StorableDocument
Parameters:
prop - A property to add to this document.
Throws:
java.io.IOException - Thrown if the property already exists in this document, or if an error occurred while modifying the document.
java.lang.UnsupportedOperationException - (unchecked) Thrown if this method is not supported by the implementation of this interface.
java.lang.IllegalStateException - (unchecked) Thrown if close() has been called for this object.
Since:
API 2.0, 2008-04-10

setDataStream

public void setDataStream(java.io.InputStream in)
                   throws java.io.IOException
Establish the input data stream containing the contents of this repository document.

Specified by:
setDataStream in interface StorableDocument
Parameters:
in - A binary data stream from which the contents of the document are to be read. The reading occurs when the RepositoryWriter.storeDocument() method is called and passed this document object. The stream will be closed (by calling its close() method) after the data is completely read from the stream (i.e., its read() method returns -1). The stream will also be closed (if it is still open) when this document object's close() method is called.
Throws:
java.io.IOException - Thrown if an error occurred while accessing the document.
java.lang.NullPointerException - (unchecked) Thrown if in is null.
Since:
API 2.0, 2008-04-10

doneReading

public void doneReading()
Indicate that reading of the input data stream for this repository document is complete.

This method is called when the RepositoryWriter.storeDocument() method is called and passed this document object, once all of the content data for the document has been read. The input stream is closed (by calling its close() method), and then this method is called. Any other resources associated with this document should then be deallocated.

Specified by:
doneReading in interface StorableDocument
Since:
API 2.0, 2008-04-10