Search in sources :

Example 1 with TurnoutOperationManager

use of jmri.TurnoutOperationManager in project JMRI by JMRI.

the class TurnoutOperationManagerXml method load.

@Override
public boolean load(Element sharedOperations, Element perNodeOperations) {
    boolean result = true;
    TurnoutOperationManager manager = TurnoutOperationManager.getInstance();
    if (sharedOperations.getAttribute("automate") != null) {
        try {
            manager.setDoOperations(sharedOperations.getAttribute("automate").getValue().equals("true"));
        } catch (NumberFormatException ex) {
            result = false;
        }
    }
    List<Element> operationsList = sharedOperations.getChildren("operation");
    if (log.isDebugEnabled()) {
        log.debug("Found " + operationsList.size() + " operations");
    }
    for (int i = 0; i < operationsList.size(); i++) {
        TurnoutOperationXml.loadOperation(operationsList.get(i));
    }
    return result;
}
Also used : Element(org.jdom2.Element) TurnoutOperationManager(jmri.TurnoutOperationManager)

Example 2 with TurnoutOperationManager

use of jmri.TurnoutOperationManager in project JMRI by JMRI.

the class TurnoutOperationManagerXml method store.

@Override
public Element store(Object o) {
    Element elem = new Element("operations");
    if (o instanceof TurnoutOperationManager) {
        TurnoutOperationManager manager = (TurnoutOperationManager) o;
        elem.setAttribute("automate", String.valueOf(manager.getDoOperations()));
        TurnoutOperation[] operations = manager.getTurnoutOperations();
        for (int i = 0; i < operations.length; ++i) {
            TurnoutOperation op = operations[i];
            if (!op.isNonce()) {
                // nonces are stored with their respective turnouts
                TurnoutOperationXml adapter = TurnoutOperationXml.getAdapter(op);
                if (adapter != null) {
                    Element opElem = adapter.store(op);
                    if (opElem != null) {
                        elem.addContent(opElem);
                    }
                }
            }
        }
    }
    return elem;
}
Also used : TurnoutOperation(jmri.TurnoutOperation) Element(org.jdom2.Element) TurnoutOperationXml(jmri.configurexml.turnoutoperations.TurnoutOperationXml) TurnoutOperationManager(jmri.TurnoutOperationManager)

Aggregations

TurnoutOperationManager (jmri.TurnoutOperationManager)2 Element (org.jdom2.Element)2 TurnoutOperation (jmri.TurnoutOperation)1 TurnoutOperationXml (jmri.configurexml.turnoutoperations.TurnoutOperationXml)1