Package jmri.util.prefs
Class JmriPreferencesProvider
- java.lang.Object
-
- jmri.util.prefs.JmriPreferencesProvider
-
public final class JmriPreferencesProvider extends java.lang.Object
Provides instances ofPreferences
backed by a JMRI-specific storage implementation based on a Properties file.There are two Properties files per
Profile
andNodeIdentity
, both stored in the directoryprofile:profile
:profile.properties
preferences that are shared across multiple nodes for a single profile. An example of such a preference would be the Railroad Name preference.<node-identity>/profile.properties
preferences that are specific to the profile running on a specific host (<node-identity> is the identity returned byNodeIdentity.storageIdentity()
). An example of such a preference would be a file location.
Non-profile specific configuration that applies to all profiles is stored in the file
settings:preferences/preferences.properties
.
-
-
Constructor Summary
Constructors Constructor Description JmriPreferencesProvider(java.io.File path, boolean shared)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
findCNBForClass(java.lang.Class<?> cls)
Returns the name of the package for the class in a format that is treated as a single token.static java.lang.String
findCNBForPackage(java.lang.Package pkg)
Returns the name of the package in a format that is treated as a single token.(package private) static JmriPreferencesProvider
findProvider(java.io.File path, boolean shared)
Get the JmriPreferencesProvider for the specified profile path.static java.util.prefs.Preferences
getPreferences(java.io.File path, java.lang.Class<?> clazz, boolean shared)
Get thePreferences
for the specified class in the specified path.(package private) java.util.prefs.Preferences
getPreferences(java.lang.Class<?> clazz)
Get thePreferences
for the specified class.(package private) java.util.prefs.Preferences
getPreferences(java.lang.Package pkg)
Get thePreferences
for the specified package.(package private) java.util.prefs.Preferences
getPreferences(java.lang.String pkg)
Get thePreferences
for the specified package.static java.util.prefs.Preferences
getPreferences(Profile project, java.lang.Class<?> clazz, boolean shared)
Get thePreferences
for the specified class in the specified profile.static java.util.prefs.Preferences
getPreferences(Profile project, java.lang.Package pkg, boolean shared)
Get thePreferences
for the specified package in the specified profile.static java.util.prefs.Preferences
getPreferences(Profile project, java.lang.String pkg, boolean shared)
Get thePreferences
for the specified package in the specified profile.(package private) java.io.File
getPreferencesFile()
protected boolean
isBackedUp()
boolean
isFirstUse()
Return true if the properties file had not been written for a JMRIProfile
before this instance of JMRI was launched.protected void
setBackedUp(boolean backedUp)
-
-
-
Constructor Detail
-
JmriPreferencesProvider
JmriPreferencesProvider(@CheckForNull java.io.File path, boolean shared)
-
-
Method Detail
-
findProvider
@Nonnull static JmriPreferencesProvider findProvider(@CheckForNull java.io.File path, boolean shared)
Get the JmriPreferencesProvider for the specified profile path.- Parameters:
path
- The root path of aProfile
. This is most frequently the path returned byProfile.getPath()
.shared
- True if the preferences apply to the profile at path regardless of host. If false, the preferences only apply to this computer.- Returns:
- The shared or private JmriPreferencesProvider for the project at path.
-
getPreferences
@Nonnull public static java.util.prefs.Preferences getPreferences(@CheckForNull Profile project, @CheckForNull java.lang.Class<?> clazz, boolean shared)
Get thePreferences
for the specified class in the specified profile.- Parameters:
project
- The profile. This is most often the profile returned by theProfileManager.getActiveProfile()
method of the ProfileManager returned byProfileManager.getDefault()
. If null, preferences apply to all profiles on the computer and the value of shared is ignored.clazz
- The class requesting preferences. Note that the preferences returned are for the package containing the class.shared
- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of project is null.- Returns:
- The shared or private Preferences node for the package containing clazz for project.
-
getPreferences
@Nonnull public static java.util.prefs.Preferences getPreferences(@CheckForNull Profile project, @CheckForNull java.lang.Package pkg, boolean shared)
Get thePreferences
for the specified package in the specified profile.- Parameters:
project
- The profile. This is most often the profile returned by theProfileManager.getActiveProfile()
method of the ProfileManager returned byProfileManager.getDefault()
. If null, preferences apply to all profiles on the computer and the value of shared is ignored.pkg
- The package requesting preferences.shared
- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of project is null.- Returns:
- The shared or private Preferences node for the package for project.
-
getPreferences
@Nonnull public static java.util.prefs.Preferences getPreferences(@CheckForNull Profile project, @CheckForNull java.lang.String pkg, boolean shared)
Get thePreferences
for the specified package in the specified profile.Use of
getPreferences(Profile, Class, boolean)
orgetPreferences(Profile, Package, boolean)
is preferred and recommended unless reading preferences for a non-existent package or class.- Parameters:
project
- The profile. This is most often the profile returned by theProfileManager.getActiveProfile()
method of the ProfileManager returned byProfileManager.getDefault()
. If null, preferences apply to all profiles on the computer and the value of shared is ignored.pkg
- The package requesting preferences.shared
- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of project is null.- Returns:
- The shared or private Preferences node for the package.
-
getPreferences
public static java.util.prefs.Preferences getPreferences(@CheckForNull java.io.File path, @CheckForNull java.lang.Class<?> clazz, boolean shared)
Get thePreferences
for the specified class in the specified path.Use of
getPreferences(jmri.profile.Profile, java.lang.Class, boolean)
is preferred and recommended unless being used to during the construction of a Profile object.- Parameters:
path
- The path to a profile. This is most often the result ofProfile.getPath()
for a given Profile. If null, preferences apply to all profiles on the computer and the value of shared is ignored.clazz
- The class requesting preferences. Note that the preferences returned are for the package containing the class.shared
- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of path is null.- Returns:
- The shared or private Preferences node for the package containing clazz for project.
-
getPreferences
java.util.prefs.Preferences getPreferences(@CheckForNull java.lang.Package pkg)
Get thePreferences
for the specified package.- Parameters:
pkg
- The package requesting preferences.- Returns:
- The shared or private Preferences node for the package.
-
getPreferences
java.util.prefs.Preferences getPreferences(@CheckForNull java.lang.Class<?> clazz)
Get thePreferences
for the specified class.- Parameters:
clazz
- The class requesting preferences. Note that the preferences returned are for the package containing the class.- Returns:
- The shared or private Preferences node for the package containing clazz.
-
getPreferences
java.util.prefs.Preferences getPreferences(@CheckForNull java.lang.String pkg)
Get thePreferences
for the specified package.- Parameters:
pkg
- The package for which preferences are needed.- Returns:
- The shared or private Preferences node for the package.
-
isFirstUse
public boolean isFirstUse()
Return true if the properties file had not been written for a JMRIProfile
before this instance of JMRI was launched. Note that the first use of a node-specific setting can be different than the first use of a multi-node setting.- Returns:
- true if new or newly migrated profile, false otherwise
-
findCNBForClass
public static java.lang.String findCNBForClass(@Nonnull java.lang.Class<?> cls)
Returns the name of the package for the class in a format that is treated as a single token.- Parameters:
cls
- The class for which a sanitized package name is needed- Returns:
- A sanitized package name
-
findCNBForPackage
public static java.lang.String findCNBForPackage(@Nonnull java.lang.Package pkg)
Returns the name of the package in a format that is treated as a single token.- Parameters:
pkg
- The package for which a sanitized name is needed- Returns:
- A sanitized package name
-
getPreferencesFile
@Nonnull java.io.File getPreferencesFile()
-
isBackedUp
protected boolean isBackedUp()
- Returns:
- the backedUp
-
setBackedUp
protected void setBackedUp(boolean backedUp)
- Parameters:
backedUp
- the backedUp to set
-
-