001package jmri.jmrit.logixng.expressions.configurexml;
002
003import jmri.*;
004import jmri.jmrit.logixng.DigitalExpressionManager;
005import jmri.jmrit.logixng.Is_IsNot_Enum;
006import jmri.jmrit.logixng.expressions.ExpressionReference;
007
008import org.jdom2.Element;
009
010/**
011 * Handle XML configuration for ActionLightXml objects.
012 *
013 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
014 * @author Daniel Bergqvist Copyright (C) 2019
015 */
016public class ExpressionReferenceXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
017
018    public ExpressionReferenceXml() {
019    }
020    
021    /**
022     * Default implementation for storing the contents of a SE8cSignalHead
023     *
024     * @param o Object to store, of type TripleLightSignalHead
025     * @return Element containing the complete info
026     */
027    @Override
028    public Element store(Object o) {
029        ExpressionReference p = (ExpressionReference) o;
030
031        Element element = new Element("ExpressionReference");
032        element.setAttribute("class", this.getClass().getName());
033        element.addContent(new Element("systemName").addContent(p.getSystemName()));
034
035        storeCommon(p, element);
036
037        element.addContent(new Element("reference").addContent(p.getReference()));
038        
039        element.addContent(new Element("is_isNot").addContent(p.get_Is_IsNot().name()));
040        element.addContent(new Element("pointsTo").addContent(p.getPointsTo().name()));
041
042        return element;
043    }
044    
045    @Override
046    public boolean load(Element shared, Element perNode) {
047        String sys = getSystemName(shared);
048        String uname = getUserName(shared);
049        ExpressionReference h = new ExpressionReference(sys, uname);
050
051        loadCommon(h, shared);
052
053        Element reference = shared.getChild("reference");
054        if (reference != null) {
055            h.setReference(reference.getTextTrim());
056        }
057
058        Element is_IsNot = shared.getChild("is_isNot");
059        if (is_IsNot != null) {
060            h.set_Is_IsNot(Is_IsNot_Enum.valueOf(is_IsNot.getTextTrim()));
061        }
062
063        Element type = shared.getChild("pointsTo");
064        if (type != null) {
065            h.setPointsTo(ExpressionReference.PointsTo.valueOf(type.getTextTrim()));
066        }
067
068        InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h);
069        return true;
070    }
071    
072//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ExpressionLightXml.class);
073}