1
2
3
4
5
6 package gov.nist.secauto.metaschema.core.model.constraint;
7
8 import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
9 import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
10 import gov.nist.secauto.metaschema.core.model.constraint.impl.DefaultExpectConstraint;
11 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
12
13 import edu.umd.cs.findbugs.annotations.NonNull;
14
15
16
17
18
19
20
21 public interface IExpectConstraint extends IConstraint {
22
23
24
25
26
27 @NonNull
28 String getTest();
29
30
31
32
33
34
35
36 String getMessage();
37
38
39
40
41
42
43
44
45
46
47
48 String generateMessage(@NonNull INodeItem item, @NonNull DynamicContext context);
49
50 @Override
51 default <T, R> R accept(IConstraintVisitor<T, R> visitor, T state) {
52 return visitor.visitExpectConstraint(this, state);
53 }
54
55
56
57
58
59
60 @NonNull
61 static Builder builder() {
62 return new Builder();
63 }
64
65 final class Builder
66 extends AbstractConstraintBuilder<Builder, IExpectConstraint> {
67 private String test;
68 private String message;
69
70 private Builder() {
71
72 }
73
74
75
76
77
78
79
80
81 @NonNull
82 public Builder test(@NonNull String test) {
83 this.test = test;
84 return this;
85 }
86
87
88
89
90
91
92
93
94
95 @NonNull
96 public Builder message(@NonNull String message) {
97 this.message = message;
98 return this;
99 }
100
101 @Override
102 protected Builder getThis() {
103 return this;
104 }
105
106 @Override
107 protected void validate() {
108 super.validate();
109
110 ObjectUtils.requireNonNull(getTest());
111 }
112
113 private String getTest() {
114 return test;
115 }
116
117 private String getMessage() {
118 return message;
119 }
120
121 @Override
122 protected IExpectConstraint newInstance() {
123 return new DefaultExpectConstraint(
124 getId(),
125 getFormalName(),
126 getDescription(),
127 ObjectUtils.notNull(getSource()),
128 getLevel(),
129 getTarget(),
130 getProperties(),
131 ObjectUtils.requireNonNull(getTest()),
132 getMessage(),
133 getRemarks());
134 }
135 }
136 }