001package jmri.jmrix.direct.simulator.configurexml;
002
003import jmri.jmrix.configurexml.AbstractSerialConnectionConfigXml;
004import jmri.jmrix.direct.simulator.ConnectionConfig;
005import jmri.jmrix.direct.simulator.SimulatorAdapter;
006
007/**
008 * Handle XML persistence of layout connections by persisting the
009 * SerialDriverAdapter (and connections).
010 * <p>
011 * Note this is named as the XML version of a ConnectionConfig object,
012 * but it's actually persisting the SerialDriverAdapter.
013 * <p>
014 * This class is invoked from jmrix.JmrixConfigPaneXml on write, as that class
015 * is the one actually registered. Reads are brought here directly via the class
016 * attribute in the XML.
017 *
018 * @author Bob Jacobsen Copyright (c) 2003 copied from NCE/Tams code
019 * @author kcameron Copyright (c) 2014
020 */
021public class ConnectionConfigXml extends AbstractSerialConnectionConfigXml {
022
023    public ConnectionConfigXml() {
024        super();
025    }
026
027    @Override
028    protected void getInstance(Object object) {
029        adapter = ((ConnectionConfig) object).getAdapter();
030    }
031
032    @Override
033    protected void getInstance() {
034        if (adapter == null) {
035            adapter = new SimulatorAdapter();
036        }
037    }
038
039    @Override
040    protected void register() {
041        this.register(new ConnectionConfig(adapter));
042    }
043
044}