Search in sources :

Example 1 with DefaultLogix

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

the class DefaultLogixManager method createNewLogix.

/**
     * Method to create a new Logix if the Logix does not exist.
     * <p>
     * Returns null if
     * a Logix with the same systemName or userName already exists, or if there
     * is trouble creating a new Logix.
     */
@Override
public Logix createNewLogix(String systemName, String userName) {
    // Check that Logix does not already exist
    Logix x;
    if (userName != null && !userName.equals("")) {
        x = getByUserName(userName);
        if (x != null) {
            return null;
        }
    }
    x = getBySystemName(systemName);
    if (x == null) {
        // for compatibility?
        x = getBySystemName(systemName.toUpperCase());
    }
    if (x != null) {
        return null;
    }
    // Logix does not exist, create a new Logix
    x = new DefaultLogix(systemName, userName);
    // save in the maps
    register(x);
    /*The following keeps track of the last created auto system name.
         currently we do not reuse numbers, although there is nothing to stop the
         user from manually recreating them*/
    if (systemName.startsWith("IX:AUTO:")) {
        try {
            int autoNumber = Integer.parseInt(systemName.substring(8));
            if (autoNumber > lastAutoLogixRef) {
                lastAutoLogixRef = autoNumber;
            }
        } catch (NumberFormatException e) {
            log.warn("Auto generated SystemName " + systemName + " is not in the correct format");
        }
    }
    return x;
}
Also used : Logix(jmri.Logix) DefaultLogix(jmri.implementation.DefaultLogix) DefaultLogix(jmri.implementation.DefaultLogix)

Aggregations

Logix (jmri.Logix)1 DefaultLogix (jmri.implementation.DefaultLogix)1