Example #1
0
  private void addChild(Container context, Element e) throws LoadFailedException {
    ModelObject model = null;
    boolean port = false;
    if (e.getLocalName().equals("node")) {
      String controlName = getAttributeNS(e, BIGRAPH, "control");
      Control c = bigraph.getSignature().getControl(controlName);
      if (c == null)
        throw new LoadFailedException(
            "The control \"" + controlName + "\" isn't defined by " + "this bigraph's signature.");

      model = new Node(c);
    } else if (e.getLocalName().equals("port") && context instanceof Node) {
      /*
       * <port /> tags shouldn't actually create anything, so let the
       * special handling commence!
       */
      port = true;
    } else if (e.getLocalName().equals("edge")) {
      String linksort = getAttributeNS(e, BIGRAPH, "linksort");
      if (linksort == null || linksort.equals("none")) {
        linksort = "";
      }
      model = new Edge();
      addChange(((Edge) model).changeLinkSort(linksort));
    } else if (e.getLocalName().equals("innername")) {
      String innersort = getAttributeNS(e, BIGRAPH, "innersort");
      if (innersort == null || innersort.equals("none")) {
        innersort = "";
      }
      model = new InnerName();
      addChange(((InnerName) model).changeInnerSort(innersort));
    } else if (e.getLocalName().equals("outername")) {
      String linksort = getAttributeNS(e, BIGRAPH, "linksort");
      if (linksort == null || linksort.equals("none")) {
        linksort = "";
      }
      model = new OuterName();
      ((OuterName) model).setLinkSort(linksort);
    } else {
      model = BigraphXMLLoader.getNewObject(e.getLocalName());
    }

    if (model instanceof Layoutable)
      addChange(context.changeAddChild((Layoutable) model, getAttributeNS(e, BIGRAPH, "name")));

    if (model instanceof Container) {
      processContainer(e, (Container) model);
    } else if (port) {
      Node n = (Node) context;
      processPoint(e, n.getPort(getAttributeNS(e, BIGRAPH, "name")));
    } else if (model instanceof InnerName) {
      processPoint(e, (InnerName) model);
    }

    if (model != null) executeUndecorators(model, e);
  }
  private void recHandleParams(Layoutable l) throws SaveFailedException {
    if (l instanceof Node) {
      Node n = (Node) l;
      String param = ParameterUtilities.getParameter(n);
      if (param != null) writeControl(n.getControl(), param);
    }

    if (l instanceof Container)
      for (Layoutable i : ((Container) l).getChildren()) recHandleParams(i);
  }