1
2
3
4
5
6 package gov.nist.secauto.metaschema.core.model.constraint;
7
8 import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
9 import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
10 import gov.nist.secauto.metaschema.core.metapath.IMetapathExpression;
11 import gov.nist.secauto.metaschema.core.metapath.MetapathException;
12 import gov.nist.secauto.metaschema.core.metapath.item.ISequence;
13 import gov.nist.secauto.metaschema.core.metapath.item.node.IDefinitionNodeItem;
14 import gov.nist.secauto.metaschema.core.model.IAttributable;
15 import gov.nist.secauto.metaschema.core.model.IDescribable;
16 import gov.nist.secauto.metaschema.core.model.ISource;
17 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
18
19 import edu.umd.cs.findbugs.annotations.NonNull;
20 import edu.umd.cs.findbugs.annotations.Nullable;
21
22
23
24
25
26 public interface IConstraint extends IAttributable, IDescribable {
27
28
29
30 enum Type {
31 ALLOWED_VALUES("allowed-values"),
32 CARDINALITY("cardinality"),
33 EXPECT("expect"),
34 INDEX("index"),
35 UNIQUE("unique"),
36 INDEX_HAS_KEY("index-has-key"),
37 MATCHES("matches");
38
39 @NonNull
40 private final String name;
41
42 Type(@NonNull String name) {
43 this.name = name;
44 }
45
46 @NonNull
47 public String getName() {
48 return name;
49 }
50 }
51
52
53
54
55
56
57 enum Level {
58
59
60
61 NONE,
62
63
64
65 INFORMATIONAL,
66
67
68
69
70 DEBUG,
71
72
73
74 WARNING,
75
76
77
78
79 ERROR,
80
81
82
83
84 CRITICAL;
85 }
86
87
88
89
90
91
92 @NonNull
93 static Level defaultLevel() {
94 return Level.ERROR;
95 }
96
97
98
99
100
101
102 @NonNull
103 static IMetapathExpression defaultTarget() {
104 return IMetapathExpression.contextNode();
105 }
106
107
108
109
110
111
112
113
114
115 @NonNull
116 static String getConstraintIdentity(@NonNull IConstraint constraint) {
117 String identity;
118 if (constraint.getId() != null) {
119 identity = String.format("with id '%s'", constraint.getId());
120 } else if (constraint.getFormalName() != null) {
121 identity = String.format("with the formal name '%s'", constraint.getFormalName());
122 } else {
123 identity = String.format("targeting '%s'", constraint.getTarget().getPath());
124 }
125 return ObjectUtils.notNull(identity);
126 }
127
128
129
130
131
132
133 @NonNull
134 Type getType();
135
136
137
138
139
140
141 @Nullable
142 String getId();
143
144
145
146
147
148
149 @NonNull
150 ISource getSource();
151
152
153
154
155
156
157 @NonNull
158 Level getLevel();
159
160
161
162
163
164
165
166 @NonNull
167 IMetapathExpression getTarget();
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 @NonNull
183 ISequence<? extends IDefinitionNodeItem<?, ?>> matchTargets(
184 @NonNull IDefinitionNodeItem<?, ?> item,
185 @NonNull DynamicContext dynamicContext);
186
187
188
189
190
191
192 MarkupMultiline getRemarks();
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209 <T, R> R accept(@NonNull IConstraintVisitor<T, R> visitor, T state);
210 }