org.openide.filesystems
Class Repository

java.lang.Object
  |
  +--org.openide.filesystems.Repository
All Implemented Interfaces:
Serializable

public final class Repository
extends Object
implements Serializable

This singleton object contains all FileSystems in the IDE. It corresponds to the Filesystems tab in the Explorer, or more precisely to Filesystems Settings in Project Settings.

At any given time, no two file systems in the pool may share the same name (unless all but one are invalid).

Use TopManager.getRepository() to retrieve the default instance.

Note that you may construct additional instances of the Repository if you wish. The serialization replacer of this class specifically deals with the default instance as stored by the top manager; however you may safely call the readExternal(java.io.ObjectInput) and writeExternal(java.io.ObjectOutput) methods directly to implement persistence of a non-default instance.

See Also:
Serialized Form

Constructor Summary
Repository(FileSystem def)
          Creates new instance of file system pool and registers it as the default one.
 
Method Summary
 void addFileSystem(FileSystem fs)
          Adds new file system to the pool.
 void addRepositoryListener(RepositoryListener list)
          Adds new listener.
 Enumeration fileSystems()
          Returns enumeration of all file systems.
 FileObject find(String aPackage, String name, String ext)
          Finds file when its name is provided.
 Enumeration findAll(String aPackage, String name, String ext)
          Finds all files among all file systems matching a given name, returning all matches.
 Enumeration findAllResources(String name)
          Searches for the given resource among all file systems, returning all matches.
 FileSystem findFileSystem(String systemName)
          Finds file system when only its system name is known.
 FileObject findResource(String name)
          Searches for the given resource among all file systems.
static Repository getDefault()
          Access method to get default instance of repository in the system.
 FileSystem getDefaultFileSystem()
          Gets the default filesystem of the IDE.
 Enumeration getFileSystems()
          Returns enumeration of all file systems.
 void readExternal(ObjectInput ois)
          Reads object from stream.
 void removeFileSystem(FileSystem fs)
          Removes a file system from the pool.
 void removeRepositoryListener(RepositoryListener list)
          Removes listener.
 void reorder(int[] perm)
          Reorders FileSystems by given permutation.
 FileSystem[] toArray()
          Returns a sorted array of file systems.
 void writeExternal(ObjectOutput oos)
          Saves pool to stream by saving all file systems.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Repository

public Repository(FileSystem def)
Creates new instance of file system pool and registers it as the default one. Also registers the default file system.
Parameters:
def - the default filesystem
Method Detail

getDefault

public static Repository getDefault()
Access method to get default instance of repository in the system. The instance is either taken as a result of org.openide.util.Lookup.getDefault ().lookup (Repository.class) or (if the lookup query returns null) a default instance is created.
Returns:
default repository for the system

getDefaultFileSystem

public FileSystem getDefaultFileSystem()
Gets the default filesystem of the IDE.
Returns:
the default filesystem

addFileSystem

public final void addFileSystem(FileSystem fs)
Adds new file system to the pool. Note that a file system cannot be assigned to more than one file system pool at one time (though currently there is only one pool anyway).
Parameters:
fs - file system to add

removeFileSystem

public final void removeFileSystem(FileSystem fs)
Removes a file system from the pool.
Parameters:
fs - file system to remove

reorder

public final void reorder(int[] perm)
Reorders FileSystems by given permutation. For example, if there are three file systems, new int[] {2, 0, 1} cycles the file systems forwards.
Parameters:
perm - an array of integers
Throws:
IllegalArgumentException - if the array is not a permutation, or is not the same length as the current number of file systems in the pool

getFileSystems

public final Enumeration getFileSystems()
Returns enumeration of all file systems.
Returns:
enumeration of type FileSystem

fileSystems

public final Enumeration fileSystems()
Returns enumeration of all file systems.
Returns:
enumeration of type FileSystem

toArray

public final FileSystem[] toArray()
Returns a sorted array of file systems.

findFileSystem

public final FileSystem findFileSystem(String systemName)
Finds file system when only its system name is known.
Parameters:
systemName - name of the file system
Returns:
the file system or null if there is no such file system

writeExternal

public void writeExternal(ObjectOutput oos)
                   throws IOException
Saves pool to stream by saving all file systems. The default (system) file system, or any persistent file systems, are skipped.
Parameters:
oos - object output stream
Throws:
IOException - if an error occures

readExternal

public void readExternal(ObjectInput ois)
                  throws IOException,
                         ClassNotFoundException
Reads object from stream. Reads all filesystems. Persistent and system file systems are untouched; all others are removed and possibly reread.
Parameters:
oos - object output stream
Throws:
IOException - if an error occures
ClassNotFoundException - if read class is not found

find

public final FileObject find(String aPackage,
                             String name,
                             String ext)
Finds file when its name is provided. It scans in the list of file systems and asks them for the specified file by a call to find. The first object that is found is returned or null if none of the file systems contain such a file.
Parameters:
aPackage - package name where each package is separated by a dot
name - name of the file (without dots) or null if one wants to obtain the name of a package and not a file in it
ext - extension of the file or null if one needs a package and not a file name
Returns:
FileObject that represents file with given name or null if the file does not exist

findResource

public FileObject findResource(String name)
Searches for the given resource among all file systems.
Parameters:
name - a name of the resource
Returns:
file object or null if the resource can not be found
See Also:
FileSystem.findResource(java.lang.String)

findAllResources

public Enumeration findAllResources(String name)
Searches for the given resource among all file systems, returning all matches.
Parameters:
name - name of the resource
Returns:
enumeration of FileObjects

findAll

public final Enumeration findAll(String aPackage,
                                 String name,
                                 String ext)
Finds all files among all file systems matching a given name, returning all matches. All file systems are queried with FileSystem.find(java.lang.String, java.lang.String, java.lang.String).
Parameters:
aPackage - package name where each package is separated by a dot
name - name of the file (without dots) or null if one wants to obtain the name of a package and not a file in it
ext - extension of the file or null if one needs a package and not a file name
Returns:
enumeration of FileObjects

addRepositoryListener

public void addRepositoryListener(RepositoryListener list)
Adds new listener.
Parameters:
list - the listener

removeRepositoryListener

public void removeRepositoryListener(RepositoryListener list)
Removes listener.
Parameters:
list - the listener


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.