Class AbstractManager<E extends NamedBean>
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.beans.VetoableChangeSupport
-
- jmri.managers.AbstractManager<E>
-
- Type Parameters:
E
- the class this manager supports
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.beans.VetoableChangeListener
,java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,Manager<E>
- Direct Known Subclasses:
AbstractAnalogIOManager
,AbstractAudioManager
,AbstractBaseManager
,AbstractLightManager
,AbstractMemoryManager
,AbstractMeterManager
,AbstractReporterManager
,AbstractSensorManager
,AbstractSignalHeadManager
,AbstractStringIOManager
,AbstractTurnoutManager
,BlockManager
,DefaultCatalogTreeManager
,DefaultConditionalManager
,DefaultConditionalNGManager
,DefaultGlobalVariableManager
,DefaultIdTagManager
,DefaultLogixManager
,DefaultLogixNGManager
,DefaultModuleManager
,DefaultNamedTableManager
,DefaultRouteManager
,DefaultSectionManager
,DefaultSignalGroupManager
,DefaultSignalMastLogicManager
,DefaultSignalMastManager
,DefaultSignalSystemManager
,DefaultTransitManager
,DefaultVariableLightManager
,EcosLocoAddressManager
,LayoutBlockManager
,NamedBeanHandleManager
,OBlockManager
,WarrantManager
public abstract class AbstractManager<E extends NamedBean> extends VetoableChangeSupport implements Manager<E>, java.beans.PropertyChangeListener, java.beans.VetoableChangeListener
Abstract partial implementation for all Manager-type classes.Note that this does not enforce any particular system naming convention at the present time. They're just names...
It does include, with AbstractNamedBean, the implementation of the normalized user name.
See source file for extensive implementation notes.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.Manager
Manager.ManagerDataEvent<E extends NamedBean>, Manager.ManagerDataListener<E extends NamedBean>, Manager.NameValidity
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.TreeSet<E>
_beans
protected java.util.Hashtable<java.lang.String,E>
_tsys
protected java.util.Hashtable<java.lang.String,E>
_tuser
(package private) java.util.concurrent.atomic.AtomicInteger
lastAutoNamedBeanRef
protected SystemConnectionMemo
memo
(package private) java.text.DecimalFormat
paddedNumber
protected java.util.Set<java.lang.String>
silenceableProperties
protected java.util.Map<java.lang.String,java.lang.Boolean>
silencedProperties
-
Fields inherited from class jmri.beans.VetoableChangeSupport
vetoableChangeSupport
-
Fields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupport
-
Fields inherited from interface jmri.Manager
ANALOGIOS, AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, CTCDATA, ENTRYEXIT, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXNG_ANALOG_ACTIONS, LOGIXNG_ANALOG_EXPRESSIONS, LOGIXNG_CONDITIONALNGS, LOGIXNG_DIGITAL_ACTIONS, LOGIXNG_DIGITAL_BOOLEAN_ACTIONS, LOGIXNG_DIGITAL_EXPRESSIONS, LOGIXNG_GLOBAL_VARIABLES, LOGIXNG_MODULES, LOGIXNG_STRING_ACTIONS, LOGIXNG_STRING_EXPRESSIONS, LOGIXNG_TABLES, LOGIXNGS, LOGIXS, MEMORIES, METERFRAMES, METERS, OBLOCKS, PANELFILES, REPORTERS, ROUTES, SECTIONS, SENSORGROUPS, SENSORS, SIGNALGROUPS, SIGNALHEADS, SIGNALMASTLOGICS, SIGNALMASTS, STRINGIOS, TIMEBASE, TRANSITS, TURNOUTS, WARRANTS
-
-
Constructor Summary
Constructors Constructor Description AbstractManager()
AbstractManager(SystemConnectionMemo memo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDataListener(Manager.ManagerDataListener<E> e)
Register aManager.ManagerDataListener
to hear about adding or removing items from the list of NamedBeans.protected java.lang.String
checkNumeric(java.lang.String curAddress)
checks for numeric-only system names.java.lang.String
createSystemName(java.lang.String curAddress, java.lang.String prefix)
Create a System Name from hardware address and system letter prefix.void
deleteBean(E bean, java.lang.String property)
Method for a UI to delete a bean.void
deregister(E s)
Forget a NamedBean Object created outside the manager.void
dispose()
Free resources when no longer used.protected void
fireDataListenersAdded(int start, int end, E changedBean)
protected void
fireDataListenersRemoved(int start, int end, E changedBean)
void
fireVetoableChange(java.lang.String p, java.lang.Object old, java.lang.Object n)
Inform all registered listeners of a vetoable change.java.lang.String
getAutoSystemName()
E
getBySystemName(java.lang.String systemName)
Locate an existing instance based on a system name.protected E
getBySystemName(java.lang.String systemName, java.util.Comparator<java.lang.String> comparator)
Protected method used by subclasses to over-ride the default behavior of getBySystemName when a simple string lookup is not sufficient.E
getByUserName(java.lang.String userName)
Locate an existing instance based on a user name.java.util.List<NamedBeanPropertyDescriptor<?>>
getKnownBeanProperties()
By default there are no custom properties.SystemConnectionMemo
getMemo()
Get the system connection for this manager.E
getNamedBean(java.lang.String name)
Locate an existing instance based on a name.java.util.SortedSet<E>
getNamedBeanSet()
Provide an unmodifiable SortedSet of NamedBeans in system-name order.int
getObjectCount()
Get the count of managed objects.protected E
getOuterBean(E bean)
Get the outer bean of an encapsulated bean.java.lang.String
getSystemPrefix()
Provide access to the system prefix string.protected void
handleUserNameUniqueness(E s)
Invoked byregisterUserName(NamedBean)
to ensure uniqueness of the NamedBean during registration.java.lang.String
makeSystemName(java.lang.String s, boolean logErrors, java.util.Locale locale)
Create a SystemName by prepending the system name prefix to the name if not already present.void
propertyChange(java.beans.PropertyChangeEvent e)
The PropertyChangeListener interface in this class is intended to keep track of user name changes to individual NamedBeans.void
register(E s)
Remember a NamedBean Object created outside the manager.protected void
registerSelf()
By default, register this manager to store as configuration information.protected void
registerUserName(E s)
Invoked byregister(NamedBean)
to register the user name of the bean.void
removeDataListener(Manager.ManagerDataListener<E> e)
Unregister a previously-addedManager.ManagerDataListener
.void
setDataListenerMute(boolean m)
Temporarily suppress DataListener notifications.void
setPropertyChangesSilenced(java.lang.String propertyName, boolean silenced)
Suppress sendingPropertyChangeEvent
s for the named property.(package private) void
setRegisterSelf()
void
updateAutoNumber(java.lang.String systemName)
Manager.NameValidity
validSystemNameFormat(java.lang.String systemName)
Test if parameter is a properly formatted system name.void
vetoableChange(java.beans.PropertyChangeEvent evt)
-
Methods inherited from class jmri.beans.VetoableChangeSupport
addVetoableChangeListener, addVetoableChangeListener, fireVetoableChange, fireVetoableChange, fireVetoableChange, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.Manager
getBeanTypeHandled, getBeanTypeHandled, getEntryToolTip, getNamedBeanClass, getSubSystemNamePrefix, getSystemNamePrefix, getXMLOrder, isValidSystemNameFormat, makeSystemName, makeSystemName, typeLetter, validateBadCharsInSystemNameFormat, validateIntegerSystemNameFormat, validateNmraAccessorySystemNameFormat, validateSystemNameFormat, validateSystemNameFormat, validateSystemNameFormatOnlyNumeric, validateSystemNamePrefix, validateTrimmedMin1NumberSystemNameFormat, validateTrimmedSystemNameFormat, validateUppercaseTrimmedSystemNameFormat
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface jmri.beans.VetoableChangeProvider
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
-
-
-
Field Detail
-
memo
protected final SystemConnectionMemo memo
-
silencedProperties
protected final java.util.Map<java.lang.String,java.lang.Boolean> silencedProperties
-
silenceableProperties
protected final java.util.Set<java.lang.String> silenceableProperties
-
lastAutoNamedBeanRef
java.util.concurrent.atomic.AtomicInteger lastAutoNamedBeanRef
-
paddedNumber
java.text.DecimalFormat paddedNumber
-
-
Constructor Detail
-
AbstractManager
public AbstractManager(SystemConnectionMemo memo)
-
AbstractManager
public AbstractManager()
-
-
Method Detail
-
setRegisterSelf
final void setRegisterSelf()
-
registerSelf
@OverridingMethodsMustInvokeSuper protected void registerSelf()
By default, register this manager to store as configuration information. Override to change that.
-
getMemo
@Nonnull public SystemConnectionMemo getMemo()
Get the system connection for this manager.
-
makeSystemName
@Nonnull public java.lang.String makeSystemName(@Nonnull java.lang.String s, boolean logErrors, java.util.Locale locale)
Create a SystemName by prepending the system name prefix to the name if not already present.The
logErrors
parameter is present to allow user interface input validation to use this method without logging system name validation errors as the user types.Note: implementations must call
Manager.validateSystemNameFormat(java.lang.String, java.util.Locale)
to ensure the returned name is valid.- Specified by:
makeSystemName
in interfaceManager<E extends NamedBean>
- Parameters:
s
- the item to make the system name forlogErrors
- true to log errors; false to not log errorslocale
- the locale for a localized exception; this is needed for the JMRI web server, which supports multiple locales- Returns:
- a valid system name
-
dispose
@OverridingMethodsMustInvokeSuper public void dispose()
Free resources when no longer used. Specifically, remove all references to and from this object, so it can be garbage-collected.
-
getBySystemName
@CheckForNull public E getBySystemName(@Nonnull java.lang.String systemName)
Locate an existing instance based on a system name.- Specified by:
getBySystemName
in interfaceManager<E extends NamedBean>
- Parameters:
systemName
- System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
getBySystemName
@CheckForNull protected E getBySystemName(java.lang.String systemName, java.util.Comparator<java.lang.String> comparator)
Protected method used by subclasses to over-ride the default behavior of getBySystemName when a simple string lookup is not sufficient.- Parameters:
systemName
- the system name to checkcomparator
- a Comparator encapsulating the system specific comparison behavior- Returns:
- a named bean of the appropriate type, or null if not found
-
getByUserName
@CheckForNull public E getByUserName(@Nonnull java.lang.String userName)
Locate an existing instance based on a user name.- Specified by:
getByUserName
in interfaceManager<E extends NamedBean>
- Parameters:
userName
- System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
getNamedBean
@CheckForNull public E getNamedBean(@Nonnull java.lang.String name)
Locate an existing instance based on a name.- Specified by:
getNamedBean
in interfaceManager<E extends NamedBean>
- Parameters:
name
- User Name or System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
deleteBean
@OverridingMethodsMustInvokeSuper public void deleteBean(@Nonnull E bean, @Nonnull java.lang.String property) throws java.beans.PropertyVetoException
Method for a UI to delete a bean.The UI should first request a "CanDelete", this will return a list of locations (and descriptions) where the bean is in use via throwing a VetoException, then if that comes back clear, or the user agrees with the actions, then a "DoDelete" can be called which inform the listeners to delete the bean, then it will be deregistered and disposed of.
If a property name of "DoNotDelete" is thrown back in the VetoException then the delete process should be aborted.
- Specified by:
deleteBean
in interfaceManager<E extends NamedBean>
- Parameters:
bean
- The NamedBean to be deletedproperty
- The programmatic name of the request. "CanDelete" will enquire with all listeners if the item can be deleted. "DoDelete" tells the listener to delete the item- Throws:
java.beans.PropertyVetoException
- If the recipients wishes the delete to be aborted (see above)
-
register
@OverridingMethodsMustInvokeSuper public void register(@Nonnull E s)
Remember a NamedBean Object created outside the manager.The non-system-specific SignalHeadManagers use this method extensively.
-
registerUserName
protected void registerUserName(E s)
Invoked byregister(NamedBean)
to register the user name of the bean.- Parameters:
s
- the bean to register
-
handleUserNameUniqueness
protected void handleUserNameUniqueness(E s)
Invoked byregisterUserName(NamedBean)
to ensure uniqueness of the NamedBean during registration.- Parameters:
s
- the bean to register
-
deregister
@OverridingMethodsMustInvokeSuper public void deregister(@Nonnull E s)
Forget a NamedBean Object created outside the manager.The non-system-specific RouteManager uses this method.
- Specified by:
deregister
in interfaceManager<E extends NamedBean>
- Parameters:
s
- the bean
-
getKnownBeanProperties
@Nonnull public java.util.List<NamedBeanPropertyDescriptor<?>> getKnownBeanProperties()
By default there are no custom properties.- Specified by:
getKnownBeanProperties
in interfaceManager<E extends NamedBean>
- Returns:
- empty list
-
getOuterBean
protected E getOuterBean(E bean)
Get the outer bean of an encapsulated bean. Some managers encapsulates the beans and those managers needs to override this method.- Parameters:
bean
- the bean- Returns:
- the most outer bean or the bean itself if there is no outer bean
-
propertyChange
@OverridingMethodsMustInvokeSuper public void propertyChange(java.beans.PropertyChangeEvent e)
The PropertyChangeListener interface in this class is intended to keep track of user name changes to individual NamedBeans. It is not completely implemented yet. In particular, listeners are not added to newly registered objects.- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Parameters:
e
- the event
-
getObjectCount
@CheckReturnValue public int getObjectCount()
Get the count of managed objects.- Specified by:
getObjectCount
in interfaceManager<E extends NamedBean>
- Returns:
- the number of managed objects
-
getNamedBeanSet
@Nonnull public java.util.SortedSet<E> getNamedBeanSet()
Provide an unmodifiable SortedSet of NamedBeans in system-name order.Note: This is the fastest of the accessors, and is the only long-term form.
Note: This is a live set; the contents are kept up to date
- Specified by:
getNamedBeanSet
in interfaceManager<E extends NamedBean>
- Returns:
- Unmodifiable access to a SortedSet of NamedBeans
-
fireVetoableChange
@OverridingMethodsMustInvokeSuper public void fireVetoableChange(java.lang.String p, java.lang.Object old, java.lang.Object n) throws java.beans.PropertyVetoException
Inform all registered listeners of a vetoable change. If the propertyName is "CanDelete" ALL listeners with an interest in the bean will throw an exception, which is recorded returned back to the invoking method, so that it can be presented back to the user. However if a listener decides that the bean can not be deleted then it should throw an exception with a property name of "DoNotDelete", this is thrown back up to the user and the delete process should be aborted.- Specified by:
fireVetoableChange
in interfaceVetoableChangeFirer
- Overrides:
fireVetoableChange
in classVetoableChangeSupport
- Parameters:
p
- The programmatic name of the property that is to be changed. "CanDelete" will inquire with all listeners if the item can be deleted. "DoDelete" tells the listener to delete the item.old
- The old value of the property.n
- The new value of the property.- Throws:
java.beans.PropertyVetoException
- if the recipients wishes the delete to be aborted.
-
vetoableChange
@OverridingMethodsMustInvokeSuper public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException
- Specified by:
vetoableChange
in interfacejava.beans.VetoableChangeListener
- Throws:
java.beans.PropertyVetoException
-
validSystemNameFormat
public Manager.NameValidity validSystemNameFormat(@Nonnull java.lang.String systemName)
Test if parameter is a properly formatted system name. Implementations of this method must not throw an exception, log an error, or otherwise disrupt the user.- Specified by:
validSystemNameFormat
in interfaceManager<E extends NamedBean>
- Parameters:
systemName
- the system name- Returns:
Manager.NameValidity.INVALID
if system name does not start withManager.getSystemNamePrefix()
;Manager.NameValidity.VALID_AS_PREFIX_ONLY
if system name equalsManager.getSystemNamePrefix()
; otherwiseManager.NameValidity.VALID
to allow Managers that do not perform more specific validation to be considered valid.
-
getSystemPrefix
@Nonnull public final java.lang.String getSystemPrefix()
Provide access to the system prefix string. This was previously called the "System letter" The implementation inAbstractManager
should be final, but is not for four managers that have arbitrary prefixes.- Specified by:
getSystemPrefix
in interfaceManager<E extends NamedBean>
- Returns:
- the system prefix
-
setPropertyChangesSilenced
@OverridingMethodsMustInvokeSuper public void setPropertyChangesSilenced(@Nonnull java.lang.String propertyName, boolean silenced)
Suppress sendingPropertyChangeEvent
s for the named property.Stopping the suppression of sending change events may send a PropertyChangeEvent if the property changed while silenced, but otherwise should not fire a PropertyChangeEvent.
- Specified by:
setPropertyChangesSilenced
in interfaceSilenceablePropertyChangeProvider
- Parameters:
propertyName
- the name of the property to mutesilenced
- true if events are to be suppressed; false otherwise
-
addDataListener
public void addDataListener(Manager.ManagerDataListener<E> e)
Register aManager.ManagerDataListener
to hear about adding or removing items from the list of NamedBeans.- Specified by:
addDataListener
in interfaceManager<E extends NamedBean>
- Parameters:
e
- the data listener to add
-
removeDataListener
public void removeDataListener(Manager.ManagerDataListener<E> e)
Unregister a previously-addedManager.ManagerDataListener
.- Specified by:
removeDataListener
in interfaceManager<E extends NamedBean>
- Parameters:
e
- the data listener to remove- See Also:
Manager.addDataListener(ManagerDataListener)
-
setDataListenerMute
public void setDataListenerMute(boolean m)
Temporarily suppress DataListener notifications.This avoids O(N^2) behavior when doing bulk updates, i.e. when loading lots of Beans. Note that this is (1) optional, in the sense that the manager is not required to mute and (2) if present, its' temporary, in the sense that the manager must do a cumulative notification when done.
- Specified by:
setDataListenerMute
in interfaceManager<E extends NamedBean>
- Parameters:
m
- true if notifications should be suppressed; false otherwise
-
fireDataListenersAdded
protected void fireDataListenersAdded(int start, int end, E changedBean)
-
fireDataListenersRemoved
protected void fireDataListenersRemoved(int start, int end, E changedBean)
-
updateAutoNumber
public void updateAutoNumber(java.lang.String systemName)
-
getAutoSystemName
public java.lang.String getAutoSystemName()
-
createSystemName
public java.lang.String createSystemName(@Nonnull java.lang.String curAddress, @Nonnull java.lang.String prefix) throws JmriException
Create a System Name from hardware address and system letter prefix. AbstractManager performs no validation.- Parameters:
curAddress
- hardware address, no system prefix or type letter.prefix
- - just system prefix, not including Type Letter.- Returns:
- full system name with system prefix, type letter and hardware address.
- Throws:
JmriException
- if unable to create a system name.
-
checkNumeric
protected java.lang.String checkNumeric(@Nonnull java.lang.String curAddress) throws JmriException
checks for numeric-only system names.- Parameters:
curAddress
- the System name ( excluding both prefix and type letter) to check.- Returns:
- unchanged if is numeric string.
- Throws:
JmriException
- if not numeric.
-
-