001package jmri.jmrit.logixng.expressions.configurexml;
002
003import jmri.*;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.*;
006import jmri.jmrit.logixng.expressions.ExpressionPower;
007import jmri.jmrit.logixng.util.parser.ParserException;
008
009import org.jdom2.Element;
010
011/**
012 * Handle XML configuration for ExpressionPower objects.
013 *
014 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
015 * @author Daniel Bergqvist Copyright (C) 2021
016 */
017public class ExpressionPowerXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
018
019    public ExpressionPowerXml() {
020    }
021    
022    /**
023     * Default implementation for storing the contents of a ExpressionPower
024     *
025     * @param o Object to store, of type ExpressionPower
026     * @return Element containing the complete info
027     */
028    @Override
029    public Element store(Object o) {
030        ExpressionPower p = (ExpressionPower) o;
031
032        Element element = new Element("ExpressionPower");
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("is_isNot").addContent(p.get_Is_IsNot().name()));
039        
040        element.addContent(new Element("powerState").addContent(p.getBeanState().name()));
041
042        return element;
043    }
044    
045    @Override
046    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {
047        String sys = getSystemName(shared);
048        String uname = getUserName(shared);
049        ExpressionPower h = new ExpressionPower(sys, uname);
050        
051        loadCommon(h, shared);
052        
053        Element is_IsNot = shared.getChild("is_isNot");
054        if (is_IsNot != null) {
055            h.set_Is_IsNot(Is_IsNot_Enum.valueOf(is_IsNot.getTextTrim()));
056        }
057        
058        Element powerState = shared.getChild("powerState");
059        if (powerState != null) {
060            h.setBeanState(ExpressionPower.PowerState.valueOf(powerState.getTextTrim()));
061        }
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(ExpressionPowerXml.class);
068}