org.millstone.base.data.util
Class FilesystemContainer

java.lang.Object
  |
  +--org.millstone.base.data.util.FilesystemContainer
All Implemented Interfaces:
Container, Container.Hierarchical

public class FilesystemContainer
extends java.lang.Object
implements Container.Hierarchical

A hierarchical container wrapper for a filesystem.

Since:
3.0
Version:
3.0.3
Author:
IT Mill Ltd.

Nested Class Summary
 class FilesystemContainer.FileExtensionFilter
          Generic file extension filter for displaying only files having certain extension.
 class FilesystemContainer.FileItem
          A Item wrapper for files in a filesystem.
 
Nested classes inherited from class org.millstone.base.data.Container
Container.Editor, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Viewer
 
Field Summary
static java.util.Collection FILE_PROPERTIES
          List of the string identifiers for the available properties
static java.lang.String PROPERTY_ICON
          String identifier of a file's "icon" property.
static java.lang.String PROPERTY_LASTMODIFIED
          String identifier of a file's "last modified" property.
static java.lang.String PROPERTY_NAME
          String identifier of a file's "name" property.
static java.lang.String PROPERTY_SIZE
          String identifier of a file's "size" property.
 
Fields inherited from interface org.millstone.base.data.Container
NULL_ITEM_ID
 
Constructor Summary
FilesystemContainer(java.io.File root)
          Construct a new FileSystemContainer with the specified file as the root of the filesystem.
FilesystemContainer(java.io.File root, boolean recursive)
          Construct a new FileSystemContainer with the specified file as the root of the filesystem.
FilesystemContainer(java.io.File root, java.io.FilenameFilter filter, boolean recursive)
          Construct a new FileSystemContainer with the specified root and recursivity status.
FilesystemContainer(java.io.File root, java.lang.String extension, boolean recursive)
          Construct a new FileSystemContainer with the specified file as the root of the filesystem.
 
Method Summary
 boolean addContainerProperty(java.lang.Object propertyId, java.lang.Class type, java.lang.Object defaultValue)
          Adds a new Property to all Items in the Container.
 java.lang.Object addItem()
          Creates a new Item into the Container, and assign it an automatic ID.
 Item addItem(java.lang.Object itemId)
          Creates a new Item with the given ID into the Container.
 void addRoot(java.io.File root)
          Add new root file directory.
 boolean areChildrenAllowed(java.lang.Object itemId)
          Tests if the specified Item in the container may have children.
 boolean containsId(java.lang.Object itemId)
          Tests if the Container contains the specified Item
 java.util.Collection getChildren(java.lang.Object itemId)
          Gets the IDs of all Items that are children of the specified Item.
 Property getContainerProperty(java.lang.Object itemId, java.lang.Object propertyId)
          Gets the specified property of the specified file Item.
 java.util.Collection getContainerPropertyIds()
          Gets the collection of available file properties.
 java.io.FilenameFilter getFilter()
          Returns the file filter used to limit the files in this container.
 Item getItem(java.lang.Object itemId)
          Gets the Item with the given Item ID from the Container.
 java.util.Collection getItemIds()
          Gets the ID's of all Items stored in the Container.
 java.lang.Object getParent(java.lang.Object itemId)
          Gets the ID of the parent Item of the specified Item.
 java.lang.Class getType(java.lang.Object propertyId)
          Gets the specified property's data type.
 boolean hasChildren(java.lang.Object itemId)
          Tests if the Item specified with itemId has any child Items, that is, is it a leaf Item.
 boolean isRecursive()
          Is this container recursive filesystem.
 boolean isRoot(java.lang.Object itemId)
          Tests if the Item specified with itemId is a root Item.
 boolean removeAllItems()
          Removes all Items from the Container.
 boolean removeContainerProperty(java.lang.Object propertyId)
          Removes a Property specified by the given Property ID from the Container.
 boolean removeItem(java.lang.Object itemId)
          Removes the Item identified by ItemId from the Container.
 java.util.Collection rootItemIds()
          Gets the IDs of all Items in the container that don't have a parent.
 boolean setChildrenAllowed(java.lang.Object itemId, boolean areChildrenAllowed)
          Return false - conversion from files to directories is not supported.
 void setFilter(java.io.FilenameFilter filter)
          Sets the file filter used to limit the files in this container.
 void setFilter(java.lang.String extension)
          Sets the file filter used to limit the files in this container.
 boolean setParent(java.lang.Object itemId, java.lang.Object newParentId)
          Return false - moving files around in the filesystem is not supported.
 void setRecursive(boolean recursive)
          Sets the container recursive property.
 int size()
          Gets the number of Items in the container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_NAME

public static java.lang.String PROPERTY_NAME
String identifier of a file's "name" property.


PROPERTY_SIZE

public static java.lang.String PROPERTY_SIZE
String identifier of a file's "size" property.


PROPERTY_ICON

public static java.lang.String PROPERTY_ICON
String identifier of a file's "icon" property.


PROPERTY_LASTMODIFIED

public static java.lang.String PROPERTY_LASTMODIFIED
String identifier of a file's "last modified" property.


FILE_PROPERTIES

public static java.util.Collection FILE_PROPERTIES
List of the string identifiers for the available properties

Constructor Detail

FilesystemContainer

public FilesystemContainer(java.io.File root)
Construct a new FileSystemContainer with the specified file as the root of the filesystem. The files are included recursively.

Parameters:
root - root file for the new file-system container. Null values are ignored.

FilesystemContainer

public FilesystemContainer(java.io.File root,
                           boolean recursive)
Construct a new FileSystemContainer with the specified file as the root of the filesystem. The files are included recursively.

Parameters:
root - root file for the new file-system container
recursive - should the container recursively contain subdirectories.

FilesystemContainer

public FilesystemContainer(java.io.File root,
                           java.lang.String extension,
                           boolean recursive)
Construct a new FileSystemContainer with the specified file as the root of the filesystem.

Parameters:
root - root file for the new file-system container
extension - Filename extension (w/o separator) to limit the files in container.
recursive - should the container recursively contain subdirectories.

FilesystemContainer

public FilesystemContainer(java.io.File root,
                           java.io.FilenameFilter filter,
                           boolean recursive)
Construct a new FileSystemContainer with the specified root and recursivity status.

Parameters:
root - root file for the new file-system container
filter - Filename filter to limit the files in container.
recursive - should the container recursively contain subdirectories.
Method Detail

addRoot

public void addRoot(java.io.File root)
Add new root file directory. Adds a file to be included as root file directory in the FilesystemContainer.

Parameters:
root - File to be added as root directory. Null values are ignored.

areChildrenAllowed

public boolean areChildrenAllowed(java.lang.Object itemId)
Tests if the specified Item in the container may have children. Since a FileSystemContainer contains files and directories, this method returns true for directory Items only.

Specified by:
areChildrenAllowed in interface Container.Hierarchical
Parameters:
itemId - ID of the Item in the container whose child capability is to be tested
Returns:
true if the specified Item is a directory, false otherwise.

getChildren

public java.util.Collection getChildren(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical
Gets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.

Specified by:
getChildren in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose children the caller is interested in
Returns:
An unmodifiable collection containing the IDs of all other Items that are children in the container hierarchy

getParent

public java.lang.Object getParent(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical
Gets the ID of the parent Item of the specified Item.

Specified by:
getParent in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose parent the caller wishes to find out.
Returns:
the ID of the parent Item. Will be null if the specified Item is a root element.

hasChildren

public boolean hasChildren(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical

Tests if the Item specified with itemId has any child Items, that is, is it a leaf Item. The Container.Hierarchical.getChildren(Object itemId) method always returns null for leaf Items.

Note that being a leaf does not imply whether or not an Item is allowed to have children.

.

Specified by:
hasChildren in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose leaf status is to be tested
Returns:
true if the specified Item is a leaf, false if not

isRoot

public boolean isRoot(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical
Tests if the Item specified with itemId is a root Item. The hierarchical container can have more than one root and must have at least one unless it is empty. The Container.Hierarchical.getParent(Object itemId) method always returns null for root Items.

Specified by:
isRoot in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose root status is to be tested
Returns:
true if the specified Item is a root, false if not

rootItemIds

public java.util.Collection rootItemIds()
Description copied from interface: Container.Hierarchical
Gets the IDs of all Items in the container that don't have a parent. Such items are called root Items. The returned collection is unmodifiable.

Specified by:
rootItemIds in interface Container.Hierarchical
Returns:
An unmodifiable collection containing IDs of all root elements of the container

setChildrenAllowed

public boolean setChildrenAllowed(java.lang.Object itemId,
                                  boolean areChildrenAllowed)
                           throws java.lang.UnsupportedOperationException
Return false - conversion from files to directories is not supported.

Specified by:
setChildrenAllowed in interface Container.Hierarchical
Parameters:
itemId - ID of the Item in the container whose child capability is to be set
areChildrenAllowed - boolean value specifying if the Item can have children or not
Returns:
false
java.lang.UnsupportedOperationException

setParent

public boolean setParent(java.lang.Object itemId,
                         java.lang.Object newParentId)
                  throws java.lang.UnsupportedOperationException
Return false - moving files around in the filesystem is not supported.

Specified by:
setParent in interface Container.Hierarchical
Parameters:
itemId - ID of the item to be set as the child of the Item identified with newParentId
newParentId - ID of the Item that's to be the new parent of the Item identified with itemId
Returns:
false
java.lang.UnsupportedOperationException

containsId

public boolean containsId(java.lang.Object itemId)
Description copied from interface: Container
Tests if the Container contains the specified Item

Specified by:
containsId in interface Container
Parameters:
itemId - ID the of Item to be tested
Returns:
boolean indicating if the Container holds the specified Item

getItem

public Item getItem(java.lang.Object itemId)
Description copied from interface: Container
Gets the Item with the given Item ID from the Container. If the Container does not contain the requested Item, null is returned.

Specified by:
getItem in interface Container
Parameters:
itemId - ID of the Item to retrieve
Returns:
the Item with the given ID or null if the Item is not found in the Container

getItemIds

public java.util.Collection getItemIds()
Description copied from interface: Container
Gets the ID's of all Items stored in the Container. The ID's are returned as a unmodifiable collection.

Specified by:
getItemIds in interface Container
Returns:
unmodifiable collection of Item IDs

getContainerProperty

public Property getContainerProperty(java.lang.Object itemId,
                                     java.lang.Object propertyId)
Gets the specified property of the specified file Item. The available file properties are "Name", "Size" and "Last Modified". If propertyId is not one of those, null is returned.

Specified by:
getContainerProperty in interface Container
Parameters:
itemId - ID of the file whose property is requested
propertyId - The property's ID
Returns:
the requested property's value, or null

getContainerPropertyIds

public java.util.Collection getContainerPropertyIds()
Gets the collection of available file properties.

Specified by:
getContainerPropertyIds in interface Container
Returns:
Unmodifiable collection containing all available file properties.

getType

public java.lang.Class getType(java.lang.Object propertyId)
Gets the specified property's data type. "Name" is a String, "Size" is a Long, "Last Modified" is a Date. If propertyId is not one of those, null is returned.

Specified by:
getType in interface Container
Parameters:
propertyId - ID of the property whose type is requested.
Returns:
data type of the requested property, or null

size

public int size()
Gets the number of Items in the container. In effect, this is the combined amount of files and directories.

Specified by:
size in interface Container
Returns:
Number of Items in the container.

getFilter

public java.io.FilenameFilter getFilter()
Returns the file filter used to limit the files in this container.

Returns:
Used filter instance or null if no filter is assigned.

setFilter

public void setFilter(java.io.FilenameFilter filter)
Sets the file filter used to limit the files in this container.

Parameters:
filter - The filter to set. null disables filtering.

setFilter

public void setFilter(java.lang.String extension)
Sets the file filter used to limit the files in this container.

Parameters:
extension - Filename extension (w/o separator) to limit the files in container.

isRecursive

public boolean isRecursive()
Is this container recursive filesystem.

Returns:
true if container is recursive, false otherwise.

setRecursive

public void setRecursive(boolean recursive)
Sets the container recursive property. Set this to false to limit the files directly under the root file. Note, that this is meaningful only if the root really is a directory.


addContainerProperty

public boolean addContainerProperty(java.lang.Object propertyId,
                                    java.lang.Class type,
                                    java.lang.Object defaultValue)
                             throws java.lang.UnsupportedOperationException
Description copied from interface: Container
Adds a new Property to all Items in the Container. The Property ID, data type and default value of the new Property are given as parameters. This functionality is optional.

Specified by:
addContainerProperty in interface Container
Parameters:
propertyId - ID of the Property
type - Data type of the new Property
defaultValue - The value all created Properties are initialized to
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException
See Also:
Container.addContainerProperty(Object, Class, Object)

addItem

public java.lang.Object addItem()
                         throws java.lang.UnsupportedOperationException
Description copied from interface: Container
Creates a new Item into the Container, and assign it an automatic ID.

The new ID is returned, or null if the operation fails. After a successful call you can use the getItem method to fetch the Item.

This functionality is optional.

Specified by:
addItem in interface Container
Returns:
ID of the newly created Item, or null in case of a failure
java.lang.UnsupportedOperationException
See Also:
Container.addItem()

addItem

public Item addItem(java.lang.Object itemId)
             throws java.lang.UnsupportedOperationException
Description copied from interface: Container
Creates a new Item with the given ID into the Container. The new

Item is returned, and it is ready to have its Properties modified. Returns null if the operation fails or the Container already contains a Item with the given ID.

This functionality is optional.

Specified by:
addItem in interface Container
Parameters:
itemId - ID of the Item to be created
Returns:
Created new Item, or null in case of a failure
java.lang.UnsupportedOperationException
See Also:
Container.addItem(Object)

removeAllItems

public boolean removeAllItems()
                       throws java.lang.UnsupportedOperationException
Description copied from interface: Container
Removes all Items from the Container.

Note that Property ID and type information is preserved. This functionality is optional.

Specified by:
removeAllItems in interface Container
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException
See Also:
Container.removeAllItems()

removeItem

public boolean removeItem(java.lang.Object itemId)
                   throws java.lang.UnsupportedOperationException
Description copied from interface: Container
Removes the Item identified by ItemId from the Container. This functionality is optional.

Specified by:
removeItem in interface Container
Parameters:
itemId - ID of the Item to remove
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException
See Also:
Container.removeItem(Object)

removeContainerProperty

public boolean removeContainerProperty(java.lang.Object propertyId)
                                throws java.lang.UnsupportedOperationException
Description copied from interface: Container
Removes a Property specified by the given Property ID from the Container. Note that the Property will be removed from all Items in the Container. This functionality is optional.

Specified by:
removeContainerProperty in interface Container
Parameters:
propertyId - ID of the Property to remove
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException
See Also:
Container.removeContainerProperty(Object)


Copyright © 2000,2001,2002 IT Mill Ltd. All Rights Reserved.