001package jmri.jmrix.dccpp.configurexml;
002
003import jmri.jmrix.configurexml.AbstractStreamConnectionConfigXml;
004import jmri.jmrix.dccpp.DCCppStreamConnectionConfig;
005import jmri.jmrix.dccpp.DCCppStreamPortController;
006
007/**
008 * Handle XML persistance of layout connections by persistening the
009 * DCCppStreamConnectionConfig (and connections). Note this is named as the 
010 * XML version of a ConnectionConfig object, but it's actually persisting the
011 * DCCppStreamPortController.
012 * <p>
013 * This class is invoked from jmrix.JmrixConfigPaneXml on write, as that class
014 * is the one actually registered. Reads are brought here directly via the class
015 * attribute in the XML.
016 *
017 * @author Andrew Crosland Copyright: Copyright (c) 2006
018 */
019public class DCCppStreamConnectionConfigXml extends AbstractStreamConnectionConfigXml {
020
021    public DCCppStreamConnectionConfigXml() {
022        super();
023    }
024
025    @Override
026    protected void getInstance() {
027        if (adapter == null) {
028            adapter = new DCCppStreamPortController();
029        }
030    }
031
032    @Override
033    protected void getInstance(Object object) {
034        adapter = ((DCCppStreamConnectionConfig) object).getAdapter();
035    }
036
037    @Override
038    protected void register() {
039        if (adapter != null) {
040            return; // already registered.
041        }
042        this.register(new DCCppStreamConnectionConfig(adapter));
043    }
044
045}