1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.maven.plugins.graph.dot;
17
18 import java.util.ArrayList;
19
20 import org.kuali.maven.plugins.graph.pojo.Edge;
21 import org.kuali.maven.plugins.graph.pojo.GraphNode;
22 import org.kuali.maven.plugins.graph.pojo.MavenContext;
23 import org.kuali.maven.plugins.graph.pojo.Scope;
24 import org.kuali.maven.plugins.graph.pojo.State;
25 import org.kuali.maven.plugins.graph.pojo.Style;
26 import org.kuali.maven.plugins.graph.processor.StyleProcessor;
27 import org.kuali.maven.plugins.graph.tree.Node;
28 import org.kuali.maven.plugins.graph.tree.TreeHelper;
29 import org.kuali.maven.plugins.graph.util.Counter;
30
31
32
33
34
35
36 public class EdgeGenerator {
37 StyleProcessor sp = new StyleProcessor();
38 Counter counter = new Counter(1);
39
40
41
42
43
44
45
46 public void addEdge(Node<MavenContext> node, Edge edge) {
47 MavenContext context = node.getObject();
48 GraphNode graphNode = context.getGraphNode();
49 if (graphNode.getEdges() == null) {
50 graphNode.setEdges(new ArrayList<Edge>());
51 }
52 graphNode.getEdges().add(edge);
53 }
54
55
56
57
58
59
60 public Edge getParentChildEdge(Node<MavenContext> node) {
61 GraphNode parent = node.getParent().getObject().getGraphNode();
62 MavenContext context = node.getObject();
63 GraphNode child = context.getGraphNode();
64 boolean optional = context.isOptional();
65 State state = context.getState();
66 Scope scope = Scope.getScope(context.getArtifact().getScope());
67 return getStyledEdge(parent, child, optional, scope, state);
68 }
69
70
71
72
73
74
75 public Edge getParentChildEdge(Node<MavenContext> node, Node<MavenContext> replacement, State state) {
76 GraphNode parent = node.getParent().getObject().getGraphNode();
77 MavenContext context = node.getObject();
78 GraphNode child = replacement.getObject().getGraphNode();
79 boolean optional = context.isOptional();
80 Scope scope = Scope.getScope(context.getArtifact().getScope());
81 return getStyledEdge(parent, child, optional, scope, state);
82 }
83
84
85
86
87
88
89 public Edge getParentChildEdge(Node<MavenContext> node, Node<MavenContext> replacement) {
90 return getParentChildEdge(node, replacement, node.getObject().getState());
91 }
92
93
94
95
96
97
98
99 public Edge getStyledEdge(GraphNode parent, GraphNode child, boolean optional, Scope scope, State state) {
100 Style style = sp.getStyle(scope, optional, state);
101 int id = counter.increment();
102 String label = TreeHelper.getRelationshipLabel(scope, optional, state);
103 Edge edge = new Edge(parent, child);
104 edge.setId(id);
105 sp.copyStyleProperties(edge, style);
106 edge.setLabel(label);
107 return edge;
108 }
109 }