use of org.jdom2.DataConversionException in project pcgen by PCGen.
the class NameGenPanel method loadRuleSet.
private RuleSet loadRuleSet(Element ruleSet) throws DataConversionException {
RuleSet rs = new RuleSet(allVars, ruleSet.getAttributeValue("title"), ruleSet.getAttributeValue("id"), ruleSet.getAttributeValue("usage"));
java.util.List<?> elements = ruleSet.getChildren();
ListIterator<?> elementsIterator = elements.listIterator();
int num = 0;
while (elementsIterator.hasNext()) {
Element child = (Element) elementsIterator.next();
String elementName = child.getName();
if (elementName.equals("CATEGORY")) {
loadCategory(child, rs);
} else if (elementName.equals("RULE")) {
rs.add(loadRule(child, rs.getId() + num));
}
num++;
}
return rs;
}
use of org.jdom2.DataConversionException in project pcgen by PCGen.
the class NameGenPanel method loadRule.
private String loadRule(Element rule, String id) throws DataConversionException {
Rule dataRule = new Rule(allVars, id, id, rule.getAttribute("weight").getIntValue());
java.util.List<?> elements = rule.getChildren();
for (final Object element : elements) {
Element child = (Element) element;
String elementName = child.getName();
if (elementName.equals("GETLIST")) {
String listId = child.getAttributeValue("idref");
dataRule.add(listId);
} else if (elementName.equals("SPACE")) {
SpaceRule sp = new SpaceRule();
allVars.addDataElement(sp);
dataRule.add(sp.getId());
} else if (elementName.equals("HYPHEN")) {
HyphenRule hy = new HyphenRule();
allVars.addDataElement(hy);
dataRule.add(hy.getId());
} else if (elementName.equals("CR")) {
CRRule cr = new CRRule();
allVars.addDataElement(cr);
dataRule.add(cr.getId());
} else if (elementName.equals("GETRULE")) {
String ruleId = child.getAttributeValue("idref");
dataRule.add(ruleId);
}
}
allVars.addDataElement(dataRule);
return dataRule.getId();
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class BlockManagerXml method loadPath.
/**
* Load path into an existing Block from XML.
*
* @param block Block to receive path
* @param element Element containing path information
* @return true if path added to block; false otherwise
* @throws jmri.configurexml.JmriConfigureXmlException if element contains
* malformed or
* schematically invalid
* XMl
*/
public boolean loadPath(Block block, Element element) throws JmriConfigureXmlException {
// load individual path
int toDir = 0;
int fromDir = 0;
try {
toDir = element.getAttribute("todir").getIntValue();
fromDir = element.getAttribute("fromdir").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse path attribute");
} catch (NullPointerException e) {
handleException("Block Path entry in file missing required attribute", null, block.getSystemName(), block.getUserName(), null);
}
Block toBlock = null;
if (element.getAttribute("block") != null) {
String name = element.getAttribute("block").getValue();
toBlock = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
}
Path path = new Path(toBlock, toDir, fromDir);
List<Element> settings = element.getChildren("beansetting");
for (int i = 0; i < settings.size(); i++) {
Element setting = settings.get(i);
loadBeanSetting(path, setting);
}
// check if path already in block
if (!block.hasPath(path)) {
block.addPath(path);
return true;
} else {
log.debug("Skipping load of duplicate path {}", path);
return false;
}
}
use of org.jdom2.DataConversionException 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 org.jdom2.DataConversionException in project JMRI by JMRI.
the class MergSD2SignalHeadXml method load.
@Override
public boolean load(Element shared, Element perNode) {
int aspects = 2;
List<Element> l = shared.getChildren("turnoutname");
if (l.size() == 0) {
l = shared.getChildren("turnout");
aspects = l.size() + 1;
}
NamedBeanHandle<Turnout> input1 = null;
NamedBeanHandle<Turnout> input2 = null;
NamedBeanHandle<Turnout> input3 = null;
String yesno = "";
boolean feather = false;
boolean home = true;
// put it together
String sys = getSystemName(shared);
String uname = getUserName(shared);
if (shared.getAttribute("feather") != null) {
yesno = shared.getAttribute("feather").getValue();
}
if ((yesno != null) && (!yesno.equals(""))) {
if (yesno.equals("yes")) {
feather = true;
} else if (yesno.equals("no")) {
feather = false;
}
}
if (shared.getAttribute("home") != null) {
yesno = shared.getAttribute("home").getValue();
}
if ((yesno != null) && (!yesno.equals(""))) {
if (yesno.equals("yes")) {
home = true;
} else if (yesno.equals("no")) {
home = false;
}
}
try {
aspects = shared.getAttribute("aspects").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse level attribute!");
} catch (NullPointerException e) {
// considered normal if the attribute not present
}
SignalHead h;
//@TODO could re-arange this so that it falls through
switch(aspects) {
case 2:
input1 = loadTurnout(l.get(0));
break;
case 3:
input1 = loadTurnout(l.get(0));
input2 = loadTurnout(l.get(1));
break;
case 4:
input1 = loadTurnout(l.get(0));
input2 = loadTurnout(l.get(1));
input3 = loadTurnout(l.get(2));
break;
default:
log.error("incorrect number of aspects " + aspects + " when loading Signal " + sys);
}
if (uname == null) {
h = new MergSD2SignalHead(sys, aspects, input1, input2, input3, feather, home);
} else {
h = new MergSD2SignalHead(sys, uname, aspects, input1, input2, input3, feather, home);
}
loadCommon(h, shared);
InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
return true;
}
Aggregations