use of org.jdom2.DataConversionException 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.DataConversionException in project JMRI by JMRI.
the class OBlockManagerXml method loadPath.
OPath loadPath(Element elem, OBlock block) {
String pName = elem.getAttribute("pathName").getValue();
OPath path = getPath(block, pName);
try {
Attribute attr = elem.getAttribute("fromDirection");
if (attr != null) {
path.setFromBlockDirection(attr.getIntValue());
}
attr = elem.getAttribute("toDirection");
if (attr != null) {
path.setToBlockDirection(attr.getIntValue());
}
attr = elem.getAttribute("length");
if (attr != null) {
path.setLength(attr.getFloatValue());
}
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse attribute of path (" + pName + ") block (" + block.getSystemName() + ")");
}
Attribute attr = elem.getAttribute("fromPortal");
if (attr != null) {
Portal portal = getPortal(attr.getValue());
if (portal != null) {
path.setFromPortal(portal);
portal.addPath(path);
}
}
attr = elem.getAttribute("toPortal");
if (attr != null) {
Portal portal = getPortal(attr.getValue());
if (portal != null) {
path.setToPortal(portal);
portal.addPath(path);
}
}
List<Element> settings = elem.getChildren("setting");
if (log.isDebugEnabled()) {
log.debug("Path (" + pName + ") has " + settings.size() + " settings.");
}
java.util.HashSet<String> turnouts = new java.util.HashSet<String>();
int dups = 0;
for (int i = 0; i < settings.size(); i++) {
Element setElem = settings.get(i);
int setting = 0;
try {
setting = setElem.getAttribute("set").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse 'set' attribute for path (" + pName + ") block (" + block.getSystemName() + ")");
}
String sysName = setElem.getAttribute("turnout").getValue();
if (!turnouts.contains(sysName)) {
Turnout to = InstanceManager.turnoutManagerInstance().provideTurnout(sysName);
turnouts.add(sysName);
BeanSetting bs = new BeanSetting(to, sysName, setting);
path.addSetting(bs);
} else {
dups++;
}
}
if (dups > 0) {
log.warn(dups + " duplicate settings not loaded for path \"" + pName + "\"");
}
return path;
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class OBlockManagerXml method loadPortal.
Portal loadPortal(Element elem) {
String sysName = null;
String userName = elem.getAttribute("portalName").getValue();
if (elem.getAttribute("systemName") == null) {
if (log.isDebugEnabled()) {
log.debug("Portal systemName is null");
}
} else {
sysName = elem.getAttribute("systemName").getValue();
}
String fromBlockName = null;
String toBlockName = null;
// Portals must have user names.
Portal portal = _portalMgr.getByUserName(userName);
if (portal != null) {
fromBlockName = portal.getFromBlock().getSystemName();
toBlockName = portal.getToBlock().getSystemName();
} else {
portal = _portalMgr.providePortal(userName);
}
if (portal == null) {
log.error("unable to create Portal (" + sysName + ", " + userName + ") " + elem + " " + elem.getAttributes());
return null;
}
if (log.isDebugEnabled()) {
log.debug("create Portal: (" + sysName + ", " + userName + ")");
}
OBlock fromBlock = null;
Element eFromBlk = elem.getChild("fromBlock");
if (eFromBlk != null && eFromBlk.getAttribute("blockName") != null) {
String name = eFromBlk.getAttribute("blockName").getValue();
if (fromBlockName != null && !fromBlockName.equals(name)) {
log.error("Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
} else {
fromBlock = getBlock(name);
if (fromBlock != null) {
portal.setFromBlock(fromBlock, false);
fromBlock.addPortal(portal);
List<Element> ePathsFromBlock = eFromBlk.getChildren("path");
for (int i = 0; i < ePathsFromBlock.size(); i++) {
Element e = ePathsFromBlock.get(i);
String pathName = e.getAttribute("pathName").getValue();
String blockName = e.getAttribute("blockName").getValue();
if (log.isDebugEnabled()) {
log.debug("Load portal= " + userName + " fromBlock= " + fromBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName);
}
/*(if (fromBlock.getSystemName().equals(blockName))*/
{
// path is in the fromBlock
OPath path = getPath(fromBlock, pathName);
portal.addPath(path);
}
}
}
}
} else {
log.error("Portal \"" + userName + "\" has no fromBlock!");
}
OBlock toBlock = null;
Element eToBlk = elem.getChild("toBlock");
if (eToBlk != null && eToBlk.getAttribute("blockName") != null) {
String name = eToBlk.getAttribute("blockName").getValue();
if (toBlockName != null && !toBlockName.equals(name)) {
log.error("Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
} else {
toBlock = getBlock(name);
if (toBlock != null) {
portal.setToBlock(toBlock, false);
toBlock.addPortal(portal);
List<Element> ePathsToBlock = eToBlk.getChildren("path");
for (int i = 0; i < ePathsToBlock.size(); i++) {
Element e = ePathsToBlock.get(i);
String pathName = e.getAttribute("pathName").getValue();
String blockName = e.getAttribute("blockName").getValue();
if (log.isDebugEnabled()) {
log.debug("Load portal= " + userName + " toBlock= " + toBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName);
}
/*if (toBlock.getSystemName().equals(blockName))*/
{
// path is in the toBlock
OPath path = getPath(toBlock, pathName);
portal.addPath(path);
}
}
}
}
} else {
log.error("Portal \"" + userName + "\" has no toBlock!");
}
Element eSignal = elem.getChild("fromSignal");
if (eSignal != null) {
String name = eSignal.getAttribute("signalName").getValue();
float length = 0.0f;
try {
Attribute attr = eSignal.getAttribute("signalDelay");
if (attr != null) {
length = attr.getFloatValue();
}
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
}
portal.setProtectSignal(Portal.getSignal(name), length, toBlock);
}
eSignal = elem.getChild("toSignal");
if (eSignal != null) {
String name = eSignal.getAttribute("signalName").getValue();
float length = 0.0f;
try {
Attribute attr = eSignal.getAttribute("signalDelay");
if (attr != null) {
length = attr.getFloatValue();
}
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
}
portal.setProtectSignal(Portal.getSignal(name), length, fromBlock);
}
if (log.isDebugEnabled()) {
log.debug("End Load portal " + userName);
}
return portal;
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class DefaultSignalGroupManagerXml method load.
@Override
public boolean load(Element shared, Element perNode) {
// loop over contained signalgroup elements
List<Element> list = shared.getChildren("signalgroup");
SignalGroupManager sgm = InstanceManager.getDefault(jmri.SignalGroupManager.class);
for (int i = 0; i < list.size(); i++) {
SignalGroup m;
Element e = list.get(i);
String primary;
String yesno;
boolean inverse = false;
int state = 0x00;
String sys = getSystemName(e);
m = sgm.newSignalGroup(sys);
if (getUserName(e) != null) {
m.setUserName(getUserName(e));
}
//loadCommon(m, e); // would store comment, now a separate element
loadComment(m, e);
primary = e.getAttribute("signalMast").getValue();
m.setSignalMast(primary);
// deprecated 4.7.2 for aspect
List<Element> appList = e.getChildren("appearance");
for (int y = 0; y < appList.size(); y++) {
String value = appList.get(y).getAttribute("valid").getValue();
m.addSignalMastAspect(value);
}
List<Element> aspList = e.getChildren("aspect");
for (int y = 0; y < aspList.size(); y++) {
String value = aspList.get(y).getAttribute("valid").getValue();
m.addSignalMastAspect(value);
}
List<Element> signalHeadList = list.get(i).getChildren("signalHead");
if (signalHeadList.size() > 0) {
for (int y = 0; y < signalHeadList.size(); y++) {
String head = signalHeadList.get(y).getAttribute("name").getValue();
SignalHead sigHead = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(head);
m.addSignalHead(sigHead);
yesno = signalHeadList.get(y).getAttribute("sensorTurnoutLogic").getValue();
inverse = false;
if ((yesno != null) && (!yesno.equals(""))) {
if (yesno.equals("AND")) {
inverse = true;
} else if (yesno.equals("OR")) {
inverse = false;
}
}
m.setSensorTurnoutOper(sigHead, inverse);
try {
m.setHeadOnState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("onAppearance").getValue()));
} catch (NullPointerException ex) {
// considered normal if the attributes are not present
}
try {
m.setHeadOffState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("offAppearance").getValue()));
} catch (NullPointerException ex) {
// considered normal if the attributes are not present
}
List<Element> signalTurnoutList = signalHeadList.get(y).getChildren("turnout");
if (signalTurnoutList.size() > 0) {
for (int k = 0; k < signalTurnoutList.size(); k++) {
String tName = signalTurnoutList.get(k).getAttribute("name").getValue();
jmri.Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(tName);
state = 0;
try {
state = signalTurnoutList.get(k).getAttribute("state").getIntValue();
} catch (org.jdom2.DataConversionException ex) {
log.warn("invalid state attribute value");
}
m.setHeadAlignTurnout(sigHead, turnout, state);
}
}
List<Element> signalSensorList = signalHeadList.get(y).getChildren("sensor");
if (signalSensorList.size() > 0) {
for (int k = 0; k < signalSensorList.size(); k++) {
String sName = signalSensorList.get(k).getAttribute("name").getValue();
jmri.Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(sName);
state = 0;
try {
state = signalSensorList.get(k).getAttribute("state").getIntValue();
} catch (org.jdom2.DataConversionException ex) {
log.warn("invalid style attribute value");
}
m.setHeadAlignSensor(sigHead, sensor, state);
}
}
}
}
}
return true;
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class DefaultUserMessagePreferencesXml method load.
@Override
public boolean load(Element shared, Element perNode) {
// ensure the master object exists
jmri.UserPreferencesManager p = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
p.setLoading();
List<Element> settingList = shared.getChildren("setting");
for (int i = 0; i < settingList.size(); i++) {
String name = settingList.get(i).getText();
p.setSimplePreferenceState(name, true);
}
List<Element> comboList = shared.getChildren("comboBoxLastValue");
for (int i = 0; i < comboList.size(); i++) {
List<Element> comboItem = comboList.get(i).getChildren("comboBox");
for (int x = 0; x < comboItem.size(); x++) {
String combo = comboItem.get(x).getAttribute("name").getValue();
String setting = comboItem.get(x).getAttribute("lastSelected").getValue();
p.addComboBoxLastSelection(combo, setting);
}
}
List<Element> classList = shared.getChildren("classPreferences");
for (int k = 0; k < classList.size(); k++) {
List<Element> multipleList = classList.get(k).getChildren("multipleChoice");
String strClass = classList.get(k).getAttribute("class").getValue();
for (int i = 0; i < multipleList.size(); i++) {
List<Element> multiItem = multipleList.get(i).getChildren("option");
for (int x = 0; x < multiItem.size(); x++) {
String item = multiItem.get(x).getAttribute("item").getValue();
int value = 0x00;
try {
value = multiItem.get(x).getAttribute("value").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert positional attribute");
}
p.setMultipleChoiceOption(strClass, item, value);
}
}
List<Element> preferenceList = classList.get(k).getChildren("reminderPrompts");
for (int i = 0; i < preferenceList.size(); i++) {
List<Element> reminderBoxes = preferenceList.get(i).getChildren("reminder");
for (int j = 0; j < reminderBoxes.size(); j++) {
String name = reminderBoxes.get(j).getText();
p.setPreferenceState(strClass, name, true);
}
}
}
List<Element> windowList = shared.getChildren("windowDetails");
for (int k = 0; k < windowList.size(); k++) {
String strClass = windowList.get(k).getAttribute("class").getValue();
List<Element> locListX = windowList.get(k).getChildren("locX");
double x = 0.0;
for (int i = 0; i < locListX.size(); i++) {
try {
x = Double.parseDouble(locListX.get(i).getText());
} catch (NumberFormatException e) {
log.error("failed to convert positional attribute");
}
}
List<Element> locListY = windowList.get(k).getChildren("locY");
double y = 0.0;
for (int i = 0; i < locListY.size(); i++) {
try {
y = Double.parseDouble(locListY.get(i).getText());
} catch (NumberFormatException e) {
log.error("failed to convert positional attribute");
}
}
p.setWindowLocation(strClass, new java.awt.Point((int) x, (int) y));
List<Element> sizeWidth = windowList.get(k).getChildren("width");
double width = 0.0;
for (int i = 0; i < sizeWidth.size(); i++) {
try {
width = Double.parseDouble(sizeWidth.get(i).getText());
} catch (NumberFormatException e) {
log.error("failed to convert positional attribute");
}
}
List<Element> heightList = windowList.get(k).getChildren("height");
double height = 0.0;
for (int i = 0; i < heightList.size(); i++) {
try {
height = Double.parseDouble(heightList.get(i).getText());
} catch (NumberFormatException e) {
log.error("failed to convert positional attribute");
}
}
p.setWindowSize(strClass, new java.awt.Dimension((int) width, (int) height));
Element prop = windowList.get(k).getChild("properties");
if (prop != null) {
for (Object next : prop.getChildren("property")) {
Element e = (Element) next;
try {
Class<?> cl;
Constructor<?> ctor;
// create key object
String key = e.getChild("key").getText();
// create value object
Object value = null;
if (e.getChild("value") != null) {
cl = Class.forName(e.getChild("value").getAttributeValue("class"));
ctor = cl.getConstructor(new Class<?>[] { String.class });
value = ctor.newInstance(new Object[] { e.getChild("value").getText() });
}
// store
p.setProperty(strClass, key, value);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
log.error("Error loading properties", ex);
}
}
}
}
List<Element> tablesList = shared.getChildren("tableDetails");
for (Element tables : tablesList) {
List<Element> tableList = tables.getChildren("table");
for (Element table : tableList) {
List<Element> columnList = table.getChildren("column");
String strTableName = table.getAttribute("name").getValue();
for (Element column : columnList) {
String strColumnName = column.getAttribute("name").getValue();
int order = -1;
int width = -1;
SortOrder sort = SortOrder.UNSORTED;
boolean hidden = false;
if (column.getChild("order") != null) {
order = Integer.parseInt(column.getChild("order").getText());
}
if (column.getChild("width") != null) {
width = Integer.parseInt(column.getChild("width").getText());
}
if (column.getChild("sortOrder") != null) {
sort = SortOrder.valueOf(column.getChild("sortOrder").getText());
// before 4.3.5 we used "sort" save column sort state
} else if (column.getChild("sort") != null) {
switch(Integer.parseInt(column.getChild("sort").getText())) {
case TableSorter.ASCENDING:
sort = SortOrder.ASCENDING;
break;
case TableSorter.DESCENDING:
sort = SortOrder.DESCENDING;
break;
default:
break;
}
}
if (column.getChild("hidden") != null && column.getChild("hidden").getText().equals("yes")) {
hidden = true;
}
p.setTableColumnPreferences(strTableName, strColumnName, order, width, sort, hidden);
}
}
}
p.finishLoading();
return true;
}
Aggregations