use of jmri.implementation.SignalMastRepeater in project JMRI by JMRI.
the class DefaultSignalMastManagerXml method load.
/**
* Create a DefaultSignalMastManager
*
* @param shared Top level Element to unpack.
* @param perNode Top level Element that is per-node.
* @return true if successful
*/
@Override
public boolean load(Element shared, Element perNode) {
// loop over contained signalmast elements
List<Element> list = shared.getChildren("signalmast");
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
if (e.getAttribute("class") == null) {
SignalMast m;
String sys = getSystemName(e);
try {
m = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(sys);
if (getUserName(e) != null) {
m.setUserName(getUserName(e));
}
loadCommon(m, e);
} catch (IllegalArgumentException ex) {
log.warn("Failed to provide SignalMast \"{}\" in load", sys);
}
} else {
String adapterName = e.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(e, null);
} catch (Exception ex) {
log.error("Exception while loading {}: {}", e.getName(), ex, ex);
}
}
}
list = shared.getChildren("turnoutsignalmast");
if (list != null) {
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
String adapterName = e.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(e, null);
} catch (Exception ex) {
log.error("Exception while loading {}: {}", e.getName(), ex, ex);
}
}
}
list = shared.getChildren("virtualsignalmast");
if (list != null) {
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
String adapterName = e.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(e, null);
} catch (Exception ex) {
log.error("Exception while loading {}: {}", e.getName(), ex, ex);
}
}
}
list = shared.getChildren("matrixsignalmast");
if (list != null) {
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
String adapterName = e.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(e, null);
} catch (Exception ex) {
log.error("Exception while loading {}: {}", e.getName(), ex, ex);
}
}
}
list = shared.getChildren("dccsignalmast");
if (list != null) {
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
String adapterName = e.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(e, null);
} catch (Exception ex) {
log.error("Exception while loading {}: {}", e.getName(), ex, ex);
}
}
}
list = shared.getChildren("signalmastrepeater");
if (list != null) {
DefaultSignalMastManager m = (DefaultSignalMastManager) InstanceManager.getDefault(jmri.SignalMastManager.class);
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
String masterName = e.getChild("masterMast").getText();
String slaveName = e.getChild("slaveMast").getText();
SignalMastRepeater smr = new SignalMastRepeater(masterName, slaveName);
if (e.getChild("enabled") != null && e.getChild("enabled").getText().equals("false")) {
smr.setEnabled(false);
}
if (e.getChild("update") != null) {
if (e.getChild("update").getText().equals("MasterToSlave")) {
smr.setDirection(SignalMastRepeater.MASTERTOSLAVE);
} else if (e.getChild("update").getText().equals("SlaveToMaster")) {
smr.setDirection(SignalMastRepeater.SLAVETOMASTER);
}
}
try {
m.addRepeater(smr);
} catch (jmri.JmriException ex) {
log.error("Unable to add mast repeater " + masterName + " : " + slaveName);
}
}
m.initialiseRepeaters();
}
return true;
}
use of jmri.implementation.SignalMastRepeater in project JMRI by JMRI.
the class DefaultSignalMastManager method addRepeater.
public void addRepeater(SignalMastRepeater rp) throws jmri.JmriException {
for (SignalMastRepeater rpeat : repeaterList) {
if (rpeat.getMasterMast() == rp.getMasterMast() && rpeat.getSlaveMast() == rp.getSlaveMast()) {
log.error("Signal repeater already Exists");
throw new jmri.JmriException("Signal mast Repeater already exists");
} else if (rpeat.getMasterMast() == rp.getSlaveMast() && rpeat.getSlaveMast() == rp.getMasterMast()) {
log.error("Signal repeater already Exists");
throw new jmri.JmriException("Signal mast Repeater already exists");
}
}
repeaterList.add(rp);
firePropertyChange("repeaterlength", null, null);
}
use of jmri.implementation.SignalMastRepeater in project JMRI by JMRI.
the class DefaultSignalMastManagerXml method store.
/**
* Default implementation for storing the contents of a
* DefaultSignalMastManager
*
* @param o Object to store
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
DefaultSignalMastManager m = (DefaultSignalMastManager) o;
Element element = new Element("signalmasts");
element.setAttribute("class", this.getClass().getName());
if (m != null) {
// include contents
List<String> names = m.getSystemNameList();
for (int i = 0; i < names.size(); i++) {
//Element e = new Element("signalmast");
SignalMast p = m.getSignalMast(names.get(i));
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(p);
if (e != null) {
element.addContent(e);
}
} catch (Exception ex) {
log.error("Error storing signalmast: {}", ex);
}
}
List<SignalMastRepeater> repeaterList = m.getRepeaterList();
if (repeaterList.size() > 0) {
//Element repeatElem= new Element("signalmastrepeaters");
for (SignalMastRepeater smr : repeaterList) {
if (smr.getMasterMast() != null && smr.getSlaveMast() != null) {
Element e = new Element("signalmastrepeater");
e.addContent(new Element("masterMast").addContent(smr.getMasterMastName()));
e.addContent(new Element("slaveMast").addContent(smr.getSlaveMastName()));
e.addContent(new Element("enabled").addContent(smr.getEnabled() ? "true" : "false"));
switch(smr.getDirection()) {
case 1:
e.addContent(new Element("update").addContent("MasterToSlave"));
break;
case 2:
e.addContent(new Element("update").addContent("SlaveToMaster"));
break;
default:
e.addContent(new Element("update").addContent("BothWay"));
break;
}
element.addContent(e);
}
}
//element.add(repeatElem);
}
}
return element;
}
Aggregations