Пример #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);
  }
  @Override
  public void prepare() {
    cg.clear();

    if (first instanceof Port
        && second instanceof Port
        && validateSorts(
            ((Port) first).getSpec().getPortSort(),
            ((Port) second).getSpec().getPortSort(),
            ((Port) second).getBigraph().getSignature())) {
      Bigraph b = ((Port) first).getBigraph();
      setTarget(b);
      Edge ed = new Edge(((Port) first).getSpec().getPortSort().split(":")[0]);
      cg.add(b.changeAddChild(ed, b.getFirstUnusedName(ed)));
      cg.add(((Port) first).changeConnect(ed));
      cg.add(((Port) second).changeConnect(ed));
    } else if (first instanceof Port
        && second instanceof InnerName
        && validateSorts(
            ((Port) first).getSpec().getPortSort(),
            ((InnerName) second).getInnerSort(),
            ((Port) first).getBigraph().getSignature())) {
      Bigraph b = ((Port) first).getBigraph();
      setTarget(b);
      Edge ed = new Edge(((Port) first).getSpec().getPortSort().split(":")[0]);
      cg.add(b.changeAddChild(ed, b.getFirstUnusedName(ed)));
      cg.add(((Port) first).changeConnect(ed));
      cg.add(((InnerName) second).changeConnect(ed));
    } else if (first instanceof InnerName
        && second instanceof Port
        && validateSorts(
            ((InnerName) first).getInnerSort(),
            ((Port) second).getSpec().getPortSort(),
            ((Port) second).getBigraph().getSignature())) {
      Bigraph b = ((InnerName) first).getBigraph();
      setTarget(b);
      Edge ed = new Edge(((InnerName) first).getInnerSort().split(":")[0]);
      cg.add(b.changeAddChild(ed, b.getFirstUnusedName(ed)));
      cg.add(((InnerName) first).changeConnect(ed));
      cg.add(((Port) second).changeConnect(ed));
    } else if (first instanceof InnerName
        && second instanceof InnerName
        && validateSorts(
            ((InnerName) first).getInnerSort(),
            ((InnerName) second).getInnerSort(),
            ((InnerName) second).getBigraph().getSignature())) {
      Bigraph b = ((InnerName) first).getBigraph();
      setTarget(b);
      Edge ed = new Edge(((InnerName) first).getInnerSort().split(":")[0]);
      cg.add(b.changeAddChild(ed, b.getFirstUnusedName(ed)));
      cg.add(((InnerName) first).changeConnect(ed));
      cg.add(((InnerName) second).changeConnect(ed));
    } else if (first instanceof Port
        && second instanceof Edge
        && validateSorts(
            ((Port) first).getSpec().getPortSort(),
            ((Edge) second).getLinkSort(),
            ((Port) first).getBigraph().getSignature())) {
      setTarget(((Port) first).getBigraph());
      cg.add(((Port) first).changeConnect((Edge) second));
    } else if (first instanceof Edge
        && second instanceof Port
        && validateSorts(
            ((Port) second).getSpec().getPortSort(),
            ((Edge) first).getLinkSort(),
            ((Port) second).getBigraph().getSignature())) {
      setTarget(((Port) second).getBigraph());
      cg.add(((Port) second).changeConnect((Edge) first));
    } else if (first instanceof Port
        && second instanceof OuterName
        && (((OuterName) second).getLinkSort() == null
            || ((OuterName) second).getLinkSort().equals("")
            || ((OuterName) second).getPoints().size() == 0)) {
      setTarget(((Port) first).getBigraph());
      ((OuterName) second).setLinkSort(((Port) first).getSpec().getPortSort());
      cg.add(((Port) first).changeConnect((OuterName) second));
    } else if (first instanceof Port
        && second instanceof OuterName
        && validateSorts(
            ((OuterName) second).getLinkSort(),
            ((Port) first).getSpec().getPortSort(),
            ((Port) first).getBigraph().getSignature())) {
      setTarget(((Port) first).getBigraph());
      cg.add(((Port) first).changeConnect((OuterName) second));
    } else if (first instanceof OuterName
        && second instanceof Port
        && validateSorts(
            ((OuterName) first).getLinkSort(),
            ((Port) second).getSpec().getPortSort(),
            ((Port) second).getBigraph().getSignature())) {
      setTarget(((Port) second).getBigraph());
      cg.add(((Port) second).changeConnect((OuterName) first));
    } else if (first instanceof OuterName
        && second instanceof Port
        && (((OuterName) first).getLinkSort() == null
            || ((OuterName) first).getLinkSort().equals("")
            || ((OuterName) first).getPoints().size() == 0)) {
      setTarget(((Port) second).getBigraph());
      ((OuterName) first).setLinkSort(((Port) second).getSpec().getPortSort());
      cg.add(((Port) second).changeConnect((OuterName) first));
    } else if (first instanceof InnerName
        && second instanceof Edge
        && validateSorts(
            ((InnerName) first).getInnerSort(),
            ((Edge) second).getLinkSort(),
            ((Edge) second).getBigraph().getSignature())) {
      setTarget(((InnerName) first).getBigraph());
      ((InnerName) first).setInnerSort(((Edge) second).getLinkSort() + ":none");
      cg.add(((InnerName) first).changeConnect((Edge) second));
    } else if (first instanceof Edge
        && second instanceof InnerName
        && validateSorts(
            ((InnerName) second).getInnerSort(),
            ((Edge) first).getLinkSort(),
            ((InnerName) second).getBigraph().getSignature())) {
      setTarget(((InnerName) second).getBigraph());
      ((InnerName) second).setInnerSort(((Edge) first).getLinkSort() + ":none");
      cg.add(((InnerName) second).changeConnect((Edge) first));
    } else if (first instanceof InnerName
        && second instanceof OuterName
        && (((OuterName) second).getLinkSort() == null
            || ((OuterName) second).getLinkSort().equals("")
            || ((OuterName) second).getPoints().size() == 0)) {
      setTarget(((InnerName) first).getBigraph());
      ((OuterName) second).setLinkSort(((InnerName) first).getInnerSort());
      cg.add(((InnerName) first).changeConnect((OuterName) second));
    } else if (first instanceof InnerName
        && second instanceof OuterName
        && validateSorts(
            ((OuterName) second).getLinkSort(),
            ((InnerName) first).getInnerSort(),
            ((OuterName) second).getBigraph().getSignature())) {
      setTarget(((InnerName) first).getBigraph());
      ((InnerName) first).setInnerSort(((InnerName) first).getInnerSort().split(":")[0] + ":none");
      cg.add(((InnerName) first).changeConnect((OuterName) second));
    } else if (first instanceof OuterName
        && second instanceof InnerName
        && validateSorts(
            ((OuterName) first).getLinkSort(),
            ((InnerName) second).getInnerSort(),
            ((InnerName) second).getBigraph().getSignature())) {
      setTarget(((InnerName) second).getBigraph());
      ((InnerName) second)
          .setInnerSort(((InnerName) second).getInnerSort().split(":")[0] + ":none");
      cg.add(((InnerName) second).changeConnect((OuterName) first));
    } else if (first instanceof OuterName
        && second instanceof InnerName
        && (((OuterName) first).getLinkSort() == null
            || ((OuterName) first).getLinkSort().equals("")
            || ((OuterName) first).getPoints().size() == 0)) {
      setTarget(((InnerName) second).getBigraph());
      ((OuterName) first).setLinkSort(((InnerName) second).getInnerSort());
      cg.add(((InnerName) second).changeConnect((OuterName) first));
    }
  }