001package jmri.jmrix.jmriclient; 002 003import java.util.Locale; 004import javax.annotation.Nonnull; 005import jmri.Light; 006 007/** 008 * Implement LightManager for JMRIClient systems 009 * <p> 010 * System names are "prefixnnn", where prefix is the system prefix and nnn is 011 * the light number without padding. 012 * 013 * @author Paul Bender Copyright (C) 2010 014 */ 015public class JMRIClientLightManager extends jmri.managers.AbstractLightManager { 016 017 public JMRIClientLightManager(JMRIClientSystemConnectionMemo memo) { 018 super(memo); 019 } 020 021 /** 022 * {@inheritDoc} 023 */ 024 @Override 025 @Nonnull 026 public JMRIClientSystemConnectionMemo getMemo() { 027 return (JMRIClientSystemConnectionMemo) memo; 028 } 029 030 @Override 031 @Nonnull 032 protected Light createNewLight(@Nonnull String systemName, String userName) throws IllegalArgumentException { 033 Light t; 034 int addr = Integer.parseInt(systemName.substring(getSystemNamePrefix().length())); 035 t = new JMRIClientLight(addr, getMemo()); 036 t.setUserName(userName); 037 return t; 038 } 039 040 /** 041 * {@inheritDoc} 042 */ 043 @Override 044 public NameValidity validSystemNameFormat(@Nonnull String systemName) { 045 return (systemName.startsWith(getSystemNamePrefix()) 046 && Integer.parseInt(systemName.substring(getSystemNamePrefix().length())) > 0) ? NameValidity.VALID : NameValidity.INVALID; 047 } 048 049 /** 050 * {@inheritDoc} 051 */ 052 @Override 053 @Nonnull 054 public String validateSystemNameFormat(@Nonnull String name, @Nonnull Locale locale) { 055 return super.validateIntegerSystemNameFormat(name, 0, Integer.MAX_VALUE, locale); 056 } 057 058 /** 059 * Public method to validate system name for configuration returns 'true' if 060 * system name has a valid meaning in current configuration, else returns 061 * 'false' for now, this method always returns 'true'; it is needed for the 062 * Abstract Light class 063 */ 064 @Override 065 public boolean validSystemNameConfig(@Nonnull String systemName) { 066 return (true); 067 } 068 069}