org.openide.loaders
Class InstanceDataObject

java.lang.Object
  |
  +--org.openide.loaders.DataObject
        |
        +--org.openide.loaders.MultiDataObject
              |
              +--org.openide.loaders.InstanceDataObject
All Implemented Interfaces:
InstanceCookie, Node.Cookie, Serializable

public class InstanceDataObject
extends MultiDataObject
implements InstanceCookie

A data object whose only purpose is to supply InstanceCookie. The instances are created by default instantiation; the name of the class to instantiate is stored on disk, typically right in the file name.

This data object is generally used to configure menus and toolbars, though it could be used in any situation requiring instances to be present in a folder; for example, anything using FolderInstance.

Typical instance classes are subclasses of SystemAction to make menu items or toolbar buttons; JSeparator for a menu separator; or JToolBar.Separator for a toolbar separator.

Use create(org.openide.loaders.DataFolder, java.lang.String, java.lang.String) and remove(org.openide.loaders.DataFolder, java.lang.String, java.lang.String) to make the objects. Better yet, use an XML filesystem to install them declaratively.

See Also:
Serialized Form

Inner classes inherited from class org.openide.loaders.MultiDataObject
MultiDataObject.Entry
 
Inner classes inherited from class org.openide.loaders.DataObject
DataObject.Registry
 
Inner classes inherited from class org.openide.cookies.InstanceCookie
InstanceCookie.Origin
 
Field Summary
static String INSTANCE
          File extension for instance data objects.
 
Fields inherited from class org.openide.loaders.DataObject
PROP_COOKIE, PROP_FILES, PROP_HELP, PROP_MODIFIED, PROP_NAME, PROP_PRIMARY_FILE, PROP_TEMPLATE, PROP_VALID
 
Constructor Summary
InstanceDataObject(FileObject pf, MultiFileLoader loader)
          Create a new instance.
 
Method Summary
static InstanceDataObject create(DataFolder folder, String name, Class clazz)
          Deprecated. Use of XML filesystems to install instances is preferred.
static InstanceDataObject create(DataFolder folder, String name, String className)
          Deprecated. Use of XML filesystems to install instances is preferred.
protected  Node createNodeDelegate()
          Provides node that should represent this data object.
static InstanceDataObject find(DataFolder folder, String name, Class clazz)
          Finds instance of specified name in a given folder.
static InstanceDataObject find(DataFolder folder, String name, String className)
          Finds instance of specified name in a given folder.
 HelpCtx getHelpCtx()
          Get help context for this object.
 String getName()
          Get the name of the data object.
protected  FileObject handleRename(String name)
          Rename this object (implemented in subclasses).
 Class instanceClass()
          The representation type that may be created as instances.
 Object instanceCreate()
          Create an instance.
 String instanceName()
          The bean name for the instance.
static boolean remove(DataFolder folder, String name, Class clazz)
          Deprecated. Use of XML filesystems to install instances is preferred.
static boolean remove(DataFolder folder, String name, String className)
          Deprecated. Use of XML filesystems to install instances is preferred.
 
Methods inherited from class org.openide.loaders.MultiDataObject
addSecondaryEntry, files, findSecondaryEntry, getCookie, getCookieSet, getMultiFileLoader, getPrimaryEntry, handleCopy, handleCreateFromTemplate, handleDelete, handleMove, isCopyAllowed, isDeleteAllowed, isMoveAllowed, isRenameAllowed, registerEntry, removeSecondaryEntry, secondaryEntries, setCookieSet, takePrimaryFileLock
 
Methods inherited from class org.openide.loaders.DataObject
addPropertyChangeListener, addVetoableChangeListener, copy, createFromTemplate, createFromTemplate, createShadow, delete, dispose, find, firePropertyChange, fireVetoableChange, getFolder, getLoader, getNodeDelegate, getPrimaryFile, getRegistry, handleCreateShadow, isModified, isShadowAllowed, isTemplate, isValid, markFiles, move, removePropertyChangeListener, removeVetoableChangeListener, rename, setModified, setTemplate, setValid, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INSTANCE

public static final String INSTANCE
File extension for instance data objects.
Constructor Detail

InstanceDataObject

public InstanceDataObject(FileObject pf,
                          MultiFileLoader loader)
                   throws DataObjectExistsException
Create a new instance. Do not use this to make instances; use create(org.openide.loaders.DataFolder, java.lang.String, java.lang.String).
Parameters:
pf - primary file object for this data object
loader - the loader
Throws:
DataObjectExistsException - if it already exists
Method Detail

find

public static InstanceDataObject find(DataFolder folder,
                                      String name,
                                      String className)
Finds instance of specified name in a given folder.
Parameters:
folder - the folder to create the instance data object in
name - the name to give to the object (can be null if no special name besides the class name is needed)
className - the name of the class the new object should provide an instance of
Returns:
the found instance data object or null if it does not exist

find

public static InstanceDataObject find(DataFolder folder,
                                      String name,
                                      Class clazz)
Finds instance of specified name in a given folder.
Parameters:
folder - the folder to create the instance data object in
name - the name to give to the object (can be null if no special name besides the class name is needed)
clazz - the class to create instance for (see class header for details)
Returns:
the found instance data object or null if it does not exist

create

public static InstanceDataObject create(DataFolder folder,
                                        String name,
                                        String className)
                                 throws IOException
Deprecated. Use of XML filesystems to install instances is preferred.

Create a new InstanceDataObject in a given folder. If object with specified name already exists, it is returned. You should specify the name if there is a chance another file of the same instance class already exists in the folder; or just to provide a more descriptive name, which will appear in the Explorer for example.
Parameters:
folder - the folder to create the instance data object in
name - the name to give to the object (can be null if no special name besides the class name is needed)
className - the name of the class the new object should provide an instance of (see class header for details)
Returns:
the newly created or eisting instance data object
Throws:
IOException - if the file cannot be created

create

public static InstanceDataObject create(DataFolder folder,
                                        String name,
                                        Class clazz)
                                 throws IOException
Deprecated. Use of XML filesystems to install instances is preferred.

Create a new InstanceDataObject in a given folder. If object with specified name already exists, it is returned. You should specify the name if there is a chance another file of the same instance class already exists in the folder; or just to provide a more descriptive name, which will appear in the Explorer for example.
Parameters:
folder - the folder to create the instance data object in
name - the name to give to the object (can be null if no special name besides the class name is needed)
clazz - the class to create instance for (see class header for details)
Returns:
the newly created or eisting instance data object
Throws:
IOException - if the file cannot be created

remove

public static boolean remove(DataFolder folder,
                             String name,
                             String className)
Deprecated. Use of XML filesystems to install instances is preferred.

Remove an existing instance data object. If you have the exact file name, just call DataObject.delete(); this method lets you delete an instance you do not have an exact record of the file name for, based on the same information used to create it.
Parameters:
folder - the folder to remove the file from
name - the name of the instance (can be null)
className - the name of class the object referred to (see class header for details)
Returns:
true if the instance was succesfully removed, false if not

remove

public static boolean remove(DataFolder folder,
                             String name,
                             Class clazz)
Deprecated. Use of XML filesystems to install instances is preferred.

Remove an existing instance data object. If you have the exact file name, just call DataObject.delete(); this method lets you delete an instance you do not have an exact record of the file name for, based on the same information used to create it.
Parameters:
folder - the folder to remove the file from
name - the name of the instance (can be null)
className - the name of class the object referred to (see class header for details)
Returns:
true if the instance was succesfully removed, false if not

getHelpCtx

public HelpCtx getHelpCtx()
Description copied from class: DataObject
Get help context for this object.
Overrides:
getHelpCtx in class MultiDataObject
Following copied from class: org.openide.loaders.DataObject
Returns:
the help context

createNodeDelegate

protected Node createNodeDelegate()
Description copied from class: MultiDataObject
Provides node that should represent this data object.
Overrides:
createNodeDelegate in class MultiDataObject
Following copied from class: org.openide.loaders.MultiDataObject
Returns:
the node representation
See Also:
DataNode

instanceName

public String instanceName()
Description copied from interface: InstanceCookie
The bean name for the instance.
Specified by:
instanceName in interface InstanceCookie
Following copied from interface: org.openide.cookies.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

getName

public String getName()
Description copied from class: DataObject
Get the name of the data object.

The default implementation uses the name of the primary file.

Overrides:
getName in class DataObject
Following copied from class: org.openide.loaders.DataObject
Returns:
the name

handleRename

protected FileObject handleRename(String name)
                           throws IOException
Description copied from class: DataObject
Rename this object (implemented in subclasses).
Overrides:
handleRename in class MultiDataObject
Following copied from class: org.openide.loaders.DataObject
Parameters:
name - name to rename the object to
Returns:
new primary file of the object
Throws:
IOException - if an error occures


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