Package jmri.util.prefs
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
An abstract PreferencesManager that implements some of the boilerplate that
PreferencesManager implementations would otherwise require.
-
Field Summary
Fields inherited from class jmri.beans.Bean
propertyChangeSupport -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddInitializationException(Profile profile, Exception exception) Add an error to the list of exceptions.getInitializationExceptions(Profile profile) Get the set of exceptions thrown during initialization for the provided Profile.Get the set of Classes that this PreferencesManager can be registered as a provider of in theInstanceManager.Set<Class<? extends PreferencesManager>>Get the set of PreferencesManagers that must be initialized prior to initializing this PreferencesManager.booleanisInitialized(Profile profile) Test if the PreferencesManager is initialized without errors for the provided Profile.booleanisInitializedWithExceptions(Profile profile) Test if the PreferencesManager is initialized, but threw anInitializationExceptionduring initialization, for the provided Profile.protected booleanisInitializing(Profile profile) Test if the manager is being initialized.protected Set<Class<? extends PreferencesManager>>Convenience method to allow a PreferencesManager to require all other PreferencesManager in an attempt to be the last PreferencesManager initialized.protected voidrequiresNoInitializedWithExceptions(Profile profile, String message) Require that instances of the specified classes have initialized correctly.protected voidrequiresNoInitializedWithExceptions(Profile profile, Set<Class<? extends PreferencesManager>> classes, String message) Require that instances of the specified classes have initialized correctly.protected voidsetInitialized(Profile profile, boolean initialized) Set the initialized state for the given profile.protected voidsetInitializing(Profile profile, boolean initializing) Protect against circular attempts to initialize during initialization.Methods inherited from class jmri.beans.Bean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, isNotifyOnEDT, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty, setIndexedProperty, setPropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.spi.PreferencesManager
initialize, savePreferences
-
Constructor Details
-
AbstractPreferencesManager
public AbstractPreferencesManager()
-
-
Method Details
-
isInitialized
Test if the PreferencesManager is initialized without errors for the provided Profile. Note that although both this method andPreferencesManager.isInitializedWithExceptions(jmri.profile.Profile)can be false, if isInitializedWithExceptions(Profile) returns true, this method must return false.- Specified by:
isInitializedin interfacePreferencesManager- 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
Test if the PreferencesManager is initialized, but threw anInitializationExceptionduring initialization, for the provided Profile. Note that although both this method andPreferencesManager.isInitialized(jmri.profile.Profile)can be false, if isInitialized(Profile) returns true, this method must return false.- Specified by:
isInitializedWithExceptionsin interfacePreferencesManager- 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:
getInitializationExceptionsin interfacePreferencesManager- 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
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:
getRequiresin interfacePreferencesManager- 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
Get the set of Classes that this PreferencesManager can be registered as a provider of in theInstanceManager.This implementation returns the class of the object against which this method is called.
- Specified by:
getProvidesin interfacePreferencesManager- 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
Set the initialized state for the given profile. SetsisInitializing(jmri.profile.Profile)to false if setting initialized to false.- Parameters:
profile- the profile to set initialized againstinitialized- the initialized state to set
-
setInitializing
Protect against circular attempts to initialize during initialization.- Parameters:
profile- the profile for which initializing is ongoinginitializing- the initializing state to set
-
addInitializationException
Add an error to the list of exceptions.- Parameters:
profile- the profile against which the manager is being initializedexception- the exception to add
-
requiresNoInitializedWithExceptions
protected void requiresNoInitializedWithExceptions(Profile profile, @Nonnull Set<Class<? extends PreferencesManager>> classes, @Nonnull String message) throws InitializationException Require that instances of the specified classes have initialized correctly. This method should only be called from withinPreferencesManager.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 initializedclasses- the manager classes for which all callingisInitialized(jmri.profile.Profile)must return true against all instances ofmessage- 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 bygetRequires()
-
requiresNoInitializedWithExceptions
protected void requiresNoInitializedWithExceptions(Profile profile, @Nonnull String message) throws InitializationException Require that instances of the specified classes have initialized correctly. This method should only be called from withinPreferencesManager.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 callsrequiresNoInitializedWithExceptions(jmri.profile.Profile, java.util.Set, java.lang.String)with the result ofgetRequires()as the set of classes to require.- Parameters:
profile- the profile against which the manager is being initializedmessage- 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 ofgetRequires().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
-