-
Notifications
You must be signed in to change notification settings - Fork 188
/
AxiomBuiltIn.java
327 lines (263 loc) · 11.9 KB
/
AxiomBuiltIn.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
* Copyright (c) 2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.axiom.lang.api;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import com.evolveum.axiom.api.AxiomItem;
import com.evolveum.axiom.api.AxiomName;
import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition;
import com.evolveum.axiom.api.schema.AxiomItemDefinition;
import com.evolveum.axiom.api.schema.AxiomTypeDefinition;
import com.evolveum.axiom.concepts.Lazy;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
public class AxiomBuiltIn {
public static final Lazy<Map<AxiomName, AxiomItemDefinition>> EMPTY = Lazy.instant(ImmutableMap.of());
public static final Lazy<AxiomItemDefinition> NO_ARGUMENT = Lazy.nullValue();
private AxiomBuiltIn() {
throw new UnsupportedOperationException("Utility class");
}
public static class Item implements AxiomItemDefinition {
public static final Item NAME = new Item("name", Type.IDENTIFIER, true);
public static final Item ARGUMENT = new Item("argument", Type.IDENTIFIER, false);
public static final AxiomItemDefinition DOCUMENTATION = new Item("documentation", Type.STRING, true);
public static final AxiomItemDefinition NAMESPACE = new Item("namespace", Type.STRING, true);
public static final AxiomItemDefinition VERSION = new Item("version", Type.STRING, true);
public static final AxiomItemDefinition TYPE_REFERENCE = new Item("type", Type.TYPE_REFERENCE, true);
public static final AxiomItemDefinition TYPE_DEFINITION = new Item("type", Type.TYPE_DEFINITION, false);
public static final AxiomItemDefinition SUPERTYPE_REFERENCE = new Item("supertype", Type.TYPE_REFERENCE, false);
public static final Item ROOT_DEFINITION = new Item("root", Type.ROOT_DEFINITION, false);
public static final AxiomItemDefinition ITEM_DEFINITION = new Item("item", Type.ITEM_DEFINITION, false) {
@Override
public Optional<AxiomIdentifierDefinition> identifierDefinition() {
return Optional.of(NAME_IDENTIFIER.get());
}
};
public static final AxiomItemDefinition SUBSTITUTION_DEFINITION = new Item("substitution", Type.SUBSTITUTION_DEFINITION, false) {
@Override
public Optional<AxiomIdentifierDefinition> identifierDefinition() {
return Optional.of(NAME_IDENTIFIER.get());
}
};
public static final Item MODEL_DEFINITION = new Item("model", Type.MODEL, false);
public static final AxiomItemDefinition MIN_OCCURS = new Item("minOccurs", Type.STRING, false);
public static final AxiomItemDefinition MAX_OCCURS = new Item("maxOccurs", Type.STRING, false);
public static final AxiomItemDefinition ALLOWS_SUBSTITUTION= new Item("allowsSubstitution", Type.STRING, false);
public static final AxiomItemDefinition OPERATIONAL = new Item("operational", Type.IDENTIFIER, true);
public static final AxiomItemDefinition IDENTIFIER_DEFINITION = new Item("identifier", Type.IDENTIFIER_DEFINITION, true);
public static final AxiomItemDefinition ID_MEMBER = new Item("key", Type.STRING, false);
public static final AxiomItemDefinition ID_SCOPE = new Item("scope", Type.STRING, false);
public static final AxiomItemDefinition ID_SPACE = new Item("space", Type.IDENTIFIER, false);
public static final AxiomItemDefinition TARGET = new Item("target", Type.TYPE_REFERENCE, true);
public static final AxiomItemDefinition REF_TARGET = new Item("target", Type.TYPE_DEFINITION, true);
public static final AxiomItemDefinition SUBSTITUTION_OF = new Item("target", Type.IDENTIFIER, true);
public static final AxiomItemDefinition USES = new Item("include", Type.TYPE_REFERENCE, true);
public static final AxiomItemDefinition VALUE = new Item("value", null, true);
protected static final Lazy<AxiomIdentifierDefinition> NAME_IDENTIFIER = Lazy.from(
()-> (AxiomIdentifierDefinition.parent(ITEM_DEFINITION.name(), Item.NAME.name())));
private final AxiomName identifier;
private final AxiomTypeDefinition type;
private boolean required;
private Item(String identifier, AxiomTypeDefinition type, boolean required) {
this.identifier = AxiomName.axiom(identifier);
this.type = type;
this.required = required;
}
@Override
public Optional<AxiomTypeDefinition> type() {
return Optional.of(type);
}
@Override
public AxiomName name() {
return identifier;
}
@Override
public String documentation() {
return "";
}
@Override
public AxiomTypeDefinition typeDefinition() {
return type;
}
@Override
public boolean required() {
return required;
}
@Override
public int minOccurs() {
return 0;
}
@Override
public boolean operational() {
return false;
}
@Override
public int maxOccurs() {
return Integer.MAX_VALUE;
}
@Override
public String toString() {
return AxiomItemDefinition.toString(this);
}
@Override
public AxiomTypeDefinition definingType() {
return null;
}
@Override
public Optional<AxiomIdentifierDefinition> identifierDefinition() {
return Optional.empty();
}
@Override
public Map<AxiomName, AxiomItem<?>> itemMap() {
return null;
}
@Override
public Map<AxiomName, AxiomItem<?>> infraItems() {
return null;
}
}
public static class Type implements AxiomTypeDefinition {
public static final Type UUID = new Type("uuid");
public static final Type STRING = new Type("string");
public static final Type IDENTIFIER = new Type("AxiomName");
public static final Type TYPE_REFERENCE = new Type("AxiomTypeReference", null, () -> Item.NAME, () -> itemDefs(
Item.NAME,
Item.REF_TARGET
));
public static final Type BASE_DEFINITION =
new Type("AxiomBaseDefinition", null, () -> Item.NAME, () -> itemDefs(
Item.NAME,
Item.DOCUMENTATION
));
public static final Type MODEL =
new Type("AxiomModel", BASE_DEFINITION, () -> itemDefs(
Item.NAMESPACE,
Item.VERSION,
Item.TYPE_DEFINITION,
Item.ROOT_DEFINITION
));
public static final Type TYPE_DEFINITION =
new Type("AxiomTypeDefinition", BASE_DEFINITION, () -> itemDefs(
Item.ARGUMENT,
Item.SUPERTYPE_REFERENCE,
Item.ITEM_DEFINITION,
Item.SUBSTITUTION_DEFINITION
));
public static final Type ITEM_DEFINITION =
new Type("AxiomItemDefinition", BASE_DEFINITION, () -> itemDefs(
Item.TYPE_REFERENCE,
Item.IDENTIFIER_DEFINITION,
Item.ALLOWS_SUBSTITUTION,
Item.MIN_OCCURS,
Item.MAX_OCCURS,
Item.OPERATIONAL
));
public static final Type SUBSTITUTION_DEFINITION =
new Type("AxiomSubstitutionDefinition", ITEM_DEFINITION, () -> itemDefs(
Item.SUBSTITUTION_OF
));
public static final Type ROOT_DEFINITION = new Type("AxiomRootDefinition", ITEM_DEFINITION);
public static final Type IDENTIFIER_DEFINITION =
new Type("AxiomIdentifierDefinition", BASE_DEFINITION, () -> Item.ID_MEMBER, () -> itemDefs(
Item.ID_MEMBER,
Item.ID_SCOPE,
Item.ID_SPACE
));
public static final Type IMPORT_DEFINITION = new Type("AxiomImportDeclaration");
public static final Type AUGMENTATION_DEFINITION = new Type("AxiomAugmentationDefinition",TYPE_DEFINITION);
public static final Type AXIOM_VALUE = new Type("AxiomValue", null, () -> itemDefs(
Item.TYPE_REFERENCE,
Item.VALUE
));
private final AxiomName identifier;
private final AxiomTypeDefinition superType;
private final Lazy<AxiomItemDefinition> argument;
private final Lazy<Map<AxiomName, AxiomItemDefinition>> items;
private Type(String identifier) {
this(identifier, null, Lazy.nullValue(), EMPTY);
}
private Type(String identifier, Lazy.Supplier<Map<AxiomName, AxiomItemDefinition>> items) {
this(identifier, null, Lazy.nullValue(), Lazy.from(items));
}
private Type(String identifier, AxiomTypeDefinition superType) {
this(identifier, superType, NO_ARGUMENT, EMPTY);
}
private Type(String identifier, AxiomTypeDefinition superType, Lazy.Supplier<Map<AxiomName, AxiomItemDefinition>> items) {
this(identifier, superType, NO_ARGUMENT, Lazy.from(items));
}
private Type(String identifier, AxiomTypeDefinition superType, Lazy.Supplier<AxiomItemDefinition> argument,
Lazy.Supplier<Map<AxiomName, AxiomItemDefinition>> items) {
this(identifier, superType, Lazy.from(argument), Lazy.from(items));
}
private Type(String identifier, AxiomTypeDefinition superType, Lazy<AxiomItemDefinition> argument,
Lazy<Map<AxiomName, AxiomItemDefinition>> items) {
this.identifier = AxiomName.axiom(identifier);
this.argument = argument;
this.superType = superType;
this.items = items;
}
@Override
public AxiomName name() {
return identifier;
}
@Override
public String documentation() {
return "";
}
@Override
public Optional<AxiomTypeDefinition> superType() {
return Optional.ofNullable(superType);
}
@Override
public Map<AxiomName, AxiomItemDefinition> itemDefinitions() {
return items.get();
}
private static Map<AxiomName, AxiomItemDefinition> itemDefs(AxiomItemDefinition... items) {
Builder<AxiomName, AxiomItemDefinition> builder = ImmutableMap.builder();
for (AxiomItemDefinition item : items) {
builder.put(item.name(), item);
}
return builder.build();
}
@Override
public Collection<AxiomIdentifierDefinition> identifierDefinitions() {
return Collections.emptyList();
}
@Override
public Optional<AxiomItemDefinition> argument() {
if(argument.get() != null) {
return Optional.of(argument.get());
}
if(superType != null) {
return superType.argument();
}
return Optional.empty();
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "typedef " + name();
}
@Override
public Map<AxiomName, AxiomItem<?>> itemMap() {
return null;
}
@Override
public boolean isComplex() {
if(superType != null && superType.isComplex()) {
return true;
}
return !itemDefinitions().isEmpty();
}
@Override
public Map<AxiomName, AxiomItem<?>> infraItems() {
return null;
}
}
}