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