com.metamatrix.common.tree.directory
Class PreviewableDirectoryEntry

java.lang.Object
  extended by com.metamatrix.common.tree.directory.PreviewableDirectoryEntry
All Implemented Interfaces:
PropertiedObject, DirectoryEntry, TreeNode, java.lang.Comparable

public class PreviewableDirectoryEntry
extends java.lang.Object
implements DirectoryEntry

This class represents a wrapper for a DirectoryEntry that holds off on actually writing to the DirectoryEntry so that a preview of the result can be obtained prior to writing. Once the preview is determined to be acceptable, the getPreviewStream() method can be used to actually write the previewable contents to the DirectoryEntry.

An instance of this class can only be used to wrap a DirectoryEntry that can write (i.e., DirectoryEntry.canWrite() returns true).

Version:
1.0
Author:

Field Summary
protected static int BUFFER_SIZE
           
 
Fields inherited from interface com.metamatrix.common.tree.directory.DirectoryEntry
TYPE_FILE, TYPE_FOLDER
 
Constructor Summary
PreviewableDirectoryEntry(DirectoryEntry actualEntry)
          Construct a new instance that wraps another DirectoryEntry
 
Method Summary
 boolean canRead()
          Returns true if there was anything written to the buffer.
 boolean canWrite()
          Return whether it is possible to write to this DirectoryEntry, and whether an output stream can be obtained for this entry.
 void clearPreview()
           
 int compareTo(java.lang.Object o)
          Compares this object to another.
 boolean equals(java.lang.Object o)
          Returns true if the specified object is semantically equal to this instance.
 boolean exists()
          Return whether this TreeNode represents an existing resource.
 java.lang.String getFullName()
          Obtain the full name of the TreeNode which is unique within the TreeView.
 java.io.InputStream getInputStream()
          If this DirectoryEntry is readable, then return an InputStream instance to the resource represented by this entry.
 java.lang.String getName()
          Obtain the name of this TreeNode.
 java.lang.String getNamespace()
          Obtain the namespace to which this tree node belongs.
 java.io.OutputStream getOutputStream()
          If this DirectoryEntry is writable, then return an OutputStream instance to the resource represented by this entry.
 java.lang.String getSeparator()
          Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path.
 char getSeparatorChar()
          Obtain the character that is used to separate names in a path sequence for the abstract path.
 DirectoryEntry getTargetDirectoryEntry()
           
 ObjectDefinition getType()
          Get this type for this tree node.
 boolean hasPreview()
           
 boolean isModified()
          Return whether this node has undergone changes.
 boolean loadPreview()
          Load property values associated with this DirectoryEntry and return whether the preview properties are now available.
 boolean savePreview()
          Writes the preview to the entry.
 java.net.URL toURL()
          Converts this abstract pathname into a URL.
 boolean writePreview(java.io.Writer writer, boolean closeWriterUponCompletion)
          Writes the preview to the specified writer.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.metamatrix.common.tree.TreeNode
toString
 

Field Detail

BUFFER_SIZE

protected static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

PreviewableDirectoryEntry

public PreviewableDirectoryEntry(DirectoryEntry actualEntry)
Construct a new instance that wraps another DirectoryEntry

Parameters:
actualEntry - the DirectoryEntry that this instance is a preview for; may not be null
Method Detail

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Description copied from interface: DirectoryEntry
If this DirectoryEntry is writable, then return an OutputStream instance to the resource represented by this entry.

Specified by:
getOutputStream in interface DirectoryEntry
Returns:
the OutputStream for this entry.
Throws:
java.io.IOException - if there was an error creating the stream

savePreview

public boolean savePreview()
                    throws java.io.IOException
Writes the preview to the entry.

Returns:
true if the preview was saved, or false if there was no preview to save
Throws:
java.io.IOException - if there is an error writing the contents to the DirectoryEntry

writePreview

public boolean writePreview(java.io.Writer writer,
                            boolean closeWriterUponCompletion)
                     throws java.io.IOException
Writes the preview to the specified writer.

Parameters:
writer - the Writer to which the preview contents should be written
closeWriterUponCompletion - true if this method should attempt to close writer when this method completes writing the contents
Returns:
true if the preview was written, or false if there was no preview to write
Throws:
java.io.IOException - if there is an error reading the contents or writing the contents to writer

clearPreview

public void clearPreview()
                  throws java.io.IOException
Throws:
java.io.IOException

hasPreview

public boolean hasPreview()

getTargetDirectoryEntry

public DirectoryEntry getTargetDirectoryEntry()

canRead

public boolean canRead()
Returns true if there was anything written to the buffer.

Specified by:
canRead in interface DirectoryEntry
Returns:
true if reading is possible, as well as whether an InputStream instance can be obtained by calling the getInputStream() method.
See Also:
DirectoryEntry.canRead()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from interface: DirectoryEntry
If this DirectoryEntry is readable, then return an InputStream instance to the resource represented by this entry.

Specified by:
getInputStream in interface DirectoryEntry
Returns:
the InputStream for this entry.
Throws:
java.io.IOException - if there was an error creating the stream

canWrite

public boolean canWrite()
Description copied from interface: DirectoryEntry
Return whether it is possible to write to this DirectoryEntry, and whether an output stream can be obtained for this entry. This method may return true even if this entry does not exist (i.e., exists() returns true).

Specified by:
canWrite in interface DirectoryEntry
Returns:
true if writing is possible, as well as whether an OutputStream instance can be obtained by calling the getOutputStream() method.

loadPreview

public boolean loadPreview()
Description copied from interface: DirectoryEntry
Load property values associated with this DirectoryEntry and return whether the preview properties are now available.

Specified by:
loadPreview in interface DirectoryEntry
Returns:
if the properties have been loaded.

toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException
Description copied from interface: DirectoryEntry
Converts this abstract pathname into a URL. The exact form of the URL is dependent upon the implementation. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URL will end with a slash.

Specified by:
toURL in interface DirectoryEntry
Returns:
the URL for this DirectoryEntry.
Throws:
java.net.MalformedURLException - if the URL is malformed.

exists

public boolean exists()
Description copied from interface: TreeNode
Return whether this TreeNode represents an existing resource.

Specified by:
exists in interface TreeNode
Returns:
true the entry exists, or false otherwise.

getName

public java.lang.String getName()
Description copied from interface: TreeNode
Obtain the name of this TreeNode. The name does not contain the namespace but is unique within the namespace of the TreeNode.

Specified by:
getName in interface TreeNode
Returns:
the name of the node; never null or zero-length

getFullName

public java.lang.String getFullName()
Description copied from interface: TreeNode
Obtain the full name of the TreeNode which is unique within the TreeView. The full name is the concatenation of the namespace, separator, and name of this TreeNode.

Specified by:
getFullName in interface TreeNode
Returns:
the fully qualified name of this node; never null

getNamespace

public java.lang.String getNamespace()
Description copied from interface: TreeNode
Obtain the namespace to which this tree node belongs. The separator character is used between each of the components of the namespace.

Specified by:
getNamespace in interface TreeNode
Returns:
the string that represents the namespace of this node; never null

getType

public ObjectDefinition getType()
Description copied from interface: TreeNode
Get this type for this tree node.

Specified by:
getType in interface TreeNode
Returns:
the entity's type; never null

getSeparatorChar

public char getSeparatorChar()
Description copied from interface: TreeNode
Obtain the character that is used to separate names in a path sequence for the abstract path. This character is completely dependent upon the implementation.

Specified by:
getSeparatorChar in interface TreeNode
Returns:
the charater used to delimit names in the abstract path.

getSeparator

public java.lang.String getSeparator()
Description copied from interface: TreeNode
Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path.

Specified by:
getSeparator in interface TreeNode
Returns:
the string containing the charater used to delimit names in the abstract path; never null

isModified

public boolean isModified()
Description copied from interface: TreeNode
Return whether this node has undergone changes. The time from which changes are maintained is left to the implementation.

Specified by:
isModified in interface TreeNode
Returns:
true if this TreeNode has changes, or false otherwise.

compareTo

public int compareTo(java.lang.Object o)
Description copied from interface: TreeNode
Compares this object to another. If the specified object is an instance of the TreeNode class, then this method compares the contents; otherwise, it throws a ClassCastException (as instances are comparable only to instances of the same class).

Note: this method is consistent with equals(), meaning that (compare(x, y)==0) == (x.equals(y)).

Specified by:
compareTo in interface TreeNode
Specified by:
compareTo in interface java.lang.Comparable
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object, respectively.

equals

public boolean equals(java.lang.Object o)
Description copied from interface: TreeNode
Returns true if the specified object is semantically equal to this instance. Note: this method is consistent with compareTo().

Specified by:
equals in interface TreeNode
Overrides:
equals in class java.lang.Object
Returns:
whether the object is equal to this object.


Copyright © 2009. All Rights Reserved.