001package jmri.jmrit.logixng.actions.configurexml;
002
003import java.util.ResourceBundle;
004
005import jmri.*;
006import jmri.configurexml.JmriConfigureXmlException;
007import jmri.jmrit.logixng.DigitalActionManager;
008import jmri.jmrit.logixng.actions.ActionBlock;
009import jmri.jmrit.logixng.util.configurexml.*;
010
011import org.jdom2.Element;
012
013/**
014 * Handle XML configuration for Block objects.
015 *
016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
017 * @author Daniel Bergqvist Copyright 2021
018 * @author Dave Sand Copyright (C) 2021
019 */
020public class ActionBlockXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
021
022    static final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.logixng.actions.ActionBundle");
023
024    public ActionBlockXml() {
025    }
026
027    /**
028     * Default implementation for storing the contents of a Block
029     *
030     * @param o Object to store, of type TriggerBlock
031     * @return Element containing the complete info
032     */
033    @Override
034    public Element store(Object o) {
035        ActionBlock p = (ActionBlock) o;
036
037        Element element = new Element("ActionBlock");
038        element.setAttribute("class", this.getClass().getName());
039        element.addContent(new Element("systemName").addContent(p.getSystemName()));
040
041        storeCommon(p, element);
042
043        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Block>();
044        var selectEnumXml = new LogixNG_SelectEnumXml<ActionBlock.DirectOperation>();
045        var selectStringXml = new LogixNG_SelectStringXml();
046
047        element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean"));
048        element.addContent(selectEnumXml.store(p.getSelectEnum(), "operation"));
049        element.addContent(selectStringXml.store(p.getSelectBlockValue(), "blockValueData"));
050
051        return element;
052    }
053
054    @Override
055    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {     // Test class that inherits this class throws exception
056        String sys = getSystemName(shared);
057        String uname = getUserName(shared);
058        ActionBlock h = new ActionBlock(sys, uname);
059
060        loadCommon(h, shared);
061
062        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Block>();
063        var selectEnumXml = new LogixNG_SelectEnumXml<ActionBlock.DirectOperation>();
064        var selectStringXml = new LogixNG_SelectStringXml();
065
066        selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean());
067        selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "block");
068
069        selectEnumXml.load(shared.getChild("operation"), h.getSelectEnum());
070        selectEnumXml.loadLegacy(
071                shared, h.getSelectEnum(),
072                "operationAddressing",
073                "operationDirect",
074                "operationReference",
075                "operationLocalVariable",
076                "operationFormula");
077
078        selectStringXml.load(shared.getChild("blockValueData"), h.getSelectBlockValue());
079        selectStringXml.loadLegacy(shared, h.getSelectBlockValue(),
080                "dataAddressing",
081                "blockValue",
082                "dataReference",
083                "dataLocalVariable",
084                "dataFormula");
085
086        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
087        return true;
088    }
089
090//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionBlockXml.class);
091}