Class JmriPreferencesProvider


  • public final class JmriPreferencesProvider
    extends java.lang.Object
    Provides instances of Preferences backed by a JMRI-specific storage implementation based on a Properties file.

    There are two Properties files per Profile and NodeIdentity, both stored in the directory profile: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 by NodeIdentity.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 the Preferences for the specified class in the specified path.
      (package private) java.util.prefs.Preferences getPreferences​(java.lang.Class<?> clazz)
      Get the Preferences for the specified class.
      (package private) java.util.prefs.Preferences getPreferences​(java.lang.Package pkg)
      Get the Preferences for the specified package.
      (package private) java.util.prefs.Preferences getPreferences​(java.lang.String pkg)
      Get the Preferences for the specified package.
      static java.util.prefs.Preferences getPreferences​(Profile project, java.lang.Class<?> clazz, boolean shared)
      Get the Preferences for the specified class in the specified profile.
      static java.util.prefs.Preferences getPreferences​(Profile project, java.lang.Package pkg, boolean shared)
      Get the Preferences for the specified package in the specified profile.
      static java.util.prefs.Preferences getPreferences​(Profile project, java.lang.String pkg, boolean shared)
      Get the Preferences 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 JMRI Profile before this instance of JMRI was launched.
      protected void setBackedUp​(boolean backedUp)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 a Profile. This is most frequently the path returned by Profile.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 the Preferences for the specified class in the specified profile.
        Parameters:
        project - The profile. This is most often the profile returned by the ProfileManager.getActiveProfile() method of the ProfileManager returned by ProfileManager.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 the Preferences for the specified package in the specified profile.
        Parameters:
        project - The profile. This is most often the profile returned by the ProfileManager.getActiveProfile() method of the ProfileManager returned by ProfileManager.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 the Preferences for the specified package in the specified profile.

        Use of getPreferences(Profile, Class, boolean) or getPreferences(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 the ProfileManager.getActiveProfile() method of the ProfileManager returned by ProfileManager.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 the Preferences 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 of Profile.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 the Preferences 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 the Preferences 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 the Preferences 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 JMRI Profile 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
      • isBackedUp

        protected boolean isBackedUp()
        Returns:
        the backedUp
      • setBackedUp

        protected void setBackedUp​(boolean backedUp)
        Parameters:
        backedUp - the backedUp to set