Package com.adobe.idp
Classpublic class Document
InheritanceDocument Inheritance Object

The Document class passes data of arbitrary size between different LiveCycle services and components via remote RMI calls. The Document can also be used to store the data in process maps.

These are the main features of the Document class:

Below are some examples how to use the Document class.

  1. Here is a simple usage scenario:
     java.io.InputStream is = new java.io.StringBufferInputStream("..."));
    Document input = new Document(is);
    input.passivate(); // save all data supplied by the input stream
    someLiveCycleService.loadInputData(input);
    someLiveCycleService.someBusinessMethod();
    Document output = someLiveCycleService.saveOutputData();
    java.io.InputStream resultStream = output.getInputStream();
    ...
    Note that the input.passivate call is optional. It simply guarantees that the input stream was fully read and detached from the Document instance. Without this call, reading the input stream is delayed until the data is requested, which in this case happens somewhere inside the someLiveCycleService.loadInputData call.
  2. Here is a more complex usage scenario demonstrating various Document APIs:
     Document input = new Document(new java.io.File("..."), true); // intending to own this file
    // ensure that the input document is disposed of upon the transaction end
    input.setTransactionBound(true);
    input.passivate(); // save all data supplied by the file and take over the file
    someLiveCycleService.loadInputData(data);
    someLiveCycleService.someBusinessMethod();
    Document middle = someLiveCycleService.saveOutputData();
    // ensure that the middle document is available for a long enough period of time
    middle.setDisposalTimeout(middle.getDisposalTimeout() + 60); // add extra 60 seconds
    anotherLiveCycleService.loadInputData(data);
    anotherLiveCycleService.loadInputData2(middle);
    anotherLiveCycleService.anotherBusinessMethod();
    Document output = anotherLiveCycleService.saveOutputData();
    com.adobe.service.DataBuffer dataBuffer = output.getDataBuffer();
    ...

As an indication of an error condition, any method of the Document class may throw a DocumentError exception. The DocumentError class is a runtime exception (it inherits from java.lang.RuntimeException). Runtime exceptions are also known as unchecked exceptions, as they don't need to be defined in the signature of the method throwing it. The unchecked exceptions (as opposed to checked exceptions which inherit from java.lang.Exception) simplify the user's code by trading off some type safety.

The following Document parameters are exposed through an external configuration:

NameTypeDefaultDescription
localDocumentStorageSweepIntervalpositive integer15The amount of time in seconds between attempts to delete any files that are no longer needed and that were used to pass the document data between LiveCycle components running on the same machine.
globalDocumentStorageSweepIntervalpositive integer30The amount of time in seconds between attempts to delete any files that are no longer needed that were used to pass the document data between LiveCycle components running on different machines. Specify this property only when deploying LiveCycle products in a clustered environment.
globalDocumentStorageRootDirstring pathnoneA path to an NFS shared directory used to store long-lived documents (the documents that are involved in a workflow process) and to share them among all cluster nodes. Specify this property only when deploying LiveCycle products in a clustered environment.
globalDocumentStorageForceNFStrue/falsefalseA switch controlling whether to use the NFS protocol to pass documents between different LiveCycle components. The NFS protocol must be used when deploying LiveCycle products in a clustered environment on Microsoft Windows. Note that additional NFS software should be installed on your Windows machine before enabling this option. This option does not affect UNIX deployments.
defaultDocumentMaxInlineSizepositive integer65536The maximum number of bytes that are kept in memory when passing documents between different LiveCycle components. The documents that exceed this maximum are swapped out to the disk drive. Use this property for performance tuning.
defaultDocumentDisposalTimeoutpositive integer600The maximum amount of time in seconds during which a document, which is passed between different LiveCycle components, is considered alive. After this time has passed, any files used to store this document are subject to removal. Use this property to control the use of disk space.

When using the Document class in the J2EE environment, the configuration parameters above are specified using Adobe Configuration Manager. When using the Document class in a standalone Java client, specify these parameters as Java system properties with a com.adobe.idp prefix (for example, com.adobe.idp.globalDocumentStorageRootDir).



Public Methods
 MethodDefined by
  
Document(byte[] data)
Creates a new Document out of the content specified by the byte array.
Document
  
Document(InputStream is)
Creates a new Document with the content provided by the java.io.InputStream object.
Document
  
Document(URL url)
Creates a new Document out of the content accessible via the URL.
Document
  
Document(File file, boolean own)
Creates a new Document out of the content stored in the file.
Document
  
Document(DocumentWriter writer, Object obj)
Do not use.
Document
  
Creates a copy of the Document supplied as input.
Document
  
void copyToFile(File file)
Copies the document content to a file specified by a caller.
Document
  
void dispose()
Disposes of any local temporary storage resources (for example, file, database data, and so on) occupied by the document content.
Document
  
Closes any resources opened by the Document object while reading the content with any of the Document object's read() methods.
Document
  
Serializable getAttribute(String name)
Returns the value of an attribute with a given name.
Document
  
Returns the current MIME type of the Document content.
Document
  
DataBuffer getDataBuffer()
Do not use.
Document
  
[static] Returns the default disposal timeout value.
Document
  
[static] Returns the default maximum size of the document content that can be embedded within the Document object.
Document
  
Returns the timeout value if it was set using the #setDisposalTimeout(int) method.
Document
  
File getFile()
Returns the document content in a file.
Document
  
InputStream getInputStream()
Returns the document content in a java.io.InputStream object.
Document
  
Returns the maximum size of the document content that can be embedded within the Document instance.
Document
  
Object getObject(DocumentReader reader)
Do not use.
Document
  
[static] Returns true if lazy passivation is on.
Document
  
Returns true or false depending on whether the Document lifetime is transaction-bound.
Document
  
long length()
Returns the Document content's length.
Document
  
Lists the names of all attributes associated with this Document instance.
Document
  
void passivate()
Saves the document content into some persistent form (file, database BLOB, and so on).
Document
  
Passivates the Document content (similar to the #passivate() method) in the global storage.
Document
  
int read(long pos)
Reads a byte of the Document object's content at the given position.
Document
  
int read(long pos, byte[] b, int off, int len)
Reads up to len bytes of the Document object's content into an array of bytes.
Document
  
void removeAttribute(String name)
Removes an attribute with the given name.
Document
  
void setAttribute(String name, Serializable value)
Sets the value of an attribute with a given name.
Document
  
void setContentType(String type)
Overwrites the current MIME type of the Document content.
Document
  
void setDefaultDisposalTimeout(int seconds)
[static] Sets the default disposal timeout value, which is used if the timeout is not set using the #setDisposalTimeout(int) method.
Document
  
void setDefaultMaxInlineSize(int bytes)
[static] Sets the default maximum size of the document content that can be embedded within the Document instance.
Document
  
void setDisposalTimeout(int seconds)
Sets the amount of time (in seconds) before the Document object is disposed of automatically.
Document
  
void setInitialContext(InitialContext ic)
[static] Use this method to set the InitialContext needed by the Document object in order to look up an internal server EJB, which is used to upload the Document object's content to the LiveCycle server.
Document
  
void setMaxInlineSize(int bytes)
Sets the maximum size of the document content that can be embedded within the Document instance.
Document
  
void setPassivationLazy(boolean enable)
[static] Use this method to override the default passivation behavior.
Document
  
void setTransactionBound(boolean value)
Used to specify whether the Document is transaction-bound.
Document
  
String toString()
Returns a text representation of the Document internal state.
Document
Constructor Detail
Document()
public Document(byte[] data)

Creates a new Document out of the content specified by the byte array.

In this case, the new Document simply keeps a reference to the input array. So, the input source should remain available until the Document content is passivated (saved to permanent storage). The passivation happens either explicitly when passivate() is called, or implicitly when one tries to read the Document object's content (for example, when getInputStream(), getFile(), or another access method is called). Implicit passivation can be triggered either locally (when the access method is called on the same Document instance that was created with this constructor), or remotely (when the access method is called on another Document instance that is a copy of the source Document instance done via a serialization or deserialization or passed via a remote RMI call).

Parameters
data — The byte array providing the input content.
Document() 
public Document(InputStream is)

Creates a new Document with the content provided by the java.io.InputStream object.

In this case, the new Document simply keeps a reference to the input stream. So, the input source should remain available until the Document content is passivated (saved to permanent storage). The passivation happens either explicitly when passivate() is called, or implicitly when one tries to read the Document object's content (for example, when getInputStream(), getFile(), or another access method is called). Implicit passivation can be triggered either locally (when the access method is called on the same Document instance that was created with this constructor), or remotely (when the access method is called on another Document instance that is a copy of the source Document instance done via a serialization or deserialization or passed via a remote RMI call).

Parameters
is — The java.io.InputStream object providing the input content.
Document() 
public Document(URL url)

Creates a new Document out of the content accessible via the URL.

In this case, the new Document simply keeps a reference to the input URL. So, the input source should remain available until the Document content is passivated (saved to permanent storage). The passivation happens either explicitly when passivate() is called, or implicitly when one tries to read the Document object's content (for example, when getInputStream(), getFile(), or another access method is called). Implicit passivation can be triggered either locally (when the access method is called on the same Document instance that was created with this constructor), or remotely (when the access method is called on another Document instance that is a copy of the source Document instance done via a serialization or deserialization or passed via a remote RMI call).

Parameters
url — The URL to the input content.
Document() 
public Document(File file, boolean own)

Creates a new Document out of the content stored in the file.

In this case, the new Document simply keeps a reference to the input file. So, the input source should remain available until the Document content is passivated (saved to permanent storage). The passivation happens either explicitly when passivate() is called, or implicitly when one tries to read the Document object's content (for example, when getInputStream(), getFile(), or another access method is called). Implicit passivation can be triggered either locally (when the access method is called on the same Document instance that was created with this constructor), or remotely (when the access method is called on another Document instance that is a copy of the source Document instance done via a serialization or deserialization or passed via a remote RMI call).

Setting the own flag to true means that the file will be deleted automatically when the Document instance is passivated. This can help to optimize IO, since the file can be moved rather than copied (which happens when the own flag is false) into the managed area on the disk.

Parameters
file — The file providing the input content.
 
own — The boolean flag controlling whether the new Document should take over the file when the Document is passivated.
Document() 
public Document(DocumentWriter writer, Object obj)
Deprecated: 

Do not use.

Parameters
writer
 
obj
Document() 
public Document(Document doc)

Creates a copy of the Document supplied as input.

Parameters
doc — The source Document instance.
Method Detail
copyToFile()
public void copyToFile(File file)

Copies the document content to a file specified by a caller. If the specified file already exists, it will be overwritten.

Note that after this method returns, it becomes the caller's responsibility to remove the file.

Parameters

file — The file to which to copy the document content. If the file exists, this method will overwrite it. If the file does not exist, this method will create one.

dispose() 
public void dispose()

Disposes of any local temporary storage resources (for example, file, database data, and so on) occupied by the document content. Once disposed, the Document instance becomes invalid, meaning that it becomes impossible to use the Document for any purpose.

In a few cases the Document can also be disposed of automatically. This occurs when the disposal timeout ends, which is set using the setDisposalTimeout(int) method, or when the current transaction ends and the Document is set as transaction-bound using the setTransactionBound(boolean) method.

See also

doneReading() 
public void doneReading()

Closes any resources opened by the Document object while reading the content with any of the Document object's read() methods.

This method is also called by the dispose() method.

See also

getAttribute() 
public Serializable getAttribute(String name)

Returns the value of an attribute with a given name.

An attribute is an arbitrary (preferably small) serializable object passed along with the Document instance. Every attribute should have a unique name. The predefined attributes are:

AttributeDescription
fileThe original file name (as a string), if the Document was created with the Document(java.io.File, boolean) constructor.
urlThe original URL (as a string), if the Document was created with the Document(java.net.URL) constructor.

Parameters

name — The attribute name.

Returns
The attribute value.

See also

getContentType() 
public String getContentType()

Returns the current MIME type of the Document content.

The content type is a MIME string identifying the Document content (for example, "application/octet-stream", "text/plain", and so on). The content type is set either explicitly using the setContentType() method, or implicitly when the Document(java.net.URL), Document(java.io.File, boolean), or Document(java.io.InputStream) constructor is called. To determine the content type, the first and second constructors use a file/URL extension to map it to the MIME content type using a default javax.activation.FileTypeMap instance. The third constructor requests the content type from DataBuffer using the DataBuffer.getContentType() method.

If the Document is created using the Document(java.net.URL) constructor, and the URL does not have a file component in it (for example, http://www.adobe.com), then this method cannot determine the correct content type and most likely returns "application/octet-stream" as a result. This is done to avoid opening a java.net.URLConnection to this URL prematurely. If such behavior is not acceptable, consider setting the content type on the new Document instance explicitly, using the setContentType() method.

Returns
The current MIME content type. It can return null if the content type is unknown.

See also

getDataBuffer() 
public DataBuffer getDataBuffer()
Deprecated: For internal use only.

Do not use.

Returns
getDefaultDisposalTimeout() 
public static int getDefaultDisposalTimeout()

Returns the default disposal timeout value. If the default disposal timeout is not set, this method uses a value of a configurable defaultDocumentDisposalTimeout property. The default timeout is 600 seconds.

Returns
The default disposal timeout in seconds.

See also

getDefaultMaxInlineSize() 
public static int getDefaultMaxInlineSize()

Returns the default maximum size of the document content that can be embedded within the Document object.

If the default inline size is not set using the setDefaultMaxInlineSize(int) method, this method uses a value of a configurable defaultDocumentMaxInlineSize property. The default value is 64 Kbytes.

Returns
The default maximum inline size in bytes.

See also

getDisposalTimeout() 
public int getDisposalTimeout()

Returns the timeout value if it was set using the setDisposalTimeout(int) method. Otherwise, it returns the default timeout value (see the static getDefaultDisposalTimeout() method).

Returns
The current disposal timeout.

See also

getFile() 
public File getFile()
Deprecated: Use the copyToFile() method instead.

Returns the document content in a file.

The only option available to the caller of this method is to open the returned file for reading. The caller should not try any other options (for example, writing to a file, renaming, removing, and so on) as this file is created and managed by the Document object.

If this method is called within the standalone client environment, the resulting file is created in the local temporary directory and is not managed. However, the file is marked with the java.io.File.deleteOnExit() method.

Returns
The java.io.File object containing the document content.
getInputStream() 
public InputStream getInputStream()

Returns the document content in a java.io.InputStream object.

Returns
The java.io.InputStream object containing the document content.
getMaxInlineSize() 
public int getMaxInlineSize()

Returns the maximum size of the document content that can be embedded within the Document instance. If this value is not set with the setMaxInlineSize(int) method, the default value is controlled by the setDefaultMaxInlineSize(int) method.

Returns
The maximum inline size in bytes.

See also

getObject() 
public Object getObject(DocumentReader reader)
Deprecated: For internal use only.

Do not use.

Parameters

reader

Returns
isPassivationLazy() 
public static boolean isPassivationLazy()

Returns true if lazy passivation is on. If this is the case, the Document content is not passivated until the receiving side requests the content (unless it is passivated explicitly via the passivate() call). If it is off, the Document is passivated during its serialization (for example, when making an RMI/EJB call with a Document object as an input parameter).

Lazy passivation is a default behavior within the J2EE environment. For standalone J2SE applications, lazy passivation is off by default. This is because the lazy passivation might require a remote callback from the side receiving the Document object to the side supplying one. Such a callback might be problematic for standalone J2SE applications (for example, because the supplier side is behind a network firewall, or because the secure connection is a must but the supplier side does not support the SSL protocol in the callback direction).

Returns
true if the lazy passivation is on; false otherwise.

See also

isTransactionBound() 
public boolean isTransactionBound()

Returns true or false depending on whether the Document lifetime is transaction-bound.

Returns
The boolean value indicating if the Document is transaction-bound.

See also

length() 
public long length()

Returns the Document content's length. This method passivates the Document content internally using the passivate() method to cover the cases when the length is not known a priori (for example, when the Document is created with data whose length is unknown until the content is fully read, such as java.io.InpuStream or java.net.URL).

Returns
The Document content's length.

See also

listAttributes() 
public Set listAttributes()

Lists the names of all attributes associated with this Document instance.

Returns
The set of all attribute names.

See also

passivate() 
public void passivate()

Saves the document content into some persistent form (file, database BLOB, and so on). After this method is called, the Document no longer keeps a reference to the object that provided the input for the document content (for example, the byte array, the java.io.InputStream, or the file provided by the corresponding Document constructor calls).

passivateGlobally() 
public void passivateGlobally()

Passivates the Document content (similar to the passivate() method) in the global storage.

read() 
public int read(long pos)

Reads a byte of the Document object's content at the given position.

Parameters

pos — The position from which to read the byte.

Returns
The value of the byte, which can be in the range of 0 to 255, or -1 if the end of the data has been reached.
read() 
public int read(long pos, byte[] b, int off, int len)

Reads up to len bytes of the Document object's content into an array of bytes. While this method attempts to read as many as len bytes, a smaller number (0 to len bytes) may be read.

The very first call of this method passivates the Document. If the content is not stored in memory as part of the Document object, the very first call of this method also opens an internal resource, such as java.io.RandomAccessFile, to read the data. Thus, to help prevent resource leakage, it is important to call doneReading() when finished reading.

Parameters

pos — The position from which to read the bytes.
 
b — The buffer into which the data is read.
 
off — The starting index in the buffer (b) to which the data is written.
 
len — The maximum number of bytes to read.

Returns
The total number of bytes read into the buffer, or -1 if the end of the data has been reached.
removeAttribute() 
public void removeAttribute(String name)

Removes an attribute with the given name.

Parameters

name — The attribute name.

See also

setAttribute() 
public void setAttribute(String name, Serializable value)

Sets the value of an attribute with a given name.

Parameters

name — The attribute name.
 
value — The attribute value.

See also

setContentType() 
public void setContentType(String type)

Overwrites the current MIME type of the Document content.

The content type is a MIME string identifying the Document content (for example, "application/octet-stream", "text/plain", and so on).

Parameters

type — The new content type.

See also

setDefaultDisposalTimeout() 
public static void setDefaultDisposalTimeout(int seconds)

Sets the default disposal timeout value, which is used if the timeout is not set using the setDisposalTimeout(int) method.

Parameters

seconds — The new default disposal timeout.

setDefaultMaxInlineSize() 
public static void setDefaultMaxInlineSize(int bytes)

Sets the default maximum size of the document content that can be embedded within the Document instance.

Parameters

bytes — The default maximum inline size in bytes.

See also

setDisposalTimeout() 
public void setDisposalTimeout(int seconds)

Sets the amount of time (in seconds) before the Document object is disposed of automatically. Use this method to guarantee disposal of any local temporary storage resources (for example, file, database data, and so on) occupied by the document content after a particular time elapsed. After the Document is disposed of, its content will no longer be available.

The recommended usage is document.setDisposalTimeout(document.getDisposalTimeout() + extraTime). Thus, changing the default disposal timeout at start-up can still affect the local disposal timeout.

The Document can also be disposed of either explicitly, when the dispose() method is called, or implicitly, when the current transaction ends and the Document is set as transaction-bound using the setTransactionBound(boolean) method.

If this method is never called, the Document is assigned a default disposal timeout (see the static getDefaultDisposalTimeout() method).

Parameters

seconds — The new disposal timeout in seconds.

See also

setInitialContext() 
public static void setInitialContext(InitialContext ic)

Use this method to set the InitialContext needed by the Document object in order to look up an internal server EJB, which is used to upload the Document object's content to the LiveCycle server. This method should be called by standalone client applications at initialization time. If this method is not called, the Document object will use an InitialContext object created with an empty constructor.

Parameters

ic

setMaxInlineSize() 
public void setMaxInlineSize(int bytes)

Sets the maximum size of the document content that can be embedded within the Document instance. If this value is not set, the default value controlled by the setDefaultMaxInlineSize(int) method is used.

Parameters

bytes — The maximum inline size in bytes.

See also

setPassivationLazy() 
public static void setPassivationLazy(boolean enable)

Use this method to override the default passivation behavior.

Parameters

enable — Set to true to enable lazy passivation.

See also

setTransactionBound() 
public void setTransactionBound(boolean value)

Used to specify whether the Document is transaction-bound.

If this method is called with value set to true, the Document instance is automatically disposed of upon the end of the transaction associated with the current thread (the Document becomes transaction-bound). By default, the Document is not transaction-bound.

When calling this method with the value set to true, make sure that the calling thread is associated with a J2EE transaction context. Otherwise, a DocumentError exception will be thrown.

The Document can also be disposed of in a few other ways. It can be disposed of explicitly, via the dispose() method call, or automatically: when the disposal timeout expires, or when the transaction ends (whichever happens earlier).

Parameters

value — The boolean value specifying whether the Document is transaction-bound.

See also

toString() 
public String toString()

Returns a text representation of the Document internal state. Use this method for debugging only.

Returns
A java.lang.String with the Document internal state in XML format.




 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/javadoc/com/adobe/idp/Document.html