/** * Store the contents of a WarrantManager. * * @param o Object to store, of type warrantManager * @return Element containing the complete info */ public Element store(Object o) { Element warrants = new Element("warrants"); warrants.setAttribute("class", "jmri.jmrit.logix.configurexml.WarrantManagerXml"); if (!GraphicsEnvironment.isHeadless()) { storeNXParams(warrants); } 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= " + sname + ", userName= "******"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()); } 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.getBlockOrders(); 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; }
public NamedBean addBean(String sysName, String userName) { return manager.createNewWarrant(sysName, userName, false, 0); }
public NamedBean addBean(String name) { return manager.provideWarrant(name); }
@Override public boolean load(Element shared, Element perNode) { WarrantManager manager = InstanceManager.getDefault(WarrantManager.class); // don't continue on to build NXFrame if no content if (shared.getChildren().size() == 0) return true; if (!GraphicsEnvironment.isHeadless()) { NXFrame nxFrame = NXFrame.getInstance(); loadNXParams(nxFrame, shared.getChild("nxparams")); // nxFrame.init(); don't make visible } List<Element> warrantList = shared.getChildren("warrant"); if (log.isDebugEnabled()) log.debug("Found " + warrantList.size() + " Warrant objects"); for (int i = 0; i < warrantList.size(); i++) { Element elem = warrantList.get(i); if (elem.getAttribute("systemName") == null) { log.warn("unexpected null in systemName " + elem + " " + elem.getAttributes()); 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 " + wType.getValue() + " for " + 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 \"" + sysName + "(" + userName + ")\" previously loaded. This version not loaded."); continue; } 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)); } List<Element> throttleCmds = elem.getChildren("throttleCommand"); for (int k = 0; k < throttleCmds.size(); k++) { warrant.addThrottleCommand(loadThrottleCommand(throttleCmds.get(k))); } Element train = elem.getChild("train"); if (train != null) { loadTrain(train, warrant); } } return true; }