001package jmri.script.configurexml;
002
003import jmri.script.ScriptEngineSelector;
004
005import org.jdom2.Element;
006
007/**
008 * Xml class for jmri.script.ScriptEngineSelector.
009 *
010 * @author Daniel Bergqvist (C) 2022
011 */
012public class ScriptEngineSelectorXml {
013
014    /**
015     * Default implementation for storing the contents of a ScriptEngineSelector
016     *
017     * @param scriptEngineSelector the LogixNG_SelectTable object
018     * @param tagName the name of the element
019     * @return Element containing the complete info
020     */
021    public Element store(ScriptEngineSelector scriptEngineSelector, String tagName) {
022        Element scriptTypeElement = new Element(tagName);
023
024        ScriptEngineSelector.Engine engine = scriptEngineSelector.getSelectedEngine();
025        if (engine != null) {
026            scriptTypeElement.addContent(new Element("language").addContent(engine.getLanguageName()));
027        }
028
029        return scriptTypeElement;
030    }
031
032    public void load(Element scriptTypeElement, ScriptEngineSelector scriptEngineSelector) {
033
034        if (scriptTypeElement != null) {
035            Element elem = scriptTypeElement.getChild("language");
036            if (elem != null) {
037                scriptEngineSelector.setSelectedEngine(elem.getTextTrim());
038            }
039        }
040    }
041
042}