Class AbstractManager<E extends NamedBean>
- Type Parameters:
E- the class this manager supports
- All Implemented Interfaces:
PropertyChangeListener,VetoableChangeListener,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
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
FieldsModifier and TypeFieldDescription(package private) AtomicIntegerprotected final SystemConnectionMemo(package private) DecimalFormatFields inherited from class jmri.beans.VetoableChangeSupport
vetoableChangeSupportFields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupportFields 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, PROPERTY_BEANS, PROPERTY_CAN_DELETE, PROPERTY_DISPLAY_LIST_NAME, PROPERTY_DO_DELETE, PROPERTY_DO_NOT_DELETE, PROPERTY_LENGTH, REPORTERS, ROUTES, SECTIONS, SENSORGROUPS, SENSORS, SIGNALGROUPS, SIGNALHEADS, SIGNALMASTLOGICS, SIGNALMASTS, STRINGIOS, TIMEBASE, TRANSITS, TURNOUTS, WARRANTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRegister aManager.ManagerDataListenerto hear about adding or removing items from the list of NamedBeans.protected StringcheckNumeric(String curAddress) checks for numeric-only system names.createSystemName(String curAddress, String prefix) Create a System Name from hardware address and system letter prefix.voiddeleteBean(E bean, String property) Method for a UI to delete a bean.voidderegister(E s) Forget a NamedBean Object created outside the manager.voiddispose()Free resources when no longer used.protected voidfireDataListenersAdded(int start, int end, E changedBean) protected voidfireDataListenersRemoved(int start, int end, E changedBean) voidfireVetoableChange(String p, Object old, Object n) Inform all registered listeners of a vetoable change.getBySystemName(String systemName) Locate an existing instance based on a system name.protected EgetBySystemName(String systemName, Comparator<String> comparator) Protected method used by subclasses to over-ride the default behavior of getBySystemName when a simple string lookup is not sufficient.getByUserName(String userName) Locate an existing instance based on a user name.By default there are no custom properties.getMemo()Get the system connection for this manager.getNamedBean(String name) Locate an existing instance based on a name.Provide an unmodifiable SortedSet of NamedBeans in system-name order.intGet the count of managed objects.protected EgetOuterBean(E bean) Get the outer bean of an encapsulated bean.final StringProvide access to the system prefix string.protected voidInvoked byregisterUserName(NamedBean)to ensure uniqueness of the NamedBean during registration.makeSystemName(String s, boolean logErrors, Locale locale) Create a SystemName by prepending the system name prefix to the name if not already present.voidThe PropertyChangeListener interface in this class is intended to keep track of user name changes to individual NamedBeans.voidRemember a NamedBean Object created outside the manager.protected voidBy default, register this manager to store as configuration information.protected voidInvoked byregister(NamedBean)to register the user name of the bean.voidUnregister a previously-addedManager.ManagerDataListener.voidsetDataListenerMute(boolean m) Temporarily suppress DataListener notifications.voidsetPropertyChangesSilenced(String propertyName, boolean silenced) Suppress sendingPropertyChangeEvents for the named property.(package private) final voidvoidupdateAutoNumber(String systemName) validSystemNameFormat(String systemName) Test if parameter is a properly formatted system name.voidMethods inherited from class jmri.beans.VetoableChangeSupport
addVetoableChangeListener, addVetoableChangeListener, fireVetoableChange, fireVetoableChange, fireVetoableChange, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListenerMethods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, validateUppercaseTrimmedSystemNameFormatMethods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from interface jmri.beans.VetoableChangeProvider
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
Field Details
-
memo
-
_beans
-
_tsys
-
_tuser
-
silencedProperties
-
silenceableProperties
-
lastAutoNamedBeanRef
-
paddedNumber
-
-
Constructor Details
-
AbstractManager
-
AbstractManager
public AbstractManager()
-
-
Method Details
-
setRegisterSelf
-
registerSelf
By default, register this manager to store as configuration information. Override to change that. -
getMemo
Get the system connection for this manager. -
makeSystemName
Create a SystemName by prepending the system name prefix to the name if not already present.The
logErrorsparameter 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:
makeSystemNamein 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
Free resources when no longer used. Specifically, remove all references to and from this object, so it can be garbage-collected. -
getBySystemName
Locate an existing instance based on a system name.- Specified by:
getBySystemNamein interfaceManager<E extends NamedBean>- Parameters:
systemName- System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
getBySystemName
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
Locate an existing instance based on a user name.- Specified by:
getByUserNamein interfaceManager<E extends NamedBean>- Parameters:
userName- System Name of the required NamedBean- Returns:
- requested NamedBean object or null if none exists
-
getNamedBean
Locate an existing instance based on a name.- Specified by:
getNamedBeanin 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 String property) throws 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:
deleteBeanin 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:
PropertyVetoException- If the recipients wishes the delete to be aborted (see above)
-
register
Remember a NamedBean Object created outside the manager.The non-system-specific SignalHeadManagers use this method extensively.
-
registerUserName
Invoked byregister(NamedBean)to register the user name of the bean.- Parameters:
s- the bean to register
-
handleUserNameUniqueness
Invoked byregisterUserName(NamedBean)to ensure uniqueness of the NamedBean during registration.- Parameters:
s- the bean to register
-
deregister
Forget a NamedBean Object created outside the manager.The non-system-specific RouteManager uses this method.
- Specified by:
deregisterin interfaceManager<E extends NamedBean>- Parameters:
s- the bean
-
getKnownBeanProperties
By default there are no custom properties.- Specified by:
getKnownBeanPropertiesin interfaceManager<E extends NamedBean>- Returns:
- empty list
-
getOuterBean
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
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:
propertyChangein interfacePropertyChangeListener- Parameters:
e- the event
-
getObjectCount
Get the count of managed objects.- Specified by:
getObjectCountin interfaceManager<E extends NamedBean>- Returns:
- the number of managed objects
-
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:
getNamedBeanSetin interfaceManager<E extends NamedBean>- Returns:
- Unmodifiable access to a SortedSet of NamedBeans
-
fireVetoableChange
@OverridingMethodsMustInvokeSuper public void fireVetoableChange(String p, Object old, Object n) throws 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:
fireVetoableChangein interfaceVetoableChangeFirer- Overrides:
fireVetoableChangein 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:
PropertyVetoException- if the recipients wishes the delete to be aborted.
-
vetoableChange
@OverridingMethodsMustInvokeSuper public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException - Specified by:
vetoableChangein interfaceVetoableChangeListener- Throws:
PropertyVetoException
-
validSystemNameFormat
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:
validSystemNameFormatin interfaceManager<E extends NamedBean>- Parameters:
systemName- the system name- Returns:
Manager.NameValidity.INVALIDif system name does not start withManager.getSystemNamePrefix();Manager.NameValidity.VALID_AS_PREFIX_ONLYif system name equalsManager.getSystemNamePrefix(); otherwiseManager.NameValidity.VALIDto allow Managers that do not perform more specific validation to be considered valid.
-
getSystemPrefix
Provide access to the system prefix string. This was previously called the "System letter" The implementation inAbstractManagershould be final, but is not for four managers that have arbitrary prefixes.- Specified by:
getSystemPrefixin interfaceManager<E extends NamedBean>- Returns:
- the system prefix
-
setPropertyChangesSilenced
@OverridingMethodsMustInvokeSuper public void setPropertyChangesSilenced(@Nonnull String propertyName, boolean silenced) Suppress sendingPropertyChangeEvents 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:
setPropertyChangesSilencedin interfaceSilenceablePropertyChangeProvider- Parameters:
propertyName- the name of the property to mutesilenced- true if events are to be suppressed; false otherwise
-
addDataListener
Register aManager.ManagerDataListenerto hear about adding or removing items from the list of NamedBeans.- Specified by:
addDataListenerin interfaceManager<E extends NamedBean>- Parameters:
e- the data listener to add
-
removeDataListener
Unregister a previously-addedManager.ManagerDataListener.- Specified by:
removeDataListenerin interfaceManager<E extends NamedBean>- Parameters:
e- the data listener to remove- See Also:
-
setDataListenerMute
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:
setDataListenerMutein interfaceManager<E extends NamedBean>- Parameters:
m- true if notifications should be suppressed; false otherwise
-
fireDataListenersAdded
-
fireDataListenersRemoved
-
updateAutoNumber
-
getAutoSystemName
-
createSystemName
public String createSystemName(@Nonnull String curAddress, @Nonnull 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
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.
-