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