|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ArchiveWriter<DocType extends WritableDocument>
Generic document archive storage writer.
This interface contains the basic methods for implementing a document archive writer application. Such an application is responsible for managing a document storage system (or archive) that allows clients to store documents into it. How the archive system is implemented and what exactly constitutes a document is determined by each particular subclass that implements this interface.
A document consists of content data (such as an image, text, or other kind of user data) and one or more properties. Typically, the properties comprise the indices used to store the document in the archive system.
To create and store documents into an archive system, first an archive writer
object is created. The type of this object is a subclass which extends the
ArchiveWriter
class:
class MyArchiveWriter
extends ArchiveWriter
<MyWritableDocument>
{ ... }
Likewise, the documents that are stored into this archive system are of a
subclass which extends the WritableDocument
class:
class MyWritableDocument
extends WritableDocument
{ ...}
An archive writer is created and its initialize()
method
is called to initialize it:
MyArchiveWriter arch; Properties props; arch = new MyArchiveWriter(...); props = ...; arch.initialize(props);
Next, a connection to the archive system must be established and attached to the archive writer:
try
{
arch.open
();
}
catch (IOException ex)
{ ... }
Next, a new document is created and its properties are established:
MyWritableDocument doc;WritableProperty
prop; doc = arch.createDocument
(); prop = new WritableProperty(...); prop.setType
(...); prop.setLength
(...); ...other attributes of the property can be set... doc.addProperty
(prop); ...repeat for each document property...
Next, the contents of the document are established:
OutputStream ds;
ds = doc.putDataStream
();
...write content data to the document stream...
ds.close();
At this point, the document is fully populated and ready to be stored into the archive system:
try { String id; id = arch.storeDocument
(doc); ...store the document ID somewhere... doc.close
(); } catch (IOException ex) { ... }
This is repeated for each document that needs to be stored in the archive system.
Archive system implementations may optionally allow documents to be removed from the archive. This is done by specifying a specific document ID to be deleted. Implementations that allow this operation must ensure that the document ID uniquely identifies a single document within the archive:
try
{
String id;
id = ...;
arch.removeDocument
(id);
}
catch (IOException ex)
{ ... }
Once all documents have been stored or removed, the archive writer must be closed, breaking the connection and detaching it from the archive system:
arch.close
();
Exceptions (IOException) are thrown if any errors occur during processing.
Note: This requires Java 1.5 or later.
WritableDocument
,
WritableProperty
,
ArchiveReader
Field Summary | |
---|---|
static java.lang.String |
REV
|
Method Summary | |
---|---|
DocType |
createDocument()
Create a new empty document for the archive attached to this archive writer. |
void |
removeDocument(java.lang.String id)
Remove a document from the archive attached to this archive writer. |
void |
setDefaultProperties(DocumentProperty[] defs)
Establish the default properties for documents created by this archive writer. |
java.lang.String |
storeDocument(DocType doc)
Store a document into the archive attached to this archive writer. |
Methods inherited from interface tribble.archive.Archive |
---|
close, getDefaultProperties, initialize, open |
Field Detail |
---|
static final java.lang.String REV
Method Detail |
---|
void setDefaultProperties(DocumentProperty[] defs) throws java.io.IOException
Note that implementations are not required to support default document properties, in which case this method can throw an UnsupportedOperationException or simply do nothing.
java.lang.IllegalStateException
- (unchecked)
Thrown if initialize()
has not been called yet.
java.lang.UnsupportedOperationException
- (unchecked)
This operation is not supported, i.e., the implementation does not support
default document properties.
java.io.IOException
DocType createDocument() throws java.io.IOException
setDefaultProperties()
.
After the contents and properties are established for the document, it can
be stored in the archive by calling
storeDocument()
.
java.io.IOException
- Thrown if an error occurs while creating the document.
java.lang.IllegalStateException
- (unchecked)
Thrown if initialize()
has not been called yet.java.lang.String storeDocument(DocType doc) throws java.io.IOException
doc
- Document to store into the archive.
java.io.IOException
- Thrown if an error occurs while storing the document in the archive
system.
java.lang.IllegalStateException
- (unchecked)
Thrown if initialize()
has not been called yet.void removeDocument(java.lang.String id) throws java.io.IOException, java.lang.UnsupportedOperationException
id
- ID of a previously stored document to remove from the archive.
java.io.IOException
- Thrown if an error occurs while removing the document from the archive
system.
java.lang.UnsupportedOperationException
- (unchecked)
Thrown if this operation is not allowed by the implementation, i.e.,
if documents cannot be deleted from the archive.
java.lang.IllegalStateException
- (unchecked)
Thrown if initialize()
has not been called yet.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |