use of org.jdom2.Comment in project JMRI by JMRI.
the class VariableTableModel method createIndexedVariableFromElement.
/**
* Create an IndexedVariableValue object of a specific type from a
* describing element.
*
* @return null if no valid element
*/
protected VariableValue createIndexedVariableFromElement(Element e, String name, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String cv, String mask, String item, String productID, String modelID, String familyID) throws NumberFormatException {
VariableValue iv = null;
Element child;
if ((child = e.getChild("indexedVal")) != null) {
iv = processIndexedVal(child, name, comment, cvName, readOnly, infoOnly, writeOnly, opsOnly, cv, mask, item);
} else if ((child = e.getChild("ienumVal")) != null) {
iv = processIEnumVal(child, name, comment, cvName, readOnly, infoOnly, writeOnly, opsOnly, cv, mask, item, productID, modelID, familyID);
} else if ((child = e.getChild("indexedPairVal")) != null) {
iv = processIndexedPairVal(child, readOnly, infoOnly, writeOnly, name, comment, cvName, opsOnly, cv, mask, item);
}
return iv;
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class VariableTableModel method processIndexedVal.
protected VariableValue processIndexedVal(Element child, String name, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String cv, String mask, String item) throws NumberFormatException {
VariableValue iv;
int minVal = 0;
int maxVal = 255;
Attribute a;
if ((a = child.getAttribute("min")) != null) {
minVal = Integer.valueOf(a.getValue()).intValue();
}
if ((a = child.getAttribute("max")) != null) {
maxVal = Integer.valueOf(a.getValue()).intValue();
}
iv = new IndexedVariableValue(name, comment, cvName, readOnly, infoOnly, writeOnly, opsOnly, cv, mask, minVal, maxVal, _indxCvModel.allIndxCvMap(), _status, item);
return iv;
}
use of org.jdom2.Comment 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 org.jdom2.Comment in project JMRI by JMRI.
the class OBlockManagerXml method loadBlock.
void loadBlock(Element elem) {
if (elem.getAttribute("systemName") == null) {
log.error("unexpected null in systemName " + elem + " " + elem.getAttributes());
return;
}
String sysName = elem.getAttribute("systemName").getValue();
String userName = null;
if (elem.getAttribute("userName") != null) {
userName = elem.getAttribute("userName").getValue();
}
if (log.isDebugEnabled()) {
log.debug("Load block sysName= " + sysName + " userName= " + userName);
}
// Portal may have already created a skeleton of this block
OBlock block = getBlock(sysName);
if (block == null) {
log.error("Null block!! sysName= " + sysName + ", userName= " + userName);
return;
}
block.setUserName(userName);
String c = elem.getChildText("comment");
if (c != null) {
block.setComment(c);
}
if (elem.getAttribute("units") != null) {
block.setMetricUnits(elem.getAttribute("units").getValue().equals("true"));
} else {
block.setMetricUnits(false);
}
if (elem.getAttribute("length") != null) {
block.setLength(Float.valueOf(elem.getAttribute("length").getValue()).floatValue());
}
if (elem.getAttribute("curve") != null) {
block.setCurvature(Integer.parseInt((elem.getAttribute("curve")).getValue()));
}
List<Element> sensors = elem.getChildren("sensor");
if (sensors.size() > 1) {
log.error("More than one sensor present: " + sensors.size());
}
if (sensors.size() > 0) {
// sensor
String name = sensors.get(0).getAttribute("systemName").getValue();
block.setSensor(name);
}
Element errSensor = elem.getChild("errorSensor");
if (errSensor != null) {
// sensor
String name = errSensor.getAttribute("systemName").getValue();
block.setErrorSensor(name);
}
Element reporter = elem.getChild("reporter");
if (reporter != null) {
// sensor
String name = reporter.getAttribute("systemName").getValue();
try {
Reporter rep = InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(name);
if (rep != null) {
block.setReporter(rep);
}
} catch (Exception ex) {
log.error("No Reporter named \"" + name + "\" found. threw exception: " + ex);
}
if (reporter.getAttribute("reportCurrent") != null) {
block.setReportingCurrent(reporter.getAttribute("reportCurrent").getValue().equals("true"));
} else {
block.setReportingCurrent(false);
}
}
if (elem.getAttribute("permissive") != null) {
block.setPermissiveWorking(elem.getAttribute("permissive").getValue().equals("true"));
} else {
block.setPermissiveWorking(false);
}
if (elem.getAttribute("speedNotch") != null) {
try {
block.setBlockSpeed(elem.getAttribute("speedNotch").getValue());
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + elem.getAttribute("speedNotch").getValue());
}
}
List<Element> portals = elem.getChildren("portal");
for (int k = 0; k < portals.size(); k++) {
block.addPortal(loadPortal(portals.get(k)));
}
List<Element> paths = elem.getChildren("path");
for (int j = 0; j < paths.size(); j++) {
if (!block.addPath(loadPath(paths.get(j), block))) {
log.error("load: block \"" + sysName + "\" failed to add path \"" + paths.get(j).getName() + "\" in block \"" + block.getSystemName() + "\"");
}
}
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class CarLoads method store.
/**
* Create an XML element to represent this Entry. This member has to remain
* synchronized with the detailed DTD in operations-cars.dtd.
* @param root The common Element for operations-cars.dtd.
*
*/
public void store(Element root) {
Element values = new Element(Xml.LOADS);
// store default load and empty
Element defaults = new Element(Xml.DEFAULTS);
defaults.setAttribute(Xml.EMPTY, getDefaultEmptyName());
defaults.setAttribute(Xml.LOAD, getDefaultLoadName());
values.addContent(defaults);
// store loads based on car types
Enumeration<String> en = listCarLoads.keys();
while (en.hasMoreElements()) {
String carType = en.nextElement();
// check to see if car type still exists
if (!CarTypes.instance().containsName(carType)) {
continue;
}
List<CarLoad> loads = getSortedList(carType);
Element xmlLoad = new Element(Xml.LOAD);
xmlLoad.setAttribute(Xml.TYPE, carType);
// only store loads that aren't the defaults
boolean mustStore = false;
for (CarLoad load : loads) {
// don't store the defaults / low priority / no comment
if ((load.getName().equals(getDefaultEmptyName()) || load.getName().equals(getDefaultLoadName())) && load.getPriority().equals(CarLoad.PRIORITY_LOW) && load.getPickupComment().equals(CarLoad.NONE) && load.getDropComment().equals(CarLoad.NONE))
continue;
Element xmlCarLoad = new Element(Xml.CAR_LOAD);
xmlCarLoad.setAttribute(Xml.NAME, load.getName());
if (!load.getPriority().equals(CarLoad.PRIORITY_LOW)) {
xmlCarLoad.setAttribute(Xml.PRIORITY, load.getPriority());
// must store
mustStore = true;
}
if (!load.getPickupComment().equals(CarLoad.NONE)) {
xmlCarLoad.setAttribute(Xml.PICKUP_COMMENT, load.getPickupComment());
// must store
mustStore = true;
}
if (!load.getDropComment().equals(CarLoad.NONE)) {
xmlCarLoad.setAttribute(Xml.DROP_COMMENT, load.getDropComment());
// must store
mustStore = true;
}
xmlCarLoad.setAttribute(Xml.LOAD_TYPE, load.getLoadType());
xmlLoad.addContent(xmlCarLoad);
}
if (loads.size() > 2 || mustStore) {
values.addContent(xmlLoad);
}
}
root.addContent(values);
}
Aggregations