1 /*
2 * Portions of this software was developed by employees of the National Institute
3 * of Standards and Technology (NIST), an agency of the Federal Government and is
4 * being made available as a public service. Pursuant to title 17 United States
5 * Code Section 105, works of NIST employees are not subject to copyright
6 * protection in the United States. This software may be subject to foreign
7 * copyright. Permission in the United States and in foreign countries, to the
8 * extent that NIST may hold copyright, to use, copy, modify, create derivative
9 * works, and distribute this software and its documentation without fee is hereby
10 * granted on a non-exclusive basis, provided that this notice and disclaimer
11 * of warranty appears in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
14 * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
15 * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
17 * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
18 * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
19 * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
20 * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
21 * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
22 * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
23 * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
24 * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
25 */
26
27 package gov.nist.secauto.metaschema.core.model.constraint;
28
29 import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
30 import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
31 import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
32 import gov.nist.secauto.metaschema.core.model.ModelWalker;
33
34 // TODO: remove if unused
35 abstract class ConstraintVisitingModelWalker<DATA>
36 extends ModelWalker<DATA> {
37
38 @Override
39 protected boolean visit(IAssemblyDefinition def, DATA data) {
40 boolean retval = super.visit(def, data);
41 walkConstraints(def, data);
42 return retval;
43 }
44
45 /**
46 * A callback called when visiting the {@code constraint} associated with
47 * {@code def}.
48 *
49 * @param definition
50 * the definition the constraint is associated with
51 * @param constraint
52 * the constraint associated with the definition
53 * @param data
54 * other data to use for processing
55 */
56 protected void visit(IAssemblyDefinition definition, IAllowedValuesConstraint constraint, DATA data) { // NOPMD -
57 // intentional
58 // subclasses may override this method to process the constraint
59 }
60
61 /**
62 * A callback called when visiting the {@code constraint} associated with
63 * {@code def}.
64 *
65 * @param definition
66 * the definition the constraint is associated with
67 * @param constraint
68 * the constraint associated with the definition
69 * @param data
70 * other data to use for processing
71 */
72 protected void visit(IAssemblyDefinition definition, ICardinalityConstraint constraint, DATA data) { // NOPMD -
73 // intentional
74 // subclasses may override this method to process the constraint
75 }
76
77 /**
78 * A callback called when visiting the {@code constraint} associated with
79 * {@code def}.
80 *
81 * @param definition
82 * the definition the constraint is associated with
83 * @param constraint
84 * the constraint associated with the definition
85 * @param data
86 * other data to use for processing
87 */
88 protected void visit(IAssemblyDefinition definition, IExpectConstraint constraint, DATA data) { // NOPMD - intentional
89 // subclasses may override this method to process the constraint
90 }
91
92 /**
93 * A callback called when visiting the {@code constraint} associated with
94 * {@code def}.
95 *
96 * @param definition
97 * the definition the constraint is associated with
98 * @param constraint
99 * the constraint associated with the definition
100 * @param data
101 * other data to use for processing
102 */
103 protected void visit(IAssemblyDefinition definition, IIndexConstraint constraint, DATA data) { // NOPMD - intentional
104 // subclasses may override this method to process the constraint
105 }
106
107 /**
108 * A callback called when visiting the {@code constraint} associated with
109 * {@code def}.
110 *
111 * @param definition
112 * the definition the constraint is associated with
113 * @param constraint
114 * the constraint associated with the definition
115 * @param data
116 * other data to use for processing
117 */
118 protected void visit(IAssemblyDefinition definition, IIndexHasKeyConstraint constraint, // NOPMD - intentional
119 DATA data) {
120 // subclasses may override this method to process the constraint
121 }
122
123 /**
124 * A callback called when visiting the {@code constraint} associated with
125 * {@code def}.
126 *
127 * @param definition
128 * the definition the constraint is associated with
129 * @param constraint
130 * the constraint associated with the definition
131 * @param data
132 * other data to use for processing
133 */
134 protected void visit(IAssemblyDefinition definition, IMatchesConstraint constraint, // NOPMD - intentional
135 DATA data) {
136 // subclasses may override this method to process the constraint
137 }
138
139 /**
140 * A callback called when visiting the {@code constraint} associated with
141 * {@code def}.
142 *
143 * @param definition
144 * the definition the constraint is associated with
145 * @param constraint
146 * the constraint associated with the definition
147 * @param data
148 * other data to use for processing
149 */
150 protected void visit(IAssemblyDefinition definition, IUniqueConstraint constraint, DATA data) { // NOPMD - intentional
151 // subclasses may override this method to process the constraint
152 }
153
154 @Override
155 protected boolean visit(IFieldDefinition def, DATA data) {
156 boolean retval = super.visit(def, data);
157 walkConstraints(def, data);
158 return retval;
159 }
160
161 /**
162 * A callback called when visiting the {@code constraint} associated with
163 * {@code def}.
164 *
165 * @param definition
166 * the definition the constraint is associated with
167 * @param constraint
168 * the constraint associated with the definition
169 * @param data
170 * other data to use for processing
171 */
172 protected void visit(IFieldDefinition definition, IAllowedValuesConstraint constraint, // NOPMD - intentional
173 DATA data) {
174 // subclasses may override this method to process the constraint
175 }
176
177 /**
178 * A callback called when visiting the {@code constraint} associated with
179 * {@code def}.
180 *
181 * @param definition
182 * the definition the constraint is associated with
183 * @param constraint
184 * the constraint associated with the definition
185 * @param data
186 * other data to use for processing
187 */
188 protected void visit(IFieldDefinition definition, IExpectConstraint constraint, DATA data) { // NOPMD - intentional
189 // subclasses may override this method to process the constraint
190 }
191
192 /**
193 * A callback called when visiting the {@code constraint} associated with
194 * {@code def}.
195 *
196 * @param definition
197 * the definition the constraint is associated with
198 * @param constraint
199 * the constraint associated with the definition
200 * @param data
201 * other data to use for processing
202 */
203 protected void visit(IFieldDefinition definition, IIndexHasKeyConstraint constraint, // NOPMD - intentional
204 DATA data) {
205 // subclasses may override this method to process the constraint
206 }
207
208 /**
209 * A callback called when visiting the {@code constraint} associated with
210 * {@code def}.
211 *
212 * @param definition
213 * the definition the constraint is associated with
214 * @param constraint
215 * the constraint associated with the definition
216 * @param data
217 * other data to use for processing
218 */
219 protected void visit(IFieldDefinition definition, IMatchesConstraint constraint, DATA data) { // NOPMD - intentional
220 // subclasses may override this method to process the constraint
221 }
222
223 @Override
224 protected void visit(IFlagDefinition def, DATA data) {
225 walkConstraints(def, data);
226 }
227
228 /**
229 * A callback called when visiting the {@code constraint} associated with
230 * {@code def}.
231 *
232 * @param definition
233 * the definition the constraint is associated with
234 * @param constraint
235 * the constraint associated with the definition
236 * @param data
237 * other data to use for processing
238 */
239 protected void visit(IFlagDefinition definition, IAllowedValuesConstraint constraint, // NOPMD - intentional
240 DATA data) {
241 // subclasses may override this method to process the constraint
242 }
243
244 /**
245 * A callback called when visiting the {@code constraint} associated with
246 * {@code def}.
247 *
248 * @param definition
249 * the definition the constraint is associated with
250 * @param constraint
251 * the constraint associated with the definition
252 * @param data
253 * other data to use for processing
254 */
255 protected void visit(IFlagDefinition definition, IExpectConstraint constraint, DATA data) { // NOPMD - intentional
256 // subclasses may override this method to process the constraint
257 }
258
259 /**
260 * A callback called when visiting the {@code constraint} associated with
261 * {@code def}.
262 *
263 * @param definition
264 * the definition the constraint is associated with
265 * @param constraint
266 * the constraint associated with the definition
267 * @param data
268 * other data to use for processing
269 */
270 protected void visit(IFlagDefinition definition, IIndexHasKeyConstraint constraint, // NOPMD - intentional
271 DATA data) {
272 // subclasses may override this method to process the constraint
273 }
274
275 /**
276 * A callback called when visiting the {@code constraint} associated with
277 * {@code def}.
278 *
279 * @param definition
280 * the definition the constraint is associated with
281 * @param constraint
282 * the constraint associated with the definition
283 * @param data
284 * other data to use for processing
285 */
286 protected void visit(IFlagDefinition definition, IMatchesConstraint constraint, DATA data) { // NOPMD - intentional
287 // subclasses may override this method to process the constraint
288 }
289
290 /**
291 * Walk the constraints associated with the {@code definition}.
292 *
293 * @param definition
294 * the definition the constraints to walk are associated with
295 * @param data
296 * other data to use for processing
297 */
298 protected void walkConstraints(IAssemblyDefinition definition, DATA data) {
299 for (IAllowedValuesConstraint constraint : definition.getAllowedValuesConstraints()) {
300 visit(definition, constraint, data);
301 }
302
303 for (IMatchesConstraint constraint : definition.getMatchesConstraints()) {
304 visit(definition, constraint, data);
305 }
306
307 for (IExpectConstraint constraint : definition.getExpectConstraints()) {
308 visit(definition, constraint, data);
309 }
310
311 for (IUniqueConstraint constraint : definition.getUniqueConstraints()) {
312 visit(definition, constraint, data);
313 }
314
315 for (IIndexConstraint constraint : definition.getIndexConstraints()) {
316 visit(definition, constraint, data);
317 }
318
319 for (IIndexHasKeyConstraint constraint : definition.getIndexHasKeyConstraints()) {
320 visit(definition, constraint, data);
321 }
322
323 for (ICardinalityConstraint constraint : definition.getHasCardinalityConstraints()) {
324 visit(definition, constraint, data);
325 }
326 }
327
328 /**
329 * Walk the constraints associated with the {@code definition}.
330 *
331 * @param definition
332 * the definition the constraints to walk are associated with
333 * @param data
334 * other data to use for processing
335 */
336 protected void walkConstraints(IFieldDefinition definition, DATA data) {
337 for (IAllowedValuesConstraint constraint : definition.getAllowedValuesConstraints()) {
338 visit(definition, constraint, data);
339 }
340
341 for (IMatchesConstraint constraint : definition.getMatchesConstraints()) {
342 visit(definition, constraint, data);
343 }
344
345 for (IExpectConstraint constraint : definition.getExpectConstraints()) {
346 visit(definition, constraint, data);
347 }
348
349 for (IIndexHasKeyConstraint constraint : definition.getIndexHasKeyConstraints()) {
350 visit(definition, constraint, data);
351 }
352 }
353
354 /**
355 * Walk the constraints associated with the {@code definition}.
356 *
357 * @param definition
358 * the definition the constraints to walk are associated with
359 * @param data
360 * other data to use for processing
361 */
362 protected void walkConstraints(IFlagDefinition definition, DATA data) {
363 for (IAllowedValuesConstraint constraint : definition.getAllowedValuesConstraints()) {
364 visit(definition, constraint, data);
365 }
366
367 for (IMatchesConstraint constraint : definition.getMatchesConstraints()) {
368 visit(definition, constraint, data);
369 }
370
371 for (IExpectConstraint constraint : definition.getExpectConstraints()) {
372 visit(definition, constraint, data);
373 }
374
375 for (IIndexHasKeyConstraint constraint : definition.getIndexHasKeyConstraints()) {
376 visit(definition, constraint, data);
377 }
378 }
379
380 }