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
public abstract class AbstractPreferencesManager extends Bean implements PreferencesManager
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 Constructor Description AbstractPreferencesManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addInitializationException(Profile profile, java.lang.Exception exception)
Add an error to the list of exceptions.java.util.List<java.lang.Exception>
getInitializationExceptions(Profile profile)
Get the set of exceptions thrown during initialization for the provided Profile.java.util.Set<java.lang.Class<?>>
getProvides()
Get the set of Classes that this PreferencesManager can be registered as a provider of in theInstanceManager
.java.util.Set<java.lang.Class<? extends PreferencesManager>>
getRequires()
Get the set of PreferencesManagers that must be initialized prior to initializing this PreferencesManager.boolean
isInitialized(Profile profile)
Test if the PreferencesManager is initialized without errors for the provided Profile.boolean
isInitializedWithExceptions(Profile profile)
Test if the PreferencesManager is initialized, but threw anInitializationException
during initialization, for the provided Profile.protected boolean
isInitializing(Profile profile)
Test if the manager is being initialized.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.protected void
requiresNoInitializedWithExceptions(Profile profile, java.lang.String message)
Require that instances of the specified classes have initialized correctly.protected void
requiresNoInitializedWithExceptions(Profile profile, java.util.Set<java.lang.Class<? extends PreferencesManager>> classes, java.lang.String message)
Require that instances of the specified classes have initialized correctly.protected void
setInitialized(Profile profile, boolean initialized)
Set the initialized state for the given profile.protected void
setInitializing(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, removePropertyChangeListener
-
Methods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty, setIndexedProperty, setProperty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.spi.PreferencesManager
initialize, savePreferences
-
-
-
-
Constructor Detail
-
AbstractPreferencesManager
public 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 andPreferencesManager.isInitializedWithExceptions(jmri.profile.Profile)
can be false, if isInitializedWithExceptions(Profile) returns true, this method must return false.- Specified by:
isInitialized
in 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
public boolean isInitializedWithExceptions(Profile profile)
Test if the PreferencesManager is initialized, but threw anInitializationException
during 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:
isInitializedWithExceptions
in 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
@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 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
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 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
@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 theInstanceManager
.This implementation returns the class of the object against which this method is called.
- Specified by:
getProvides
in 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
protected void setInitialized(Profile profile, boolean initialized)
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
protected void setInitializing(Profile profile, boolean initializing)
Protect against circular attempts to initialize during initialization.- Parameters:
profile
- the profile for which initializing is ongoinginitializing
- 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 initializedexception
- 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 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)java.lang.IllegalArgumentException
- if any member of classes is not also in the set of classes returned bygetRequires()
-
requiresNoInitializedWithExceptions
protected void requiresNoInitializedWithExceptions(Profile profile, @Nonnull java.lang.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
@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 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
-
-