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;
}
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;
}
Aggregations