001package jmri.jmrix.xpa;
002
003import javax.annotation.Nonnull;
004import jmri.Turnout;
005
006/**
007 * Implement turnout manager for Xpa+Modem connections to XpressNet Based
008 * systems.
009 * <p>
010 * System names are "PTnnn", where P is the user configurable system prefix,
011 * nnn is the turnout number without padding.
012 *
013 * @author Paul Bender Copyright (C) 2004,2016
014 */
015public class XpaTurnoutManager extends jmri.managers.AbstractTurnoutManager {
016
017    public XpaTurnoutManager(XpaSystemConnectionMemo memo) {
018         super(memo);
019    }
020
021    /**
022     * {@inheritDoc}
023     */
024    @Override
025    @Nonnull
026    public XpaSystemConnectionMemo getMemo() {
027        return (XpaSystemConnectionMemo) memo;
028    }
029
030    /**
031     * {@inheritDoc}
032     */
033    @Nonnull
034    @Override
035    protected Turnout createNewTurnout(@Nonnull String systemName, String userName) throws IllegalArgumentException {
036        int addr;
037        try {
038            addr = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1));
039        } catch (NumberFormatException e) {
040            throw new IllegalArgumentException("Failed to convert systemName '"+systemName+"' to a Turnout address");
041        }
042        Turnout t = new XpaTurnout(addr, getMemo());
043        t.setUserName(userName);
044        return t;
045    }
046
047    @Override
048    public boolean allowMultipleAdditions(@Nonnull String systemName) {
049        return true;
050    }
051    
052    /**
053     * Validates to only numeric.
054     * {@inheritDoc}
055     */
056    @Override
057    @Nonnull
058    public String validateSystemNameFormat(@Nonnull String name, @Nonnull java.util.Locale locale) throws jmri.NamedBean.BadSystemNameException {
059        return validateSystemNameFormatOnlyNumeric(name,locale);
060    }
061
062}