001package jmri.jmrix.jmriclient; 002 003import javax.annotation.Nonnull; 004import jmri.Sensor; 005 006/** 007 * Implement sensor manager for JMRIClient systems. 008 * <p> 009 * System names are "prefixnnn", where prefix is the system prefix and nnn is 010 * the sensor number without padding. 011 * 012 * @author Paul Bender Copyright (C) 2010 013 */ 014public class JMRIClientSensorManager extends jmri.managers.AbstractSensorManager { 015 016 public JMRIClientSensorManager(JMRIClientSystemConnectionMemo memo) { 017 super(memo); 018 } 019 020 /** 021 * {@inheritDoc} 022 */ 023 @Override 024 @Nonnull 025 public JMRIClientSystemConnectionMemo getMemo() { 026 return (JMRIClientSystemConnectionMemo) memo; 027 } 028 029 /** 030 * {@inheritDoc} 031 * 032 * @throws IllegalArgumentException when SystemName can't be converted 033 */ 034 @Override 035 @Nonnull 036 protected Sensor createNewSensor(@Nonnull String systemName, String userName) throws IllegalArgumentException { 037 Sensor t; 038 int addr; 039 try { 040 addr = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1)); // .length() only? TODO 041 } catch (NumberFormatException e) { 042 throw new IllegalArgumentException("Can't convert " + // NOI18N 043 systemName.substring(getSystemPrefix().length() + 1) + 044 " to JMRIClient sensor address"); // NOI18N 045 } 046 t = new JMRIClientSensor(addr, getMemo()); 047 t.setUserName(userName); 048 return t; 049 } 050 051 /* 052 * JMRIClient Sensors can take arbitrary names to match the names used 053 * on the server. 054 */ 055 @Override 056 @Nonnull 057 public String createSystemName(@Nonnull String curAddress, @Nonnull String prefix) throws jmri.JmriException { 058 return prefix + typeLetter() + curAddress; 059 } 060 061 /** 062 * Validates to only numeric. 063 * {@inheritDoc} 064 */ 065 @Override 066 @Nonnull 067 public String validateSystemNameFormat(@Nonnull String name, @Nonnull java.util.Locale locale) throws jmri.NamedBean.BadSystemNameException { 068 return validateSystemNameFormatOnlyNumeric(name,locale); 069 } 070 071 072}