001package jmri.jmrix.jmriclient;
002
003import javax.annotation.Nonnull;
004import jmri.Turnout;
005
006/**
007 * Implement turnout manager for JMRIClient systems
008 * <p>
009 * System names are "prefixnnn", where prefix is the system prefix and nnn is
010 * the turnout number without padding.
011 *
012 * @author Paul Bender Copyright (C) 2010
013 */
014public class JMRIClientTurnoutManager extends jmri.managers.AbstractTurnoutManager {
015
016    public JMRIClientTurnoutManager(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    @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(getSystemNamePrefix().length()));
038        } catch (NumberFormatException e) {
039            throw new IllegalArgumentException("Failed to convert systemName '"+systemName+"' to a Turnout.");
040        }
041        Turnout t = new JMRIClientTurnout(addr, getMemo());
042        t.setUserName(userName);
043        return t;
044    }
045
046    /*
047     * JMRIClient Turnouts can take arbitrary names to match the names used
048     * on the server.
049     */
050    @Override
051    public String createSystemName(@Nonnull String curAddress, @Nonnull String prefix) throws jmri.JmriException {
052        return prefix + typeLetter() + curAddress;
053    }
054
055    @Override
056    public boolean allowMultipleAdditions(@Nonnull String systemName) {
057        return true;
058    }
059    
060    /**
061     * Validates to only numeric.
062     * {@inheritDoc}
063     */
064    @Override
065    @Nonnull
066    public String validateSystemNameFormat(@Nonnull String name, @Nonnull java.util.Locale locale) throws jmri.NamedBean.BadSystemNameException {
067        return validateSystemNameFormatOnlyNumeric(name,locale);
068    }
069
070}