示例#1
0
 private static Element storePortal(Portal portal) {
   Element elem = new Element("portal");
   elem.setAttribute("systemName", portal.getSystemName());
   elem.setAttribute("portalName", portal.getName());
   OBlock block = portal.getFromBlock();
   if (block != null) {
     Element fromElem = new Element("fromBlock");
     fromElem.setAttribute("blockName", block.getSystemName());
     List<OPath> paths = portal.getFromPaths();
     if (paths != null) {
       for (int i = 0; i < paths.size(); i++) {
         OPath path = paths.get(i);
         fromElem.addContent(storePathKey(path));
       }
     }
     elem.addContent(fromElem);
   } else {
     log.error("Portal \"" + portal.getName() + "\" has no fromBlock!");
   }
   NamedBean signal = portal.getFromSignal();
   if (signal != null) {
     Element fromElem = new Element("fromSignal");
     fromElem.setAttribute("signalName", signal.getSystemName());
     fromElem.setAttribute("signalDelay", "" + portal.getFromSignalOffset());
     elem.addContent(fromElem);
   }
   block = portal.getToBlock();
   if (block != null) {
     Element toElem = new Element("toBlock");
     toElem.setAttribute("blockName", block.getSystemName());
     List<OPath> paths = portal.getToPaths();
     if (paths != null) {
       for (int i = 0; i < paths.size(); i++) {
         OPath path = paths.get(i);
         toElem.addContent(storePathKey(path));
       }
     }
     elem.addContent(toElem);
   } else {
     log.error("Portal \"" + portal.getName() + "\" has no toBlock!");
   }
   signal = portal.getToSignal();
   if (signal != null) {
     Element toElem = new Element("toSignal");
     toElem.setAttribute("signalName", signal.getSystemName());
     toElem.setAttribute("signalDelay", "" + portal.getToSignalOffset());
     elem.addContent(toElem);
   }
   return elem;
 }
示例#2
0
  Portal loadPortal(Element elem) {
    String sysName = null;
    String userName = elem.getAttribute("portalName").getValue();
    if (elem.getAttribute("systemName") == null) {
      if (log.isDebugEnabled()) {
        log.debug("Portal systemName is null");
      }
    } else {
      sysName = elem.getAttribute("systemName").getValue();
    }
    String fromBlockName = null;
    String toBlockName = null;
    // Portals must have user names.
    Portal portal = _portalMgr.getByUserName(userName);
    if (portal != null) {
      fromBlockName = portal.getFromBlock().getSystemName();
      toBlockName = portal.getToBlock().getSystemName();
    } else {
      portal = _portalMgr.providePortal(userName);
    }
    if (portal == null) {
      log.error(
          "unable to create Portal ("
              + sysName
              + ", "
              + userName
              + ") "
              + elem
              + " "
              + elem.getAttributes());
      return null;
    }
    if (log.isDebugEnabled()) {
      log.debug("create Portal: (" + sysName + ", " + userName + ")");
    }

    OBlock fromBlock = null;
    Element eFromBlk = elem.getChild("fromBlock");
    if (eFromBlk != null && eFromBlk.getAttribute("blockName") != null) {
      String name = eFromBlk.getAttribute("blockName").getValue();
      if (fromBlockName != null && !fromBlockName.equals(name)) {
        log.error(
            "Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
      } else {
        fromBlock = getBlock(name);
        if (fromBlock != null) {
          portal.setFromBlock(fromBlock, false);
          fromBlock.addPortal(portal);

          List<Element> ePathsFromBlock = eFromBlk.getChildren("path");
          for (int i = 0; i < ePathsFromBlock.size(); i++) {
            Element e = ePathsFromBlock.get(i);
            String pathName = e.getAttribute("pathName").getValue();
            String blockName = e.getAttribute("blockName").getValue();
            if (log.isDebugEnabled()) {
              log.debug(
                  "Load portal= "
                      + userName
                      + " fromBlock= "
                      + fromBlock.getSystemName()
                      + " pathName= "
                      + pathName
                      + " blockName= "
                      + blockName);
            }
            /*(if (fromBlock.getSystemName().equals(blockName))*/ {
              // path is in the fromBlock
              OPath path = getPath(fromBlock, pathName);
              portal.addPath(path);
            }
          }
        }
      }
    } else {
      log.error("Portal \"" + userName + "\" has no fromBlock!");
    }

    OBlock toBlock = null;
    Element eToBlk = elem.getChild("toBlock");
    if (eToBlk != null && eToBlk.getAttribute("blockName") != null) {
      String name = eToBlk.getAttribute("blockName").getValue();
      if (toBlockName != null && !toBlockName.equals(name)) {
        log.error(
            "Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
      } else {
        toBlock = getBlock(name);
        if (toBlock != null) {
          portal.setToBlock(toBlock, false);
          toBlock.addPortal(portal);

          List<Element> ePathsToBlock = eToBlk.getChildren("path");
          for (int i = 0; i < ePathsToBlock.size(); i++) {
            Element e = ePathsToBlock.get(i);
            String pathName = e.getAttribute("pathName").getValue();
            String blockName = e.getAttribute("blockName").getValue();
            if (log.isDebugEnabled()) {
              log.debug(
                  "Load portal= "
                      + userName
                      + " toBlock= "
                      + toBlock.getSystemName()
                      + " pathName= "
                      + pathName
                      + " blockName= "
                      + blockName);
            }
            /*if (toBlock.getSystemName().equals(blockName))*/ {
              // path is in the toBlock
              OPath path = getPath(toBlock, pathName);
              portal.addPath(path);
            }
          }
        }
      }
    } else {
      log.error("Portal \"" + userName + "\" has no toBlock!");
    }
    Element eSignal = elem.getChild("fromSignal");
    if (eSignal != null) {
      String name = eSignal.getAttribute("signalName").getValue();
      float length = 0.0f;
      try {
        Attribute attr = eSignal.getAttribute("signalDelay");
        if (attr != null) {
          length = attr.getFloatValue();
        }
      } catch (org.jdom2.DataConversionException e) {
        log.error(
            "Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
      }
      portal.setProtectSignal(Portal.getSignal(name), length, toBlock);
    }
    eSignal = elem.getChild("toSignal");
    if (eSignal != null) {
      String name = eSignal.getAttribute("signalName").getValue();
      float length = 0.0f;
      try {
        Attribute attr = eSignal.getAttribute("signalDelay");
        if (attr != null) {
          length = attr.getFloatValue();
        }
      } catch (org.jdom2.DataConversionException e) {
        log.error(
            "Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
      }
      portal.setProtectSignal(Portal.getSignal(name), length, fromBlock);
    }

    if (log.isDebugEnabled()) {
      log.debug("End Load portal " + userName);
    }
    return portal;
  }