use of com.zhan_dui.utils.m3u8.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 com.zhan_dui.utils.m3u8.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 com.zhan_dui.utils.m3u8.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 com.zhan_dui.utils.m3u8.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;
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class LsDecSignalHeadXml 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) {
LsDecSignalHead p = (LsDecSignalHead) o;
Element element = new Element("signalhead");
element.setAttribute("class", this.getClass().getName());
element.addContent(new Element("systemName").addContent(p.getSystemName()));
storeCommon(p, element);
element.addContent(addTurnoutElement(p.getGreen().getName(), p.getGreenState()));
element.addContent(addTurnoutElement(p.getYellow().getName(), p.getYellowState()));
element.addContent(addTurnoutElement(p.getRed().getName(), p.getRedState()));
element.addContent(addTurnoutElement(p.getFlashGreen().getName(), p.getFlashGreenState()));
element.addContent(addTurnoutElement(p.getFlashYellow().getName(), p.getFlashYellowState()));
element.addContent(addTurnoutElement(p.getFlashRed().getName(), p.getFlashRedState()));
element.addContent(addTurnoutElement(p.getDark().getName(), p.getDarkState()));
return element;
}
Aggregations