Search in sources :

Example 1 with DefaultSignalSystem

use of jmri.implementation.DefaultSignalSystem in project JMRI by JMRI.

the class DefaultSignalSystemManager method makeBean.

SignalSystem makeBean(String name) {
    //First check to see if the bean is in the default system directory
    URL path = FileUtil.findURL("xml/signals/" + name + "/aspects.xml", FileUtil.Location.INSTALLED);
    log.debug("load from {}", path);
    XmlFile xf = new AspectFile();
    if (path != null) {
        try {
            Element root = xf.rootFromURL(path);
            DefaultSignalSystem s = new DefaultSignalSystem(name);
            loadBean(s, root);
            return s;
        } catch (IOException | JDOMException e) {
            log.error("Could not parse aspect file \"{}\" due to: {}", path, e);
        }
    }
    //if the file doesn't exist or fails the load from the default location then try the user directory
    path = FileUtil.findURL("signals/" + name + "/aspects.xml", FileUtil.Location.USER, "xml", "resources");
    log.debug("load from {}", path);
    if (path != null) {
        xf = new AspectFile();
        try {
            Element root = xf.rootFromURL(path);
            DefaultSignalSystem s = new DefaultSignalSystem(name);
            loadBean(s, root);
            return s;
        } catch (IOException | JDOMException e) {
            log.error("Could not parse aspect file \"{}\" due to: {}", path, e);
        }
    }
    return null;
}
Also used : DefaultSignalSystem(jmri.implementation.DefaultSignalSystem) XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)1 URL (java.net.URL)1 DefaultSignalSystem (jmri.implementation.DefaultSignalSystem)1 XmlFile (jmri.jmrit.XmlFile)1 Element (org.jdom2.Element)1 JDOMException (org.jdom2.JDOMException)1