com.borland.primetime.node
Class FileNode

java.lang.Object
  |
  +--com.borland.primetime.node.Node
        |
        +--com.borland.primetime.node.UrlNode
              |
              +--com.borland.primetime.node.FileNode
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
BinaryResourceFileNode, ClassFileNode, EJBGRPFileNode, ImageFileNode, JarFileNode, SoundFileNode, TextFileNode

public class FileNode
extends UrlNode

FileNode instances represent nodes within a project that are associated with storage outside the project file. Each FileNode has a single associated Url that represents storage available to the node, and no two FileNode instances in the same project may be associated with the same Url.

See Also:
LightweightNode

Fields inherited from class com.borland.primetime.node.Node
EMPTY_ARRAY, nodeListeners
 
Constructor Summary
FileNode(Project project, Node parent, Url url)
          All FileNode subtypes must expose this constructor signature.
 
Method Summary
 void check()
          Updates the node to ensure that any manipulation done outside of the IDE is reflected on returning to the IDE by check if the underlying file has been modified using Buffer.check().
 Buffer findBuffer()
          Find an existing Buffer associated with this Node.
static java.lang.Class findFileNodeClass(java.lang.String extension, boolean includeBackups)
          Searches the node class registry to attempt to match a file extension with a node type.
static java.lang.Class findFileNodeClass(Url url)
          Searches the node class registry to attempt to match a file extension with a node type assuming that backup files should be matched to the original file's node type.
static java.lang.Class findFileNodeClass(Url url, boolean includeBackups)
          Searches the node class registry to attempt to match a file extension with a node type.
 Buffer getBuffer()
          Provide lazy buffer loading by requesting a Buffer instance using the VFS the first time it is required and then caching the result.
 javax.swing.Icon getDisplayIcon()
          Returns the default icon for a FileNode.
 java.lang.String getDisplayName()
          Uses the the FileNode's underlying Url to derive a short display name.
 int getDisplaySequence()
          Determines the overall grouping order for nodes in the project pane.
 java.io.InputStream getInputStream()
          Create an input stream to read from the underlying Url.
 java.lang.String getLongDisplayName()
          Use the Url's file component for display purposes except for the NewFilesystem where the full path is meaningless.
 java.io.OutputStream getOutputStream()
          Create an output stream to write to the underlying Url.
 long getTimestamp()
          Return any last modified timestamp associated with this buffer.
 Url getUrl()
          Returns the node's associated Url.
 boolean isModified()
          Return if any existing Buffer for this Node is modified or not.
 boolean isNew()
          Returns whether nor the Url filesystem is the NewFilesystem.
 boolean isPersistant()
          Determines whether or not the node definition and its properties will be saved with in a project file.
 boolean isReadOnly()
          Returns if Buffer or file is read-only or not.
static void registerFileNodeClass(java.lang.String extension, java.lang.String description, java.lang.Class nodeClass, javax.swing.Icon icon)
          Add a new node type to the registry of known types and their assocaited extensions.
 void rename(Url url)
          Attempt to rename FileNode (it is not allowed to change the type of a FileNode) to match the given Url.
 void revert()
          Attempt to revert the file associated with this Node by reloading it from storage.
 void save()
          Attempt to save FileNode (unless it is using the NewFilesystem).
 void saveAs(Url url)
          Attempt to save FileNode (it is not allowed to change the type of a FileNode) to the given Url (overwriting existing files) causing a name change if needed.
protected  void setUrl(Url url)
          Changes the node's associated Url.
 
Methods inherited from class com.borland.primetime.node.UrlNode
getSuggestedUrl
 
Methods inherited from class com.borland.primetime.node.Node
addNodeListener, compareTo, dumpNodes, dumpNodes, dumpNodes, equals, fireNodeRenamed, getChildren, getDisplayChildren, getNodeID, getParent, getProject, getProperties, getProperty, getProperty, getProperty, hasChildren, hasDisplayChildren, hashCode, makePersistant, removeNodeListener, setParent, setProperty, setProperty, setProperty, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileNode

public FileNode(Project project,
                Node parent,
                Url url)
         throws DuplicateNodeException
All FileNode subtypes must expose this constructor signature.
Parameters:
project - Project (cannot be null) to which this node will be associated.
parent - Immediate parent (may be null) of this node and must be of same Project.
url - The storage available to this node.
Throws:
DuplicateNodeException - if node already registered.
See Also:
Project.getNode(com.borland.primetime.vfs.Url)
Method Detail

getUrl

public Url getUrl()
Returns the node's associated Url.
Overrides:
getUrl in class UrlNode
Returns:
The Url associated with this FileNode.

setUrl

protected void setUrl(Url url)
               throws DuplicateNodeException
Changes the node's associated Url. Most code should avoid using this method directly and call rename or saveAs instead.
Parameters:
url - The new Url to associate with this FileNode.
Throws:
DuplicateNodeException - If another node belonging to the same project is already associated with the new Url.

registerFileNodeClass

public static void registerFileNodeClass(java.lang.String extension,
                                         java.lang.String description,
                                         java.lang.Class nodeClass,
                                         javax.swing.Icon icon)
Add a new node type to the registry of known types and their assocaited extensions.
Parameters:
type - The extension that this registration is associated with. Extensions are case-insensitive and do not include the leading period character.
description - A user-viewable description of the file type.
bufferClass - A subclass of FileNode that NodeSystem should instantiate to represent files with the matching extension.

findFileNodeClass

public static java.lang.Class findFileNodeClass(Url url)
Searches the node class registry to attempt to match a file extension with a node type assuming that backup files should be matched to the original file's node type.
Parameters:
url - The Url for which a suitable Node subclass should be found.
Returns:
A subclass of Node that should be used to manage the Url in question. If no node classes are registered for the Url's extension then the class com.borland.primetime.node.FileNode is returned.

findFileNodeClass

public static java.lang.Class findFileNodeClass(Url url,
                                                boolean includeBackups)
Searches the node class registry to attempt to match a file extension with a node type.
Parameters:
url - The Url for which a suitable Node subclass should be found.
includeBackups - True if VFS backup files should be matched to the original file's node type.
Returns:
A subclass of Node that should be used to manage the Url in question. If no node classes are registered for the Url's extension then the class com.borland.primetime.node.FileNode is returned.

findFileNodeClass

public static java.lang.Class findFileNodeClass(java.lang.String extension,
                                                boolean includeBackups)
Searches the node class registry to attempt to match a file extension with a node type.
Parameters:
extension - The extension for which a suitable Node subclass should be found.
includeBackups - True if VFS backup files should be matched to the original file's node type.
Returns:
A subclass of Node that should be used to manage the Url in question. If no node classes are registered for the Url's extension then the class com.borland.primetime.node.FileNode is returned.

getBuffer

public Buffer getBuffer()
                 throws java.io.IOException
Provide lazy buffer loading by requesting a Buffer instance using the VFS the first time it is required and then caching the result.
Returns:
The Buffer reference returned is guaranteed to be non-null.
Throws:
java.io.IOException - If the buffer cannot be loaded.
See Also:
Buffer

findBuffer

public Buffer findBuffer()
Find an existing Buffer associated with this Node.
Returns:
The Buffer reference returned may be null.
See Also:
Buffer

getTimestamp

public long getTimestamp()
Return any last modified timestamp associated with this buffer.
Returns:
Returns last modified timestamp or MODIFIED_NEVER.
See Also:
Buffer

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Create an input stream to read from the underlying Url. This will reflect the current state of the in-memory buffer, if one exists.
Returns:
Returns InputStream if one exists.
Throws:
java.io.IOException - If the Url specifies a resource that could not be read, or if no matching filesystem could be found for the Url.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException,
                                            VFSException
Create an output stream to write to the underlying Url. This will modify the in-memory buffer, if one exists, but will also modify the file on disk when the stream is closed.

To modify the state of the in-memory buffer without immediately saving the results to disk use getBuffer().getOutputStream() instead.

Returns:
Returns OutputStream if one exists.
Throws:
java.io.IOException - If the Url specifies a resource that could not be written to.

isReadOnly

public boolean isReadOnly()
Returns if Buffer or file is read-only or not. Return if buffer is read-only.
Returns:
Returns true if Buffer or file is read-only.

isNew

public boolean isNew()
Returns whether nor the Url filesystem is the NewFilesystem.
Overrides:
isNew in class UrlNode
Returns:
Returns true if Url filesystem is the NewFilesystem.
See Also:
NewFilesystem

isModified

public boolean isModified()
Return if any existing Buffer for this Node is modified or not.
Overrides:
isModified in class UrlNode
Returns:
Returns true if the Buffer if modified or not.

revert

public void revert()
            throws java.io.IOException
Attempt to revert the file associated with this Node by reloading it from storage.
Overrides:
revert in class UrlNode
Throws:
java.io.IOException - If the Url specifies a resource that could not be successfully reverted.

rename

public void rename(Url url)
            throws java.io.IOException,
                   InvalidUrlException,
                   DuplicateNodeException,
                   ReadOnlyException
Attempt to rename FileNode (it is not allowed to change the type of a FileNode) to match the given Url.
Overrides:
rename in class UrlNode
Parameters:
url - Url with new name.
Throws:
java.io.IOException -  
InvalidUrlException -  
DuplicateNodeException -  
ReadOnlyException -  

saveAs

public void saveAs(Url url)
            throws java.io.IOException,
                   InvalidUrlException,
                   DuplicateNodeException
Attempt to save FileNode (it is not allowed to change the type of a FileNode) to the given Url (overwriting existing files) causing a name change if needed.
Overrides:
saveAs in class UrlNode
Parameters:
url - Url with new name where to save.
Throws:
java.io.IOException -  
InvalidUrlException -  
DuplicateNodeException -  

save

public void save()
          throws java.io.IOException,
                 InvalidUrlException
Attempt to save FileNode (unless it is using the NewFilesystem).
Overrides:
save in class UrlNode
Throws:
java.io.IOException -  
InvalidUrlException -  

isPersistant

public boolean isPersistant()
Determines whether or not the node definition and its properties will be saved with in a project file. A FileNode whose Url belongs to the NewFilesystem is not persisted.
Overrides:
isPersistant in class Node
Returns:
True if the node should be saved, false otherwise.

getDisplayIcon

public javax.swing.Icon getDisplayIcon()
Returns the default icon for a FileNode.
Overrides:
getDisplayIcon in class Node
Returns:
Returns the ICON_FILEBINARY icon.

getDisplayName

public java.lang.String getDisplayName()
Uses the the FileNode's underlying Url to derive a short display name.
Overrides:
getDisplayName in class Node
Returns:
The short name derrived from the Node's Url.

getLongDisplayName

public java.lang.String getLongDisplayName()
Use the Url's file component for display purposes except for the NewFilesystem where the full path is meaningless.
Overrides:
getLongDisplayName in class Node
Returns:
A full path suitable for end-user display.

getDisplaySequence

public int getDisplaySequence()
Determines the overall grouping order for nodes in the project pane. By default, all file nodes share the same grouping level and are therefore sorted alphabetically.
Overrides:
getDisplaySequence in class Node
Returns:
The value 500.

check

public void check()
Updates the node to ensure that any manipulation done outside of the IDE is reflected on returning to the IDE by check if the underlying file has been modified using Buffer.check().
Overrides:
check in class Node