Esempio n. 1
0
  @Test
  public void testName() throws Exception {
    Relationship rel = new MockRelationship();

    String tstName = "tst_name";
    rel.setName(tstName);
    assertEquals(tstName, rel.getName());
  }
Esempio n. 2
0
  /** Adds new relationship to the entity. */
  public void addRelationship(Relationship relationship) {
    if (relationship.getName() == null)
      throw new IllegalArgumentException("Attempt to insert unnamed relationship.");

    // block overrides

    // TODO: change method signature to return replaced attribute and make sure the
    // Modeler handles it...
    Object existingRelationship = relationships.get(relationship.getName());
    if (existingRelationship != null) {
      if (existingRelationship == relationship) return;
      else
        throw new IllegalArgumentException(
            "An attempt to override relationship '" + relationship.getName() + "'");
    }

    // Check that there aren't any attributes with the same name as the given
    // relationship.
    Object existingAttribute = attributes.get(relationship.getName());
    if (existingAttribute != null)
      throw new IllegalArgumentException(
          "Relationship name conflict with existing attribute '" + relationship.getName() + "'");

    relationships.put(relationship.getName(), relationship);
    relationship.setSourceEntity(this);
  }
Esempio n. 3
0
  public void updateShVertexList(ArrayList<Stakeholder> SHList) {
    // remove all vertices and edges currently graphed
    panGraph.removeCells(panGraph.getChildVertices(panGraph.getDefaultParent()), true);

    // add all stakeholders to the graph first, no edges
    for (Iterator<Stakeholder> iter = SHList.iterator(); iter.hasNext(); ) {
      Stakeholder s = iter.next();
      Object v = new Object();
      if (s.getPlacementRank() > Stakeholder.UNDEFINED) {
        panGraph.getModel().beginUpdate();
        try {
          v =
              panGraph.insertVertex(
                  graphParent,
                  null,
                  s.getName(),
                  100,
                  100,
                  s.getDiameter(),
                  s.getDiameter(),
                  s.getStyle());
        } finally {
          panGraph.getModel().endUpdate();
        }
        s.setGraphNode(v);
      }
      // What to do if a stakeholder is a "non-stakeholder", currently adds nothing to graph
      else {
        //                v = panGraph.insertVertex(graphParent, null, null, 100, 100,
        // s.getDiameter(), s.getDiameter(), s.getStyle());
        //                s.setGraphNode(v);
      }
    }
    // now add all edges
    for (Iterator<Stakeholder> mainShIter = SHList.iterator(); mainShIter.hasNext(); ) {
      Stakeholder main = mainShIter.next();
      for (Iterator<Relationship> it = main.getInfluences().iterator(); it.hasNext(); ) {
        Relationship r = it.next();
        // If the relationship magnitude is zero, don't graph it.
        if (r.getMagnitude() != 0) {
          for (Iterator<Stakeholder> secondaryShIter = SHList.iterator();
              secondaryShIter.hasNext(); ) {
            Stakeholder secondary = secondaryShIter.next();
            if (secondary.getName().equals(r.getName())) {
              //                            System.out.printf("insertEdge(%s,%s,%s)\n",
              // main.getName(), secondary.getName(), r.getLineStyle());
              panGraph.getModel().beginUpdate();
              try {
                panGraph.insertEdge(
                    graphParent,
                    null,
                    null,
                    main.getGraphNode(),
                    secondary.getGraphNode(),
                    r.getLineStyle());
              } finally {
                panGraph.getModel().endUpdate();
              }
            }
          }
        }
      }
    }
    graph();
  }
Esempio n. 4
0
 /** Adds new relationship to the entity. */
 public void addRelationship(Relationship rel) {
   relationships.put(rel.getName(), rel);
 }