001package jmri.managers; 002 003import javax.annotation.Nonnull; 004import jmri.Light; 005import jmri.LightManager; 006import jmri.Manager; 007 008/** 009 * Implementation of a LightManager that can serve as a proxy for multiple 010 * system-specific implementations. 011 * 012 * @author Bob Jacobsen Copyright (C) 2010, 2018 013 * @author Dave Duchamp Copyright (C) 2004 014 */ 015public class ProxyLightManager extends AbstractProvidingProxyManager<Light> 016 implements LightManager { 017 018 public ProxyLightManager() { 019 super(); 020 } 021 022 @Override 023 public int getXMLOrder() { 024 return jmri.Manager.LIGHTS; 025 } 026 027 @Override 028 protected AbstractManager<Light> makeInternalManager() { 029 return jmri.InstanceManager.getDefault(jmri.jmrix.internal.InternalSystemConnectionMemo.class).getLightManager(); 030 } 031 032 /** 033 * Locate via user name, then system name if needed. 034 * 035 * @return Null if nothing by that name exists 036 */ 037 @Override 038 public Light getLight(@Nonnull String name) { 039 return super.getNamedBean(name); 040 } 041 042 /** {@inheritDoc} */ 043 @Override 044 @Nonnull 045 protected Light makeBean(Manager<Light> manager, String systemName, String userName) throws IllegalArgumentException { 046 return ((LightManager) manager).newLight(systemName, userName); 047 } 048 049 /** {@inheritDoc} */ 050 @Override 051 @Nonnull 052 public Light provide(@Nonnull String name) throws IllegalArgumentException { return provideLight(name); } 053 054 /** 055 * Locate via user name, then system name if needed. If that fails, create a 056 * new Light: If the name is a valid system name, it will be used for the 057 * new Light. Otherwise, the makeSystemName method will attempt to turn it 058 * into a valid system name. 059 * 060 * @return Never null under normal circumstances 061 */ 062 @Override 063 @Nonnull 064 public Light provideLight(@Nonnull String name) throws IllegalArgumentException { 065 return super.provideNamedBean(name); 066 } 067 068 /** {@inheritDoc} */ 069 @Override 070 @Nonnull 071 public Light newLight(@Nonnull String systemName, String userName) throws IllegalArgumentException { 072 return newNamedBean(systemName, userName); 073 } 074 075 /** 076 * Validate system name against the hardware configuration Locate a system 077 * specific LightManager based on a system name. 078 * 079 * @return if a manager is found, return its determination of validity of 080 * system name format relative to the hardware configuration; false if no 081 * manager exists. 082 */ 083 @Override 084 public boolean validSystemNameConfig(@Nonnull String systemName) { 085 LightManager m = (LightManager) getManager(systemName); 086 return (m == null) ? false : m.validSystemNameConfig(systemName); 087 } 088 089 /** 090 * Convert a system name to an alternate format Locate a system specfic 091 * LightManager based on a system name. Returns "" if no manager exists. If 092 * a manager is found, return its determination of an alternate system name 093 */ 094 @Override 095 @Nonnull 096 public String convertSystemNameToAlternate(@Nonnull String systemName) { 097 LightManager m = (LightManager) getManager(systemName); 098 return (m == null) ? "" : m.convertSystemNameToAlternate(systemName); 099 } 100 101 /** 102 * Activate the control mechanism for each Light controlled by this 103 * LightManager. Relay this call to all LightManagers. 104 */ 105 @Override 106 public void activateAllLights() { 107 getManagerList().forEach(m -> ((LightManager) m).activateAllLights()); 108 } 109 110 /** 111 * Responds 'true' if Light Manager is for a System that supports variable 112 * Lights. Returns false if no manager exists. If a manager is found, return 113 * its determination of support for variable lights. 114 */ 115 @Override 116 public boolean supportsVariableLights(@Nonnull String systemName) { 117 LightManager m = (LightManager) getManager(systemName); 118 return (m == null) ? false : m.supportsVariableLights(systemName); 119 } 120 121 /** 122 * A method that determines if it is possible to add a range of lights in 123 * numerical order eg 11 thru 18, primarily used to show/not show the add 124 * range box in the add Light window. 125 */ 126 @Override 127 public boolean allowMultipleAdditions(@Nonnull String systemName) { 128 LightManager m = (LightManager) getManager(systemName); 129 return (m == null) ? false : m.allowMultipleAdditions(systemName); 130 } 131 132 @Override 133 @Nonnull 134 public String getBeanTypeHandled(boolean plural) { 135 return Bundle.getMessage(plural ? "BeanNameLights" : "BeanNameLight"); 136 } 137 138 /** 139 * {@inheritDoc} 140 */ 141 @Override 142 public Class<Light> getNamedBeanClass() { 143 return Light.class; 144 } 145 146}