Create Pref Service by hinerm · Pull Request #102 · scijava/scijava-common
This was referenced
This was referenced
and others added 16 commits
Using a static utility method for Prefs is limiting - it provides no way to override preference saving/loading behavior. This creates problems when there are errors or negative interactions with the Preferences implementation - for example, in MATLAB there are known bugs regarding the Java Preferences implementation. By converting to a PrefService we can now control this behavior more precisely, as needed. The Prefs utility class will remain for now, but will delegate to the PrefService when it has been created - allowing the utility method behavior to be overridden similarly.
Added API to save/load ModuleItems. This will allow Contextual classes to move away from ModuleItem#loadValue and ModuleItem#saveValue, which are not Contextual and go directly through the Prefs utility class. Adds a default implementation in DefaultModuleService, using the PrefService if able (which requires an AbstractModuleItem). If necessary, still falls back to ModuleItem's saveValue and loadValue methods.
ModuleItem#saveValue and ModuleItem#loadValue are now deprecated in favor of ModuleService methods, which can be called from a Contextual environment and thus use the new PrefService API.
Updated classes that were using ModuleItem#saveValue and ModuleItem#loadValue to use the appropriate ModuleService methods.
It was discovered that the initialize method of multiple PrefService impls was being invoked - leading to the LOWEST priority overwriting the static service field in the Prefs utility class (since it was the last initialize method to execute). Added a check for priority so that lower priority services don't overwrite higher.
This was an unnecessary method. Originally thought that each service would need a reminder to set itself as the static PrefService... but that's exactly what the initialize method of AbstractPrefService is for.
The whole point of the PrefService is to allow for any preference implementation, while the DefaultPrefService uses java.util.Preferences. Thus the java.util.Preferences imports have been removed from the PrefService, and the necessary Class and String-based indexing methods have been added. Updated the DefaultPrefService implementation and usage of the service accordingly.
We have a short name PrefService, so we should use a short package name instead of a long package name.
hinerm added a commit that referenced this pull request
hinerm
deleted the
create_pref_service
branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters