jmri
Class AbstractLightManager

java.lang.Object
  extended by jmri.AbstractManager
      extended by jmri.AbstractLightManager
All Implemented Interfaces:
PropertyChangeListener, EventListener, LightManager, Manager
Direct Known Subclasses:
AcelaLightManager, LnLightManager, SerialLightManager, SerialLightManager, SerialLightManager, SerialLightManager, SerialLightManager, SerialLightManager, XNetLightManager

public abstract class AbstractLightManager
extends AbstractManager
implements LightManager, PropertyChangeListener

Abstract partial implementation of a LightManager.

Based on AbstractSignalHeadManager.java and AbstractSensorManager.java

Author:
Dave Duchamp Copyright (C) 2004

Field Summary
 
Fields inherited from class jmri.AbstractManager
_tsys, _tuser
 
Constructor Summary
AbstractLightManager()
           
 
Method Summary
 void activateAllLights()
          Activate the control mechanism for each Light controlled by this LightManager.
 String convertSystemNameToAlternate(String systemName)
          Convert the system name to a normalized alternate name This routine is to allow testing to ensure that two Lights with alternate names that refer to the same output bit are not created.
protected abstract  Light createNewLight(String systemName, String userName)
          Internal method to invoke the factory, after all the logic for returning an existing method has been invoked.
 Light getBySystemName(String name)
          Locate a Light by its system name
 Light getByUserName(String key)
          Locate a Light by its user name
 Light getLight(String name)
          Locate via user name, then system name if needed.
 Light newLight(String sysName, String userName)
          Return an instance with the specified system and user names.
 String normalizeSystemName(String systemName)
          Normalize the system name This routine is used to ensure that each system name is uniquely linked to one C/MRI bit, by removing extra zeros inserted by the user.
 Light provideLight(String name)
          Locate via user name, then system name if needed.
 char typeLetter()
          Returns the second letter in the system name for a Light
 
Methods inherited from class jmri.AbstractManager
addPropertyChangeListener, deregister, dispose, firePropertyChange, getInstanceBySystemName, getInstanceByUserName, getSystemNameList, makeSystemName, propertyChange, register, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.LightManager
dispose, getSystemNameList, validSystemNameConfig, validSystemNameFormat
 
Methods inherited from interface jmri.Manager
addPropertyChangeListener, deregister, makeSystemName, register, removePropertyChangeListener, systemLetter
 
Methods inherited from interface java.beans.PropertyChangeListener
propertyChange
 

Constructor Detail

AbstractLightManager

public AbstractLightManager()
Method Detail

typeLetter

public char typeLetter()
Returns the second letter in the system name for a Light

Specified by:
typeLetter in interface Manager
Returns:
The type letter for a specific implementation

provideLight

public Light provideLight(String name)
Locate via user name, then system name if needed. If that fails, create a new Light: If the name is a valid system name, it will be used for the new Light. Otherwise, the makeSystemName method will attempt to turn it into a valid system name.

Specified by:
provideLight in interface LightManager
Parameters:
name -
Returns:
Never null unless valid systemName cannot be found

getLight

public Light getLight(String name)
Locate via user name, then system name if needed. Does not create a new one if nothing found

Specified by:
getLight in interface LightManager
Parameters:
name -
Returns:
null if no match found

getBySystemName

public Light getBySystemName(String name)
Locate a Light by its system name

Specified by:
getBySystemName in interface LightManager

getByUserName

public Light getByUserName(String key)
Locate a Light by its user name

Specified by:
getByUserName in interface LightManager

newLight

public Light newLight(String sysName,
                      String userName)
Return an instance with the specified system and user names. Note that two calls with the same arguments will get the same instance; there is only one Light object representing a given physical Light and therefore only one with a specific system or user name.

This will always return a valid object reference; a new object will be created if necessary. In that case:

Note that it is possible to make an inconsistent request if both addresses are provided, but the given values are associated with different objects. This is a problem, and we don't have a good solution except to issue warnings. This will mostly happen if you're creating Lights when you should be looking them up.

Specified by:
newLight in interface LightManager
Returns:
requested Light object (never null)

createNewLight

protected abstract Light createNewLight(String systemName,
                                        String userName)
Internal method to invoke the factory, after all the logic for returning an existing method has been invoked.

Returns:
new null

activateAllLights

public void activateAllLights()
Activate the control mechanism for each Light controlled by this LightManager. Note that some Lights don't require any activation. The activateLight method in AbstractLight.java determines what needs to be done for each Light.

Specified by:
activateAllLights in interface LightManager

normalizeSystemName

public String normalizeSystemName(String systemName)
Normalize the system name

This routine is used to ensure that each system name is uniquely linked to one C/MRI bit, by removing extra zeros inserted by the user.

If a system implementation has names that could be normalized, the system-specific Light Manager should override this routine and supply a normalized system name.

Specified by:
normalizeSystemName in interface LightManager

convertSystemNameToAlternate

public String convertSystemNameToAlternate(String systemName)
Convert the system name to a normalized alternate name

This routine is to allow testing to ensure that two Lights with alternate names that refer to the same output bit are not created.

If a system implementation has alternate names, the system specific Light Manager should override this routine and supply the alternate name.

Specified by:
convertSystemNameToAlternate in interface LightManager


Copyright © 1997 - 2008 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: SourceForge_Logo