public abstract class AbstractFileSystem extends FileSystem
FileSystem
and is generally more pleasant to create
subclasses of.
It caches information about the filesystem in memory and periodically refreshes its content. Many other
operations are performed in a safer manner so as to reuse experience of NetBeans developers; should be
substantially simpler to subclass than FileSystem
itself.
Besides what is mentioned here, the AbstractFileSystem
subclass be configurable as a JavaBean
(e.g. server address, prefix, whatever it needs).
First of all, you need not separately implement a FileObject
- this is taken care of for you. You
need only provide some information about how essential actions should be carried out.
You should implement AbstractFileSystem.getDisplayName()
to set the display name.
You may cause the filesystem to automatically refresh itself at periodic intervals, in case it is not
possible to be notified of changes directly. To do so, call AbstractFileSystem.setRefreshTime(int)
, e.g. from the
constructor.
AbstractFileSystem.refreshRoot()
must be called if the filesystem supports changing of its root directory (as the
local filesystem does, for example).
Most of the meat of the implementation is provided by setting appropriate values for four protected variables, which should be initialized in the constructor; each represents an implementation of a separate interface handling one aspect of the filesystem.
List member
The variableAbstractFileSystem.list
should contain an implementation of AbstractFileSystem.List
. This only
specifies a way of accessing the list of children in a folder.
Info member
AbstractFileSystem.info
contains an AbstractFileSystem.Info
which provides basic file statistics.
It also specifies the raw implementation of two basic types of actions: getting input and output streams for the file; and locking and unlocking it physically (optional and not to be confused with locking within NetBeans).
Change member
AbstractFileSystem.change
is an AbstractFileSystem.Change
which provides the interface to create new folders
and files; delete them; and rename them (within the same directory).
Attribute member
AbstractFileSystem.attr
is an AbstractFileSystem.Attr
allowing NetBeans to read and write serializable
attributes (meta-information) to be associated with the file. Such attributes are not much used any more, but
they are occasionally.
There is a default implementation in DefaultAttributes
which stores attributes in a file called
.nbattrs
in each folder for which a file has some attributes, using XML augmented by Java
serialization, though the regular filesystems in NetBeans now instead store all attributes globally in
$userdir/var/attributes.xml
. If you do use DefaultAttributes
, use it not only for
AbstractFileSystem.attr
but also for AbstractFileSystem.list
(passing in a separate private AbstractFileSystem.List
implementation to its constructor) in order to filter the .nbattrs
files from view.
Modifier and Type | Class and Description |
---|---|
static interface |
AbstractFileSystem.Attr
Handle attributes of files.
|
static interface |
AbstractFileSystem.Change
Controls modification of files.
|
static interface |
AbstractFileSystem.Info
Information about files.
|
static interface |
AbstractFileSystem.List
Provides access to the hierarchy of resources.
|
static interface |
AbstractFileSystem.SymlinkInfo
Information about files related to symbolic links.
|
static interface |
AbstractFileSystem.Transfer
Controls on moving of files.
|
FileSystem.AtomicAction
Modifier and Type | Field and Description |
---|---|
protected AbstractFileSystem.Attr |
attr
Handling of attributes for files.
|
protected AbstractFileSystem.Change |
change
Methods for modification of files.
|
protected AbstractFileSystem.Info |
info
Methods for obtaining information about files.
|
protected AbstractFileSystem.List |
list
Provider of hierarchy of files.
|
protected AbstractFileSystem.Transfer |
transfer
Methods for moving of files.
|
PROP_DISPLAY_NAME, PROP_HIDDEN, PROP_READ_ONLY, PROP_ROOT, PROP_SYSTEM_NAME, PROP_VALID
Constructor and Description |
---|
AbstractFileSystem() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canRead(String name)
Tests if this file can be read.
|
protected boolean |
canWrite(String name)
Tests if this file can be written to.
|
protected boolean |
checkVirtual(String name)
This method is called from AbstractFileObject.isVirtual.
|
protected <T extends FileObject> |
createReference(T fo)
Creates Reference.
|
protected Enumeration<? extends FileObject> |
existingFileObjects(FileObject fo)
For the FileObject specified as parameter, returns the recursive enumeration
of existing children fileobjects (both folders and data).
|
protected Reference<? extends FileObject> |
findReference(String resourceName)
This method allows to find Reference to resourceName
|
FileObject |
findResource(String name)
Finds a file given its full resource path.
|
abstract String |
getDisplayName()
Provides a name for the system that can be presented to the user.
|
protected int |
getRefreshTime()
Get the number of milliseconds between automatic
refreshes of the directory structure.
|
FileObject |
getRoot()
Getter for root folder in the filesystem.
|
protected void |
markImportant(String name,
boolean important)
Mark the file as being important or unimportant.
|
void |
refresh(boolean expected)
Actually implements contract of FileSystem.refresh().
|
protected void |
refreshResource(String name,
boolean expected)
Allows subclasses to fire that a change occured in a
file or folder.
|
protected FileObject |
refreshRoot()
Instruct the filesystem
that the root should change.
|
protected void |
setRefreshTime(int ms)
Set the number of milliseconds between automatic
refreshes of the directory structure.
|
addFileChangeListener, addFileStatusListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, createTempFile, find, findExtrasFor, fireFileStatusChanged, firePropertyChange, fireVetoableChange, getDecorator, getSystemName, getTempFolder, isDefault, isReadOnly, isValid, removeFileChangeListener, removeFileStatusListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, runAtomicAction, setSystemName, toString
protected AbstractFileSystem.List list
protected AbstractFileSystem.Change change
protected AbstractFileSystem.Transfer transfer
protected AbstractFileSystem.Info info
protected AbstractFileSystem.Attr attr
public void refresh(boolean expected)
refresh
in class FileSystem
expected
- should the file events be marked as expected change or not?FileEvent.isExpected()
public abstract String getDisplayName()
FileSystem
This call should never be used to attempt to identify the file root
of the filesystem. On some systems it may happen to look the same but this is a
coincidence and may well change in the future. Either check whether
you are working with a LocalFileSystem
or similar implementation and use
LocalFileSystem.getRootDirectory()
; or better, try
FileUtil.toFile(org.openide.filesystems.FileObject)
which is designed to do this correctly.
Note: for most purposes it is probably a bad idea to use
this method. Instead look at FileUtil.getFileDisplayName(org.openide.filesystems.FileObject)
.
getDisplayName
in class FileSystem
public FileObject getRoot()
FileSystem
getRoot
in class FileSystem
public FileObject findResource(String name)
FileSystem
findResource
in class FileSystem
name
- the resource path, e.g. "dir/subdir/file.ext" or "dir/subdir" or "dir"null
if no such file existsprotected <T extends FileObject> Reference<T> createReference(T fo)
fo
- is FileObject. It`s reference yourequire to get.protected final Reference<? extends FileObject> findReference(String resourceName)
resourceName
- is name of resourceprotected final void setRefreshTime(int ms)
ms
- number of milliseconds between two refreshes; if <= 0
then refreshing is disabledprotected final int getRefreshTime()
0
if refreshing is disabledprotected final FileObject refreshRoot()
protected final void refreshResource(String name, boolean expected)
name
- resource name of the file where the change occuredexpected
- true if the user initiated change and expects itprotected final Enumeration<? extends FileObject> existingFileObjects(FileObject fo)
fo
- the starting point for the recursive fileobject searchprotected boolean checkVirtual(String name)
name
- of the fileprotected boolean canWrite(String name)
name
- resource nameprotected boolean canRead(String name)
name
- resource nameprotected void markImportant(String name, boolean important)
name
- the file to markimportant
- true indicates that file is important, false conversely
file is unimportant.