001package jmri.jmrix.anyma.configurexml;
002
003import jmri.jmrix.ConnectionConfig;
004import jmri.jmrix.UsbPortAdapter;
005import jmri.jmrix.anyma.AnymaDMX_ConnectionConfig;
006import jmri.jmrix.anyma.AnymaDMX_UsbPortAdapter;
007import jmri.jmrix.configurexml.AbstractUsbConnectionConfigXml;
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011/**
012 * Handle XML persistence of layout connections by persisting the
013 * AnymaDMX_UsbPortAdapter. Note this is named as the XML version of a
014 * AnymaDMX_ConnectionConfig object, but it's actually persisting the
015 * AnymaDMX_UsbPortAdapter.
016 * <p>
017 * This class is invoked from jmrix.JmrixConfigPaneXml on write, as that class
018 * is the one actually registered. Reads are brought here directly via the class
019 * attribute in the XML.
020 *
021 * @author George Warner Copyright (c) 2017-2018
022 * @since 4.9.6
023 */
024public class AnymaDMX_ConnectionConfigXml extends AbstractUsbConnectionConfigXml {
025
026    /**
027     * constructor
028     */
029    public AnymaDMX_ConnectionConfigXml() {
030        super();
031        log.debug("* constructor()");
032    }
033
034    /**
035     * get instance
036     */
037    @Override
038    protected void getInstance() {
039        log.debug("* getInstance()");
040        if (getAdapter() == null) {
041            setAdapter(new AnymaDMX_UsbPortAdapter());
042            //if (adapter.getAnymaDMX_Controller() == null) {
043            //    try {
044            //        this.creationErrorEncountered("Not running on Anyma DMX.", adapter.getSystemPrefix(), adapter.getUserName(), null);
045            //    } catch (JmriConfigureXmlException ex) {
046            //        log.error("Not running on Anyma DMX.", ex);
047            //    }
048            //}
049        }
050    }
051
052    /**
053     * {@inheritDoc}
054     */
055    @Override
056    protected void getInstance(Object object) {
057        setAdapter((UsbPortAdapter) ((ConnectionConfig) object).getAdapter());
058    }
059
060    /**
061     * register
062     */
063    @Override
064    protected void register() {
065        if (adapter instanceof AnymaDMX_UsbPortAdapter) {
066            this.register(new AnymaDMX_ConnectionConfig(
067                    (AnymaDMX_UsbPortAdapter) adapter));
068        }
069    }
070
071    private final static Logger log
072            = LoggerFactory.getLogger(AnymaDMX_ConnectionConfigXml.class);
073}