@Test public void testLoadSimpleGraph() throws Exception { SimpleGraphProvider topologyProvider = new SimpleGraphProvider(); topologyProvider.load(URI.create("file:target/test-classes/simple-graph.xml")); assertEquals(7, topologyProvider.getVertices().size()); assertEquals(7, topologyProvider.getEdges().size()); Vertex v0 = topologyProvider.getVertex("vertex", "v0"); Vertex v1 = topologyProvider.getVertex("vertex", "v1"); Vertex v2 = topologyProvider.getVertex("vertex", "v2"); Vertex v3 = topologyProvider.getVertex("vertex", "v3"); Vertex v4 = topologyProvider.getVertex("vertex", "v4"); Vertex g0 = topologyProvider.getVertex("vertex", "g0"); assertEquals("Vertex v0", v0.getLabel()); assertEquals("64.146.64.214", v0.getIpAddress()); assertEquals(false, v0.isLocked()); assertEquals(new Integer(-1), v0.getNodeID()); assertEquals(false, v0.isSelected()); assertEquals(new Integer(50), v0.getX()); assertEquals(new Integer(100), v0.getY()); assertEquals(g0, v0.getParent()); assertEquals(2, topologyProvider.getChildren(g0).size()); assertEquals(0, topologyProvider.getSemanticZoomLevel(g0)); assertEquals(1, topologyProvider.getSemanticZoomLevel(v0)); assertEquals(3, topologyProvider.getEdgeIdsForVertex(v0).length); assertEquals(3, topologyProvider.getEdgeIdsForVertex(v1).length); assertEquals(3, topologyProvider.getEdgeIdsForVertex(v2).length); assertEquals(3, topologyProvider.getEdgeIdsForVertex(v3).length); assertEquals(2, topologyProvider.getEdgeIdsForVertex(v4).length); for (Vertex vertex : topologyProvider.getVertices()) { assertEquals("vertex", vertex.getNamespace()); assertTrue(vertex.getIpAddress(), "127.0.0.1".equals(vertex.getIpAddress()) || "64.146.64.214".equals(vertex.getIpAddress())); } for (Edge edge : topologyProvider.getEdges()) { assertEquals("vertex", edge.getNamespace()); } }
private void load(final URI source, final WrappedGraph graph) { String namespace = graph.m_namespace == null ? TOPOLOGY_NAMESPACE_SIMPLE : graph.m_namespace; if (getVertexNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new vertex provider with namespace {}", namespace); m_vertexProvider = new SimpleVertexProvider(namespace); } if (getEdgeNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new edge provider with namespace {}", namespace); m_edgeProvider = new SimpleEdgeProvider(namespace); } clearVertices(); for (WrappedVertex vertex : graph.m_vertices) { if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", source.toString(), vertex); } else if (vertex.id.startsWith(SIMPLE_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(SIMPLE_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex; if (vertex.group) { newVertex = new SimpleGroup(vertex.namespace, vertex.id); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); } else { newVertex = new SimpleLeafVertex(vertex.namespace, vertex.id, vertex.x, vertex.y); } newVertex.setIconKey(vertex.iconKey); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLabel(vertex.label); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (!newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); addVertices(newVertex); } clearEdges(); for (WrappedEdge edge : graph.m_edges) { if (edge.namespace == null) { edge.namespace = getEdgeNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on edge to default: {}", edge); } if (edge.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid edge unmarshalled from {}: {}", source.toString(), edge); } else if (edge.id.startsWith(SIMPLE_EDGE_ID_PREFIX)) { try { } catch (NumberFormatException e) { } } AbstractEdge newEdge = connectVertices(edge.id, edge.source, edge.target); newEdge.setLabel(edge.label); newEdge.setTooltipText(edge.tooltipText); } for (WrappedVertex vertex: graph.m_vertices) { if (vertex.parent != null && !vertex.equals(vertex.parent)) { LoggerFactory.getLogger(this.getClass()).debug("Setting parent of " + vertex + " to " + vertex.parent); setParent(vertex, vertex.parent); } } }
SimpleGraphProvider extends AbstractTopologyProvider implements GraphProvider { private void load(final URI source, final WrappedGraph graph) { String namespace = graph.m_namespace == null ? TOPOLOGY_NAMESPACE_SIMPLE : graph.m_namespace; if (getVertexNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new vertex provider with namespace {}", namespace); m_vertexProvider = new SimpleVertexProvider(namespace); } if (getEdgeNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new edge provider with namespace {}", namespace); m_edgeProvider = new SimpleEdgeProvider(namespace); } clearVertices(); for (WrappedVertex vertex : graph.m_vertices) { if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", source.toString(), vertex); } else if (vertex.id.startsWith(SIMPLE_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(SIMPLE_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex; if (vertex.group) { newVertex = new SimpleGroup(vertex.namespace, vertex.id); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); } else { newVertex = new SimpleLeafVertex(vertex.namespace, vertex.id, vertex.x, vertex.y); } newVertex.setIconKey(vertex.iconKey); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLabel(vertex.label); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (!newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); addVertices(newVertex); } clearEdges(); for (WrappedEdge edge : graph.m_edges) { if (edge.namespace == null) { edge.namespace = getEdgeNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on edge to default: {}", edge); } if (edge.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid edge unmarshalled from {}: {}", source.toString(), edge); } else if (edge.id.startsWith(SIMPLE_EDGE_ID_PREFIX)) { try { } catch (NumberFormatException e) { } } AbstractEdge newEdge = connectVertices(edge.id, edge.source, edge.target); newEdge.setLabel(edge.label); newEdge.setTooltipText(edge.tooltipText); } for (WrappedVertex vertex: graph.m_vertices) { if (vertex.parent != null && !vertex.equals(vertex.parent)) { LoggerFactory.getLogger(this.getClass()).debug("Setting parent of " + vertex + " to " + vertex.parent); setParent(vertex, vertex.parent); } } } }
SimpleGraphProvider extends AbstractTopologyProvider implements GraphProvider { private void load(final URI source, final WrappedGraph graph) { String namespace = graph.m_namespace == null ? TOPOLOGY_NAMESPACE_SIMPLE : graph.m_namespace; if (getVertexNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new vertex provider with namespace {}", namespace); m_vertexProvider = new SimpleVertexProvider(namespace); } if (getEdgeNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new edge provider with namespace {}", namespace); m_edgeProvider = new SimpleEdgeProvider(namespace); } clearVertices(); for (WrappedVertex vertex : graph.m_vertices) { if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", source.toString(), vertex); } else if (vertex.id.startsWith(SIMPLE_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(SIMPLE_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex; if (vertex.group) { newVertex = new SimpleGroup(vertex.namespace, vertex.id); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); } else { newVertex = new SimpleLeafVertex(vertex.namespace, vertex.id, vertex.x, vertex.y); } newVertex.setIconKey(vertex.iconKey); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLabel(vertex.label); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (!newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); addVertices(newVertex); } clearEdges(); for (WrappedEdge edge : graph.m_edges) { if (edge.namespace == null) { edge.namespace = getEdgeNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on edge to default: {}", edge); } if (edge.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid edge unmarshalled from {}: {}", source.toString(), edge); } else if (edge.id.startsWith(SIMPLE_EDGE_ID_PREFIX)) { try { } catch (NumberFormatException e) { } } AbstractEdge newEdge = connectVertices(edge.id, edge.source, edge.target); newEdge.setLabel(edge.label); newEdge.setTooltipText(edge.tooltipText); } for (WrappedVertex vertex: graph.m_vertices) { if (vertex.parent != null && !vertex.equals(vertex.parent)) { LoggerFactory.getLogger(this.getClass()).debug("Setting parent of " + vertex + " to " + vertex.parent); setParent(vertex, vertex.parent); } } } SimpleGraphProvider();  SimpleGraphProvider(String namespace); }
SimpleGraphProvider extends AbstractTopologyProvider implements GraphProvider { private void load(final URI source, final WrappedGraph graph) { String namespace = graph.m_namespace == null ? TOPOLOGY_NAMESPACE_SIMPLE : graph.m_namespace; if (getVertexNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new vertex provider with namespace {}", namespace); m_vertexProvider = new SimpleVertexProvider(namespace); } if (getEdgeNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new edge provider with namespace {}", namespace); m_edgeProvider = new SimpleEdgeProvider(namespace); } clearVertices(); for (WrappedVertex vertex : graph.m_vertices) { if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", source.toString(), vertex); } else if (vertex.id.startsWith(SIMPLE_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(SIMPLE_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex; if (vertex.group) { newVertex = new SimpleGroup(vertex.namespace, vertex.id); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); } else { newVertex = new SimpleLeafVertex(vertex.namespace, vertex.id, vertex.x, vertex.y); } newVertex.setIconKey(vertex.iconKey); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLabel(vertex.label); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (!newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); addVertices(newVertex); } clearEdges(); for (WrappedEdge edge : graph.m_edges) { if (edge.namespace == null) { edge.namespace = getEdgeNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on edge to default: {}", edge); } if (edge.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid edge unmarshalled from {}: {}", source.toString(), edge); } else if (edge.id.startsWith(SIMPLE_EDGE_ID_PREFIX)) { try { } catch (NumberFormatException e) { } } AbstractEdge newEdge = connectVertices(edge.id, edge.source, edge.target); newEdge.setLabel(edge.label); newEdge.setTooltipText(edge.tooltipText); } for (WrappedVertex vertex: graph.m_vertices) { if (vertex.parent != null && !vertex.equals(vertex.parent)) { LoggerFactory.getLogger(this.getClass()).debug("Setting parent of " + vertex + " to " + vertex.parent); setParent(vertex, vertex.parent); } } } SimpleGraphProvider();  SimpleGraphProvider(String namespace); URI getTopologyLocation(); void setTopologyLocation(URI topologyLocation); void save(String filename); @Override void save(); void refresh(); @Override void load(String filename); }
SimpleGraphProvider extends AbstractTopologyProvider implements GraphProvider { private void load(final URI source, final WrappedGraph graph) { String namespace = graph.m_namespace == null ? TOPOLOGY_NAMESPACE_SIMPLE : graph.m_namespace; if (getVertexNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new vertex provider with namespace {}", namespace); m_vertexProvider = new SimpleVertexProvider(namespace); } if (getEdgeNamespace() != namespace) { LoggerFactory.getLogger(this.getClass()).info("Creating new edge provider with namespace {}", namespace); m_edgeProvider = new SimpleEdgeProvider(namespace); } clearVertices(); for (WrappedVertex vertex : graph.m_vertices) { if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", source.toString(), vertex); } else if (vertex.id.startsWith(SIMPLE_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(SIMPLE_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex; if (vertex.group) { newVertex = new SimpleGroup(vertex.namespace, vertex.id); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); } else { newVertex = new SimpleLeafVertex(vertex.namespace, vertex.id, vertex.x, vertex.y); } newVertex.setIconKey(vertex.iconKey); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLabel(vertex.label); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (!newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); addVertices(newVertex); } clearEdges(); for (WrappedEdge edge : graph.m_edges) { if (edge.namespace == null) { edge.namespace = getEdgeNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on edge to default: {}", edge); } if (edge.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid edge unmarshalled from {}: {}", source.toString(), edge); } else if (edge.id.startsWith(SIMPLE_EDGE_ID_PREFIX)) { try { } catch (NumberFormatException e) { } } AbstractEdge newEdge = connectVertices(edge.id, edge.source, edge.target); newEdge.setLabel(edge.label); newEdge.setTooltipText(edge.tooltipText); } for (WrappedVertex vertex: graph.m_vertices) { if (vertex.parent != null && !vertex.equals(vertex.parent)) { LoggerFactory.getLogger(this.getClass()).debug("Setting parent of " + vertex + " to " + vertex.parent); setParent(vertex, vertex.parent); } } } SimpleGraphProvider();  SimpleGraphProvider(String namespace); URI getTopologyLocation(); void setTopologyLocation(URI topologyLocation); void save(String filename); @Override void save(); void refresh(); @Override void load(String filename);  }