Reputation: 171
Our program stores user settings using the Preferences class, accessed via Preferences.userNodeForPackage()
. We just finished a major refactor and discovered that all of the user settings are forgotten post-refactor, because the class passed to userNodeForPackage()
is different. E.g. instead of org.foo.MyClass
we now have org.foo.bar.MyClass
.
I want to "import" the old Preferences so our users don't notice things being forgotten. If necessary I can manually copy individual key/value pairs across from the old Preferences object to a new one, but I must be able to get that old Preferences object first. Without access to the old class, I don't see how this is possible.
Am I missing something? I see the Preferences.node()
/ Preferences.nodeExists()
methods which seem promising, except that they only operate on an existing Preferences that contains the desired node. Thus we'd have to be able to get a tree that contains the old root node, and we have no classes above where that old node was (part of the point of refactoring was de-flattening our hierarchy).
I'd really rather not pollute our nice clean source code with dummy files, just so we can access old preferences. Can you assign a package to an anonymous class generated at runtime, perhaps? Or is there some other way to get a Preferences object for a specific package short of passing in the class for that package?
Thanks in advance.
Upvotes: 0
Views: 64
Reputation: 171
RC's comment of using Preferences.userRoot()
is what I needed -- that gets you the root of the entire Preferences tree, and you can then traverse it using Preferences.node()
to get to whatever value you need. Thanks, RC!
Upvotes: 2