示例#1
0
  public Turnout createNewTurnout(String systemName, String userName) {
    Turnout t;
    int addr = Integer.valueOf(systemName.substring(2)).intValue();
    t = new DccTurnout(addr);
    t.setUserName(userName);

    return t;
  }
示例#2
0
 public void testRemoveListener() {
   Listen ln = new Listen();
   t.addPropertyChangeListener(ln);
   t.removePropertyChangeListener(ln);
   listenerResult = false;
   t.setUserName("user id");
   Assert.assertTrue(
       "listener should not have heard message after removeListner", !listenerResult);
 }
示例#3
0
 public void testAddListener() {
   t.addPropertyChangeListener(new Listen());
   listenerResult = false;
   t.setUserName("user id");
   Assert.assertTrue("listener invoked by setUserName", listenerResult);
   listenerResult = false;
   t.setCommandedState(Turnout.CLOSED);
   Assert.assertTrue("listener invoked by setCommandedState", listenerResult);
 }
示例#4
0
 @Test
 public void testRename() {
   // get turnout
   Turnout t1 = l.newTurnout(getSystemName(getNumToTest1()), "before");
   Assert.assertNotNull("t1 real object ", t1);
   t1.setUserName("after");
   Turnout t2 = l.getByUserName("after");
   Assert.assertEquals("same object", t1, t2);
   Assert.assertEquals("no old object", null, l.getByUserName("before"));
 }
示例#5
0
 public Turnout createNewTurnout(String systemName, String userName) {
   int addr;
   try {
     addr = Integer.valueOf(systemName.substring(getSystemPrefix().length() + 1)).intValue();
   } catch (java.lang.NumberFormatException e) {
     log.error("failed to convert systemName " + systemName + " to a turnout address");
     return null;
   }
   Turnout t = new MarklinTurnout(addr, getSystemPrefix(), tc);
   t.setUserName(userName);
   return t;
 }
示例#6
0
 // DCCpp-specific methods
 public Turnout createNewTurnout(String systemName, String userName) {
   int addr = Integer.valueOf(systemName.substring(prefix.length() + 1)).intValue();
   Turnout t = new DCCppTurnout(prefix, addr, tc);
   t.setUserName(userName);
   return t;
 }
示例#7
0
  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;
  }