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 package gov.nist.secauto.metaschema.core.model.constraint;
28
29 import gov.nist.secauto.metaschema.core.metapath.MetapathExpression;
30 import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
31 import gov.nist.secauto.metaschema.core.model.IDefinition;
32 import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
33 import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
34 import gov.nist.secauto.metaschema.core.model.constraint.impl.IFeatureValueConstrained;
35
36 import java.util.Locale;
37
38 import edu.umd.cs.findbugs.annotations.NonNull;
39
40
41
42
43
44
45
46
47 public abstract class AbstractTargetedConstraints<T extends IValueConstrained>
48 implements ITargetedConstaints, IFeatureValueConstrained {
49 @NonNull
50 private final MetapathExpression targetExpression;
51 @NonNull
52 private final T constraints;
53
54 public AbstractTargetedConstraints(
55 @NonNull MetapathExpression targetExpression,
56 @NonNull T constraints) {
57 this.targetExpression = targetExpression;
58 this.constraints = constraints;
59 }
60
61 @Override
62 public MetapathExpression getTargetExpression() {
63 return targetExpression;
64 }
65
66 @Override
67 public T getConstraintSupport() {
68 return constraints;
69 }
70
71 @SuppressWarnings("null")
72 protected void applyTo(@NonNull IDefinition definition) {
73 getAllowedValuesConstraints().forEach(constraint -> definition.addConstraint(constraint));
74 getMatchesConstraints().forEach(constraint -> definition.addConstraint(constraint));
75 getIndexHasKeyConstraints().forEach(constraint -> definition.addConstraint(constraint));
76 getExpectConstraints().forEach(constraint -> definition.addConstraint(constraint));
77 }
78
79 @Override
80 public void target(@NonNull IFlagDefinition definition) {
81 throw new IllegalStateException(
82 String.format("The targeted definition '%s' from metaschema '%s' is not a %s definition.",
83 definition.getEffectiveName(),
84 definition.getContainingModule().getQName().toString(),
85 definition.getModelType().name().toLowerCase(Locale.ROOT)));
86 }
87
88 @Override
89 public void target(@NonNull IFieldDefinition definition) {
90 throw new IllegalStateException(
91 String.format("The targeted definition '%s' from metaschema '%s' is not a %s definition.",
92 definition.getEffectiveName(),
93 definition.getContainingModule().getQName().toString(),
94 definition.getModelType().name().toLowerCase(Locale.ROOT)));
95 }
96
97 @Override
98 public void target(@NonNull IAssemblyDefinition definition) {
99 throw new IllegalStateException(
100 String.format("The targeted definition '%s' from metaschema '%s' is not a %s definition.",
101 definition.getEffectiveName(),
102 definition.getContainingModule().getQName().toString(),
103 definition.getModelType().name().toLowerCase(Locale.ROOT)));
104 }
105 }