001package jmri.jmrix.jmriclient.networkdriver.configurexml;
002
003import jmri.jmrix.configurexml.AbstractNetworkConnectionConfigXml;
004import jmri.jmrix.jmriclient.JMRIClientSystemConnectionMemo;
005import jmri.jmrix.jmriclient.networkdriver.ConnectionConfig;
006import jmri.jmrix.jmriclient.networkdriver.NetworkDriverAdapter;
007import org.jdom2.Element;
008
009/**
010 * Handle XML persistance of layout connections by persistening the
011 * NetworkDriverAdapter (and connections).
012 * <p>
013 * Note this is named as the XML version of a ConnectionConfig object, but it's
014 * actually persisting the NetworkDriverAdapter.
015 * <p>
016 * This class is invoked from jmrix.JmrixConfigPaneXml on write, as that class
017 * is the one actually registered. Reads are brought here directly via the class
018 * attribute in the XML.
019 *
020 * @author Bob Jacobsen Copyright: Copyright (c) 2003
021 * @author Paul Bender Copyright: Copyright (c) 2010
022 */
023public class ConnectionConfigXml extends AbstractNetworkConnectionConfigXml {
024
025    public ConnectionConfigXml() {
026        super();
027    }
028
029    @Override
030    protected void getInstance() {
031        if (adapter == null) {
032            adapter = new NetworkDriverAdapter();
033        }
034    }
035
036    @Override
037    protected void getInstance(Object object) {
038        adapter = ((ConnectionConfig) object).getAdapter();
039    }
040
041    @Override
042    protected void register() {
043        this.register(new ConnectionConfig(adapter));
044    }
045
046    /**
047     * Customizable method if you need to add anything more
048     *
049     * @param e Element being created, update as needed
050     */
051    @Override
052    protected void extendElement(Element e) {
053        if (adapter.getSystemConnectionMemo() != null) {
054            e.setAttribute("transmitPrefix", ((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).getTransmitPrefix());
055        }
056    }
057
058    @Override
059    protected void unpackElement(Element shared, Element perNode) {
060        if (shared.getAttribute("transmitPrefix") != null) {
061            ((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).setTransmitPrefix(shared.getAttribute("transmitPrefix").getValue());
062        }
063    }
064
065}