public abstract class DataLoaderPool extends Object implements Serializable
loaders
in the system. They are used to find valid data objects
for given files.
The default instance can be retrieved using lookup.
Modifier | Constructor and Description |
---|---|
protected |
DataLoaderPool()
Create new loader pool.
|
protected |
DataLoaderPool(DataLoader loader)
Create new loader pool and set preferred loader.
|
Modifier and Type | Method and Description |
---|---|
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<DataLoader> |
allLoaders()
Get an enumeration of all loaders, including the preferred and system loaders.
|
static OperationListener |
createWeakOperationListener(OperationListener l,
Object s)
Factory to create weak OperationListener
|
static <T extends DataObject> |
factory(Class<T> dataObjectClass,
String mimeType,
Image image)
Factory method to create default implementation of a factory for
data objects.
|
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<? extends DataObject> clazz)
Finds the first producer of a representation class.
|
static DataLoaderPool |
getDefault()
Getter for the default pool of loaders used in the system.
|
static DataLoader |
getPreferredLoader(FileObject fo)
Get the preferred loader for a file.
|
protected abstract Enumeration<? extends DataLoader> |
loaders()
Get an enumeration of data loaders.
|
Enumeration<DataLoader> |
producersOf(Class<? extends DataObject> 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.
|
protected DataLoaderPool()
protected DataLoaderPool(DataLoader loader)
loader
- the preferred loaderpublic static DataLoaderPool getDefault()
protected abstract Enumeration<? extends DataLoader> loaders()
public final void addChangeListener(ChangeListener chl)
chl
- new listenerpublic final void removeChangeListener(ChangeListener chl)
chl
- listener to removeprotected final void fireChangeEvent(ChangeEvent che)
che
- change eventpublic static OperationListener createWeakOperationListener(OperationListener l, Object s)
l
- listeners
- the source the new listener will be attached topublic final void addOperationListener(OperationListener l)
l
- the listenerpublic final void removeOperationListener(OperationListener l)
l
- the listenerpublic final Enumeration<DataLoader> allLoaders()
public DataLoader[] toArray()
DataLoaderPool.loaders()
public final DataLoader firstProducerOf(Class<? extends DataObject> clazz)
clazz
.clazz
- class to find producer fornull
if there is no loader that
can produce the classpublic final Enumeration<DataLoader> producersOf(Class<? extends DataObject> clazz)
clazz
- class to find producers forDataLoaderPool.firstProducerOf(java.lang.Class<? extends org.openide.loaders.DataObject>)
public DataObject findDataObject(FileObject fo) throws IOException
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.
fo
- file object to recognizenull
if
no loader recognizes this fileDataObjectExistsException
- if the object for this primary file
already existsIOException
- if the data object is recognized but
an error occurs during instantiationDataLoaderPool.findDataObject(FileObject, DataLoader.RecognizedFiles)
public DataObject findDataObject(FileObject fo, DataLoader.RecognizedFiles r) throws IOException
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, java.util.Set<? super org.openide.filesystems.FileObject>)
is used.
fo
- file object to recognizer
- recognized files bufferDataObjectExistsException
- if the object for this primary file
already existsIOException
- if the data object is recognized but
an error occurs during instantiationpublic static void setPreferredLoader(FileObject fo, DataLoader loader) throws IOException
fo
- file to markloader
- the loader to assign to the file or null if previous
association should be clearedIOException
- if setting the file's attribute failedpublic static DataLoader getPreferredLoader(FileObject fo)
fo
- the file to get loader frompublic static <T extends DataObject> DataObject.Factory factory(Class<T> dataObjectClass, String mimeType, Image image)
DataObject
and
is ready to call its constructor. The constructor needs to take two
arguments: FileObject
and MultiFileLoader
. It can throw IOException
as
is usual among DataObject
constructors.
You can also invoke this method from a layer by following definition:
<file name="nameofyourfile.instance"> <attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/> <attr name="dataObjectClass" stringvalue="org.your.pkg.YourDataObject"/> <attr name="mimeType" stringvalue="yourmime/type"/> <attr name="iconBase" stringvalue="org/your/pkg/YourDataObject.png"/> </file>
clazz
- the class of the data object to create. Must have appropriate
constructor.mimeType
- the mime type associated with the object, used for
example to create the right actions for the object's nodeimage
- icon to use by default for nodes representing data objects
created with this factoryLoaders/mime/type/Factories
in some module layer file