Ejemplo n.º 1
0
  /**
   * Store the contents of a OBlockManager.
   *
   * @param o Object to store, of type BlockManager
   * @return Element containing the complete info
   */
  public Element store(Object o) {
    Element blocks = new Element("oblocks");
    blocks.setAttribute("class", "jmri.jmrit.logix.configurexml.OBlockManagerXml");
    OBlockManager manager = (OBlockManager) o;
    Iterator<String> iter = manager.getSystemNameList().iterator();
    while (iter.hasNext()) {
      String sname = iter.next();
      OBlock block = manager.getBySystemName(sname);
      String uname = block.getUserName();
      if (log.isDebugEnabled()) {
        log.debug("OBlock: sysName= " + sname + ", userName= "******"oblock");
      elem.setAttribute("systemName", sname);
      if (uname != null && uname.length() > 0) {
        elem.setAttribute("userName", uname); // doing this for compatibility during 2.9.* series
        elem.addContent(new Element("userName").addContent(uname));
      }
      String comment = block.getComment();
      if (comment != null) {
        Element c = new Element("comment");
        c.addContent(comment);
        elem.addContent(c);
      }
      elem.setAttribute("length", "" + block.getLengthMm());
      elem.setAttribute("units", block.isMetric() ? "true" : "false");
      elem.setAttribute("curve", "" + block.getCurvature());
      if (block.getNamedSensor() != null) {
        Element se = new Element("sensor");
        se.setAttribute("systemName", block.getNamedSensor().getName());
        elem.addContent(se);
      }
      if (block.getNamedErrorSensor() != null) {
        Element se = new Element("errorSensor");
        se.setAttribute("systemName", block.getNamedErrorSensor().getName());
        elem.addContent(se);
      }
      if (block.getReporter() != null) {
        Element se = new Element("reporter");
        se.setAttribute("systemName", block.getReporter().getSystemName());
        se.setAttribute("reportCurrent", block.isReportingCurrent() ? "true" : "false");
        elem.addContent(se);
      }
      elem.setAttribute("permissive", block.getPermissiveWorking() ? "true" : "false");
      elem.setAttribute("speedNotch", block.getBlockSpeed());

      List<Path> paths = block.getPaths();
      for (int j = 0; j < paths.size(); j++) {
        elem.addContent(storePath((OPath) paths.get(j)));
      }
      List<Portal> portals = block.getPortals();
      for (int i = 0; i < portals.size(); i++) {
        elem.addContent(storePortal(portals.get(i)));
      }
      // and put this element out
      blocks.addContent(elem);
    }

    return blocks;
  }