Class NamedBeanHandleManager
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.beans.VetoableChangeSupport
-
- jmri.managers.AbstractManager<NamedBean>
-
- jmri.NamedBeanHandleManager
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.beans.VetoableChangeListener
,java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,InstanceManagerAutoDefault
,Manager<NamedBean>
public class NamedBeanHandleManager extends AbstractManager<NamedBean> implements InstanceManagerAutoDefault
Instance for controlling the issuing of NamedBeanHandles.
The NamedBeanHandleManager, deals with controlling and updatingNamedBean
objects across JMRI. When a piece of code requires persistent access to a bean, it should use aNamedBeanHandle
. TheNamedBeanHandle
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 ofNamedBean
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) java.util.ArrayList<NamedBeanHandle>
namedBeanHandles
-
Fields inherited from class jmri.managers.AbstractManager
_beans, _tsys, _tuser, memo, silenceableProperties, 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 NamedBeanHandleManager()
-
Method Summary
All Methods Instance Methods Concrete Methods 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.java.lang.String
getBeanTypeHandled(boolean plural)
Get the user-readable name of the type of NamedBean handled by this manager.java.lang.Class<NamedBean>
getNamedBeanClass()
Get the class of NamedBean supported by this Manager.<T extends NamedBean>
NamedBeanHandle<T>getNamedBeanHandle(java.lang.String name, T bean)
int
getXMLOrder()
Determine the order that types should be written when storing panel files.<T extends NamedBean>
booleaninUse(java.lang.String name, T bean)
java.lang.String
makeSystemName(java.lang.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, java.lang.String name)
Effectively move a name from one bean to another.<T extends NamedBean>
NamedBeanHandle<T>newNamedBeanHandle(java.lang.String name, T bean, java.lang.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(java.lang.String oldName, java.lang.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, getKnownBeanProperties, getMemo, getNamedBean, getNamedBeanSet, getObjectCount, getOuterBean, 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
getBeanTypeHandled, getEntryToolTip, getSubSystemNamePrefix, getSystemNamePrefix, isValidSystemNameFormat, makeSystemName, 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
-
namedBeanHandles
java.util.ArrayList<NamedBeanHandle> namedBeanHandles
-
-
Constructor Detail
-
NamedBeanHandleManager
public NamedBeanHandleManager()
-
-
Method Detail
-
getNamedBeanHandle
@Nonnull @CheckReturnValue public <T extends NamedBean> NamedBeanHandle<T> getNamedBeanHandle(@Nonnull java.lang.String name, @Nonnull T bean)
-
renameBean
public <T extends NamedBean> void renameBean(@Nonnull java.lang.String oldName, @Nonnull java.lang.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 java.lang.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
public void updateBeanFromUserToSystem(@Nonnull NamedBean bean)
-
updateBeanFromSystemToUser
public void updateBeanFromSystemToUser(@Nonnull NamedBean bean) throws JmriException
- Throws:
JmriException
-
inUse
@CheckReturnValue public <T extends NamedBean> boolean inUse(@Nonnull java.lang.String name, @Nonnull T bean)
-
newNamedBeanHandle
@CheckForNull @CheckReturnValue public <T extends NamedBean> NamedBeanHandle<T> newNamedBeanHandle(@Nonnull java.lang.String name, @Nonnull T bean, @Nonnull java.lang.Class<T> type)
-
dispose
public void 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
protected void registerSelf()
Don't want to store this information- Overrides:
registerSelf
in classAbstractManager<NamedBean>
-
typeLetter
@CheckReturnValue public char typeLetter()
- Specified by:
typeLetter
in interfaceManager<NamedBean>
- Returns:
- The type letter for a specific implementation
-
makeSystemName
@Nonnull @CheckReturnValue public java.lang.String makeSystemName(@Nonnull java.lang.String s)
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.
-
register
public void register(@Nonnull NamedBean n)
Description copied from class:AbstractManager
Remember a NamedBean Object created outside the manager.The non-system-specific SignalHeadManagers use this method extensively.
-
deregister
public void deregister(@Nonnull NamedBean n)
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
@CheckReturnValue public int 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
@Nonnull @CheckReturnValue public java.lang.String getBeanTypeHandled(boolean plural)
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
public java.lang.Class<NamedBean> 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.
-
-