Search in sources :

Example 1 with CommonTurnoutOperation

use of jmri.CommonTurnoutOperation in project JMRI by JMRI.

the class CommonTurnoutOperationXml method loadOne.

/**
     * called for a newly-constructed object to load it from an XML element
     *
     * @param e the XML element of type "turnoutOperation"
     * @param constr constructor of subclass of TurnoutOperation to create
     * @param di default interval
     * @param dmt default max tries
     * @return a TurnoutOperation or null if unable to load from e
     */
public TurnoutOperation loadOne(Element e, Constructor<?> constr, int di, int dmt) {
    int interval = di;
    int maxTries = dmt;
    //  boolean noDelete = false;
    TurnoutOperation result = null;
    if (e.getAttribute("name") == null) {
        log.warn("unexpected null in name " + e + " " + e.getAttributes());
        return null;
    }
    String name = e.getAttribute("name").getValue();
    if (e.getAttribute("interval") != null) {
        try {
            interval = Integer.parseInt(e.getAttribute("interval").getValue());
        } catch (NumberFormatException ex) {
        }
    }
    if (e.getAttribute("maxtries") != null) {
        try {
            maxTries = Integer.parseInt(e.getAttribute("maxtries").getValue());
        } catch (NumberFormatException ex) {
        }
    }
    // constructor takes care of enrolling the new operation
    try {
        result = (TurnoutOperation) constr.newInstance(new Object[] { name, interval, maxTries });
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException e1) {
        log.error("while creating CommonTurnoutOperation", e1);
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("create turnout operation: (" + name + ")");
    }
    return result;
}
Also used : TurnoutOperation(jmri.TurnoutOperation) CommonTurnoutOperation(jmri.CommonTurnoutOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with CommonTurnoutOperation

use of jmri.CommonTurnoutOperation in project JMRI by JMRI.

the class CommonTurnoutOperationXml method store.

@Override
public Element store(Object op) {
    CommonTurnoutOperation myOp = (CommonTurnoutOperation) op;
    Element elem = super.store(op);
    elem.setAttribute("interval", String.valueOf(myOp.getInterval()));
    elem.setAttribute("maxtries", String.valueOf(myOp.getMaxTries()));
    return elem;
}
Also used : Element(org.jdom2.Element) CommonTurnoutOperation(jmri.CommonTurnoutOperation)

Aggregations

CommonTurnoutOperation (jmri.CommonTurnoutOperation)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 TurnoutOperation (jmri.TurnoutOperation)1 Element (org.jdom2.Element)1