Interface NamedBean
- All Superinterfaces:
Comparable<NamedBean>,PropertyChangeProvider
- All Known Subinterfaces:
AddressedIdTag,AnalogActionBean,AnalogExpressionBean,AnalogIO,Audio,AudioBuffer,AudioListener,AudioSource,AverageMeter,CatalogTree,CollectingReporter,Conditional,ConditionalNG,CurrentMeter,DigitalActionBean,DigitalBooleanActionBean,DigitalExpressionBean,DigitalIO,GlobalVariable,IdTag,Light,Logix,LogixNG,MaleAnalogActionSocket,MaleAnalogExpressionSocket,MaleDigitalActionSocket,MaleDigitalBooleanActionSocket,MaleDigitalExpressionSocket,MaleStringActionSocket,MaleStringExpressionSocket,Memory,Meter,Module,NamedTable,RailCom,Reporter,Route,Section,Sensor,Signal,SignalGroup,SignalHead,SignalMast,SignalMastLogic,SignalSystem,StringActionBean,StringExpressionBean,StringIO,Timebase,Transit,Turnout,VariableControlSpanBean,VariableLight,VoltageMeter
- All Known Implementing Classes:
AbstractAnalogAction,AbstractAnalogExpression,AbstractAnalogIO,AbstractAudio,AbstractAudioBuffer,AbstractAudioListener,AbstractAudioSource,AbstractBase,AbstractCatalogTree,AbstractDigitalAction,AbstractDigitalBooleanAction,AbstractDigitalExpression,AbstractIdTag,AbstractIdTagReporter,AbstractLight,AbstractMemory,AbstractNamedBean,AbstractNamedBeanDecorator,AbstractNamedTable,AbstractRailComReporter,AbstractReporter,AbstractSensor,AbstractSignalHead,AbstractSignalMast,AbstractStringAction,AbstractStringExpression,AbstractStringIO,AbstractTurnout,AbstractVariableLight,AcelaLight,AcelaSensor,AcelaSignalHead,AcelaTurnout,ActionAtomicBoolean,ActionAudio,ActionAudioIcon,ActionBlock,ActionClearSlots,ActionClock,ActionClockRate,ActionCreateBeansFromTable,ActionDispatcher,ActionEntryExit,ActionFindTableRowOrColumn,ActionLayoutTurnout,ActionLight,ActionLightIntensity,ActionListenOnBeans,ActionListenOnBeansLocalVariable,ActionListenOnBeansTable,ActionLocalVariable,ActionMemory,ActionOBlock,ActionPositionable,ActionPositionableByClass,ActionPower,ActionReporter,ActionRequestUpdateAllSensors,ActionRequestUpdateOfSensor,ActionRequestUpdateOfTurnout,ActionScript,ActionSensor,ActionSetReporter,ActionShutDownTask,ActionSignalHead,ActionSignalMast,ActionSound,ActionTable,ActionThrottle,ActionThrottleFunction,ActionTimer,ActionTurnout,ActionTurnoutLock,ActionUpdateSlots,ActionWarrant,AnalogActionLightIntensity,AnalogActionMemory,AnalogExpressionAnalogIO,AnalogExpressionConstant,AnalogExpressionLocalVariable,AnalogExpressionMemory,AnalogFormula,AnalogMany,And,Antecedent,AnymaDMX_UsbLight,BiDiBLight,BiDiBReporter,BiDiBSensor,BiDiBSignalMast,BiDiBTurnout,Block,Break,CatalogTreeFS,CatalogTreeIndex,CbusLight,CbusReporter,CbusSensor,CbusTurnout,ClipboardMany,ConnectionName,Continue,Dcc4PcReporter,Dcc4PcSensor,DCCppLight,DCCppSensor,DCCppTurnout,DccSignalHead,DccSignalMast,DebuggerMaleAnalogActionSocket,DebuggerMaleAnalogExpressionSocket,DebuggerMaleDigitalActionSocket,DebuggerMaleDigitalBooleanActionSocket,DebuggerMaleDigitalExpressionSocket,DebuggerMaleStringActionSocket,DebuggerMaleStringExpressionSocket,DefaultAverageMeter,DefaultClipboard,DefaultConditional,DefaultConditionalNG,DefaultCsvNamedTable,DefaultGlobalVariable,DefaultIdTag,DefaultInternalNamedTable,DefaultLogix,DefaultLogixNG,DefaultMaleAnalogActionSocket,DefaultMaleAnalogExpressionSocket,DefaultMaleDigitalActionSocket,DefaultMaleDigitalBooleanActionSocket,DefaultMaleDigitalExpressionSocket,DefaultMaleStringActionSocket,DefaultMaleStringExpressionSocket,DefaultMemory,DefaultMeter,DefaultMeter.DefaultCurrentMeter,DefaultMeter.DefaultVoltageMeter,DefaultModule,DefaultRailCom,DefaultRoute,DefaultSection,DefaultSignalAppearanceMap,DefaultSignalGroup,DefaultSignalHead,DefaultSignalMastLogic,DefaultSignalSystem,DefaultStringIO,DefaultTransit,DestinationPoints,DigitalBooleanLogixAction,DigitalBooleanMany,DigitalCallModule,DigitalCallModule,DigitalFormula,DigitalFormula,DigitalMany,DoAnalogAction,DoStringAction,DoubleTurnoutSignalHead,EasyDccTurnout,EcosReporter,EcosSensor,EcosTurnout,EliteXNetTurnout,EnableLogix,EnableLogixNG,Error,ExecuteAction,ExecuteDelayed,ExecuteProgram,Exit,ExpressionAudio,ExpressionBlock,ExpressionClock,ExpressionConditional,ExpressionDispatcher,ExpressionEntryExit,ExpressionLight,ExpressionLinuxLinePower,ExpressionLocalVariable,ExpressionMemory,ExpressionOBlock,ExpressionPower,ExpressionReference,ExpressionReporter,ExpressionScript,ExpressionSection,ExpressionSensor,ExpressionSensorEdge,ExpressionSignalHead,ExpressionSignalMast,ExpressionSlotUsage,ExpressionTransit,ExpressionTurnout,ExpressionWarrant,False,FileAsFlag,For,ForEach,ForEachWithDelay,Hold,IfThenElse,IpocsLight,IpocsSensor,IpocsTurnout,JavaSoundAudioBuffer,JavaSoundAudioListener,JavaSoundAudioSource,JMRIClientLight,JMRIClientReporter,JMRIClientSensor,JMRIClientTurnout,JoalAudioBuffer,JoalAudioListener,JoalAudioSource,JsonDecode,LastResultOfDigitalExpression,LayoutBlock,LNCPSignalMast,LnLight,LnReporter,LnSensor,LnThrottleStringIO,LnTurnout,LogData,LogData,Logix,LogLocalVariables,LsDecSignalHead,MarklinSensor,MarklinTurnout,MatrixSignalMast,MergSD2SignalHead,MqttLight,MqttReporter,MqttSensor,MqttSignalMast,MqttTurnout,MrcTurnout,Mx1Turnout,NceLight,NceSensor,NceTurnout,Not,NullAudioBuffer,NullAudioListener,NullAudioSource,NullBase,OBlock,OlcbLight,OlcbReporter,OlcbSensor,OlcbSignalMast,OlcbStringIO,OlcbTurnout,OperationsProStartAutomation,Or,ProgramOnMain,Publish,QuadOutputSignalHead,RaspberryPiSensor,RaspberryPiTurnout,Return,RfidReporter,RfidSensor,RpsReporter,RpsSensor,RunOnce,SCWarrant,SE8cSignalHead,SE8cSignalHead,SendMergCbusEvent,SensorGroupConditional,Sequence,SerialLight,SerialLight,SerialLight,SerialLight,SerialLight,SerialLight,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SerialSignalHead,SerialTurnout,SerialTurnout,SerialTurnout,SerialTurnout,SerialTurnout,SerialTurnout,SerialTurnout,SerialX10Light,SetLocalVariables,SetSpeedZero,ShowDialog,ShutdownComputer,SignalHeadSignalMast,SimpleTimebase,SimulateTurnoutFeedback,SingleTurnoutSignalHead,SpecificDmxLight,SpecificInsteonLight,SpecificInsteonLight,SpecificLight,SpecificLight,SpecificLight,SpecificX10Light,SpecificX10Light,SprogCSTurnout,SprogTurnout,SRCPSensor,SRCPTurnout,StringActionMemory,StringActionStringIO,StringExpressionConstant,StringExpressionMemory,StringExpressionStringIO,StringFormula,StringMany,Subscribe,TableForEach,TamsSensor,TamsTurnout,Timeout,TimeoutReporter,TimeoutRfidSensor,Timer,TimeSinceMidnight,TrackReporter,TranspondingTag,TriggerOnce,TriggerRoute,TripleOutputSignalHead,TripleTurnoutSignalHead,True,TurnoutSignalMast,VirtualSignalHead,VirtualSignalMast,Warrant,WebBrowser,WebRequest,WindowManagement,XBeeLight,XBeeSensor,XBeeTurnout,XNetLight,XNetSensor,XNetTurnout,XpaTurnout,Z21CanReporter,Z21CanSensor,Z21Reporter,Z21RMBusSensor,Z21XNetTurnout,ZTC611XNetTurnout
Each object has two types of names:
The "system" name is provided by the system-specific implementations, and provides a unique mapping to the layout control system (for example LocoNet or NCE) and address within that system. It must be present and unique across the JMRI instance. Two beans are identical if they have the same system name; if not, not.
The "user" name is optional. It's free form text except for two restrictions:
- It can't be the empty string "". (A non-existant user name is coded as a null)
- And eventually, we may insist on normalizing user names to a specific
form, e.g. remove leading and trailing white space; see the
normalizeUserName(java.lang.String)method
Each of these two names must be unique for every NamedBean of the same type on the layout and a single NamedBean cannot have a user name that is the same as the system name of another NamedBean of the same type. (The complex wording is saying that a single NamedBean object is allowed to have its system name and user name be the same, but that's the only non-uniqueness that's allowed within a specific type). Note that the uniqueness restrictions are currently not completely enforced, only warned about; a future version of JMRI will enforce this restriction.
For more information, see the Names and Naming page in the Technical Info pages.
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 ClassesModifier and TypeInterfaceDescriptionstatic classParent class for a set of classes that describe if a user name or system name is a bad name.static classstatic classstatic enumDisplay options forgetDisplayName(DisplayOptions).static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringFormat used forgetDisplayName(DisplayOptions)when displaying the user name and system name without quotation marks around the user name.static final intConstant representing an "inconsistent" state, indicating that some inconsistency has been detected in the hardware readback.static final StringProperty of Comment updated.static final StringProperty of Enabled state ( Light / Logix / LogixNG / Route / SML ).static final StringProperty of known state.static final StringProperty of changed state.static final StringProperty of User Name.static final StringFormat used forgetDisplayName(DisplayOptions)when displaying the user name and system name with quotation marks around the user name.static final intConstant representing an "unknown" state, indicating that the object's state is not necessarily that of the actual layout hardware. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertyChangeListener(PropertyChangeListener listener, String name, String listenerRef) Request a call-back when a bound property changes.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener, String name, String listenerRef) Request a call-back when a bound property changes.intcompareSystemNameSuffix(String suffix1, String suffix2, NamedBean n2) Compare the suffix of this NamedBean's name with the suffix of the argument NamedBean's name for thecompareTo(jmri.NamedBean)operation.default intProvide a comparison between the system names of two beans.describeState(int state) Provide human-readable, localized version of state value.voiddispose()Deactivate this object, so that it releases as many resources as possible and no longer effects others.For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.Get associated comment text.default StringGet user name if it exists, otherwise return System name.default StringgetDisplayName(NamedBean.DisplayOptions options) Get the name to display, formatted perNamedBean.DisplayOptions.Get the textual reference for the specific listenerReturns a list of all the listeners referencesintNumber of current listeners.getProperty(String key) Retrieve the value associated with a key.Get a list of all the property change listeners that are registered using a specific nameRetrieve the complete current set of keys.default StringGet a recommended text for a tooltip when displaying the NamedBean, e.g. in a list or table.intgetState()Provide generic access to internal state.Get a system-specific name.default List<NamedBeanUsageReport>getUsageReport(NamedBean bean) Get a list of references for the specified bean.User's identification for the item.static StringnormalizeUserName(String inputName) Enforces, and as a user convenience converts to, the standard form for a user name.voidremoveProperty(String key) Remove the key/value pair against the NamedBean.voidsetComment(String comment) Set associated comment text.voidsetProperty(String key, Object value) Attach a key/value pair to the NamedBean, which can be retrieved later.voidsetState(int s) Provide generic access to internal state.voidSet the user name, normalizing it if needed.toString()Display the system-specific name.voidupdateListenerRef(PropertyChangeListener l, String newName) voidMethods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Field Details
-
UNKNOWN
Constant representing an "unknown" state, indicating that the object's state is not necessarily that of the actual layout hardware. This is the initial state of a newly created object before communication with the layout.- See Also:
-
INCONSISTENT
Constant representing an "inconsistent" state, indicating that some inconsistency has been detected in the hardware readback.- See Also:
-
DISPLAY_NAME_FORMAT
Format used forgetDisplayName(DisplayOptions)when displaying the user name and system name without quotation marks around the user name.- See Also:
-
QUOTED_NAME_FORMAT
Format used forgetDisplayName(DisplayOptions)when displaying the user name and system name with quotation marks around the user name.- See Also:
-
PROPERTY_STATE
Property of changed state.- See Also:
-
PROPERTY_KNOWN_STATE
Property of known state.- See Also:
-
PROPERTY_ENABLED
Property of Enabled state ( Light / Logix / LogixNG / Route / SML ).- See Also:
-
PROPERTY_COMMENT
Property of Comment updated.- See Also:
-
PROPERTY_USERNAME
Property of User Name.- See Also:
-
-
Method Details
-
getUserName
User's identification for the item. Bound parameter so manager(s) can listen to changes. Any given user name must be unique within the layout. Must not match the system name.- Returns:
- null if not set
-
setUserName
Set the user name, normalizing it if needed.- Parameters:
s- the new user name- Throws:
NamedBean.BadUserNameException- if the user name can not be normalized
-
getSystemName
Get a system-specific name. This encodes the hardware addressing information. Any given system name must be unique within the layout.- Returns:
- the system-specific name
-
toString
Display the system-specific name.Note that this is a firm contract: toString() in all implementing classes must return the system name followed by optional additional information. Using code can assume that the result of toString() will always be or start with the system name followed by some kind of separator character.
-
getDisplayName
Get user name if it exists, otherwise return System name.- Returns:
- the user name or system-specific name
-
getDisplayName
Get the name to display, formatted perNamedBean.DisplayOptions.- Parameters:
options- the DisplayOptions to use- Returns:
- the display name formatted per options
-
getRecommendedToolTip
Get a recommended text for a tooltip when displaying the NamedBean, e.g. in a list or table. By default, this is the comment from the NamedBean, on the theory that the system name and/or user name are being displayed directly. Specific system implementations may override that.- Returns:
- empty String if no recommendation.
-
addPropertyChangeListener
void addPropertyChangeListener(@Nonnull PropertyChangeListener listener, String name, String listenerRef) Request a call-back when a bound property changes. Bound properties are the known state, commanded state, user and system names.- Parameters:
listener- The listener. This may change in the future to be a subclass of NamedProprtyChangeListener that carries the name and listenerRef values internallyname- The name (either system or user) that the listener uses for this namedBean, this parameter is used to help determine when which listeners should be moved when the username is moved from one bean to anotherlistenerRef- A textual reference for the listener, that can be presented to the user when a delete is called
-
addPropertyChangeListener
void addPropertyChangeListener(@Nonnull String propertyName, @Nonnull PropertyChangeListener listener, String name, String listenerRef) Request a call-back when a bound property changes. Bound properties are the known state, commanded state, user and system names.- Parameters:
propertyName- The name of the property to listen tolistener- The listener. This may change in the future to be a subclass of NamedProprtyChangeListener that carries the name and listenerRef values internallyname- The name (either system or user) that the listener uses for this namedBean, this parameter is used to help determine when which listeners should be moved when the username is moved from one bean to anotherlistenerRef- A textual reference for the listener, that can be presented to the user when a delete is called
-
updateListenerRef
-
vetoableChange
- Throws:
PropertyVetoException
-
getListenerRef
Get the textual reference for the specific listener- Parameters:
l- the listener of interest- Returns:
- the textual reference
-
getListenerRefs
Returns a list of all the listeners references- Returns:
- a list of textual references
-
getNumPropertyChangeListeners
Number of current listeners. May return -1 if the information is not available for some reason.- Returns:
- the number of listeners.
-
getPropertyChangeListenersByReference
@CheckReturnValue @Nonnull PropertyChangeListener[] getPropertyChangeListenersByReference(@Nonnull String name) Get a list of all the property change listeners that are registered using a specific name- Parameters:
name- The name (either system or user) that the listener has registered as referencing this namedBean- Returns:
- empty list if none
-
dispose
void dispose()Deactivate this object, so that it releases as many resources as possible and no longer effects others.For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.
It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.
Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.
-
setState
Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (e.g. setCommandedState in Turnout). This is provided to make scripts access easier to read.
- Parameters:
s- the state- Throws:
JmriException- general error when setting the state fails
-
getState
Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (e.g. getCommandedState in Turnout). This is provided to make scripts easier to read.
- Returns:
- the state
-
describeState
Provide human-readable, localized version of state value.This method is intended for use when presenting to a human operator.
- Parameters:
state- the state to describe- Returns:
- the state in localized form
-
getComment
Get associated comment text.- Returns:
- the comment or null
-
setComment
Set associated comment text.Comments can be any valid text.
- Parameters:
comment- the comment or null to remove an existing comment
-
getUsageReport
Get a list of references for the specified bean.- Parameters:
bean- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-
setProperty
Attach a key/value pair to the NamedBean, which can be retrieved later. These are not bound properties as yet, and don't throw events on modification. Key must not be null.The key is constrained to String to make these behave like normal Java Beans.
- Parameters:
key- the property to setvalue- the value of the property
-
getProperty
Retrieve the value associated with a key. If no value has been set for that key, returns null.- Parameters:
key- the property to get- Returns:
- The value of the property or null.
-
removeProperty
Remove the key/value pair against the NamedBean.- Parameters:
key- the property to remove
-
getPropertyKeys
Retrieve the complete current set of keys.- Returns:
- empty set if none
-
getBeanType
For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
normalizeUserName
@CheckReturnValue @CheckForNull static String normalizeUserName(@CheckForNull String inputName) throws NamedBean.BadUserNameException Enforces, and as a user convenience converts to, the standard form for a user name.This implementation just does a trim(), but later versions might e.g. do more extensive things.
- Parameters:
inputName- User name to be normalized- Returns:
- A user name in standard normalized form or null if inputName was null
- Throws:
NamedBean.BadUserNameException- If the inputName can't be converted to normalized form
-
compareTo
Provide a comparison between the system names of two beans. This provides a implementation for e.g.Comparator. Returns 0 if the names are the same, -1 if the first argument orders before the second argument's name, +1 if the first argument's name orders after the second argument's name. The comparison is alphanumeric on the system prefix, then alphabetic on the type letter, then system-specific comparison on the two suffix parts via thecompareSystemNameSuffix(java.lang.String, java.lang.String, jmri.NamedBean)method.- Specified by:
compareToin interfaceComparable<NamedBean>- Parameters:
n2- The second NamedBean in the comparison ("this" is the first one)- Returns:
- -1,0,+1 for ordering if the names are well-formed; may not provide proper ordering if the names are not well-formed.
-
compareSystemNameSuffix
@CheckReturnValue int compareSystemNameSuffix(@Nonnull String suffix1, @Nonnull String suffix2, @Nonnull NamedBean n2) Compare the suffix of this NamedBean's name with the suffix of the argument NamedBean's name for thecompareTo(jmri.NamedBean)operation. This is intended to be a system-specific comparison that understands the various formats, etc.- Parameters:
suffix1- The suffix for the 1st bean in the comparisonsuffix2- The suffix for the 2nd bean in the comparisonn2- The other (second) NamedBean in the comparison- Returns:
- -1,0,+1 for ordering if the names are well-formed; may not provide proper ordering if the names are not well-formed.
-