Class AbstractPreferencesManager

    • Method Detail

      • 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
      • getInitializationExceptions

        @Nonnull
        public java.util.List<java.lang.Exception> getInitializationExceptions​(Profile profile)
        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

        @Nonnull
        public java.util.Set<java.lang.Class<? extends PreferencesManager>> 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 java.util.Set<java.lang.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
                                                  java.lang.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

        protected void requiresNoInitializedWithExceptions​(Profile profile,
                                                           @Nonnull
                                                           java.util.Set<java.lang.Class<? extends PreferencesManager>> classes,
                                                           @Nonnull
                                                           java.lang.String message)
                                                    throws InitializationException
        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)
        java.lang.IllegalArgumentException - if any member of classes is not also in the set of classes returned by getRequires()
      • requireAllOther

        @Nonnull
        protected java.util.Set<java.lang.Class<? extends PreferencesManager>> 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