Search in sources :

Example 1 with MergSD2SignalHead

use of jmri.implementation.MergSD2SignalHead in project JMRI by JMRI.

the class MergSD2SignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    int aspects = 2;
    List<Element> l = shared.getChildren("turnoutname");
    if (l.size() == 0) {
        l = shared.getChildren("turnout");
        aspects = l.size() + 1;
    }
    NamedBeanHandle<Turnout> input1 = null;
    NamedBeanHandle<Turnout> input2 = null;
    NamedBeanHandle<Turnout> input3 = null;
    String yesno = "";
    boolean feather = false;
    boolean home = true;
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    if (shared.getAttribute("feather") != null) {
        yesno = shared.getAttribute("feather").getValue();
    }
    if ((yesno != null) && (!yesno.equals(""))) {
        if (yesno.equals("yes")) {
            feather = true;
        } else if (yesno.equals("no")) {
            feather = false;
        }
    }
    if (shared.getAttribute("home") != null) {
        yesno = shared.getAttribute("home").getValue();
    }
    if ((yesno != null) && (!yesno.equals(""))) {
        if (yesno.equals("yes")) {
            home = true;
        } else if (yesno.equals("no")) {
            home = false;
        }
    }
    try {
        aspects = shared.getAttribute("aspects").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse level attribute!");
    } catch (NullPointerException e) {
    // considered normal if the attribute not present
    }
    SignalHead h;
    //@TODO could re-arange this so that it falls through
    switch(aspects) {
        case 2:
            input1 = loadTurnout(l.get(0));
            break;
        case 3:
            input1 = loadTurnout(l.get(0));
            input2 = loadTurnout(l.get(1));
            break;
        case 4:
            input1 = loadTurnout(l.get(0));
            input2 = loadTurnout(l.get(1));
            input3 = loadTurnout(l.get(2));
            break;
        default:
            log.error("incorrect number of aspects " + aspects + " when loading Signal " + sys);
    }
    if (uname == null) {
        h = new MergSD2SignalHead(sys, aspects, input1, input2, input3, feather, home);
    } else {
        h = new MergSD2SignalHead(sys, uname, aspects, input1, input2, input3, feather, home);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : Element(org.jdom2.Element) MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) SignalHead(jmri.SignalHead) MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) Turnout(jmri.Turnout)

Example 2 with MergSD2SignalHead

use of jmri.implementation.MergSD2SignalHead in project JMRI by JMRI.

the class MergSD2SignalHeadXml method store.

/**
     * Default implementation for storing the contents of a MergSD2SignalHead
     *
     * @param o Object to store, of type MergSD2SignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    MergSD2SignalHead p = (MergSD2SignalHead) o;
    Element element = new Element("signalhead");
    element.setAttribute("class", this.getClass().getName());
    element.addContent(new Element("systemName").addContent(p.getSystemName()));
    element.setAttribute("aspects", p.getAspects() + "");
    if (p.getFeather()) {
        element.setAttribute("feather", "yes");
    }
    storeCommon(p, element);
    int aspects = p.getAspects();
    //@TODO could re-arange this so that it falls through
    switch(aspects) {
        case 2:
            element.addContent(addTurnoutElement(p.getInput1(), "input1"));
            if (!p.getHome()) {
                element.setAttribute("home", "no");
            }
            break;
        case 3:
            element.addContent(addTurnoutElement(p.getInput1(), "input1"));
            element.addContent(addTurnoutElement(p.getInput2(), "input2"));
            break;
        case 4:
            element.addContent(addTurnoutElement(p.getInput1(), "input1"));
            element.addContent(addTurnoutElement(p.getInput2(), "input2"));
            element.addContent(addTurnoutElement(p.getInput3(), "input3"));
            break;
        default:
            log.error("incorrect number of aspects " + aspects + " for Signal " + p.getDisplayName());
    }
    return element;
}
Also used : MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) Element(org.jdom2.Element)

Aggregations

MergSD2SignalHead (jmri.implementation.MergSD2SignalHead)2 Element (org.jdom2.Element)2 SignalHead (jmri.SignalHead)1 Turnout (jmri.Turnout)1