001package jmri.jmrix.srcp;
002
003import javax.annotation.Nonnull;
004import jmri.Sensor;
005
006/**
007 * Implement SensorMmanager for SRCP systems.
008 * <p>
009 * System names are "DSnnn", where D is the user configurable system prefix,
010 * nnn is the sensor number without padding.
011 *
012 * @author Bob Jacobsen Copyright (C) 2001, 2008
013 */
014public class SRCPSensorManager extends jmri.managers.AbstractSensorManager {
015
016    public SRCPSensorManager(SRCPBusConnectionMemo memo) {
017        super(memo);
018    }
019
020    /**
021     * {@inheritDoc}
022     */
023    @Override
024    @Nonnull
025    public SRCPBusConnectionMemo getMemo() {
026        return (SRCPBusConnectionMemo) memo;
027    }
028
029    /**
030     * {@inheritDoc}
031     * <p>
032     * System name is normalized to ensure uniqueness.
033     * @throws IllegalArgumentException when SystemName can't be converted
034     */
035    @Override
036    @Nonnull
037    protected Sensor createNewSensor(@Nonnull String systemName, String userName) throws IllegalArgumentException {
038        Sensor t;
039        int addr;
040        try {
041            addr = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1));
042        } catch (NumberFormatException e) {
043            throw new IllegalArgumentException("Unable to convert " +  // NOI18N
044                    systemName.substring(getSystemPrefix().length() + 1) +
045                    " to SRCP sensor address"); // NOI18N
046        }
047        t = new SRCPSensor(addr, getMemo());
048        t.setUserName(userName);
049
050        return t;
051    }
052
053    /**
054     * Validates to only numeric.
055     * {@inheritDoc}
056     */
057    @Override
058    @Nonnull
059    public String validateSystemNameFormat(@Nonnull String name, @Nonnull java.util.Locale locale) throws jmri.NamedBean.BadSystemNameException {
060        return validateSystemNameFormatOnlyNumeric(name,locale);
061    }
062
063}