org.openide.loaders
Class FolderInstance

java.lang.Object
  |
  +--org.openide.util.Task
        |
        +--org.openide.loaders.FolderInstance
All Implemented Interfaces:
InstanceCookie, Node.Cookie, Runnable

public abstract class FolderInstance
extends Task
implements InstanceCookie

Support class for creation of an object from the content of a folder. It implements InstanceCookie, so it can be used as a cookie for a node or data object.

When created on a folder and started by invoking run method, it scans its content (in a separate thread) and creates a list of instances from which the new instance of this object should be composed. The object automatically listens to changes of components in the folder, and if some change occurs, it allows the subclass to create a new object.


Inner classes inherited from class org.openide.cookies.InstanceCookie
InstanceCookie.Origin
 
Field Summary
protected  DataFolder folder
          Folder to work with.
 
Fields inherited from class org.openide.util.Task
EMPTY
 
Constructor Summary
FolderInstance(DataFolder df)
          Create new folder instance.
 
Method Summary
protected  InstanceCookie acceptCookie(InstanceCookie cookie)
          Allows subclasses to decide whether they want to work with the specified InstanceCookie or not.
protected  InstanceCookie acceptDataObject(DataObject dob)
          Allows subclasses to decide whether they want to work with the specified DataObject or not.
protected  InstanceCookie acceptFolder(DataFolder df)
          Allows subclasses to decide how they want to work with a provided folder.
protected abstract  Object createInstance(InstanceCookie[] cookies)
          Notifies subclasses that the set of cookies for this folder has changed.
 Class instanceClass()
          The representation type that may be created as instances.
 Object instanceCreate()
          Create an instance.
 void instanceFinished()
          Wait for instance initialization to finish.
protected  Object instanceForCookie(DataObject obj, InstanceCookie cookie)
          Method that is called when a the folder instance really wants to create an object from provided cookie.
 String instanceName()
          Full name of the data folder's primary file, separated by periods.
 void recreate()
          Starts recreation of the instance in special thread.
 
Methods inherited from class org.openide.util.Task
addTaskListener, isFinished, notifyFinished, removeTaskListener, run, toString, waitFinished
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

folder

protected DataFolder folder
Folder to work with.
Constructor Detail

FolderInstance

public FolderInstance(DataFolder df)
Create new folder instance.
Parameters:
df - data folder to create instances from
Method Detail

instanceName

public String instanceName()
Full name of the data folder's primary file, separated by periods.
Specified by:
instanceName in interface InstanceCookie
Returns:
the name

instanceClass

public Class instanceClass()
                    throws IOException,
                           ClassNotFoundException
Description copied from interface: InstanceCookie
The representation type that may be created as instances. Can be used to test whether the instance is of an appropriate class without actually creating it.
Specified by:
instanceClass in interface InstanceCookie
Following copied from interface: org.openide.cookies.InstanceCookie
Returns:
the representation class of the instance
Throws:
IOException - if an I/O error occurred
ClassNotFoundException - if a class was not found

instanceCreate

public Object instanceCreate()
                      throws IOException,
                             ClassNotFoundException
Description copied from interface: InstanceCookie
Create an instance.
Specified by:
instanceCreate in interface InstanceCookie
Following copied from interface: org.openide.cookies.InstanceCookie
Returns:
the instance of type InstanceCookie.instanceClass()
Throws:
IOException - if an I/O error occured
ClassNotFoundException - if a class was not found

instanceFinished

public final void instanceFinished()
Wait for instance initialization to finish.

acceptDataObject

protected InstanceCookie acceptDataObject(DataObject dob)
Allows subclasses to decide whether they want to work with the specified DataObject or not.
Parameters:
dob - a DataObject to test
Returns:
the cookie for the DataObject or null if it should not be used

acceptCookie

protected InstanceCookie acceptCookie(InstanceCookie cookie)
                               throws IOException,
                                      ClassNotFoundException
Allows subclasses to decide whether they want to work with the specified InstanceCookie or not.

The default implementation simply returns the same cookie, but subclasses may decide to return null or a different cookie.

Parameters:
cookie - the instance cookie to test
Returns:
the cookie to use or null if this cookie should not be used
Throws:
IOException - if an I/O error occurred calling a cookie method
ClassNotFoundException - if a class is not found in a call to a cookie method

acceptFolder

protected InstanceCookie acceptFolder(DataFolder df)
Allows subclasses to decide how they want to work with a provided folder. The default implementation simply returns null to indicate that folders should not be recursed, but subclasses can do otherwise.
Parameters:
df - data folder to create cookie for
Returns:
the cookie for this folder or null if this folder should not be used

createInstance

protected abstract Object createInstance(InstanceCookie[] cookies)
                                  throws IOException,
                                         ClassNotFoundException
Notifies subclasses that the set of cookies for this folder has changed. A new object representing the folder should be created (or the old one updated). Called both upon initialization of the class, and change of its cookies.
Parameters:
cookies - updated array of instance cookies for the folder
Returns:
object to represent these cookies
Throws:
IOException - an I/O error occured
ClassNotFoundException - a class has not been found

recreate

public void recreate()
Starts recreation of the instance in special thread.

instanceForCookie

protected Object instanceForCookie(DataObject obj,
                                   InstanceCookie cookie)
                            throws IOException,
                                   ClassNotFoundException
Method that is called when a the folder instance really wants to create an object from provided cookie. It allows subclasses to overwrite the default behaviour (which is to call cookie.instanceCreate).
Parameters:
obj - the data object that is the source of the cookie
cookie - the instance cookie to read the instance from
Throws:
IOException - when there I/O error
ClassNotFoundException - if the class cannot be found


Built on February 22 2001.  |  Portions Copyright 1997-2000 Sun Microsystems, Inc. All rights reserved.