001package jmri.jmrit.display.logixng.configurexml;
002
003import jmri.*;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.DigitalActionManager;
006import jmri.jmrit.logixng.NamedBeanAddressing;
007import jmri.jmrit.display.logixng.ActionPositionableByClass;
008import jmri.jmrit.logixng.util.parser.ParserException;
009
010import org.jdom2.Element;
011
012/**
013 * Handle XML configuration for ActionPositionableByClass objects.
014 *
015 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
016 * @author Daniel Bergqvist Copyright (C) 2023
017 */
018public class ActionPositionableByClassXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
019
020    public ActionPositionableByClassXml() {
021    }
022
023    /**
024     * Default implementation for storing the contents of a ActionPositionableByClass
025     *
026     * @param o Object to store, of type TripleTurnoutSignalHead
027     * @return Element containing the complete info
028     */
029    @Override
030    public Element store(Object o) {
031        ActionPositionableByClass p = (ActionPositionableByClass) o;
032
033        Element element = new Element("DisplayActionPositionableByClass");
034        element.setAttribute("class", this.getClass().getName());
035        element.addContent(new Element("systemName").addContent(p.getSystemName()));
036
037        storeCommon(p, element);
038
039        String editorName = p.getEditorName();
040        if (editorName != null) {
041            element.addContent(new Element("editorName").addContent(editorName));
042        }
043
044        String className = p.getClassName();
045        if (className != null) {
046            element.addContent(new Element("className").addContent(className));
047        }
048
049        element.addContent(new Element("addressing").addContent(p.getAddressing().name()));
050        element.addContent(new Element("reference").addContent(p.getReference()));
051        element.addContent(new Element("localVariable").addContent(p.getLocalVariable()));
052        element.addContent(new Element("formula").addContent(p.getFormula()));
053
054        element.addContent(new Element("stateAddressing").addContent(p.getStateAddressing().name()));
055        element.addContent(new Element("operation").addContent(p.getOperation().name()));
056        element.addContent(new Element("stateReference").addContent(p.getStateReference()));
057        element.addContent(new Element("stateLocalVariable").addContent(p.getStateLocalVariable()));
058        element.addContent(new Element("stateFormula").addContent(p.getStateFormula()));
059
060        return element;
061    }
062
063    @Override
064    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {     // Test class that inherits this class throws exception
065        String sys = getSystemName(shared);
066        String uname = getUserName(shared);
067        ActionPositionableByClass h = new ActionPositionableByClass(sys, uname);
068
069        loadCommon(h, shared);
070
071        Element elem = shared.getChild("editorName");
072        if (elem != null) {
073            h.setEditor(elem.getTextTrim());
074        }
075
076        elem = shared.getChild("className");
077        if (elem != null) {
078            h.setClassName(elem.getTextTrim());
079        }
080
081        try {
082            elem = shared.getChild("addressing");
083            if (elem != null) {
084                h.setAddressing(NamedBeanAddressing.valueOf(elem.getTextTrim()));
085            }
086
087            elem = shared.getChild("reference");
088            if (elem != null) h.setReference(elem.getTextTrim());
089
090            elem = shared.getChild("localVariable");
091            if (elem != null) h.setLocalVariable(elem.getTextTrim());
092
093            elem = shared.getChild("formula");
094            if (elem != null) h.setFormula(elem.getTextTrim());
095
096
097            elem = shared.getChild("stateAddressing");
098            if (elem != null) {
099                h.setStateAddressing(NamedBeanAddressing.valueOf(elem.getTextTrim()));
100            }
101
102            Element isControlling = shared.getChild("operation");
103            if (isControlling != null) {
104                h.setOperation(ActionPositionableByClass.Operation.valueOf(isControlling.getTextTrim()));
105            }
106
107            elem = shared.getChild("stateReference");
108            if (elem != null) h.setStateReference(elem.getTextTrim());
109
110            elem = shared.getChild("stateLocalVariable");
111            if (elem != null) h.setStateLocalVariable(elem.getTextTrim());
112
113            elem = shared.getChild("stateFormula");
114            if (elem != null) h.setStateFormula(elem.getTextTrim());
115
116        } catch (ParserException e) {
117            throw new JmriConfigureXmlException(e);
118        }
119
120        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
121        return true;
122    }
123
124//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionPositionableByClassXml.class);
125}