1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package name.angoca.zemucan.grammarReader.api;
30
31 import name.angoca.zemucan.AbstractZemucanException;
32 import name.angoca.zemucan.core.graph.model.Graph;
33 import name.angoca.zemucan.tools.Constants;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public final class ImplementationInMemoryGrammarReader extends
52 AbstractGrammarReader {
53
54
55
56
57 private static final String DELIMITERS = " ,()";
58
59
60
61
62 private final Graph graph;
63
64
65
66
67
68
69
70
71
72
73
74 public ImplementationInMemoryGrammarReader(final Graph
75 final String
76 super();
77
78 assert graphToFill != null;
79 assert grammarName != null;
80
81 this.graph = graphToFill;
82
83 if (grammarName.equals("sa_conf-test-grammar1.xml")) {
84
85 super.setDelimiters(ImplementationInMemoryGrammarReader.DELIMITERS);
86
87 this.testGraph1(graphToFill);
88
89 super.setStartingNode(graphToFill.getStartingNode());
90 } else if (grammarName.equals("sa_conf-test-grammar2.xml")) {
91
92 super.setDelimiters(ImplementationInMemoryGrammarReader.DELIMITERS);
93
94 this.testGraph2(graphToFill);
95
96 super.setStartingNode(graphToFill.getStartingNode());
97 } else if (grammarName.equals("sa_conf-test-grammarIdentical1.xml")
98 || grammarName.equals("sa_conf-test-grammarIdentical2.xml")) {
99
100 super.setDelimiters(ImplementationInMemoryGrammarReader.DELIMITERS);
101
102 this.testGraph3(graphToFill);
103
104 super.setStartingNode(graphToFill.getStartingNode());
105 } else {
106 throw new Exception("Grammar not identified");
107 }
108 }
109
110 @Override
111 public Graph
112 super.setGrammarProcessed(true);
113
114 assert this.graph != null;
115
116 return this.graph;
117 }
118
119 private void testGraph1(final Graph
120 throws AbstractZemucanException {
121 assert graphToFill != null;
122
123
124 final String create = "create";
125 final String table = "table";
126
127 graphToFill.addNode(Constants.STARTING_NODE, Constants.STARTING_NODE,
128 true);
129 graphToFill.addNode(create, create, true);
130 graphToFill.addNode(table, table, true);
131 graphToFill.addNode(Constants.ENDING_NODE, Constants.ENDING_NODE, true);
132 graphToFill.firstPhaseFinished();
133 graphToFill.addRelation(Constants.STARTING_NODE, create);
134 graphToFill.addRelation(create, table);
135 graphToFill.addRelation(table, Constants.ENDING_NODE);
136 graphToFill.secondPhaseFinished();
137 }
138
139 private void testGraph2(final Graph
140 throws AbstractZemucanException {
141 assert graphToFill != null;
142
143
144 final String create = "create";
145 final String tablespace = "tablespace";
146
147 graphToFill.addNode(Constants.STARTING_NODE, Constants.STARTING_NODE,
148 true);
149 graphToFill.addNode(create, create, true);
150 graphToFill.addNode(tablespace, tablespace, true);
151 graphToFill.addNode(Constants.ENDING_NODE, Constants.ENDING_NODE, true);
152 graphToFill.firstPhaseFinished();
153 graphToFill.addRelation(Constants.STARTING_NODE, create);
154 graphToFill.addRelation(create, tablespace);
155 graphToFill.addRelation(tablespace, Constants.ENDING_NODE);
156 graphToFill.secondPhaseFinished();
157 }
158
159 private void testGraph3(final Graph
160 throws AbstractZemucanException {
161 assert graphToFill != null;
162
163
164 final String create = "create";
165
166 graphToFill.addNode(Constants.STARTING_NODE, Constants.STARTING_NODE,
167 true);
168 graphToFill.addNode(create, create, true);
169 graphToFill.addNode(Constants.ENDING_NODE, Constants.ENDING_NODE, true);
170 graphToFill.firstPhaseFinished();
171 graphToFill.addRelation(Constants.STARTING_NODE, create);
172 graphToFill.addRelation(create, Constants.ENDING_NODE);
173 graphToFill.secondPhaseFinished();
174 }
175 }