Class NamedBeanHandleManager
- All Implemented Interfaces:
PropertyChangeListener,VetoableChangeListener,EventListener,PropertyChangeFirer,PropertyChangeProvider,SilenceablePropertyChangeProvider,VetoableChangeFirer,VetoableChangeProvider,InstanceManagerAutoDefault,Manager<NamedBean>
The NamedBeanHandleManager, deals with controlling and updating
NamedBean objects
across JMRI. When a piece of code requires persistent access to a bean, it
should use a NamedBeanHandle. The NamedBeanHandle stores not only the bean
that has been requested but also the named that was used to request it
(either User or System Name).
This Manager will only issue out one NamedBeanHandle per Bean/Name request.
The Manager also deals with updates and changes to the names of NamedBean objects, along
with moving usernames between different beans.
If a beans username is changed by the user, then the name will be updated in the NamedBeanHandle. If a username is moved from one bean to another, then the bean reference will be updated and the propertyChangeListener attached to that bean will also be moved, so long as the correct method of adding the listener has been used.
This file is part of JMRI.
JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- See Also:
-
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
FieldsFields inherited from class jmri.managers.AbstractManager
_beans, _tsys, _tuser, memo, silenceableProperties, silencedPropertiesFields 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 TypeMethodDescriptionvoidForget a NamedBean Object created outside the manager.voiddispose()Free resources when no longer used.getBeanTypeHandled(boolean plural) Get the user-readable name of the type of NamedBean handled by this manager.Get the class of NamedBean supported by this Manager.<T extends NamedBean>
NamedBeanHandle<T>getNamedBeanHandle(String name, T bean) intDetermine the order that types should be written when storing panel files.<T extends NamedBean>
booleanCreate a SystemName by prepending the system name prefix to the name if not already present.<T extends NamedBean>
voidEffectively move a name from one bean to another.<T extends NamedBean>
NamedBeanHandle<T>newNamedBeanHandle(String name, T bean, Class<T> type) voidRemember a NamedBean Object created outside the manager.protected voidDon't want to store this information<T extends NamedBean>
voidrenameBean(String oldName, String newName, T bean) Update the name of a bean in its references.charvoidvoidMethods inherited from class jmri.managers.AbstractManager
addDataListener, checkNumeric, createSystemName, deleteBean, fireDataListenersAdded, fireDataListenersRemoved, fireVetoableChange, getAutoSystemName, getBySystemName, getBySystemName, getByUserName, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanSet, getObjectCount, getOuterBean, getSystemPrefix, handleUserNameUniqueness, makeSystemName, propertyChange, registerUserName, removeDataListener, setDataListenerMute, setPropertyChangesSilenced, updateAutoNumber, validSystemNameFormat, vetoableChangeMethods 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, getEntryToolTip, getSubSystemNamePrefix, getSystemNamePrefix, isValidSystemNameFormat, makeSystemName, 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
-
namedBeanHandles
-
-
Constructor Details
-
NamedBeanHandleManager
public NamedBeanHandleManager()
-
-
Method Details
-
getNamedBeanHandle
@Nonnull @CheckReturnValue public <T extends NamedBean> NamedBeanHandle<T> getNamedBeanHandle(@Nonnull String name, @Nonnull T bean) -
renameBean
public <T extends NamedBean> void renameBean(@Nonnull String oldName, @Nonnull String newName, @Nonnull T bean) Update the name of a bean in its references.Note this does not change the name on the bean, it only changes the references.
- Type Parameters:
T- the type of the bean- Parameters:
oldName- the name changing fromnewName- the name changing tobean- the bean being renamed
-
moveBean
public <T extends NamedBean> void moveBean(@Nonnull T oldBean, @Nonnull T newBean, @Nonnull String name) Effectively move a name from one bean to another.Note only updates the references to point to the new bean; does not move the name provided from one bean to another.
- Type Parameters:
T- the bean type- Parameters:
oldBean- bean loosing the namename- name being movednewBean- bean gaining the name
-
updateBeanFromUserToSystem
-
updateBeanFromSystemToUser
- Throws:
JmriException
-
inUse
-
newNamedBeanHandle
@CheckForNull @CheckReturnValue public <T extends NamedBean> NamedBeanHandle<T> newNamedBeanHandle(@Nonnull String name, @Nonnull T bean, @Nonnull Class<T> type) -
dispose
Description copied from class:AbstractManagerFree resources when no longer used. Specifically, remove all references to and from this object, so it can be garbage-collected. -
registerSelf
Don't want to store this information- Overrides:
registerSelfin classAbstractManager<NamedBean>
-
typeLetter
- Specified by:
typeLetterin interfaceManager<NamedBean>- Returns:
- The type letter for a specific implementation
-
makeSystemName
Description copied from interface:ManagerCreate a SystemName by prepending the system name prefix to the name if not already present.Note: implementations must call
Manager.validateSystemNameFormat(java.lang.String, java.util.Locale)to ensure the returned name is valid.- Specified by:
makeSystemNamein interfaceManager<NamedBean>- Parameters:
s- the item to make the system name for- Returns:
- A system name from a user input, typically a number.
-
register
Description copied from class:AbstractManagerRemember a NamedBean Object created outside the manager.The non-system-specific SignalHeadManagers use this method extensively.
-
deregister
Description copied from class:AbstractManagerForget a NamedBean Object created outside the manager.The non-system-specific RouteManager uses this method.
- Specified by:
deregisterin interfaceManager<NamedBean>- Overrides:
deregisterin classAbstractManager<NamedBean>- Parameters:
n- the bean
-
getXMLOrder
Description copied from interface:ManagerDetermine the order that types should be written when storing panel files. Uses one of the constants defined in this class.Yes, that's an overly-centralized methodology, but it works for now.
- Specified by:
getXMLOrderin interfaceManager<NamedBean>- Returns:
- write order for this Manager; larger is later.
-
getBeanTypeHandled
Description copied from interface:ManagerGet the user-readable name of the type of NamedBean handled by this manager.For instance, in the code where we are dealing with just a bean and a message that needs to be passed to the user or in a log.
- Specified by:
getBeanTypeHandledin interfaceManager<NamedBean>- Parameters:
plural- true to return plural form of the type; false to return singular form- Returns:
- a string of the bean type that the manager handles, eg Turnout, Sensor etc
-
getNamedBeanClass
Get the class of NamedBean supported by this Manager. This should be the generic class used in the Manager's class declaration.- Specified by:
getNamedBeanClassin interfaceManager<NamedBean>- Returns:
- the class supported by this Manager.
-