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.datatype.markup.MarkupLine;
30 import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
31 import gov.nist.secauto.metaschema.core.metapath.MetapathExpression;
32 import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem;
33 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
34
35 import java.util.LinkedHashMap;
36 import java.util.Map;
37 import java.util.Set;
38
39 import javax.xml.namespace.QName;
40
41 import edu.umd.cs.findbugs.annotations.NonNull;
42 import edu.umd.cs.findbugs.annotations.Nullable;
43
44 public final class DefaultAllowedValuesConstraint
45 extends AbstractConstraint
46 implements IAllowedValuesConstraint {
47 private final boolean allowedOther;
48 @NonNull
49 private final Extensible extensible;
50 @NonNull
51 private final Map<String, DefaultAllowedValue> allowedValues;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 private DefaultAllowedValuesConstraint(
89 @Nullable String id,
90 @Nullable String formalName,
91 @Nullable MarkupLine description,
92 @NonNull ISource source,
93 @NonNull Level level,
94 @NonNull MetapathExpression target,
95 @NonNull Map<QName, Set<String>> properties,
96 @NonNull Map<String, DefaultAllowedValue> allowedValues,
97 boolean allowedOther,
98 @NonNull Extensible extensible,
99 @Nullable MarkupMultiline remarks) {
100 super(id, formalName, description, source, level, target, properties, remarks);
101 this.allowedValues = allowedValues;
102 this.allowedOther = allowedOther;
103 this.extensible = extensible;
104 }
105
106 @Override
107 public Map<String, DefaultAllowedValue> getAllowedValues() {
108 return allowedValues;
109 }
110
111 @Override
112 public boolean isAllowedOther() {
113 return allowedOther;
114 }
115
116 @Override
117 public Extensible getExtensible() {
118 return extensible;
119 }
120
121 @Override
122 public <T, R> R accept(IConstraintVisitor<T, R> visitor, T state) {
123 return visitor.visitAllowedValues(this, state);
124 }
125
126 @NonNull
127 public static Builder builder() {
128 return new Builder();
129 }
130
131 public static final class Builder
132 extends AbstractConstraintBuilder<Builder, DefaultAllowedValuesConstraint> {
133 @NonNull
134 private final Map<String, DefaultAllowedValue> allowedValues = new LinkedHashMap<>();
135 private boolean allowedOther = IAllowedValuesConstraint.DEFAULT_ALLOW_OTHER;
136 @NonNull
137 private Extensible extensible = IAllowedValuesConstraint.DEFAULT_EXTENSIBLE;
138
139 private Builder() {
140
141 }
142
143 public Builder allowedValue(@NonNull DefaultAllowedValue allowedValue) {
144 this.allowedValues.put(allowedValue.getValue(), allowedValue);
145 return this;
146 }
147
148 public Builder allowedValues(@NonNull Map<String, DefaultAllowedValue> allowedValues) {
149 this.allowedValues.putAll(allowedValues);
150 return this;
151 }
152
153 public Builder allowedOther(boolean bool) {
154 this.allowedOther = bool;
155 return this;
156 }
157
158 public Builder extensible(@NonNull Extensible extensible) {
159 this.extensible = extensible;
160 return this;
161 }
162
163 @Override
164 protected Builder getThis() {
165 return this;
166 }
167
168 @NonNull
169 protected Map<String, DefaultAllowedValue> getAllowedValues() {
170 return allowedValues;
171 }
172
173 protected boolean isAllowedOther() {
174 return allowedOther;
175 }
176
177 @NonNull
178 protected Extensible getExtensible() {
179 return extensible;
180 }
181
182 @Override
183 protected DefaultAllowedValuesConstraint newInstance() {
184 return new DefaultAllowedValuesConstraint(
185 getId(),
186 getFormalName(),
187 getDescription(),
188 ObjectUtils.notNull(getSource()),
189 getLevel(),
190 getTarget(),
191 getProperties(),
192 getAllowedValues(),
193 isAllowedOther(),
194 getExtensible(),
195 getRemarks());
196 }
197 }
198 }