001package jmri.jmrix.marklin;
002
003import javax.annotation.Nonnull;
004import jmri.Turnout;
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007
008/**
009 * Implement turnout manager for Marklin systems.
010 * <p>
011 * Based on work by Bob Jacobsen
012 *
013 * @author Kevin Dickerson Copyright (C) 2012
014 */
015public class MarklinTurnoutManager extends jmri.managers.AbstractTurnoutManager {
016
017    public MarklinTurnoutManager(MarklinSystemConnectionMemo memo) {
018        super(memo);
019        tc = memo.getTrafficController();
020    }
021
022    MarklinTrafficController tc;
023
024    /**
025     * {@inheritDoc}
026     */
027    @Override
028    @Nonnull
029    public MarklinSystemConnectionMemo getMemo() {
030        return (MarklinSystemConnectionMemo) memo;
031    }
032
033    /**
034     * {@inheritDoc}
035     */
036    @Nonnull
037    @Override
038    protected Turnout createNewTurnout(@Nonnull String systemName, String userName) throws IllegalArgumentException {
039        int addr;
040        try {
041            addr = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1));
042        } catch (NumberFormatException e) {
043            log.error("Failed to convert systemName {} to a turnout address", systemName);
044            throw new IllegalArgumentException("failed to convert systemName '"+systemName+"' to a Turnout address");
045        }
046        Turnout t = new MarklinTurnout(addr, getSystemPrefix(), tc);
047        t.setUserName(userName);
048        return t;
049    }
050
051    @Override
052    public boolean allowMultipleAdditions(@Nonnull String systemName) {
053        return true;
054    }
055
056    boolean noWarnDelete = false;
057
058    private final static Logger log = LoggerFactory.getLogger(MarklinTurnoutManager.class);
059
060}