use of jmri.jmrit.logix.SCWarrant in project JMRI by JMRI.
the class WarrantManagerXml method load.
@Override
public boolean load(Element shared, Element perNode) {
WarrantManager manager = InstanceManager.getDefault(WarrantManager.class);
if (shared.getChildren().isEmpty()) {
return true;
}
List<Element> warrantList = shared.getChildren("warrant");
if (log.isDebugEnabled())
log.debug("Found {} Warrant objects", warrantList.size());
for (int i = 0; i < warrantList.size(); i++) {
Element elem = warrantList.get(i);
if (elem.getAttribute("systemName") == null) {
log.warn("unexpected null for systemName in elem {}", elem);
break;
}
String sysName = null;
if (elem.getAttribute("systemName") != null)
sysName = elem.getAttribute("systemName").getValue();
String userName = null;
if (elem.getAttribute("userName") != null)
userName = elem.getAttribute("userName").getValue();
boolean SCWa = true;
log.debug("loading warrant {}", sysName);
Attribute wType = elem.getAttribute("wtype");
if (wType == null) {
log.debug("wtype is null for {}", sysName);
SCWa = false;
} else if (!wType.getValue().equals("SC")) {
log.debug("wtype is {} for {}", wType.getValue(), sysName);
SCWa = false;
}
long timeToPlatform = 500;
Attribute TTP = elem.getAttribute("timeToPlatform");
if (TTP != null) {
try {
timeToPlatform = TTP.getLongValue();
} catch (DataConversionException e) {
log.debug("ignoring DataConversionException (and reverting to default value): " + e.toString());
}
}
Warrant warrant = manager.createNewWarrant(sysName, userName, SCWa, timeToPlatform);
if (warrant == null) {
log.info("Warrant \"{}\" (userName={}) previously loaded. This version not loaded.", sysName, userName);
continue;
}
if (SCWa) {
if (elem.getAttribute("forward") != null) {
((SCWarrant) warrant).setForward(elem.getAttribute("forward").getValue().equals("true"));
}
warrant.setNoRamp(SCWa);
warrant.setShareRoute(SCWa);
}
List<Element> orders = elem.getChildren("blockOrder");
for (int k = 0; k < orders.size(); k++) {
BlockOrder bo = loadBlockOrder(orders.get(k));
if (bo == null) {
break;
}
warrant.addBlockOrder(bo);
}
String c = elem.getChildText("comment");
if (c != null) {
warrant.setComment(c);
}
Element order = elem.getChild("viaOrder");
if (order != null) {
warrant.setViaOrder(loadBlockOrder(order));
}
order = elem.getChild("avoidOrder");
if (order != null) {
warrant.setAvoidOrder(loadBlockOrder(order));
}
boolean forward = true;
List<Element> throttleCmds = elem.getChildren("throttleCommand");
if (throttleCmds != null) {
for (int k = 0; k < throttleCmds.size(); k++) {
ThrottleSetting ts = loadThrottleCommand(throttleCmds.get(k));
warrant.addThrottleCommand(ts);
if (ts.getCommand().toUpperCase().equals("FORWARD")) {
forward = ts.getValue().toUpperCase().equals("TRUE");
}
}
}
if (SCWa) {
if (elem.getAttribute("forward") != null) {
forward = elem.getAttribute("forward").getValue().equals("true");
}
((SCWarrant) warrant).setForward(forward);
warrant.setNoRamp(SCWa);
warrant.setShareRoute(SCWa);
}
Element train = elem.getChild("train");
if (train != null) {
loadTrain(train, warrant);
}
}
return true;
}
use of jmri.jmrit.logix.SCWarrant in project JMRI by JMRI.
the class WarrantManagerXml method store.
/**
* Store the contents of a WarrantManager.
*
* @param o Object to store, of type warrantManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element warrants = new Element("warrants");
warrants.setAttribute("class", "jmri.jmrit.logix.configurexml.WarrantManagerXml");
WarrantManager manager = (WarrantManager) o;
Iterator<String> iter = manager.getSystemNameList().iterator();
while (iter.hasNext()) {
String sname = iter.next();
Warrant warrant = manager.getBySystemName(sname);
String uname = warrant.getUserName();
if (log.isDebugEnabled())
log.debug("Warrant: sysName= {}, userName= {}", sname, uname);
Element elem = new Element("warrant");
elem.setAttribute("systemName", sname);
if (uname == null)
uname = "";
if (uname.length() > 0) {
elem.setAttribute("userName", uname);
}
if (warrant instanceof SCWarrant) {
elem.setAttribute("wtype", "SC");
elem.setAttribute("timeToPlatform", "" + ((SCWarrant) warrant).getTimeToPlatform());
elem.setAttribute("forward", ((SCWarrant) warrant).getForward() ? "true" : "false");
} else {
elem.setAttribute("wtype", "normal");
}
String comment = warrant.getComment();
if (comment != null) {
Element c = new Element("comment");
c.addContent(comment);
elem.addContent(c);
}
List<BlockOrder> orders = warrant.getSavedOrders();
for (int j = 0; j < orders.size(); j++) {
elem.addContent(storeOrder(orders.get(j), "blockOrder"));
}
BlockOrder viaOrder = warrant.getViaOrder();
if (viaOrder != null) {
elem.addContent(storeOrder(viaOrder, "viaOrder"));
}
BlockOrder avoidOrder = warrant.getAvoidOrder();
if (avoidOrder != null) {
elem.addContent(storeOrder(avoidOrder, "avoidOrder"));
}
List<ThrottleSetting> throttleCmds = warrant.getThrottleCommands();
for (int j = 0; j < throttleCmds.size(); j++) {
elem.addContent(storeCommand(throttleCmds.get(j), "throttleCommand"));
}
elem.addContent(storeTrain(warrant, "train"));
// and put this element out
warrants.addContent(elem);
}
return warrants;
}
Aggregations