LogixNG - Create Expressions, Actions, and so on

The locking mechanism

LogixNG has a lock that has three possible values.

  • NONE - The item is not locked.
  • USER_LOCK - The item is locked by the user and can be unlocked by the user.
  • HARD_LOCK - The item is locked by a hard lock that cannot be unlocked by the user by the user interface. But it can be removed by editing the xml file. This lock is used for items that normally shouldn't be changed.

The Base interface

Expressions, Actions, and others, all implements the Base interface. It has methods that are common to everything in LogixNG.

Methods

getSystemName

This is the same method as NamedBean.getSystemName(). It's included here to give the XML classes access to this method having MaleSocket extend NamedBean.

getConfiguratorClassName

Returns the fully qualified class name of the class that is used to configurate this class. That class needs to implement the jmri.jmrit.logixng.swing.PluginConfiguratorInterface interface.

getShortDescription

Get a short description of this item.

getLongDescription

Get a long description of this item.

getChild

Get a child of this item.

getChildCount

Get the number of children.

getCategory

Get the category.

isExternal

Is this external? Does it affects or is dependent on external things, like turnouts and sensors? Timers are considered as internal since they behavies the same on every computer on every layout.

getLock

Get the status of the lock.

setLock

Set the status of the lock.

Creating an Expression

An expression must implement the Expression interface, that in turn inherits the NamedBean interface. It's recommended that expression classes extends the AbstractExpression class which has a default implementation of the NamedBean interface.

Methods

evaluate

Evaluates the expression and returns the result of the expression.

reset

Resets the evaluation. The method reset() is called then when the closest ancestor Action is activated. An example is a timer who is used to delay the execution of an action's child action.

A parent expression must to call reset() on its children when the method reset() is called on the parent.

Creating an Action

An action must implement the Action interface, that in turn inherits the NamedBean interface. It's recommended that action classes extends the AbstractAction class which has a default implementation of the NamedBean interface.

Methods

executeStart

Start execution of this Action.

executeContinue

Continue execution of this Action.

executeRestart

Restart the execute of this Action.

abort

Abort this action.

Creating an AnalogExpression

An analog expression must implement the AnalogExpression interface, that in turn inherits the NamedBean interface. It's recommended that expression classes extends the AbstractAnalogExpression class which has a default implementation of the NamedBean interface.

Methods

evaluate

Evaluates the expression and returns the result of the expression.

Creating an AnalogAction

An analog action must implement the AnalogAction interface, that in turn inherits the NamedBean interface. It's recommended that analog action classes extends the AbstractAnalogAction class which has a default implementation of the NamedBean interface.

Methods

setValue

Set an analog value.

Creating an StringExpression

A string expression must implement the Expression interface, that in turn inherits the NamedBean interface. It's recommended that string expression classes extends the AbstractStringExpression class which has a default implementation of the NamedBean interface.

Methods

evaluate

Evaluates the string expression and returns the result of the string expression.

Creating an StringAction

A string action must implement the StringAction interface, that in turn inherits the NamedBean interface. It's recommended that string action classes extends the AbstractStringAction class which has a default implementation of the NamedBean interface.

Methods

setValue

Set a string value.

Register an expression or an action

In order for JMRI to be able to use the expression or the action, it needs to be told about it. That is done by implementing a ExpressionFactory or a ActionFactory that can tell JMRI about the expressions or actions and then mark it with the @ServiceProvider annotation. A single factory can register many classes. For classes that are supplied with JMRI, it's recommended to use the DefaultExpressionFactory and the DefaultActionFactory.

AbstractExpression and AbstractAction vs AbstractNamedBean

The NamedBean interface has the methods setState() and getState(). These should never be implemented in expressions and actions.

For expressions, getState() returns Expression.TRUE or Expression.FALSE dependent on the last result of the expression, but this is handled automaticly by InternalExpression. The method setState() has no impact on expressions.

For actions, neither of setState() or getState() will ever be called since InternalAction will prevent that.