Note: These pages are being reviewed.
Should I register an object in my layer file using .instance or .settings files? What about .shadow files or serialization?
There are a number of kinds of files which are treated (and can be transformed into) instances of objects.
What | When to Use It | How |
---|---|---|
|
Almost all the time |
Create a file whose name is the fully qualified name of the class you want to register, with the . characters replaced with - characters and the extension If you want to use a factory method and set up some configuration of the object using your own FileObject attributes, you can instead <ul><li>Create a public static method on some class, which takes a `FileObject as an argument, e.g.<blockquote>`<file name="x.instance"> <attr name="instanceClass" stringvalue="com.foo.mymodule.MyStatusBarElementProvider"/> <attr name="instanceCreate" methodvalue="com.foo.mymodule.MyStatusBarElementProvider.factoryMethod"/> attr name="yourCustomAttribute" stringvalue="someValueYouCareAbout"/></file>`</blockquote> ---- |
|
In specialized situations when the object may be saved back to disk with changed state at runtime and you cannot simply use |
Create an XML file in your module for your settings file, populated as described in the .settings file FAQ. Register that file in some folder by specifying the XML file as the URL of the |
|
If you want your object to be a pseudo-singleton, but it will be registered in multiple folders, or the user may delete the shadow file and you need to provide a way for the user to recover it (i.e. a way to create a new |
|
|
Basically never |
Write a serialized object out to disk in a file with the extension |
Your own file type |
Basically never |
Any DataObject type which contains an |
Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqRegisterObjectsViaInstanceOrSettingsFiles , that was last modified by NetBeans user Jglick on 2010-06-14T22:30:44Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.