use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class BlockManagerXml method addPath.
void addPath(Element e, Path p) {
// for now, persist two directions and a bean setting
Element pe = new Element("path");
pe.setAttribute("todir", "" + p.getToBlockDirection());
pe.setAttribute("fromdir", "" + p.getFromBlockDirection());
if (p.getBlock() != null) {
pe.setAttribute("block", "" + p.getBlock().getSystemName());
}
List<BeanSetting> l = p.getSettings();
if (l != null) {
for (int i = 0; i < l.size(); i++) {
addBeanSetting(pe, l.get(i));
}
}
e.addContent(pe);
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class BlockManagerXml method loadBlock.
/**
* Utility method to load the individual Block objects.
*
* @param element Element containing one block
* @throws jmri.configurexml.JmriConfigureXmlException if element contains
* malformed or
* schematically invalid
* XMl
*/
public void loadBlock(Element element) throws JmriConfigureXmlException {
String sysName = getSystemName(element);
String userName = getUserName(element);
if (log.isDebugEnabled()) {
log.debug("defined Block: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
}
Block block = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(sysName);
if (block == null) {
// create it if doesn't exist
InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock(sysName, userName);
block = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(sysName);
}
if (block == null) {
log.error("Unable to load block with system name " + sysName + " and username of " + (userName == null ? "<null>" : userName));
return;
}
if (userName != null) {
block.setUserName(userName);
}
if (element.getAttribute("length") != null) {
// load length in millimeters
block.setLength(Float.parseFloat(element.getAttribute("length").getValue()));
}
if (element.getAttribute("curve") != null) {
// load curve attribute
block.setCurvature(Integer.parseInt((element.getAttribute("curve")).getValue()));
}
try {
block.setBlockSpeed("Global");
if (element.getChild("speed") != null) {
String speed = element.getChild("speed").getText();
if (speed != null && !speed.equals("") && !speed.contains("Global")) {
block.setBlockSpeed(speed);
}
}
} catch (jmri.JmriException ex) {
log.error(ex.toString());
}
if (element.getChild("permissive") != null) {
boolean permissive = false;
if (element.getChild("permissive").getText().equals("yes")) {
permissive = true;
}
block.setPermissiveWorking(permissive);
}
Element deniedBlocks = element.getChild("deniedBlocks");
if (deniedBlocks != null) {
List<Element> denyBlock = deniedBlocks.getChildren("block");
for (Element deny : denyBlock) {
block.addBlockDenyList(deny.getText());
}
}
// load common parts
loadCommon(block, element);
// load sensor if present
List<Element> sensors = element.getChildren("sensor");
if (sensors.size() > 1) {
log.error("More than one sensor present: " + sensors.size());
}
if (sensors.size() == 1) {
//Old method of saving sensors
if (sensors.get(0).getAttribute("systemName") != null) {
String name = sensors.get(0).getAttribute("systemName").getValue();
if (!name.equals("")) {
block.setSensor(name);
}
}
}
if (element.getChild("occupancysensor") != null) {
String name = element.getChild("occupancysensor").getText();
if (!name.equals("")) {
block.setSensor(name);
}
}
// load Reporter if present
List<Element> reporters = element.getChildren("reporter");
if (reporters.size() > 1) {
log.error("More than one reporter present: " + reporters.size());
}
if (reporters.size() == 1) {
// Reporter
String name = reporters.get(0).getAttribute("systemName").getValue();
try {
Reporter reporter = InstanceManager.getDefault(jmri.ReporterManager.class).provideReporter(name);
block.setReporter(reporter);
block.setReportingCurrent(reporters.get(0).getAttribute("useCurrent").getValue().equals("yes"));
} catch (IllegalArgumentException ex) {
log.warn("failed to create Reporter \"{}\" during Block load", name);
}
}
// load paths if present
List<Element> paths = element.getChildren("path");
int startSize = block.getPaths().size();
int loadCount = 0;
for (int i = 0; i < paths.size(); i++) {
Element path = paths.get(i);
if (loadPath(block, path)) {
loadCount++;
}
}
if (startSize > 0 && loadCount > 0) {
log.warn("Added " + loadCount++ + " paths to block " + sysName + " that already had " + startSize + " blocks.");
}
if (startSize + loadCount != block.getPaths().size()) {
log.error("Started with " + startSize + " paths in block " + sysName + ", added " + loadCount + " but final count is " + block.getPaths().size() + "; something not right.");
}
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class ConfigXmlManager method addUserPrefsStore.
protected void addUserPrefsStore(Element root) {
for (int i = 0; i < uplist.size(); i++) {
Object o = uplist.get(i);
Element e = elementFromObject(o);
if (e != null) {
root.addContent(e);
}
}
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class BlockManagerXml method loadBeanSetting.
/**
* Load BeanSetting into an existing Path.
*
* @param path Path to receive BeanSetting
* @param element Element containing beansetting information
*/
public void loadBeanSetting(Path path, Element element) {
int setting = 0;
try {
setting = element.getAttribute("setting").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse beansetting attribute");
}
List<Element> turnouts = element.getChildren("turnout");
if (turnouts.size() != 1) {
log.error("invalid number of turnout element children");
}
String name = turnouts.get(0).getAttribute("systemName").getValue();
try {
Turnout t = InstanceManager.turnoutManagerInstance().provideTurnout(name);
BeanSetting bs = new BeanSetting(t, name, setting);
path.addSetting(bs);
} catch (IllegalArgumentException ex) {
log.warn("failed to create Turnout \"{}\" during Block load", name);
}
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class ConfigXmlManager method addPrefsStore.
protected void addPrefsStore(Element root) {
for (int i = 0; i < plist.size(); i++) {
Object o = plist.get(i);
Element e = elementFromObject(o);
if (e != null) {
root.addContent(e);
}
}
}
Aggregations