public abstract class FileSystem extends Object implements Serializable
Implementing classes should also have associated subclasses of FileObject
.
But most subclasses will be of either AbstractFileSystem
or MultiFileSystem
.
When using the org.netbeans.modules.masterfs
module, you do not need
to explicitly create any filesystems just to access disk files; use FileUtil.toFileObject(java.io.File)
instead.
The system filesystem may be gotten from FileUtil.getConfigRoot()
and
normally includes XML layers created using XMLFileSystem
.
Since version 7.1 you can dynamically change the content of the system filesystem.
Either by inserting your own implementation of a filesystem directly or by
registering so called Repository.LayerProvider
. With the
provider
you can show a dialog letting the user log in
to some server and only later make additional XML layers
available.
In case you need to insert a dynamic file system with various definitions (NetBeans Platform menus,
toolbars, layout of windows, etc.), you can create a filesystem implementation,
then register it in default lookup.
It is easiest to subclass AbstractFileSystem
and implement
few simple query interfaces (AbstractFileSystem.List
,
AbstractFileSystem.Info
, AbstractFileSystem.Change
).
For example:
@
ServiceProviders
({@
ServiceProvider
(service=FileSystem.class),@
ServiceProvider
(service=LoginFileSystem.class) }) public class LoginFileSystem extends AbstractFileSystem implementsAbstractFileSystem.List
,AbstractFileSystem.Info
,AbstractFileSystem.Change
{ public LoginFileSystem() { this.info = this; this.change = this; this.list = this; } public static void initialize() throws SAXException { LoginFileSystem lfs =Lookup
.getDefault().lookup(LoginFileSystem.class); lfs.initializeSomehow(); } private void initializeSomehow() { // do some initialization super.refresh(); } public String[] children(String path) { // compute list of children somehow } // other method implementations follow... }
Since version 7.3 you can also return Boolean.TRUE
from a call to
yourFS.getRoot().getAttribute("fallback")
so as to place your filesystem
behind all layers provided by standard modules.
Modifier and Type | Class and Description |
---|---|
static interface |
FileSystem.AtomicAction
An action that it is to be called atomically with respect to filesystem event notification.
|
Modifier and Type | Field and Description |
---|---|
static String |
PROP_DISPLAY_NAME
Property name giving display name of filesystem.
|
static String |
PROP_HIDDEN
Deprecated.
The property is now hidden.
|
static String |
PROP_READ_ONLY
Property name giving read-only state.
|
static String |
PROP_ROOT
Property name giving root folder of filesystem.
|
static String |
PROP_SYSTEM_NAME
Deprecated.
This system name should now be avoided in favor of identifying files persistently by URL.
|
static String |
PROP_VALID
Property name indicating validity of filesystem.
|
Constructor and Description |
---|
FileSystem()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addFileChangeListener(FileChangeListener fcl)
Add new listener to this object.
|
void |
addFileStatusListener(FileStatusListener listener)
Registers FileStatusListener to receive events.
|
void |
addNotify()
Notifies this filesystem that it has been added to the repository.
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Registers PropertyChangeListener to receive events.
|
void |
addVetoableChangeListener(VetoableChangeListener listener)
Adds listener for the veto of property change.
|
FileObject |
createTempFile(FileObject parent,
String prefix,
String suffix,
boolean deleteOnExit)
Creates temporary file in the given parent folder.
|
FileObject |
find(String aPackage,
String name,
String ext)
Deprecated.
Please use the ClassPath API instead, or use
FileSystem.findResource(java.lang.String) if you are not interested in classpaths. |
Lookup |
findExtrasFor(Set<FileObject> objects)
Finds various extensions for set of file objects coming from
this file system.
|
abstract FileObject |
findResource(String name)
Finds a file given its full resource path.
|
protected void |
fireFileStatusChanged(FileStatusEvent event)
Notifies all registered listeners about change of status of some files.
|
protected void |
firePropertyChange(String name,
Object o,
Object n)
Fires property change event.
|
protected void |
fireVetoableChange(String name,
Object o,
Object n)
Fires property vetoable event.
|
StatusDecorator |
getDecorator()
Gets a status object that can annotate a set of files by changing the names or icons
associated with them.
|
abstract String |
getDisplayName()
Provides a name for the system that can be presented to the user.
|
abstract FileObject |
getRoot()
Getter for root folder in the filesystem.
|
String |
getSystemName()
Deprecated.
The system name should now be avoided in favor of identifying files persistently by URL.
|
FileObject |
getTempFolder()
Returns temporary folder if it is avaliable on this file system.
|
boolean |
isDefault()
Returns
true if the filesystem is default. |
abstract boolean |
isReadOnly()
Test if the filesystem is read-only or not.
|
boolean |
isValid()
Test whether filesystem is valid.
|
void |
refresh(boolean expected)
Should check for external modifications.
|
void |
removeFileChangeListener(FileChangeListener fcl)
Remove listener from this object.
|
void |
removeFileStatusListener(FileStatusListener listener)
Removes FileStatusListener from the list of listeners.
|
void |
removeNotify()
Notifies this filesystem that it has been removed from the repository.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes PropertyChangeListener from the list of listeners.
|
void |
removeVetoableChangeListener(VetoableChangeListener listener)
Removes listener for the veto of property change.
|
void |
runAtomicAction(FileSystem.AtomicAction run)
Executes atomic action.
|
protected void |
setSystemName(String name)
Deprecated.
The system name should now be avoided in favor of identifying files persistently by URL.
|
String |
toString() |
public static final String PROP_VALID
@Deprecated public static final String PROP_HIDDEN
@Deprecated public static final String PROP_SYSTEM_NAME
public static final String PROP_DISPLAY_NAME
public static final String PROP_ROOT
public static final String PROP_READ_ONLY
public void refresh(boolean expected)
expected
- should the file events be marked as expected change or not?FileEvent.isExpected()
public final boolean isValid()
public abstract String getDisplayName()
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)
.
@Deprecated public final String getSystemName()
A change of the system name should be interpreted as a change of the internal state of the filesystem. For example, if the root directory is moved to different location, one should rebuild representations for all files in the system.
This call should never be used to attempt to identify the file root
of the filesystem. On Unix 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.
@Deprecated protected final void setSystemName(String name) throws PropertyVetoException
Warning: this method is protected so that only subclasses can change the system name.
name
- new system namePropertyVetoException
- if the change is not allowed by a listenerpublic final boolean isDefault()
true
if the filesystem is default.Repository.getDefaultFileSystem()
public abstract boolean isReadOnly()
public abstract FileObject getRoot()
@Deprecated public FileObject find(String aPackage, String name, String ext)
FileSystem.findResource(java.lang.String)
if you are not interested in classpaths.
The default implementation converts dots in the package name into slashes,
concatenates the strings, adds any extension prefixed by a dot and calls
the findResource
method.
Note: when both of name
and ext
are null
then name and
extension should be ignored and scan should look only for a package.
aPackage
- package name where each package component is separated by a dotname
- name of the file (without dots) or null
if
one wants to obtain a folder (package) and not a file in itext
- extension of the file (without leading dot) or null
if one needs
a package and not a filenull
if the file does not existpublic abstract FileObject findResource(String name)
name
- the resource path, e.g. "dir/subdir/file.ext" or "dir/subdir" or "dir"null
if no such file existspublic FileObject getTempFolder() throws IOException
IOException
public FileObject createTempFile(FileObject parent, String prefix, String suffix, boolean deleteOnExit) throws IOException
parent
- the parent folder where temporary file will be createdprefix
- prefix of the name of created filesuffix
- suffix of the name of created filedeleteOnExit
- delete file on exitIOException
public Lookup findExtrasFor(Set<FileObject> objects)
actions = fs.findExtrasFor
(foSet).lookupAll
(Action
);
objects
- the set of objectspublic StatusDecorator getDecorator()
The default implementation returns a status object making no modifications,
unless this FileSystem.isDefault()
in which case certain special attributes
will be honored as of org.openide.filesystems 7.25:
displayName
Status#annotateName
. Often used with bundlevalue
in an XMLFileSystem
.SystemFileSystem.localizingBundle
NbBundle.getBundle(String)
) in which to look up a display name.
The bundle key is the FileObject.getPath()
.
displayName
is preferred for new code.iconBase
Status#annotateIcon
.
_32
will be inserted before the file suffix for 32x32 icons.SystemFileSystem.icon
and SystemFileSystem.icon32
URL
(usually nbresloc
protocol)
or Image
. iconBase
is preferred for new code.public final void runAtomicAction(FileSystem.AtomicAction run) throws IOException
Warning: the action should not take a significant amount of time, and should finish as soon as possible--otherwise all event notifications will be blocked.
Warning: do not be misled by the name of this method; it does not require the filesystem to treat the changes as an atomic block of commits in the database sense! That is, if an exception is thrown in the middle of the action, partial results will not be undone (in general this would be impossible to implement for all filesystems anyway).
run
- the action to runIOException
- if there is an IOException
thrown in the actions' run
methodpublic final void addFileStatusListener(FileStatusListener listener)
listener
- The listener to register.public final void removeFileStatusListener(FileStatusListener listener)
listener
- The listener to remove.protected final void fireFileStatusChanged(FileStatusEvent event)
event
- The event to be firedpublic final void addVetoableChangeListener(VetoableChangeListener listener)
listener
- the listenerpublic final void removeVetoableChangeListener(VetoableChangeListener listener)
listener
- the listenerprotected final void fireVetoableChange(String name, Object o, Object n) throws PropertyVetoException
name
- name of the propertyo
- old value of the propertyn
- new value of the propertyPropertyVetoException
- if an listener vetoed the changepublic final void addPropertyChangeListener(PropertyChangeListener listener)
listener
- The listener to register.public final void removePropertyChangeListener(PropertyChangeListener listener)
listener
- The listener to remove.protected final void firePropertyChange(String name, Object o, Object n)
name
- name of the propertyo
- old value of the propertyn
- new value of the propertypublic void addNotify()
Note that this method is advisory and serves as an optimization to avoid retaining resources for too long etc. Filesystems should maintain correct semantics regardless of whether and when this method is called.
public void removeNotify()
Note that this method is advisory and serves as an optimization to avoid retaining resources for too long etc. Filesystems should maintain correct semantics regardless of whether and when this method is called.
public final void addFileChangeListener(FileChangeListener fcl)
fcl
- the listenerpublic final void removeFileChangeListener(FileChangeListener fcl)
fcl
- the listener