use of org.jdom2.Element 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;
}
use of org.jdom2.Element in project JMRI by JMRI.
the class LsDecSignalHeadXml method loadTurnout.
NamedBeanHandle<Turnout> loadTurnout(Object o) {
Element e = (Element) o;
String name = e.getAttribute("systemName").getValue();
Turnout t = InstanceManager.turnoutManagerInstance().getTurnout(name);
return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
}
use of org.jdom2.Element in project JMRI by JMRI.
the class MatrixSignalMastXml method store.
/**
* Default implementation for storing the contents of a
* MatrixSignalMastManager
*
* @param o Object to store, of type MatrixSignalMast
* @return e Element containing the complete info
*/
@Override
public Element store(Object o) {
// from mast p to XML
MatrixSignalMast p = (MatrixSignalMast) o;
Element e = new Element("matrixsignalmast");
e.setAttribute("class", this.getClass().getName());
// include content
e.addContent(new Element("systemName").addContent(p.getSystemName()));
// username, comment & properties
storeCommon(p, e);
// mast properties:
Element unlit = new Element("unlit");
if (p.allowUnLit()) {
unlit.setAttribute("allowed", "yes");
unlit.addContent(new Element("bitString").addContent(p.getUnLitChars()));
} else {
unlit.setAttribute("allowed", "no");
}
e.addContent(unlit);
List<String> outputs = p.getOutputs();
// convert char[] to xml-storable simple String
// max. 5 outputs (either: turnouts (bean names) [or ToDo: DCC addresses (numbers)]
// spotted by FindBugs as to never be null (check on creation of MatrixMast)
Element outps = new Element("outputs");
int i = 1;
for (String _output : outputs) {
String key = ("output" + i);
Element outp = new Element("output");
outp.setAttribute("matrixCol", key);
// get name (Turnout)
outp.addContent(p.getOutputName(i));
outps.addContent(outp);
i++;
}
if (outputs.size() != 0) {
e.addContent(outps);
}
// string of max. 6 chars "001010" describing matrix row per aspect
SignalAppearanceMap appMap = p.getAppearanceMap();
if (appMap != null) {
Element bss = new Element("bitStrings");
java.util.Enumeration<String> aspects = appMap.getAspects();
while (aspects.hasMoreElements()) {
String key = aspects.nextElement();
Element bs = new Element("bitString");
bs.setAttribute("aspect", key);
bs.addContent(p.getBitstring(key));
bss.addContent(bs);
}
e.addContent(bss);
}
List<String> disabledAspects = p.getDisabledAspects();
if (disabledAspects != null) {
Element el = new Element("disabledAspects");
for (String aspect : disabledAspects) {
Element ele = new Element("disabledAspect");
ele.addContent(aspect);
el.addContent(ele);
}
if (disabledAspects.size() != 0) {
e.addContent(el);
}
}
return e;
}
use of org.jdom2.Element in project JMRI by JMRI.
the class DccSignalHeadXml method store.
/**
* Default implementation for storing the contents of a LsDecSignalHead
*
* @param o Object to store, of type LsDecSignalHead
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
DccSignalHead p = (DccSignalHead) o;
Element element = new Element("signalhead");
element.setAttribute("class", this.getClass().getName());
element.addContent(new Element("systemName").addContent(p.getSystemName()));
storeCommon(p, element);
if (p.useAddressOffSet()) {
element.addContent(new Element("useAddressOffSet").addContent("yes"));
} else {
element.addContent(new Element("useAddressOffSet").addContent("no"));
}
for (int i = 0; i < p.getValidStates().length; i++) {
String aspect = p.getValidStateNames()[i];
//String address = p.getOutputForAppearance(i);
Element el = new Element("aspect");
el.setAttribute("defines", aspect);
el.addContent(new Element("number").addContent(Integer.toString(p.getOutputForAppearance(p.getValidStates()[i]))));
element.addContent(el);
}
return element;
}
use of org.jdom2.Element in project JMRI by JMRI.
the class MergSD2SignalHeadXml method store.
/**
* Default implementation for storing the contents of a MergSD2SignalHead
*
* @param o Object to store, of type MergSD2SignalHead
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
MergSD2SignalHead p = (MergSD2SignalHead) o;
Element element = new Element("signalhead");
element.setAttribute("class", this.getClass().getName());
element.addContent(new Element("systemName").addContent(p.getSystemName()));
element.setAttribute("aspects", p.getAspects() + "");
if (p.getFeather()) {
element.setAttribute("feather", "yes");
}
storeCommon(p, element);
int aspects = p.getAspects();
//@TODO could re-arange this so that it falls through
switch(aspects) {
case 2:
element.addContent(addTurnoutElement(p.getInput1(), "input1"));
if (!p.getHome()) {
element.setAttribute("home", "no");
}
break;
case 3:
element.addContent(addTurnoutElement(p.getInput1(), "input1"));
element.addContent(addTurnoutElement(p.getInput2(), "input2"));
break;
case 4:
element.addContent(addTurnoutElement(p.getInput1(), "input1"));
element.addContent(addTurnoutElement(p.getInput2(), "input2"));
element.addContent(addTurnoutElement(p.getInput3(), "input3"));
break;
default:
log.error("incorrect number of aspects " + aspects + " for Signal " + p.getDisplayName());
}
return element;
}
Aggregations