Search in sources :

Example 1 with LogixManager

use of jmri.LogixManager in project JMRI by JMRI.

the class DefaultLogixManagerXml method store.

/**
     * Default implementation for storing the contents of a LogixManager
     *
     * @param o Object to store, of type LogixManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element logixs = new Element("logixs");
    setStoreElementClass(logixs);
    LogixManager tm = (LogixManager) o;
    if (tm != null) {
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        // don't return an element if there are not Logix to include
        if (!iter.hasNext()) {
            return null;
        }
        // store the Logix
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during store");
            }
            log.debug("logix system name is " + sname);
            Logix x = tm.getBySystemName(sname);
            boolean enabled = x.getEnabled();
            Element elem = new Element("logix");
            elem.addContent(new Element("systemName").addContent(sname));
            // store common part
            storeCommon(x, elem);
            if (enabled) {
                elem.setAttribute("enabled", "yes");
            } else {
                elem.setAttribute("enabled", "no");
            }
            // save child Conditionals
            int numConditionals = x.getNumConditionals();
            if (numConditionals > 0) {
                String cSysName = "";
                Element cElem = null;
                for (int k = 0; k < numConditionals; k++) {
                    cSysName = x.getConditionalByNumberOrder(k);
                    cElem = new Element("logixConditional");
                    cElem.setAttribute("systemName", cSysName);
                    cElem.setAttribute("order", Integer.toString(k));
                    elem.addContent(cElem);
                }
            }
            logixs.addContent(elem);
        }
    }
    return (logixs);
}
Also used : Logix(jmri.Logix) Element(org.jdom2.Element) LogixManager(jmri.LogixManager) DefaultLogixManager(jmri.managers.DefaultLogixManager)

Example 2 with LogixManager

use of jmri.LogixManager in project JMRI by JMRI.

the class DefaultLogixManagerXml method loadLogixs.

/**
     * Utility method to load the individual Logix objects. If there's no
     * additional info needed for a specific logix type, invoke this with the
     * parent of the set of Logix elements.
     *
     * @param logixs Element containing the Logix elements to load.
     */
public void loadLogixs(Element logixs) {
    List<Element> logixList = logixs.getChildren("logix");
    if (log.isDebugEnabled()) {
        log.debug("Found " + logixList.size() + " logixs");
    }
    LogixManager tm = InstanceManager.getDefault(jmri.LogixManager.class);
    for (int i = 0; i < logixList.size(); i++) {
        String sysName = getSystemName(logixList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + logixList.get(i));
            break;
        }
        String userName = getUserName(logixList.get(i));
        String yesno = "";
        if (logixList.get(i).getAttribute("enabled") != null) {
            yesno = logixList.get(i).getAttribute("enabled").getValue();
        }
        if (log.isDebugEnabled()) {
            log.debug("create logix: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Logix x = tm.createNewLogix(sysName, userName);
        if (x != null) {
            // load common part
            loadCommon(x, logixList.get(i));
            // set enabled/disabled if attribute was present
            if ((yesno != null) && (!yesno.equals(""))) {
                if (yesno.equals("yes")) {
                    x.setEnabled(true);
                } else if (yesno.equals("no")) {
                    x.setEnabled(false);
                }
            }
            // load conditionals, if there are any
            List<Element> logixConditionalList = logixList.get(i).getChildren("logixConditional");
            if (logixConditionalList.size() > 0) {
                // add conditionals
                for (int n = 0; n < logixConditionalList.size(); n++) {
                    if (logixConditionalList.get(n).getAttribute("systemName") == null) {
                        log.warn("unexpected null in systemName " + logixConditionalList.get(n) + " " + logixConditionalList.get(n).getAttributes());
                        break;
                    }
                    String cSysName = logixConditionalList.get(n).getAttribute("systemName").getValue();
                    int cOrder = Integer.parseInt(logixConditionalList.get(n).getAttribute("order").getValue());
                    // add conditional to logix
                    x.addConditional(cSysName, cOrder);
                }
            }
        }
    }
}
Also used : Logix(jmri.Logix) Element(org.jdom2.Element) LogixManager(jmri.LogixManager) DefaultLogixManager(jmri.managers.DefaultLogixManager)

Example 3 with LogixManager

use of jmri.LogixManager in project JMRI by JMRI.

the class DefaultLogixManagerTest method testCreateForms.

public void testCreateForms() {
    LogixManager m = new DefaultLogixManager();
    Logix l1 = m.createNewLogix("User name 1");
    Logix l2 = m.createNewLogix("User name 2");
    Assert.assertNotNull(m.getByUserName("User name 1"));
    Assert.assertNotNull(m.getByUserName("User name 2"));
    Assert.assertTrue(l1 != l2);
    Assert.assertTrue(!l1.equals(l2));
    Assert.assertNotNull(m.getBySystemName(l1.getSystemName()));
    Assert.assertNotNull(m.getBySystemName(l2.getSystemName()));
    Logix l3 = m.createNewLogix("IX03", "User name 3");
    Assert.assertTrue(l1 != l3);
    Assert.assertTrue(l2 != l3);
    Assert.assertTrue(!l1.equals(l3));
    Assert.assertTrue(!l2.equals(l3));
    // test of some fails
    Assert.assertNull(m.createNewLogix(l1.getUserName()));
    Assert.assertNull(m.createNewLogix(l1.getSystemName(), ""));
}
Also used : Logix(jmri.Logix) LogixManager(jmri.LogixManager)

Example 4 with LogixManager

use of jmri.LogixManager in project JMRI by JMRI.

the class DefaultLogixManagerTest method testEmptyUserName.

public void testEmptyUserName() {
    LogixManager m = new DefaultLogixManager();
    Logix l1 = m.createNewLogix("IX01", "");
    Logix l2 = m.createNewLogix("IX02", "");
    Assert.assertTrue(l1 != l2);
    Assert.assertTrue(!l1.equals(l2));
    Assert.assertNotNull(m.getBySystemName(l1.getSystemName()));
    Assert.assertNotNull(m.getBySystemName(l2.getSystemName()));
    Logix l3 = m.createNewLogix("IX03", "User name 3");
    // test of some fails
    Assert.assertNull(m.createNewLogix(l1.getSystemName(), ""));
}
Also used : Logix(jmri.Logix) LogixManager(jmri.LogixManager)

Example 5 with LogixManager

use of jmri.LogixManager in project JMRI by JMRI.

the class DefaultLogixManagerXml method replaceLogixManager.

/**
     * Replace the current LogixManager, if there is one, with one newly created
     * during a load operation. This is skipped if they are of the same absolute
     * type.
     */
protected void replaceLogixManager() {
    if (InstanceManager.getDefault(jmri.LogixManager.class).getClass().getName().equals(DefaultLogixManager.class.getName())) {
        return;
    }
    // if old manager exists, remove it from configuration process
    if (InstanceManager.getNullableDefault(jmri.LogixManager.class) != null) {
        ConfigureManager cmOD = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
        if (cmOD != null) {
            cmOD.deregister(InstanceManager.getDefault(jmri.LogixManager.class));
        }
    }
    // register new one with InstanceManager
    DefaultLogixManager pManager = DefaultLogixManager.instance();
    InstanceManager.store(pManager, LogixManager.class);
    // register new one for configuration
    ConfigureManager cmOD = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cmOD != null) {
        cmOD.registerConfig(pManager, jmri.Manager.LOGIXS);
    }
}
Also used : ConfigureManager(jmri.ConfigureManager) DefaultLogixManager(jmri.managers.DefaultLogixManager) LogixManager(jmri.LogixManager) DefaultLogixManager(jmri.managers.DefaultLogixManager)

Aggregations

LogixManager (jmri.LogixManager)5 Logix (jmri.Logix)4 DefaultLogixManager (jmri.managers.DefaultLogixManager)3 Element (org.jdom2.Element)2 ConfigureManager (jmri.ConfigureManager)1