-
Notifications
You must be signed in to change notification settings - Fork 188
/
AxiomBuiltIn.java
189 lines (153 loc) · 7.19 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
/*
* 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.Map;
import java.util.Optional;
import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.concepts.Lazy;
import com.evolveum.axiom.concepts.Lazy.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
public class AxiomBuiltIn {
public static final Lazy<Map<AxiomIdentifier, 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 AxiomItemDefinition NAME = new Item("name", Type.IDENTIFIER, true);
public static final AxiomItemDefinition IDENTIFIER = new Item("identifier", Type.IDENTIFIER, true);
public static final AxiomItemDefinition 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("extends", Type.TYPE_REFERENCE, false);
public static final AxiomItemDefinition ROOT_DEFINITION = new Item("root", Type.ITEM_DEFINITION, false);
public static final AxiomItemDefinition ITEM_DEFINITION = new Item("item", Type.ITEM_DEFINITION, false);
public static final AxiomItemDefinition 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 TARGET_TYPE = new Item("targetType", Type.IDENTIFIER, true);
private final AxiomIdentifier identifier;
private final AxiomTypeDefinition type;
private boolean required;
private Item(String identifier, AxiomTypeDefinition type, boolean required) {
this.identifier = AxiomIdentifier.axiom(identifier);
this.type = type;
this.required = required;
}
@Override
public AxiomIdentifier name() {
return identifier;
}
@Override
public String documentation() {
return "";
}
@Override
public AxiomTypeDefinition type() {
return type;
}
@Override
public boolean required() {
return required;
}
@Override
public String toString() {
return AxiomItemDefinition.toString(this);
}
}
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("AxiomIdentifier");
public static final Type TYPE_REFERENCE = new Type("AxiomTypeReference");
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
));
public static final Type ITEM_DEFINITION =
new Type("AxiomItemDefinition", BASE_DEFINITION, () -> itemDefs(
Item.TYPE_REFERENCE,
Item.MIN_OCCURS,
Item.MAX_OCCURS
));
private final AxiomIdentifier identifier;
private final AxiomTypeDefinition superType;
private final Lazy<AxiomItemDefinition> argument;
private final Lazy<Map<AxiomIdentifier, AxiomItemDefinition>> items;
private Type(String identifier) {
this(identifier, null, Lazy.nullValue(), EMPTY);
}
private Type(String identifier, Lazy.Supplier<Map<AxiomIdentifier, AxiomItemDefinition>> items) {
this(identifier, null, Lazy.nullValue(), Lazy.from(items));
}
private Type(String identifier, AxiomTypeDefinition superType, Lazy.Supplier<Map<AxiomIdentifier, AxiomItemDefinition>> items) {
this(identifier, superType, NO_ARGUMENT, Lazy.from(items));
}
private Type(String identifier, AxiomTypeDefinition superType, Lazy.Supplier<AxiomItemDefinition> argument,
Lazy.Supplier<Map<AxiomIdentifier, AxiomItemDefinition>> items) {
this(identifier, superType, Lazy.from(argument), Lazy.from(items));
}
private Type(String identifier, AxiomTypeDefinition superType, Lazy<AxiomItemDefinition> argument,
Lazy<Map<AxiomIdentifier, AxiomItemDefinition>> items) {
this.identifier = AxiomIdentifier.axiom(identifier);
this.argument = argument;
this.superType = superType;
this.items = items;
}
@Override
public AxiomIdentifier name() {
return identifier;
}
@Override
public String documentation() {
return "";
}
@Override
public Optional<AxiomTypeDefinition> superType() {
return Optional.ofNullable(superType);
}
@Override
public Map<AxiomIdentifier, AxiomItemDefinition> items() {
return items.get();
}
private static Map<AxiomIdentifier, AxiomItemDefinition> itemDefs(AxiomItemDefinition... items) {
Builder<AxiomIdentifier, AxiomItemDefinition> builder = ImmutableMap.builder();
for (AxiomItemDefinition item : items) {
builder.put(item.name(), item);
}
return builder.build();
}
@Override
public Optional<AxiomItemDefinition> argument() {
if(argument.get() != null) {
return Optional.of(argument.get());
}
if(superType != null) {
return superType.argument();
}
return Optional.empty();
}
}
}