Class NamedBeanHandleManager
- All Implemented Interfaces:
PropertyChangeListener
,VetoableChangeListener
,EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,InstanceManagerAutoDefault
,Manager<NamedBean>
public class NamedBeanHandleManager extends AbstractManager<NamedBean> implements InstanceManagerAutoDefault
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:
NamedBean
,NamedBeanHandle
-
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 (package private) ArrayList<NamedBeanHandle>
namedBeanHandles
Fields inherited from class jmri.managers.AbstractManager
_beans, _tsys, _tuser, memo, silenceableProperties, silencedProperties
Fields inherited from interface jmri.Manager
ANALOGIOS, AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, CTCDATA, deprecatedManagerLogger, ENTRYEXIT, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXNG_ANALOG_ACTIONS, LOGIXNG_ANALOG_EXPRESSIONS, LOGIXNG_CONDITIONALNGS, LOGIXNG_DIGITAL_ACTIONS, LOGIXNG_DIGITAL_BOOLEAN_ACTIONS, LOGIXNG_DIGITAL_EXPRESSIONS, 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 NamedBeanHandleManager()
-
Method Summary
Modifier and Type Method Description void
deregister(NamedBean n)
Forget a NamedBean Object created outside the manager.void
dispose()
Free resources when no longer used.String
getBeanTypeHandled(boolean plural)
Get the user-readable name of the type of NamedBean handled by this manager.Class<NamedBean>
getNamedBeanClass()
Get the class of NamedBean supported by this Manager.<T extends NamedBean>
NamedBeanHandle<T>getNamedBeanHandle(String name, T bean)
List<String>
getSystemNameList()
Deprecated.int
getXMLOrder()
Determine the order that types should be written when storing panel files.<T extends NamedBean>
booleaninUse(String name, T bean)
String
makeSystemName(String s)
Create a SystemName by prepending the system name prefix to the name if not already present.<T extends NamedBean>
voidmoveBean(T oldBean, T newBean, String name)
Effectively move a name from one bean to another.<T extends NamedBean>
NamedBeanHandle<T>newNamedBeanHandle(String name, T bean, Class<T> type)
void
register(NamedBean n)
Remember a NamedBean Object created outside the manager.protected void
registerSelf()
Don'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.char
typeLetter()
void
updateBeanFromSystemToUser(NamedBean bean)
void
updateBeanFromUserToSystem(NamedBean bean)
Methods inherited from class jmri.managers.AbstractManager
addDataListener, checkNumeric, createSystemName, deleteBean, fireDataListenersAdded, fireDataListenersRemoved, fireVetoableChange, getAutoSystemName, getBySystemName, getBySystemName, getByUserName, getIncrement, getIncrementFromExistingNumber, getInstanceBySystemName, getInstanceByUserName, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanList, getNamedBeanSet, getNextValidAddress, getNextValidAddress, getObjectCount, getSystemPrefix, handleUserNameUniqueness, makeSystemName, propertyChange, registerUserName, removeDataListener, setDataListenerMute, setPropertyChangesSilenced, updateAutoNumber, validSystemNameFormat, vetoableChange
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
getBeanBySystemName, getBeanByUserName, getBeanTypeHandled, getEntryToolTip, getSubSystemNamePrefix, getSystemNamePrefix, isValidSystemNameFormat, makeSystemName, setPropertyChangesMuted, 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 Details
-
Constructor Details
-
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:AbstractManager
Free 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:
registerSelf
in classAbstractManager<NamedBean>
-
typeLetter
- Specified by:
typeLetter
in interfaceManager<NamedBean>
- Returns:
- The type letter for a specific implementation
-
makeSystemName
Description copied from interface:Manager
Create 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:
makeSystemName
in interfaceManager<NamedBean>
- Parameters:
s
- the item to make the system name for- Returns:
- A system name from a user input, typically a number.
-
getSystemNameList
Deprecated.Description copied from class:AbstractManager
Provide an unmodifiable List of system names.Note: this is ordered by the underlying NamedBeans, not on the Strings themselves.
Note: Access via
Manager.getNamedBeanSet()
is faster.Note: This is not a live list; the contents don't stay up to date
- Specified by:
getSystemNameList
in interfaceManager<NamedBean>
- Overrides:
getSystemNameList
in classAbstractManager<NamedBean>
- Returns:
- Unmodifiable access to a list of system names
-
register
Description copied from class:AbstractManager
Remember a NamedBean Object created outside the manager.The non-system-specific SignalHeadManagers use this method extensively.
-
deregister
Description copied from class:AbstractManager
Forget a NamedBean Object created outside the manager.The non-system-specific RouteManager uses this method.
- Specified by:
deregister
in interfaceManager<NamedBean>
- Overrides:
deregister
in classAbstractManager<NamedBean>
- Parameters:
n
- the bean
-
getXMLOrder
Description copied from interface:Manager
Determine 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:
getXMLOrder
in interfaceManager<NamedBean>
- Returns:
- write order for this Manager; larger is later.
-
getBeanTypeHandled
Description copied from interface:Manager
Get 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:
getBeanTypeHandled
in 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:
getNamedBeanClass
in interfaceManager<NamedBean>
- Returns:
- the class supported by this Manager.
-