001package jmri.jmrix.loconet.logixng.configurexml;
002
003import java.util.*;
004
005import jmri.*;
006import jmri.configurexml.JmriConfigureXmlException;
007import jmri.jmrit.logixng.DigitalActionManager;
008import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
009import jmri.jmrix.loconet.logixng.ActionClearSlots;
010
011import org.jdom2.Element;
012
013/**
014 * Handle XML configuration for ExpressionSlotUsage objects.
015 *
016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
017 * @author Daniel Bergqvist Copyright (C) 2020
018 */
019public class ActionClearSlotsXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
020
021    public ActionClearSlotsXml() {
022    }
023    
024    /**
025     * Default implementation for storing the contents of a ExpressionSlotUsage
026     *
027     * @param o Object to store, of type TripleTurnoutSignalHead
028     * @return Element containing the complete info
029     */
030    @Override
031    public Element store(Object o) {
032        ActionClearSlots p = (ActionClearSlots) o;
033
034        Element element = new Element("ActionLoconetClearSlots");
035        element.setAttribute("class", this.getClass().getName());
036        element.addContent(new Element("systemName").addContent(p.getSystemName()));
037        
038        storeCommon(p, element);
039
040        if (p.getMemo() != null) {
041            element.addContent(new Element("systemConnection")
042                    .addContent(p.getMemo().getSystemPrefix()));
043        }
044        
045        return element;
046    }
047    
048    @Override
049    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {     // Test class that inherits this class throws exception
050        String sys = getSystemName(shared);
051        String uname = getUserName(shared);
052        ActionClearSlots h = new ActionClearSlots(sys, uname, null);
053
054        loadCommon(h, shared);
055
056        Element systemConnection = shared.getChild("systemConnection");
057        if (systemConnection != null) {
058            String systemConnectionName = systemConnection.getTextTrim();
059            List<LocoNetSystemConnectionMemo> systemConnections =
060                    jmri.InstanceManager.getList(LocoNetSystemConnectionMemo.class);
061            
062            for (LocoNetSystemConnectionMemo memo : systemConnections) {
063                if (memo.getSystemPrefix().equals(systemConnectionName)) {
064                    h.setMemo(memo);
065                    break;
066                }
067            }
068        }
069
070        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
071        return true;
072    }
073    
074//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionClearSlotsXml.class);
075}