public Turnout newTurnout(String systemName, String userName) {
    if (log.isDebugEnabled()) {
      log.debug(
          "newTurnout:"
              + ((systemName == null) ? "null" : systemName)
              + ";"
              + ((userName == null) ? "null" : userName));
    }
    if (systemName == null) {
      log.error(
          "SystemName cannot be null. UserName was " + ((userName == null) ? "null" : userName));
      throw new IllegalArgumentException(
          "SystemName cannot be null. UserName was " + ((userName == null) ? "null" : userName));
    }
    // is system name in correct format?
    if (!systemName.startsWith(getSystemPrefix() + typeLetter())) {
      log.error(
          "Invalid system name for turnout: "
              + systemName
              + " needed "
              + getSystemPrefix()
              + typeLetter());
      throw new IllegalArgumentException(
          "Invalid system name for turnout: "
              + systemName
              + " needed "
              + getSystemPrefix()
              + typeLetter());
    }

    // return existing if there is one
    Turnout s;
    if ((userName != null) && ((s = getByUserName(userName)) != null)) {
      if (getBySystemName(systemName) != s) {
        log.error(
            "inconsistent user ("
                + userName
                + ") and system name ("
                + systemName
                + ") results; userName related to ("
                + s.getSystemName()
                + ")");
      }
      return s;
    }
    if ((s = getBySystemName(systemName)) != null) {
      if ((s.getUserName() == null) && (userName != null)) {
        s.setUserName(userName);
      } else if (userName != null) {
        log.warn(
            "Found turnout via system name ("
                + systemName
                + ") with non-null user name ("
                + s.getUserName()
                + "). Turnout \""
                + systemName
                + "("
                + userName
                + ")\" cannot be used.");
      }
      return s;
    }

    // doesn't exist, make a new one
    s = createNewTurnout(systemName, userName);

    // if that failed, blame it on the input arguements
    if (s == null) {
      throw new IllegalArgumentException("Unable to create turnout from " + systemName);
    }

    // save in the maps if successful
    register(s);
    try {
      s.setStraightSpeed("Global");
    } catch (jmri.JmriException ex) {
      log.error(ex.toString());
    }

    try {
      s.setDivergingSpeed("Global");
    } catch (jmri.JmriException ex) {
      log.error(ex.toString());
    }
    return s;
  }
Example #2
0
  @Test
  public void testUpperLower() {
    Turnout t = l.provideTurnout("" + getNumToTest2());

    Assert.assertNull(l.getTurnout(t.getSystemName().toLowerCase()));
  }