Class AbstractPreferencesManager

java.lang.Object
jmri.beans.UnboundBean
jmri.beans.Bean
jmri.util.prefs.AbstractPreferencesManager
All Implemented Interfaces:
BeanInterface, PropertyChangeFirer, PropertyChangeProvider, JmriServiceProviderInterface, PreferencesManager
Direct Known Subclasses:
ConnectionConfigManager, ConsistPreferencesManager, FileLocationsPreferences, JmriJTablePersistenceManager, ManagerDefaultSelector, ProgrammerConfigManager, RosterConfigManager, StartupActionsManager, WarrantPreferences, WebAppManager

public abstract class AbstractPreferencesManager extends Bean implements PreferencesManager
An abstract PreferencesManager that implements some of the boilerplate that PreferencesManager implementations would otherwise require.
  • Constructor Details

  • Method Details

    • isInitialized

      public boolean isInitialized(Profile profile)
      Test if the PreferencesManager is initialized without errors for the provided Profile. Note that although both this method and PreferencesManager.isInitializedWithExceptions(jmri.profile.Profile) can be false, if isInitializedWithExceptions(Profile) returns true, this method must return false.
      Specified by:
      isInitialized in interface PreferencesManager
      Parameters:
      profile - the configuration profile to test against; may be null to test for exceptions thrown when initializing for this user regardless of profile
      Returns:
      true if the provider is initialized without exceptions
    • isInitializedWithExceptions

      public boolean isInitializedWithExceptions(Profile profile)
      Test if the PreferencesManager is initialized, but threw an InitializationException during initialization, for the provided Profile. Note that although both this method and PreferencesManager.isInitialized(jmri.profile.Profile) can be false, if isInitialized(Profile) returns true, this method must return false.
      Specified by:
      isInitializedWithExceptions in interface PreferencesManager
      Parameters:
      profile - the configuration profile to test against; may be null to test for exceptions thrown when initializing for this user regardless of profile
      Returns:
      true if the provide is initialized with exceptions
    • getInitializationExceptions

      Get the set of exceptions thrown during initialization for the provided Profile.
      Specified by:
      getInitializationExceptions in interface PreferencesManager
      Parameters:
      profile - the configuration profile to test against; may be null to test for exceptions thrown when initializing for this user regardless of profile
      Returns:
      A list of exceptions. If there are no exceptions, return an empty set instead of null.
    • isInitializing

      protected boolean isInitializing(Profile profile)
      Test if the manager is being initialized.
      Parameters:
      profile - the profile against which the manager is being initialized or null if being initialized for this user regardless of profile
      Returns:
      true if being initialized; false otherwise
    • getRequires

      Get the set of PreferencesManagers that must be initialized prior to initializing this PreferencesManager. It is generally preferable to require an Interface or an abstract Class instead of a concrete Class, since that allows all (or any) concrete implementations of the required class to be initialized to provide required services for the requiring PreferencesManager instance.

      Note that for any set of PreferencesManagers with the same requirements, or with a circular dependency between each other, the order in which the PreferencesManagers in that set are initialized should be considered non-deterministic.

      This implementation includes a default dependency on the ConnectionConfigManager.

      Specified by:
      getRequires in interface PreferencesManager
      Returns:
      An set of classes; if there are no dependencies, return an empty set instead of null; overriding implementations may add to this set directly
    • getProvides

      @Nonnull public Set<Class<?>> getProvides()
      Get the set of Classes that this PreferencesManager can be registered as a provider of in the InstanceManager.

      This implementation returns the class of the object against which this method is called.

      Specified by:
      getProvides in interface PreferencesManager
      Returns:
      A set or list of classes. If this PreferencesManager provides an instance of no other Interfaces or abstract Classes than PreferencesManager, return an empty set instead of null.
    • setInitialized

      protected void setInitialized(Profile profile, boolean initialized)
      Set the initialized state for the given profile. Sets isInitializing(jmri.profile.Profile) to false if setting initialized to false.
      Parameters:
      profile - the profile to set initialized against
      initialized - the initialized state to set
    • setInitializing

      protected void setInitializing(Profile profile, boolean initializing)
      Protect against circular attempts to initialize during initialization.
      Parameters:
      profile - the profile for which initializing is ongoing
      initializing - the initializing state to set
    • addInitializationException

      protected void addInitializationException(Profile profile, @Nonnull Exception exception)
      Add an error to the list of exceptions.
      Parameters:
      profile - the profile against which the manager is being initialized
      exception - the exception to add
    • requiresNoInitializedWithExceptions

      Require that instances of the specified classes have initialized correctly. This method should only be called from within PreferencesManager.initialize(jmri.profile.Profile), generally immediately after the PreferencesManager verifies that it is not already initialized. If this method is within a try-catch block, the exception it generates should be re-thrown by initialize(profile).
      Parameters:
      profile - the profile against which the manager is being initialized
      classes - the manager classes for which all calling isInitialized(jmri.profile.Profile) must return true against all instances of
      message - the localized message to display if an InitializationExcpetion is thrown
      Throws:
      InitializationException - if any instance of any class in classes returns false on isIntialized(profile)
      IllegalArgumentException - if any member of classes is not also in the set of classes returned by getRequires()
    • requiresNoInitializedWithExceptions

      Require that instances of the specified classes have initialized correctly. This method should only be called from within PreferencesManager.initialize(jmri.profile.Profile), generally immediately after the PreferencesManager verifies that it is not already initialized. If this method is within a try-catch block, the exception it generates should be re-thrown by initialize(profile). This calls requiresNoInitializedWithExceptions(jmri.profile.Profile, java.util.Set, java.lang.String) with the result of getRequires() as the set of classes to require.
      Parameters:
      profile - the profile against which the manager is being initialized
      message - the localized message to display if an InitializationExcpetion is thrown
      Throws:
      InitializationException - if any instance of any class in classes returns false on isIntialized(profile)
    • requireAllOther

      Convenience method to allow a PreferencesManager to require all other PreferencesManager in an attempt to be the last PreferencesManager initialized. Use this method as the body of getRequires().

      Note given a set of PreferencesManagers using this method as the body of getRequires(), the order in which those PreferencesManagers are initialized is non-deterministic.

      Returns:
      a set of all PreferencesManagers registered with the InstanceManager except this one