001package jmri.jmrix.srcp;
002
003import javax.annotation.Nonnull;
004import jmri.Turnout;
005
006/**
007 * Implement TurnoutManager for SRCP systems.
008 * <p>
009 * System names are "DTnnn", where D is the user configurable system prefix,
010 * nnn is the turnout number without padding.
011 *
012 * @author Bob Jacobsen Copyright (C) 2001, 2008
013 */
014public class SRCPTurnoutManager extends jmri.managers.AbstractTurnoutManager {
015
016    public SRCPTurnoutManager(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     */
032    @Nonnull
033    @Override
034    protected Turnout createNewTurnout(@Nonnull String systemName, String userName) throws IllegalArgumentException {
035        int addr;
036        try {
037            addr = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1));
038        } catch (NumberFormatException e) {
039            throw new IllegalArgumentException("Failed to convert systemName '"+systemName+"' to a Turnout address");
040        }
041        Turnout t = new SRCPTurnout(addr, getMemo());
042        t.setUserName(userName);
043        return t;
044    }
045
046    @Override
047    public boolean allowMultipleAdditions(@Nonnull String systemName) {
048        return true;
049    }
050
051    /**
052     * Validates to only numeric.
053     * {@inheritDoc}
054     */
055    @Override
056    @Nonnull
057    public String validateSystemNameFormat(@Nonnull String name, @Nonnull java.util.Locale locale) throws jmri.NamedBean.BadSystemNameException {
058        return validateSystemNameFormatOnlyNumeric(name,locale);
059    }
060
061    // private final static Logger log = LoggerFactory.getLogger(SRCPTurnout.class);
062
063}