@Override
  public void save() {
    List<WrappedVertex> vertices = new ArrayList<WrappedVertex>();
    for (Vertex vertex : getVertices()) {
      if (vertex.isGroup()) {
        vertices.add(new WrappedGroup(vertex));
      } else {
        vertices.add(new WrappedLeafVertex(vertex));
      }
    }
    List<WrappedEdge> edges = new ArrayList<WrappedEdge>();
    for (Edge edge : getEdges()) {
      WrappedEdge newEdge =
          new WrappedEdge(
              edge,
              new WrappedLeafVertex(m_vertexProvider.getVertex(edge.getSource().getVertex())),
              new WrappedLeafVertex(m_vertexProvider.getVertex(edge.getTarget().getVertex())));
      edges.add(newEdge);
    }

    WrappedGraph graph = new WrappedGraph(getEdgeNamespace(), vertices, edges);

    JAXB.marshal(graph, new File(getConfigurationFile()));
  }
  public void check(GraphProvider topologyProvider) {
    String vertexNamespace = topologyProvider.getVertexNamespace();
    Assert.assertEquals(8, topologyProvider.getVertices().size());

    Assert.assertEquals(8, topologyProvider.getEdges().size());

    Assert.assertTrue(topologyProvider.containsVertexId("1"));
    Assert.assertTrue(topologyProvider.containsVertexId("2"));
    Assert.assertTrue(topologyProvider.containsVertexId("3"));
    Assert.assertTrue(topologyProvider.containsVertexId("4"));
    Assert.assertTrue(topologyProvider.containsVertexId("5"));
    Assert.assertTrue(topologyProvider.containsVertexId("6"));
    Assert.assertTrue(topologyProvider.containsVertexId("7"));
    Assert.assertTrue(topologyProvider.containsVertexId("8"));
    Assert.assertTrue(!topologyProvider.containsVertexId("15"));

    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "1")).length);
    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "2")).length);
    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "3")).length);
    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "4")).length);
    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "5")).length);
    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "6")).length);
    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "7")).length);
    Assert.assertEquals(
        2, topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "8")).length);

    /**
     * This is a little hokey because it relies on the fact that edges are only judged to be equal
     * based on the namespace and id tuple.
     */
    Vertex mockVertex = EasyMock.createMock(Vertex.class);
    EasyMock.expect(mockVertex.getId()).andReturn("v0").anyTimes();
    EasyMock.expect(mockVertex.getLabel()).andReturn(null).anyTimes();
    EasyMock.replay(mockVertex);
    AbstractEdge[] edgeidsforvertex1 = {
      new AbstractEdge("nodes", "10012", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10081", mockVertex, mockVertex)
    };
    AbstractEdge[] edgeidsforvertex2 = {
      new AbstractEdge("nodes", "10012", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10023", mockVertex, mockVertex)
    };
    AbstractEdge[] edgeidsforvertex3 = {
      new AbstractEdge("nodes", "10023", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10034", mockVertex, mockVertex)
    };
    AbstractEdge[] edgeidsforvertex4 = {
      new AbstractEdge("nodes", "10034", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10045", mockVertex, mockVertex)
    };
    AbstractEdge[] edgeidsforvertex5 = {
      new AbstractEdge("nodes", "10045", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10056", mockVertex, mockVertex)
    };
    AbstractEdge[] edgeidsforvertex6 = {
      new AbstractEdge("nodes", "10056", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10067", mockVertex, mockVertex)
    };
    AbstractEdge[] edgeidsforvertex7 = {
      new AbstractEdge("nodes", "10067", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10078", mockVertex, mockVertex)
    };
    AbstractEdge[] edgeidsforvertex8 = {
      new AbstractEdge("nodes", "10078", mockVertex, mockVertex),
      new AbstractEdge("nodes", "10081", mockVertex, mockVertex)
    };

    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "1")),
        edgeidsforvertex1);
    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "2")),
        edgeidsforvertex2);
    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "3")),
        edgeidsforvertex3);
    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "4")),
        edgeidsforvertex4);
    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "5")),
        edgeidsforvertex5);
    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "6")),
        edgeidsforvertex6);
    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "7")),
        edgeidsforvertex7);
    Assert.assertArrayEquals(
        topologyProvider.getEdgeIdsForVertex(new DefaultVertexRef(vertexNamespace, "8")),
        edgeidsforvertex8);
  }
  protected String getEdgeTooltipText(DataLinkInterface link, Vertex source, Vertex target) {
    StringBuffer tooltipText = new StringBuffer();

    OnmsSnmpInterface sourceInterface =
        getSnmpInterfaceDao()
            .findByNodeIdAndIfIndex(Integer.parseInt(source.getId()), link.getIfIndex());
    OnmsSnmpInterface targetInterface =
        getSnmpInterfaceDao()
            .findByNodeIdAndIfIndex(Integer.parseInt(target.getId()), link.getParentIfIndex());

    tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
    if (sourceInterface != null
        && targetInterface != null
        && sourceInterface.getNetMask() != null
        && !sourceInterface.getNetMask().isLoopbackAddress()
        && targetInterface.getNetMask() != null
        && !targetInterface.getNetMask().isLoopbackAddress()) {
      tooltipText.append("Type of Link: Layer3/Layer2");
    } else {
      tooltipText.append("Type of Link: Layer2");
    }
    tooltipText.append(HTML_TOOLTIP_TAG_END);

    tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
    tooltipText.append("Name: &lt;endpoint1 " + source.getLabel());
    if (sourceInterface != null) tooltipText.append(":" + sourceInterface.getIfName());
    tooltipText.append(" ---- endpoint2 " + target.getLabel());
    if (targetInterface != null) tooltipText.append(":" + targetInterface.getIfName());
    tooltipText.append("&gt;");
    tooltipText.append(HTML_TOOLTIP_TAG_END);

    LinkStateMachine stateMachine = new LinkStateMachine();
    stateMachine.setParentInterfaces(sourceInterface, targetInterface);
    tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
    tooltipText.append("Link status: " + stateMachine.getLinkStatus());
    tooltipText.append(HTML_TOOLTIP_TAG_END);

    if (targetInterface != null) {
      if (targetInterface.getIfSpeed() != null) {
        tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
        tooltipText.append("Bandwidth: " + getHumanReadableIfSpeed(targetInterface.getIfSpeed()));
        tooltipText.append(HTML_TOOLTIP_TAG_END);
      }
    } else if (sourceInterface != null) {
      if (sourceInterface.getIfSpeed() != null) {
        tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
        tooltipText.append("Bandwidth: " + getHumanReadableIfSpeed(sourceInterface.getIfSpeed()));
        tooltipText.append(HTML_TOOLTIP_TAG_END);
      }
    }

    tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
    tooltipText.append("End Point 1: " + source.getLabel() + ", " + source.getIpAddress());
    tooltipText.append(HTML_TOOLTIP_TAG_END);

    tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
    tooltipText.append("End Point 2: " + target.getLabel() + ", " + target.getIpAddress());
    tooltipText.append(HTML_TOOLTIP_TAG_END);

    return tooltipText.toString();
  }