001package jmri.jmrix.bidib.configurexml;
002
003import jmri.InstanceManager;
004import jmri.jmrix.bidib.BiDiBSystemConnectionMemo;
005import org.jdom2.Element;
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009import jmri.jmrix.bidib.BiDiBTurnoutManager;
010
011/**
012 * Provides load and store functionality for configuring BiDiBTurnoutManagers.
013 * <p>
014 * Uses the store method from the abstract base class, but provides a load
015 * method here.
016 *
017 * @author Bob Jacobsen Copyright (c) 2002
018 * @author Eckart Meyer Copyright (C) 2019
019 */
020public class BiDiBTurnoutManagerXml extends jmri.managers.configurexml.AbstractTurnoutManagerConfigXML {
021
022    public BiDiBTurnoutManagerXml() {
023        super();
024    }
025
026    @Override
027    public void setStoreElementClass(Element turnouts) {
028        turnouts.setAttribute("class", this.getClass().getName());
029    }
030
031    @Override
032    public void load(Element element, Object o) {
033        log.error("Invalid method called");
034    }
035
036    @Override
037    public boolean load(Element shared, Element perNode) {
038        log.debug("load {} {}", shared, perNode);
039        // We tell the Turnout managers that we will be loading turnouts from XML and they should
040        // expect additional property set sequences. This is somewhat tricky in the face of
041        // possibly multiple connections registered.
042        for (BiDiBSystemConnectionMemo memo : InstanceManager.getList(BiDiBSystemConnectionMemo.class)) {
043            if (!memo.getDisabled()) {
044                ((BiDiBTurnoutManager)memo.getTurnoutManager()).startLoad();
045            }
046        }
047        // load individual turnouts
048        boolean result = loadTurnouts(shared, perNode);
049        
050        // Notifies turnout managers that the loading of XML is complete.
051        for (BiDiBSystemConnectionMemo memo : InstanceManager.getList(BiDiBSystemConnectionMemo.class)) {
052            if (!memo.getDisabled()) {
053                ((BiDiBTurnoutManager)memo.getTurnoutManager()).finishLoad();
054            }
055        }
056
057        return result;
058    }
059
060    private final static Logger log = LoggerFactory.getLogger(BiDiBTurnoutManagerXml.class);
061
062}