Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: persistent data



Lyderic Landry wrote:
Jerry wrote:

You can avoid this problem by making your preferences node name
have more than three levels. So, for instance, com.foo.thing goes
into the single preferences files, but com.foo,bar.thing goes into
its own plist file of the same name. How they came up with a scheme
as weird as this is anyone's guess.

Mac preferences are generally one prefs file per app. Java's Preferences are a single hierarchy, with no per-app divisions. The Mac implementation of java.util.preferences hopes that most preferences will start with 'com.SomeCompany.SomeApp'. Then all of SomeApp's preferences will be stored in com.SomeCompany.SomeApp.plist, just like a non-Java app.




1. I have a class in a package called com.example.package

2. Creating a Preferences object goes like this :
Preferences prefs = Preferences.userNodeForPackage(getClass());
- On Mac: this creates a file in $HOME/Library/Preferences called
'com.example.package.plist' + an entry in $HOME/Library/Preferences/
com.apple.java.util.prefs.plist
- On Windows: this creates an entry in the registry under
'HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\example\package'

This creates four Preferences nodes, if they don't exist: / /com /com/example /com/example/package

The last is the one returned to you.


3. Now if I remove the node with prefs.removeNode():
- On Mac: this actually removes the file in $HOME/Library/Preferences/
com.example.package.plist and the entry in $HOME/Library/Preferences/
com.apple.java.util.prefs.plist (this is perfect)
- On Windows: this removes the last node (called 'package') but not
the above tree (i.e. 'com\example') (this could be better and remove
the whole thing).

This is correct. removeNode() only deletes /com/example/package . The other nodes (including /com/example) are unchanged, even if /com/ example now contains no keys and no child nodes. The Mac version should still have entries for /, /com, and /com/example in com.apple.java.util.prefs.plist; if not, that's a Mac bug.


If all of your preferences are nested inside com.YourCompany.YourApp, then it's easy to uninstall them on any platform:

// warning: untested code
if (Preferences.userRoot().nodeExists("/com/YourCompany/ YourApp")) {
Preferences appPrefs = Preferences.userRoot().node("/com/ YourCompany/YourApp");
appPrefs.removeNode();
appPrefs.flush();
}
// repeat for systemRoot if desired


This would still leave a stale /com/YourCompany node. You could delete it if empty (check keys() and children()), or just leave it.


-- Greg Parker email@hidden Runtime Wrangler

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.