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