001package jmri.jmrix.grapevine.configurexml;
002
003import jmri.InstanceManager;
004import jmri.SignalHead;
005import jmri.jmrix.grapevine.SerialSignalHead;
006import jmri.jmrix.grapevine.GrapevineSystemConnectionMemo;
007import jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML;
008import org.jdom2.Attribute;
009import org.jdom2.Element;
010
011/**
012 * Handle XML configuration for Grapevine SerialSignalHead objects.
013 *
014 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2007, 2008
015 */
016public class SerialSignalHeadXml extends AbstractNamedBeanManagerConfigXML {
017
018    private GrapevineSystemConnectionMemo memo = null;
019
020    public SerialSignalHeadXml() {
021       memo = InstanceManager.getDefault(GrapevineSystemConnectionMemo.class);
022    }
023
024    /**
025     * Default implementation for storing the contents of a Grapevine
026     * SerialSignalHead
027     *
028     * @param o Object to store, of type SerialSignalHead
029     * @return Element containing the complete info
030     */
031    @Override
032    public Element store(Object o) {
033        SerialSignalHead p = (SerialSignalHead) o;
034
035        Element element = new Element("signalhead");
036        element.setAttribute("class", this.getClass().getName());
037
038        // include contents
039        element.setAttribute("systemName", p.getSystemName());
040
041        storeCommon(p, element);
042
043        return element;
044    }
045
046    @Override
047    public boolean load(Element shared, Element perNode) {
048        String sys = shared.getAttribute("systemName").getValue();
049        Attribute a = shared.getAttribute("userName");
050        SignalHead h;
051        if (a == null) {
052            h = new SerialSignalHead(sys, memo);
053        } else {
054            h = new SerialSignalHead(sys, a.getValue(), memo);
055        }
056
057        loadCommon(h, shared);
058
059        InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
060        return true;
061    }
062
063//    private final static Logger log = LoggerFactory.getLogger(SerialSignalHeadXml.class);
064}