예제 #1
0
  /**
   * This method serialises the data contained within a PerformanceTreeArc. It also serialises the
   * ArcPathPoints information
   */
  private static void createArcElement(
      final PerformanceTreeArc inputArc, final Element nodeElement, final Document document) {

    Element arcElement = document.createElement("arc");
    nodeElement.appendChild(arcElement);

    String arcID = inputArc.getId();
    String arcLabel = inputArc.getArcLabel();
    String arcSourceID = inputArc.getSource().getId();
    String arcTargetID;
    if (inputArc.getTarget() != null) arcTargetID = inputArc.getTarget().getId();
    else arcTargetID = "";
    String arcRequired = Boolean.toString(inputArc.isRequired());
    String arcStartX = Double.toString(inputArc.getArcPath().getStartPoint().getX());
    String arcStartY = Double.toString(inputArc.getArcPath().getStartPoint().getY());
    String arcEndX = Double.toString(inputArc.getArcPath().getEndPoint().getX());
    String arcEndY = Double.toString(inputArc.getArcPath().getEndPoint().getY());

    arcElement.setAttribute("id", arcID);
    arcElement.setAttribute("label", arcLabel);
    arcElement.setAttribute("source", arcSourceID);
    arcElement.setAttribute("target", arcTargetID);
    arcElement.setAttribute("required", arcRequired);
    arcElement.setAttribute("startX", arcStartX);
    arcElement.setAttribute("startY", arcStartY);
    arcElement.setAttribute("endX", arcEndX);
    arcElement.setAttribute("endY", arcEndY);

    // arcPathPoint information needs to be saved, too
    int arcPathPoints = inputArc.getArcPath().getArcPathDetails().length;
    String[][] point = inputArc.getArcPath().getArcPathDetails();
    for (int i = 0; i < arcPathPoints; i++) {
      MacroWriter.createArcPathPoint(
          point[i][0], point[i][1], point[i][2], arcElement, document, i);
    }
  }
예제 #2
0
  /**
   * This method serialises the information contained within a PerformanceTreeNode and recurses down
   * to serialise info about its arcs
   */
  private static void createNodeElement(
      final PerformanceTreeNode inputNode, final Element parentElement, final Document document) {

    Element nodeElement = document.createElement("node");

    // common data to serialise for all PT nodes
    String nodeID = inputNode.getId();
    Double nodePositionX = inputNode.getPositionXObject();
    Double nodePositionY = inputNode.getPositionYObject();
    PTNode nodeType = inputNode.getNodeType();
    String nodeIncomingArcID = inputNode.getIncomingArcID();
    nodeElement.setAttribute("id", nodeID);
    nodeElement.setAttribute("type", nodeType.toString());
    nodeElement.setAttribute("x", String.valueOf(nodePositionX));
    nodeElement.setAttribute("y", String.valueOf(nodePositionY));
    nodeElement.setAttribute("incomingArc", nodeIncomingArcID);

    // indicate that this node has been processed already
    MacroWriter.nodesProcessed.put(nodeID, "true");

    if (nodeIncomingArcID == null || nodeIncomingArcID.equals("")) {
      Element tree = document.createElement("tree");
      parentElement.appendChild(tree);
      tree.appendChild(nodeElement);
    } else {
      parentElement.appendChild(nodeElement);
    }

    // special cases
    if (inputNode instanceof ValueNode) {
      String nodeLabel;
      if (((ValueNode) inputNode).getNodeLabelObject() != null)
        nodeLabel = ((ValueNode) inputNode).getNodeLabel();
      else nodeLabel = "";
      nodeElement.setAttribute("label", nodeLabel);
    } else if (inputNode instanceof OperationNode) {
      String nodeOperation = ((OperationNode) inputNode).getOperation();
      nodeElement.setAttribute("operation", nodeOperation);
      Element outgoingArcsElement = document.createElement("outgoingArcs");
      nodeElement.appendChild(outgoingArcsElement);
      Collection nodeOutgoingArcIDs = ((OperationNode) inputNode).getOutgoingArcIDs();
      Iterator i = nodeOutgoingArcIDs.iterator();
      while (i.hasNext()) {
        String outgoingArcID = (String) i.next();
        PerformanceTreeArc nodeArc = MacroWriter.macro.getMacroArc(outgoingArcID);
        MacroWriter.createArcElement(nodeArc, outgoingArcsElement, document);
      }

      Element childNodesElement = document.createElement("childNodes");
      nodeElement.appendChild(childNodesElement);
      i = nodeOutgoingArcIDs.iterator();
      while (i.hasNext()) {
        String outgoingArcID = (String) i.next();
        PerformanceTreeArc nodeArc = MacroWriter.macro.getMacroArc(outgoingArcID);
        if (nodeArc.getTarget() != null) {
          PerformanceTreeNode childNode = nodeArc.getTarget();
          boolean nodeProcessedAlready = false;
          if ((MacroWriter.nodesProcessed.get(childNode.getId())).equals("true")) {
            nodeProcessedAlready = true;
          } else if ((MacroWriter.nodesProcessed.get(childNode.getId())).equals("false")) {
            nodeProcessedAlready = false;
          }
          if (!nodeProcessedAlready)
            MacroWriter.createNodeElement(childNode, childNodesElement, document);
        }
      }
    }
  }