001package jmri.jmrit.logixng.expressions.configurexml;
002
003import jmri.InstanceManager;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.DigitalExpressionManager;
006import jmri.jmrit.logixng.expressions.ConnectionName;
007
008import org.jdom2.Element;
009
010import jmri.jmrit.logixng.DigitalExpressionBean;
011import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectStringXml;
012
013/**
014 * Handle XML configuration for ConnectionName objects.
015 *
016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
017 * @author Daniel Bergqvist Copyright (C) 2022
018 */
019public class ConnectionNameXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
020
021    public ConnectionNameXml() {
022    }
023
024    /**
025     * Default implementation for storing the contents of a SE8cSignalHead
026     *
027     * @param o Object to store, of type ConnectionName
028     * @return Element containing the complete info
029     */
030    @Override
031    public Element store(Object o) {
032        ConnectionName p = (ConnectionName) o;
033
034        Element element = new Element("ConnectionName");
035        element.setAttribute("class", this.getClass().getName());
036        element.addContent(new Element("systemName").addContent(p.getSystemName()));
037
038        storeCommon(p, element);
039
040        element.addContent(new Element("manufacturer").addContent(p.getManufacturer()));
041        element.addContent(new Element("connectionName").addContent(p.getConnectionName()));
042
043        return element;
044    }
045
046    @Override
047    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {
048        String sys = getSystemName(shared);
049        String uname = getUserName(shared);
050        ConnectionName h = new ConnectionName(sys, uname);
051
052        loadCommon(h, shared);
053
054        if (shared.getChild("manufacturer") != null) {
055            h.setManufacturer(shared.getChild("manufacturer").getTextTrim());
056        }
057        if (shared.getChild("connectionName") != null) {
058            h.setConnectionName(shared.getChild("connectionName").getTextTrim());
059        }
060
061        InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h);
062        return true;
063    }
064
065//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ConnectionNameXml.class);
066}