jmri.managers
Class AbstractProxyManager

java.lang.Object
  extended by jmri.managers.AbstractProxyManager
All Implemented Interfaces:
Manager
Direct Known Subclasses:
ProxyLightManager, ProxyReporterManager, ProxySensorManager, ProxyTurnoutManager

public abstract class AbstractProxyManager
extends Object
implements Manager

Implementation of a Manager that can serves as a proxy for multiple system-specific implementations.

Automatically includes an Internal system, which need not be separately added any more.

Encapsulates access to the "Primary" manager, used by default.

Internally, this is done by using a list of all non-Internal managers, plus a separate reference to the internal manager.

Author:
Bob Jacobsen Copyright (C) 2003, 2010

Field Summary
 
Fields inherited from interface jmri.Manager
AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXS, MEMORIES, OBLOCKS, PANELFILES, REPORTERS, ROUTES, SECTIONS, SENSORGROUPS, SENSORS, SIGNALGROUPS, SIGNALHEADS, SIGNALMASTLOGICS, SIGNALMASTS, TIMEBASE, TRANSITS, TURNOUTS, WARRANTS
 
Constructor Summary
AbstractProxyManager()
           
 
Method Summary
 void addManager(Manager m)
           
 void addPropertyChangeListener(PropertyChangeListener l)
          At a minimum, subclasses must notify of changes to the list of available NamedBeans; they may have other properties that will also notify.
 void deregister(NamedBean s)
          Forget a NamedBean Object created outside the manager.
 void dispose()
          Free resources when no longer used.
 NamedBean getBeanBySystemName(String systemName)
          Locate an instance based on a system name.
protected  NamedBean getBeanByUserName(String userName)
           
 List<Manager> getManagerList()
          Returns a list of all managers, including the internal manager.
protected  AbstractManager getMgr(int index)
           
protected  NamedBean getNamedBean(String name)
          Locate via user name, then system name if needed.
 String[] getSystemNameArray()
           
 List<String> getSystemNameList()
          Get a list of all system names.
 String getSystemPrefix()
          Provides access to the system prefix string.
protected abstract  NamedBean makeBean(int index, String systemName, String userName)
          Defer creation of the proper type to the subclass
protected abstract  AbstractManager makeInternalManager()
           
 String makeSystemName(String s)
           
protected  int match(String systemname)
          Find the index of a matching manager.
protected  int matchTentative(String systemname)
          Find the index of a matching manager.
 NamedBean newNamedBean(String systemName, String userName)
          Return an instance with the specified system and user names.
protected  int nMgrs()
          Number of managers available through getManager(i) and getManagerList(), including the Internal manager
protected  NamedBean provideNamedBean(String name)
          Locate via user name, then system name if needed.
 void register(NamedBean s)
          Remember a NamedBean Object created outside the manager.
 void removePropertyChangeListener(PropertyChangeListener l)
          At a minimum, subclasses must notify of changes to the list of available NamedBeans; they may have other properties that will also notify.
 char systemLetter()
          Deprecated.  
 char typeLetter()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.Manager
getXMLOrder
 

Constructor Detail

AbstractProxyManager

public AbstractProxyManager()
Method Detail

nMgrs

protected int nMgrs()
Number of managers available through getManager(i) and getManagerList(), including the Internal manager


getMgr

protected AbstractManager getMgr(int index)

getManagerList

public List<Manager> getManagerList()
Returns a list of all managers, including the internal manager. This is not a live list.


addManager

public void addManager(Manager m)

makeInternalManager

protected abstract AbstractManager makeInternalManager()

getNamedBean

protected NamedBean getNamedBean(String name)
Locate via user name, then system name if needed. Subclasses use this to provide e.g. getSensor, getTurnout, etc via casts.

Parameters:
name -
Returns:
Null if nothing by that name exists

provideNamedBean

protected NamedBean provideNamedBean(String name)
Locate via user name, then system name if needed. If that fails, create a new NamedBean: If the name is a valid system name, it will be used for the new NamedBean. Otherwise, the makeSystemName method will attempt to turn it into a valid system name. Subclasses use this to provide e.g. getSensor, getTurnout, etc via casts.

Parameters:
name -
Returns:
Never null under normal circumstances

makeBean

protected abstract NamedBean makeBean(int index,
                                      String systemName,
                                      String userName)
Defer creation of the proper type to the subclass

Parameters:
index - Which manager to invoke

getBeanBySystemName

public NamedBean getBeanBySystemName(String systemName)
Description copied from interface: Manager
Locate an instance based on a system name. Returns null if no instance already exists.

Specified by:
getBeanBySystemName in interface Manager
Parameters:
systemName - System Name of the required NamedBean
Returns:
requested NamedBean object or null if none exists

getBeanByUserName

protected NamedBean getBeanByUserName(String userName)

newNamedBean

public NamedBean newNamedBean(String systemName,
                              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 Sensor object representing a given physical turnout and therefore only one with a specific system or user name.

This will always return a valid object reference for a valid request; 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 NamedBean when you should be looking them up.

Returns:
requested NamedBean object (never null)

dispose

public void dispose()
Description copied from interface: Manager
Free resources when no longer used. Specifically, remove all references to and from this object, so it can be garbage-collected.

Specified by:
dispose in interface Manager

matchTentative

protected int matchTentative(String systemname)
Find the index of a matching manager. Returns -1 if there is no match, which is not considered an error


match

protected int match(String systemname)
Find the index of a matching manager. Throws IllegalArgumentException if there is no match, here considered to be an error that must be reported.


register

public void register(NamedBean s)
Remember a NamedBean Object created outside the manager.

Forwards the register request to the matching system

Specified by:
register in interface Manager

deregister

public void deregister(NamedBean s)
Forget a NamedBean Object created outside the manager.

Forwards the deregister request to the matching system

Specified by:
deregister in interface Manager

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Description copied from interface: Manager
At a minimum, subclasses must notify of changes to the list of available NamedBeans; they may have other properties that will also notify.

Specified by:
addPropertyChangeListener in interface Manager

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Description copied from interface: Manager
At a minimum, subclasses must notify of changes to the list of available NamedBeans; they may have other properties that will also notify.

Specified by:
removePropertyChangeListener in interface Manager

getSystemPrefix

public String getSystemPrefix()
Description copied from interface: Manager
Provides access to the system prefix string. This was previously called the "System letter"

Specified by:
getSystemPrefix in interface Manager
Returns:
The system-specific prefix letter for the primary implementation

systemLetter

@Deprecated
public char systemLetter()
Deprecated. 

Provide 1st char of systemPrefix for now

Specified by:
systemLetter in interface Manager
Returns:
The system-specific prefix letter for a specific implementation

typeLetter

public char typeLetter()
Specified by:
typeLetter in interface Manager
Returns:
The type letter for turnouts

makeSystemName

public String makeSystemName(String s)
Specified by:
makeSystemName in interface Manager
Returns:
A system name from a user input, typically a number, from the primary system.

getSystemNameArray

public String[] getSystemNameArray()
Specified by:
getSystemNameArray in interface Manager

getSystemNameList

public List<String> getSystemNameList()
Get a list of all system names.

Specified by:
getSystemNameList in interface Manager


Copyright © 1997 - 2011 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: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads