org.openide.loaders
Class DataLoaderPool

java.lang.Object
  |
  +--org.openide.loaders.DataLoaderPool
All Implemented Interfaces:
Serializable

public abstract class DataLoaderPool
extends Object
implements Serializable

Pool of data loaders. Provides access to set of registered loaders in the system. They are used to find valid data objects for given files.

The default instance can be retrieved with TopManager.getLoaderPool().

See Also:
Serialized Form

Constructor Summary
protected DataLoaderPool()
          Create new loader pool.
protected DataLoaderPool(DataLoader loader)
          Create new loader pool and set preferred loader.
 
Method Summary
 void addChangeListener(ChangeListener chl)
          Add a new listener to the listener list.
 void addOperationListener(OperationListener l)
          Add a listener for operations on data objects.
 Enumeration allLoaders()
          Get an enumeration of all loaders, including the preferred and system loaders.
 DataObject findDataObject(FileObject fo)
          Find a data object for this file object (not for normal users of the APIs).
 DataObject findDataObject(FileObject fo, DataLoader.RecognizedFiles r)
          Find a data object for this file object, considering already-recognized files (not for normal users of the APIs).
protected  void fireChangeEvent(ChangeEvent che)
          Fire change event to all listeners.
 DataLoader firstProducerOf(Class clazz)
          Finds the first producer of a representation class.
static DataLoader getPreferredLoader(FileObject fo)
          Get the preferred loader for a file.
protected abstract  Enumeration loaders()
          Get an enumeration of data loaders.
 Enumeration producersOf(Class clazz)
          Get an enumeration of all producers of a representation class.
 void removeChangeListener(ChangeListener chl)
          Remove a listener from the listener list.
 void removeOperationListener(OperationListener l)
          Remove a listener for operations on data objects.
static void setPreferredLoader(FileObject fo, DataLoader loader)
          Utility method to mark a file as belonging to a loader.
 DataLoader[] toArray()
          Get an array of loaders that are currently registered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataLoaderPool

protected DataLoaderPool()
Create new loader pool.

DataLoaderPool

protected DataLoaderPool(DataLoader loader)
Create new loader pool and set preferred loader. The preferred loader will be asked before any other to recognize files (also before the system loader).
Parameters:
loader - the preferred loader
Method Detail

loaders

protected abstract Enumeration loaders()
Get an enumeration of data loaders. Must be overridden in subclasses to provide a list of additional loaders. The list should not include the preferred loader.
Returns:
enumeration of DataLoaders

addChangeListener

public final void addChangeListener(ChangeListener chl)
Add a new listener to the listener list. A listener is notified of any change which was made to the loader pool (add, remove, or reorder).
Parameters:
chl - new listener

removeChangeListener

public final void removeChangeListener(ChangeListener chl)
Remove a listener from the listener list.
Parameters:
chl - listener to remove

fireChangeEvent

protected final void fireChangeEvent(ChangeEvent che)
Fire change event to all listeners. Asynchronously.
Parameters:
che - change event

addOperationListener

public final void addOperationListener(OperationListener l)
Add a listener for operations on data objects.
Parameters:
l - the listener

removeOperationListener

public final void removeOperationListener(OperationListener l)
Remove a listener for operations on data objects.
Parameters:
l - the listener

allLoaders

public final Enumeration allLoaders()
Get an enumeration of all loaders, including the preferred and system loaders. This should be the list of loaders as actually used by the system. Typically it will consist of, in this order:
  1. The preferred loader, if any.
  2. The system loaders, such as may be used for folders, shadows, etc.
  3. Module-specified loaders.
  4. The loader for instance data objects.
  5. Default loaders, which may handle files not otherwise recognizable.
Applications should not rely on the exact contents of the pool, rather the fact that this contains all the loaders which are capable of recognizing files in the order in which they are called.
Returns:
enumeration of DataLoaders

toArray

public DataLoader[] toArray()
Get an array of loaders that are currently registered. Does not include special system loaders, etc.
Returns:
array of loaders
See Also:
loaders()

firstProducerOf

public final DataLoader firstProducerOf(Class clazz)
Finds the first producer of a representation class. Scans through the list of all loaders and returns the first one whose representation class is a superclass of clazz.
Parameters:
clazz - class to find producer for
Returns:
data loader or null if there is no loader that can produce the class

producersOf

public final Enumeration producersOf(Class clazz)
Get an enumeration of all producers of a representation class.
Parameters:
clazz - class to find producers for
Returns:
enumeration of DataLoaders
See Also:
firstProducerOf(java.lang.Class)

findDataObject

public DataObject findDataObject(FileObject fo)
                          throws IOException
Find a data object for this file object (not for normal users of the APIs). DO NOT USE THIS as a normal user of the APIs! Unless you really know what you are doing, use DataObject.find(org.openide.filesystems.FileObject) instead. This call will throw an exception if it already exists, and it is normally only for use by the loader infrastructure.

All loaders are asked to recognize it according to their priority.

Parameters:
fo - file object to recognize
Returns:
the data object for this object or null if no loader recognizes this file
Throws:
DataObjectExistsException - if the object for this primary file already exists
IOException - if the data object is recognized but an error occurs during instantiation
See Also:
findDataObject(FileObject, DataLoader.RecognizedFiles)

findDataObject

public DataObject findDataObject(FileObject fo,
                                 DataLoader.RecognizedFiles r)
                          throws IOException
Find a data object for this file object, considering already-recognized files (not for normal users of the APIs). DO NOT USE THIS as a normal user of the APIs! Unless you really know what you are doing, use DataObject.find(org.openide.filesystems.FileObject) instead. This call will throw an exception if it already exists, and it is normally only for use by the loader infrastructure.

First of all looks at the file extended attribute NetBeansDataLoader; if it is set and it contains the class name of a valid DataLoader, that loader is given preference. For all loaders used, the first to return non-null from DataLoader.findDataObject(org.openide.filesystems.FileObject, org.openide.loaders.DataLoader.RecognizedFiles) is used.

Parameters:
fo - file object to recognize
r - recognized files buffer
Returns:
the data object for this object
Throws:
DataObjectExistsException - if the object for this primary file already exists
IOException - if the data object is recognized but an error occurs during instantiation

setPreferredLoader

public static void setPreferredLoader(FileObject fo,
                                      DataLoader loader)
                               throws IOException
Utility method to mark a file as belonging to a loader. When the file is to be recognized this loader will be used first.
Parameters:
fo - file to mark
loader - the loader to assign to the file or null if previous association should be cleared
Throws:
IOException - if setting the file's attribute failed

getPreferredLoader

public static DataLoader getPreferredLoader(FileObject fo)
Get the preferred loader for a file.
Parameters:
file - the file to get loader from
Returns:
the loader or null if no has been found


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