From 7da830879a85c11791460143694300b0efb8083c Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 18 May 2020 17:07:58 +0200 Subject: [PATCH 01/60] Axiom: added support for imports & model isolation Added support for import namespace & namespace keywords which allow for importing type definitions from other models using fully qualified names. Signed-off-by: Tony Tkacik --- .../evolveum/axiom/api/AxiomIdentifier.java | 4 +- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 1 + .../evolveum/axiom/lang/api/AxiomModel.java | 6 + .../axiom/lang/impl/AxiomAntlrVisitor.java | 38 +-- .../lang/impl/AxiomIdentifierResolver.java | 22 +- .../axiom/lang/impl/AxiomStatementSource.java | 46 +++- .../lang/impl/AxiomTypeDefinitionImpl.java | 2 +- .../axiom/lang/impl/BasicStatementRule.java | 49 +++- .../lang/impl/CompositeIdentifierSpace.java | 40 +++ .../lang/impl/IdentifierSpaceHolder.java | 17 ++ .../lang/impl/IdentifierSpaceHolderImpl.java | 63 +++++ .../axiom/lang/impl/ModelReactorContext.java | 102 ++++---- .../axiom/lang/impl/NamespaceContext.java | 5 + .../evolveum/axiom/lang/impl/Requirement.java | 44 +++- .../axiom/lang/impl/StatementContext.java | 7 +- .../axiom/lang/impl/StatementContextImpl.java | 228 ++++++++++++++---- .../axiom/lang/impl/StatementRuleContext.java | 5 +- .../lang/impl/StatementRuleContextImpl.java | 46 +++- .../resources/axiom-base-types.axiom | 6 +- .../axiom/src/main/resources/axiom-lang.axiom | 15 +- .../axiom/lang/test/AbstractReactorTest.java | 40 +++ .../axiom/lang/test/TestAxiomMultimodule.java | 66 +++++ .../axiom/lang/test/TestAxiomParser.java | 32 +-- .../resources/multimodule/foaf-person.axiom | 17 ++ .../multimodule/schema-org-person.axiom | 19 ++ .../resources/multimodule/test-person.axiom | 23 ++ .../multimodule/test-person.axiom.invalid | 23 ++ 27 files changed, 800 insertions(+), 166 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/NamespaceContext.java rename infra/axiom/src/{test => main}/resources/axiom-base-types.axiom (83%) create mode 100644 infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java create mode 100644 infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java create mode 100644 infra/axiom/src/test/resources/multimodule/foaf-person.axiom create mode 100644 infra/axiom/src/test/resources/multimodule/schema-org-person.axiom create mode 100644 infra/axiom/src/test/resources/multimodule/test-person.axiom create mode 100644 infra/axiom/src/test/resources/multimodule/test-person.axiom.invalid diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java index 8af5ae6caba..f878f024c1a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java @@ -12,7 +12,7 @@ public class AxiomIdentifier { - public static final String AXIOM_NAMESPACE = "https://ns.evolveum.com/axiom"; + public static final String AXIOM_NAMESPACE = "https://ns.evolveum.com/axiom/language"; private final String namespace; private final String localName; @@ -60,7 +60,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return localName; + return "(" + namespace + ")" +localName; } public static AxiomIdentifier axiom(String identifier) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index f76845e020a..84ea9160a93 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -181,6 +181,7 @@ public Collection identifiers() { Item.ID_SCOPE, Item.ID_SPACE )); + public static final Type IMPORT_DEFINITION = new Type("AxiomImportDeclaration"); private final AxiomIdentifier identifier; private final AxiomTypeDefinition superType; private final Lazy argument; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java index be093c92b43..fb7da6f0a06 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java @@ -1,5 +1,11 @@ package com.evolveum.axiom.lang.api; +import com.evolveum.axiom.api.AxiomIdentifier; + public interface AxiomModel { + AxiomIdentifier NAMESPACE = AxiomIdentifier.axiom("namespace"); + AxiomIdentifier IMPORTED_NAMESPACE = AxiomIdentifier.axiom("ImportedNamespace"); + String BUILTIN_TYPES = "https://ns.evolveum.com/axiom/language"; + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java index fa6dc8b4e99..24db22ec6ca 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java @@ -28,14 +28,16 @@ public class AxiomAntlrVisitor extends AxiomBaseVisitor { private final AxiomIdentifierResolver statements; + private final AxiomIdentifierResolver arguments; private final AxiomStatementStreamListener delegate; private final Optional> limit; private final String sourceName; - public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomStatementStreamListener delegate, + public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomStatementStreamListener delegate, Set limit) { this.sourceName = name; this.statements = statements; + this.arguments = arguments; this.delegate = delegate; this.limit = Optional.ofNullable(limit); } @@ -43,7 +45,7 @@ public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomS private AxiomIdentifier statementIdentifier(IdentifierContext identifier) { String prefix = nullableText(identifier.prefix()); String localName = identifier.localIdentifier().getText(); - return statements.resolveStatementIdentifier(prefix, localName); + return statements.resolveIdentifier(prefix, localName); } private String nullableText(ParserRuleContext prefix) { @@ -80,19 +82,17 @@ public T visitArgument(ArgumentContext ctx) { } private AxiomIdentifier convert(IdentifierContext argument) { - return statementIdentifier(argument); + return argumentIdentifier(argument); } - private String convert(StringContext string) { - if(string.singleQuoteString() != null) { - return convertSingleQuote(string.singleQuoteString().getText()); - } - if(string.doubleQuoteString() != null) { - return covertDoubleQuote(string.doubleQuoteString().getText()); - } - return convertMultiline(string.multilineString().getText()); + private AxiomIdentifier argumentIdentifier(IdentifierContext identifier) { + String prefix = nullableText(identifier.prefix()); + String localName = identifier.localIdentifier().getText(); + return arguments.resolveIdentifier(prefix, localName); } + + private int sourceLine(ParserRuleContext node) { return node.start.getLine(); } @@ -101,17 +101,27 @@ private SourceLocation sourceLocation(Token start) { return SourceLocation.from(sourceName, start.getLine(), start.getCharPositionInLine()); } - private String convertSingleQuote(String text) { + static String convert(StringContext string) { + if(string.singleQuoteString() != null) { + return convertSingleQuote(string.singleQuoteString().getText()); + } + if(string.doubleQuoteString() != null) { + return covertDoubleQuote(string.doubleQuoteString().getText()); + } + return convertMultiline(string.multilineString().getText()); + } + + private static String convertSingleQuote(String text) { int stop = text.length(); return text.substring(1, stop - 1); } - private String covertDoubleQuote(String text) { + private static String covertDoubleQuote(String text) { int stop = text.length(); return text.substring(1, stop - 1); } - private String convertMultiline(String text) { + private static String convertMultiline(String text) { return text.replace("\"\"\"", ""); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomIdentifierResolver.java index 89650a2cdeb..5fe918220d3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomIdentifierResolver.java @@ -6,20 +6,40 @@ */ package com.evolveum.axiom.lang.impl; +import java.util.Set; + import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; +import com.google.common.collect.ImmutableSet; import org.jetbrains.annotations.Nullable; public interface AxiomIdentifierResolver { final AxiomIdentifierResolver AXIOM_DEFAULT_NAMESPACE = defaultNamespace(AxiomIdentifier.AXIOM_NAMESPACE); + final Set BUILTINS = ImmutableSet.of("string","boolean","uri", "int", "binary", "dateTime"); + final AxiomIdentifierResolver BUILTIN_TYPES = (prefix, localName) -> { + if((prefix == null || prefix.isEmpty()) && BUILTINS.contains(localName)) { + return AxiomIdentifier.axiom(localName); + } + return null; + }; - AxiomIdentifier resolveStatementIdentifier(@Nullable String prefix, @NotNull String localName); + AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName); static AxiomIdentifierResolver defaultNamespace(String namespace) { return (prefix, localName) -> prefix == null ? AxiomIdentifier.from(namespace, localName) : null; } + default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { + return (prefix, localName) -> { + AxiomIdentifier maybe = this.resolveIdentifier(prefix, localName); + if (maybe != null) { + return maybe; + } + return next.resolveIdentifier(prefix, localName); + }; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java index f7c3339dfb1..b689eec3a23 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java @@ -9,6 +9,8 @@ import java.beans.Statement; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import java.util.Set; @@ -17,6 +19,8 @@ import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.TokenStream; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.antlr.AxiomLexer; @@ -24,10 +28,13 @@ import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; -public class AxiomStatementSource implements AxiomModelInfo { +public class AxiomStatementSource implements AxiomModelInfo, AxiomIdentifierResolver { + private static final String IMPORT = "import"; + private static final String NAMESPACE = "namespace"; private final StatementContext root; private String sourceName; + private Map imports; public static AxiomStatementSource from(InputStream stream) throws IOException, AxiomSyntaxException { return from(null, CharStreams.fromStream(stream)); @@ -48,12 +55,13 @@ public static AxiomStatementSource from(String sourceName, CharStream stream) th parser.addErrorListener(errorListener); StatementContext statement = parser.statement(); errorListener.validate(); - return new AxiomStatementSource(sourceName, statement); + return new AxiomStatementSource(sourceName, statement, imports(statement)); } - private AxiomStatementSource(String sourceName, StatementContext statement) { + private AxiomStatementSource(String sourceName, StatementContext statement, Map imports) { this.sourceName = sourceName; this.root = statement; + this.imports = imports; } @Override @@ -63,7 +71,6 @@ public String getModelName() { @Override public String getNamespace() { - // TODO Auto-generated method stub return null; } @@ -79,7 +86,36 @@ public void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListene private void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListener listener, Optional> emitOnly) { - AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, resolver, listener, emitOnly.orElse(null)); + AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, resolver, BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly.orElse(null)); visitor.visit(root); } + + public static Map imports(AxiomParser.StatementContext root) { + Map prefixMap = new HashMap<>(); + root.statement().stream().filter(s -> IMPORT.equals(s.identifier().getText())).forEach(c -> { + String prefix = c.argument().identifier().localIdentifier().getText(); + String namespace = namespace(c); + prefixMap.put(prefix, namespace); + }); + prefixMap.put("",namespace(root)); + return prefixMap; + } + + private static String namespace(StatementContext c) { + return AxiomAntlrVisitor.convert(c.statement() + .stream().filter(s -> NAMESPACE.equals(s.identifier().getText())) + .findFirst().get().argument().string()); + } + + @Override + public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName) { + if(prefix == null) { + prefix = ""; + } + String maybeNs = imports.get(prefix); + if(maybeNs != null) { + return AxiomIdentifier.from(maybeNs, localName); + } + return null; + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java index 2ab7885138e..1b2b782dc63 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java @@ -46,7 +46,7 @@ public AxiomTypeDefinitionImpl(AxiomIdentifier keyword, AxiomIdentifier value, L Set members = idDef.children(Item.ID_MEMBER.name()).stream() .map(k -> item((AxiomIdentifier) k.value()).get()).collect(Collectors.toSet()); AxiomIdentifier space = idDef.firstValue(ID_SPACE.name(), AxiomIdentifier.class).get(); - AxiomIdentifierDefinition.Scope scope = AxiomIdentifierDefinition.scope(idDef.firstValue(ID_SCOPE.name(), Object.class).get().toString()); + AxiomIdentifierDefinition.Scope scope = AxiomIdentifierDefinition.scope(idDef.firstValue(ID_SCOPE.name(), AxiomIdentifier.class).get().getLocalName()); return AxiomIdentifierDefinition.from(space, scope, members); }).collect(Collectors.toList()); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 9e140c1e450..23ef4c4536f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -10,6 +10,7 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomModel; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; @@ -55,6 +56,45 @@ public void apply(StatementRuleContext rule) throws AxiomSemant }); } } + }, + IMPORT_DEFAULT_TYPES(all(), types(Type.MODEL)) { + + @Override + public void apply(StatementRuleContext rule) throws AxiomSemanticException { + Requirement req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES)); + req.unsatisfiedMessage(() -> rule.error("Default types not found.")); + rule.apply((ctx) -> { + ctx.parent().importIdentifierSpace(req.get()); + }); + } + }, + EXPORT_GLOBALS_FROM_MODEL(all(), types(Type.MODEL)) { + + @Override + public void apply(StatementRuleContext rule) throws AxiomSemanticException { + String namespace = rule.requiredChildValue(Item.NAMESPACE, String.class); + rule.apply(ctx -> { + ctx.exportIdentifierSpace(namespaceId(namespace)); + }); + } + }, + IMPORT_MODEL(all(),types(Type.IMPORT_DEFINITION)) { + + @Override + public void apply(StatementRuleContext rule) throws AxiomSemanticException { + String child = rule.requiredChildValue(Item.NAMESPACE, String.class); + AxiomIdentifier namespaceId = Item.NAMESPACE.name(); + Requirement req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(child)); + req.unsatisfiedMessage(() -> rule.error("Namespace %s not found.", child)); + rule.apply((ctx) -> { + ctx.parent().importIdentifierSpace(req.get()); + }); + + } + + + + }, /* * Not needed - registration is handled by identifier statement @@ -71,11 +111,12 @@ public void apply(StatementRuleContext rule) throws AxiomSemant @Override public void apply(StatementRuleContext rule) throws AxiomSemanticException { AxiomIdentifier type = rule.requireValue(); - Requirement> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); + Requirement.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); + typeDef.notFound(() -> rule.error("type '%s' was not found.", type)); + typeDef.unsatisfiedMessage(() -> rule.error("Referenced type %s is not complete.", type)); rule.apply(ctx -> { ctx.replace(typeDef); }); - rule.errorMessage(() -> rule.error("type '%s' was not found.", type)); } }; /* @@ -142,4 +183,8 @@ private static ImmutableSet items(AxiomItemDefinition... items) private static ImmutableSet all() { return ImmutableSet.of(); } + + private static IdentifierSpaceKey namespaceId(String uri) { + return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java new file mode 100644 index 00000000000..d36ccd83493 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java @@ -0,0 +1,40 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; + +public class CompositeIdentifierSpace implements IdentifierSpaceHolder, NamespaceContext { + + private final Set delegates = new HashSet<>(); + + @Override + public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + for (IdentifierSpaceHolder delegate : delegates) { + StatementContextImpl maybe = delegate.lookup(space, key); + if(maybe != null) { + return maybe; + } + } + return null; + } + + @Override + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl context) { + throw new UnsupportedOperationException(); + } + + @Override + public Map> space(AxiomIdentifier space) { + throw new UnsupportedOperationException(); + } + + public void add(IdentifierSpaceHolder holder) { + delegates.add(holder); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java new file mode 100644 index 00000000000..3ccc9e65a13 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java @@ -0,0 +1,17 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.Map; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.api.stmt.AxiomStatement; + +interface IdentifierSpaceHolder { + + void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl context); + + public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key); + + Map> space(AxiomIdentifier space); +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java new file mode 100644 index 00000000000..906f8e6b0f9 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -0,0 +1,63 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMap; + +public class IdentifierSpaceHolderImpl implements IdentifierSpaceHolder { + + Set allowedScopes; + Map>> space = new HashMap<>(); + + public IdentifierSpaceHolderImpl(Scope first, Scope... rest) { + allowedScopes = EnumSet.of(first, rest); + } + + @Override + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl item) { + Preconditions.checkArgument(allowedScopes.contains(scope), "Scope " + scope + " is not allowed");// TODO + // Auto-generated + // method stub + StatementContextImpl previous = space(space).putIfAbsent(key, item); + if (previous != null) { + throw new AxiomSemanticException(item.startLocation() + + Strings.lenientFormat("%s identifier space: Item %s is already defined at %s", space, + item.optionalValue().get(), previous.startLocation())); + } + } + + @Override + public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + return space(space).get(key); + } + + @Override + public Map> space(AxiomIdentifier spaceId) { + return space.computeIfAbsent(spaceId, k -> new HashMap<>()); + } + + Map>> build() { + ImmutableMap.Builder>> roots = ImmutableMap + .builder(); + for (Entry>> entry : space.entrySet()) { + ImmutableMap.Builder> space = ImmutableMap.builder(); + for (Entry> item : entry.getValue().entrySet()) { + space.put(item.getKey(), item.getValue().asLazy().get()); + } + roots.put(entry.getKey(), space.build()); + + } + return roots.build(); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 624177ca445..09bd476ef97 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -1,35 +1,27 @@ package com.evolveum.axiom.lang.impl; -import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; -import java.util.function.Supplier; - -import javax.management.RuntimeErrorException; import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMap; + import org.jetbrains.annotations.Nullable; @@ -38,6 +30,7 @@ public class ModelReactorContext implements AxiomIdentifierResolver { private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); private static final String AXIOM_LANG_RESOURCE = "/axiom-lang.axiom"; + private static final String AXIOM_BUILTIN_RESOURCE = "/axiom-base-types.axiom"; private static final Lazy BASE_LANGUAGE_SOURCE = Lazy.from(() -> { InputStream stream = AxiomBuiltIn.class.getResourceAsStream(AXIOM_LANG_RESOURCE); @@ -48,6 +41,15 @@ public class ModelReactorContext implements AxiomIdentifierResolver { } }); + private static final Lazy BASE_TYPES_SOURCE = Lazy.from(() -> { + InputStream stream = AxiomBuiltIn.class.getResourceAsStream(AXIOM_BUILTIN_RESOURCE); + try { + return AxiomStatementSource.from(AXIOM_BUILTIN_RESOURCE, stream); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + public static final Lazy BASE_LANGUAGE = Lazy.from(() -> { ModelReactorContext reactor = boostrapReactor(); return reactor.computeSchemaContext(); @@ -75,24 +77,29 @@ private static void defaults(ModelReactorContext reactorContext) { reactorContext.addStatementFactory(Type.TYPE_DEFINITION.name(), AxiomTypeDefinitionImpl.FACTORY); reactorContext.addStatementFactory(Type.ITEM_DEFINITION.name(), AxiomItemDefinitionImpl.FACTORY); reactorContext.loadModelFromSource(BASE_LANGUAGE_SOURCE.get()); + reactorContext.loadModelFromSource(BASE_TYPES_SOURCE.get()); + } List> rules = new ArrayList<>(); private final AxiomSchemaContext boostrapContext; + private final Map exported = new HashMap<>(); + - public ModelReactorContext(AxiomSchemaContext boostrapContext) { - this.boostrapContext = boostrapContext; - } Map> globalItems = new HashMap<>(); - Map>> globalSpace = new HashMap<>(); + IdentifierSpaceHolderImpl globalSpace = new IdentifierSpaceHolderImpl(Scope.GLOBAL); Map> typeFactories = new HashMap<>(); List outstanding = new ArrayList<>(); List> roots = new ArrayList<>(); + public ModelReactorContext(AxiomSchemaContext boostrapContext) { + this.boostrapContext = boostrapContext; + } + public AxiomSchemaContext computeSchemaContext() throws AxiomSemanticException { boolean anyCompleted = false; do { @@ -103,10 +110,12 @@ public AxiomSchemaContext computeSchemaContext() throws AxiomSemanticException { Iterator iterator = toCheck.iterator(); while (iterator.hasNext()) { StatementRuleContextImpl ruleCtx = iterator.next(); - if (ruleCtx.canProcess()) { + if (ruleCtx.canProcess() && ruleCtx.notFailed()) { ruleCtx.perform(); - iterator.remove(); - anyCompleted = true; + if(ruleCtx.successful()) { + iterator.remove(); + anyCompleted = true; + } } } // We add not finished items back to outstanding @@ -122,10 +131,15 @@ public AxiomSchemaContext computeSchemaContext() throws AxiomSemanticException { private void failOutstanding(List report) { StringBuilder messages = new StringBuilder("Can not complete models, following errors occured:\n"); - for (StatementRuleContextImpl rule : report) { + for (StatementRuleContextImpl rule : report) { RuleErrorMessage exception = rule.errorMessage(); if (exception != null) { messages.append(exception.toString()).append("\n"); + } + for (Requirement req : rule.requirements()) { + if(!req.isSatisfied()) { + messages.append(req.errorMessage()).append("\n"); + } } } @@ -134,44 +148,18 @@ private void failOutstanding(List report) { } private AxiomSchemaContext createSchemaContext() { - ImmutableMap.Builder>> roots = ImmutableMap.builder(); - for (Entry>> entry: globalSpace.entrySet()) { - ImmutableMap.Builder> space = ImmutableMap.builder(); - for (Entry> item : entry.getValue().entrySet()) { - space.put(item.getKey(), item.getValue().asLazy().get()); - } - roots.put(entry.getKey(), space.build()); - - } - return new AxiomSchemaContextImpl(roots.build()); - + return new AxiomSchemaContextImpl(globalSpace.build()); } - public void registerGlobalItem(AxiomIdentifier typeName, StatementContextImpl context) { - globalItems.put(typeName, context); - } + public IdentifierSpaceHolderImpl space() { + return globalSpace; + } public void registerGlobal(AxiomIdentifier space, IdentifierSpaceKey key, StatementContextImpl item) { - StatementContextImpl previous = globalSpace(space).putIfAbsent(key, item); - if(previous != null) { - throw new AxiomSemanticException(item.startLocation() + Strings.lenientFormat("Item %s in %s identifier space is already defined at %s", item.optionalValue(), space, previous.startLocation())); - } - } - private Map> globalSpace(AxiomIdentifier spaceId) { - return globalSpace.computeIfAbsent(spaceId, k -> new HashMap<>()); } - public Requirement> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key) { - return (Requirement) Requirement.retriableDelegate(() -> { - StatementContextImpl maybeCtx = globalSpace(space).get(key); - if (maybeCtx != null) { - return maybeCtx.asRequirement(); - } - return null; - }); - } public void addOutstanding(StatementRuleContextImpl rule) { outstanding.add(rule); @@ -199,7 +187,7 @@ public void loadModelFromSource(AxiomStatementSource statementSource) { } @Override - public AxiomIdentifier resolveStatementIdentifier(@Nullable String prefix, @NotNull String localName) { + public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName) { return AxiomIdentifier.axiom(localName); } @@ -217,7 +205,7 @@ public Optional childDef(AxiomIdentifier statement) { @Override public StatementTreeBuilder createChildNode(AxiomIdentifier identifier, SourceLocation loc) { - StatementContextImpl ret = new StatementContextImpl<>(ModelReactorContext.this, null, + StatementContextImpl ret = new StatementContextImpl.Root<>(ModelReactorContext.this, childDef(identifier).get(), loc); roots.add(ret); return ret; @@ -250,4 +238,18 @@ public void addStatementFactory(AxiomIdentifier statementType, Factory fac return (Factory) AxiomStatementImpl.factory(); } + + public void exportIdentifierSpace(IdentifierSpaceKey namespace, IdentifierSpaceHolder localSpace) { + exported(namespace).add(localSpace); + } + + private CompositeIdentifierSpace exported(IdentifierSpaceKey namespace) { + return exported.computeIfAbsent(namespace, k -> new CompositeIdentifierSpace()); + } + + public Requirement namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return Requirement.orNull(exported.get(namespaceId)); + } + + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/NamespaceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/NamespaceContext.java new file mode 100644 index 00000000000..3b9ce951c7c --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/NamespaceContext.java @@ -0,0 +1,5 @@ +package com.evolveum.axiom.lang.impl; + +public interface NamespaceContext { + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java index d0fedce26e7..478fa9becb4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java @@ -28,6 +28,19 @@ public static Requirement from(Supplier supplier) { return new Suppliable<>(supplier); } + default Requirement unsatisfiedMessage(Supplier unsatisfiedMessage) { + return this; + } + + interface Search extends Requirement { + + default Requirement.Search notFound(Supplier unsatisfiedMessage) { + return this; + } + + } + + public static abstract class Abstract implements Requirement { @@ -121,9 +134,10 @@ public T get() { } } - public final class RetriableDelegate extends Delegated { + public final class RetriableDelegate extends Delegated implements Search { - Object maybeDelegate; + private Object maybeDelegate; + private Supplier notFound; public RetriableDelegate(Supplier> lookup) { maybeDelegate = lookup; @@ -145,19 +159,37 @@ Requirement delegate() { return unsatisfied(); } + @Override + public Search notFound(Supplier unsatisfiedMessage) { + notFound = unsatisfiedMessage; + return this; + } + + @Override + public RuleErrorMessage errorMessage() { + if(maybeDelegate instanceof Supplier && notFound != null) { + return notFound.get(); + } + // TODO Auto-generated method stub + return super.errorMessage(); + } + } - static Requirement retriableDelegate(Supplier> lookup) { + static Search retriableDelegate(Supplier> lookup) { return new RetriableDelegate(lookup); } - default Requirement unsatisfiedMessage(Supplier unsatisfiedMessage) { - return this; - } static Requirement from(Optional maybe) { if(maybe.isPresent()) { return immediate(maybe.get()); } return unsatisfied(); } + static Requirement orNull(T value) { + if(value != null) { + return immediate(value); + } + return null; + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java index bb3f92e0686..29c95e8a99c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java @@ -16,8 +16,6 @@ public interface StatementContext { AxiomItemDefinition definition(); - void registerAsGlobalItem(AxiomIdentifier typeName) throws AxiomSemanticException; - StatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value); Optional optionalValue(); @@ -30,4 +28,9 @@ public interface StatementContext { V requireValue(Class type); + + void importIdentifierSpace(NamespaceContext namespaceContext); + + void exportIdentifierSpace(IdentifierSpaceKey namespace); + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 103d4075323..21045a29827 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -1,15 +1,16 @@ package com.evolveum.axiom.lang.impl; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; +import java.util.Set; import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.concepts.Optionals; -import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; @@ -17,20 +18,12 @@ import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; -import com.evolveum.axiom.lang.impl.StatementRuleContext.Action; -import com.google.common.base.Preconditions; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; -import com.google.common.collect.Multimap; -public class StatementContextImpl implements StatementContext, StatementTreeBuilder { +public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { - - - private final ModelReactorContext reactor; private final AxiomItemDefinition definition; - private final StatementContextImpl parent; + + private final IdentifierSpaceHolder localSpace; private SourceLocation startLocation; private SourceLocation endLocation; @@ -38,15 +31,22 @@ public class StatementContextImpl implements StatementContext, StatementTr private Requirement> result; - StatementContextImpl(ModelReactorContext reactor, StatementContextImpl parent, AxiomItemDefinition definition, SourceLocation loc) { - this.parent = parent; - this.reactor = reactor; + StatementContextImpl(AxiomItemDefinition definition, SourceLocation loc, Scope scope, Scope... rest) { this.definition = definition; this.startLocation = loc; - AxiomStatementBuilder builder = new AxiomStatementBuilder<>(definition.name(), reactor.typeFactory(definition.type())); + this.localSpace = new IdentifierSpaceHolderImpl(scope, rest); + } + + + protected void initResult() { + AxiomStatementBuilder builder = new AxiomStatementBuilder<>(definition.name(), typeFactory(definition.type())); this.result = new StatementContextResult<>(definition, builder); } + protected Factory> typeFactory(AxiomTypeDefinition type) { + return parent().typeFactory(type); + } + @Override public void setValue(Object value) { mutableResult().setValue((V) value); @@ -67,11 +67,15 @@ boolean isChildAllowed(AxiomIdentifier child) { @SuppressWarnings("rawtypes") @Override public StatementContextImpl createChildNode(AxiomIdentifier identifier, SourceLocation loc) { - StatementContextImpl childCtx = new StatementContextImpl(reactor, this, childDef(identifier).get(), loc); + StatementContextImpl childCtx = new StatementContextImpl.Child(this, childDef(identifier).get(), loc); mutableResult().add(childCtx); return childCtx; } + public IdentifierSpaceHolder localSpace() { + return localSpace; + } + @Override public String toString() { return "Context(" + definition.name() + ")"; @@ -97,12 +101,6 @@ public AxiomItemDefinition definition() { return definition; } - @Override - public void registerAsGlobalItem(AxiomIdentifier typeName) throws AxiomSemanticException { - reactor.registerGlobalItem(typeName, this); - } - - @Override public StatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value) { StatementContextImpl child = createChildNode(axiomIdentifier, null); @@ -113,15 +111,15 @@ public StatementContext createEffectiveChild(AxiomIdentifier axiomIdentif public void registerRule(StatementRuleContextImpl rule) { mutableResult().addRule(rule); - this.reactor.addOutstanding(rule); + addOutstanding(rule); } - public SourceLocation startLocation() { - return startLocation; + protected void addOutstanding(StatementRuleContextImpl rule) { + parent().addOutstanding(rule); } - ModelReactorContext reactor() { - return reactor; + public SourceLocation startLocation() { + return startLocation; } public Optional> firstChild(AxiomItemDefinition child) { @@ -147,9 +145,7 @@ public void replace(Requirement> supplier) { } @Override - public StatementContext parent() { - return parent; - } + abstract public StatementContextImpl parent(); @Override public void setValue(Object value, SourceLocation loc) { @@ -175,25 +171,43 @@ public boolean isSatisfied() { @Override public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key) { + register(space, scope, key, this); + } + + @Override + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl context) { switch (scope) { - case GLOBAL: - registerGlobal(space, key); - break; - case LOCAL: - registerLocalParent(space, key); - break; + case GLOBAL: + parentNs().register(space, scope, key, context); + break; + case LOCAL: + localSpace.register(space, scope, key, context); + break; default: - throw new IllegalStateException("Unsupporrted scope"); + throw new IllegalStateException("Unsupported scope"); } } - private void registerLocalParent(AxiomIdentifier space, IdentifierSpaceKey key) { - // TODO Auto-generated method stub + abstract IdentifierSpaceHolder parentNs(); + + @Override + public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + StatementContextImpl maybe = localSpace.lookup(space, key); + if(maybe != null) { + return maybe; + } + return parentNs().lookup(space, key); } - private void registerGlobal(AxiomIdentifier space, IdentifierSpaceKey key) { - reactor.registerGlobal(space, key, this); + @Override + public Map> space(AxiomIdentifier space) { + return localSpace.space(space); + } + + private void registerLocalParent(AxiomIdentifier space, IdentifierSpaceKey key) { + // TODO Auto-generated method stub + } @Override @@ -215,4 +229,130 @@ public Requirement> requireChild(AxiomItemDefinition required) }); } + protected IdentifierSpaceHolder exports() { + throw new IllegalStateException("Statement does not provide exports"); + } + + static class Child extends StatementContextImpl { + + private StatementContextImpl parent; + + public Child(StatementContextImpl parent, AxiomItemDefinition definition, SourceLocation loc) { + super(definition, loc, Scope.LOCAL); + this.parent = parent; + initResult(); + } + + @Override + public StatementContextImpl parent() { + return parent; + } + + @Override + IdentifierSpaceHolder parentNs() { + return parent; + } + + @Override + public void exportIdentifierSpace(IdentifierSpaceKey namespace) { + throw new UnsupportedOperationException("Child can not export identifier space"); + } + + @Override + public void importIdentifierSpace(NamespaceContext namespaceContext) { + throw new UnsupportedOperationException("Child can not import identifier space"); + } + } + + static class Root extends StatementContextImpl { + + private static final AxiomIdentifier IMPORTED_MODEL = AxiomIdentifier.axiom("ImportedModel"); + private final ModelReactorContext reactor; + private Set imports; + + public Root(ModelReactorContext reactor, AxiomItemDefinition definition, + SourceLocation loc) { + super(definition, loc, Scope.GLOBAL, Scope.LOCAL); + this.reactor = reactor; + this.imports = new HashSet<>(); + initResult(); + } + + @Override + protected IdentifierSpaceHolder parentNs() { + throw new UnsupportedOperationException(); + } + + @Override + protected void addOutstanding(StatementRuleContextImpl rule) { + reactor.addOutstanding(rule); + } + + @Override + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, + StatementContextImpl context) { + if (Scope.GLOBAL.equals(scope)) { + reactor.space().register(space, scope, key, context); + } + localSpace().register(space, scope, key, context); + } + + @Override + public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + StatementContextImpl maybe = localSpace().lookup(space, key); + if(maybe != null) { + return maybe; + } + for(IdentifierSpaceHolder model : imports) { + maybe = model.lookup(space, key); + if(maybe != null) { + return maybe; + } + } + return null; + } + + @Override + protected Factory> typeFactory(AxiomTypeDefinition type) { + return reactor.typeFactory(type); + } + + @Override + public StatementContextImpl parent() { + return this; + } + + @Override + protected IdentifierSpaceHolder exports() { + return localSpace(); + } + + @Override + public void exportIdentifierSpace(IdentifierSpaceKey namespace) { + reactor.exportIdentifierSpace(namespace, localSpace()); + } + + @Override + public void importIdentifierSpace(NamespaceContext namespaceContext) { + if(namespaceContext instanceof IdentifierSpaceHolder) { + imports.add((IdentifierSpaceHolder) namespaceContext); + } + } + + @Override + protected Root root() { + return this; + } + + public Requirement requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return Requirement.retriableDelegate(() -> { + return reactor.namespace(name, namespaceId); + }); + } + } + + protected Root root() { + return parent().root(); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java index 21d42969931..92f834e4d28 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java @@ -9,6 +9,7 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.impl.Requirement.Search; public interface StatementRuleContext { @@ -33,8 +34,10 @@ public interface Action { Optional optionalValue(); - Requirement> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key); + Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key); Requirement> requireChild(AxiomItemDefinition required); + Requirement requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index 3f3a23f6093..3ae8a47f769 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -1,6 +1,7 @@ package com.evolveum.axiom.lang.impl; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.function.Supplier; @@ -19,6 +20,7 @@ public class StatementRuleContextImpl implements StatementRuleContext { private Action action; private Supplier errorReport = () -> null; private boolean applied = false; + private Exception error; public StatementRuleContextImpl(StatementContextImpl context, StatementRule rule) { this.context = context; @@ -35,12 +37,18 @@ public Optional optionalChildValue(AxiomItemDefinition child, Class ty } @Override - public Requirement> requireGlobalItem(AxiomIdentifier space, + public Requirement.Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key) { - return requirement(context.reactor().requireGlobalItem(space, key)); + return requirement(Requirement.retriableDelegate(() -> { + StatementContextImpl maybe = context.lookup(space, key); + if(maybe != null) { + return (Requirement) maybe.asRequirement(); + } + return null; + })); } - private Requirement requirement(Requirement req) { + private > X requirement(X req) { this.requirements.add(req); return req; } @@ -62,8 +70,14 @@ public boolean canProcess() { } public void perform() throws AxiomSemanticException { - this.action.apply(context); - this.applied = true; + if(!applied && error == null) { + try { + this.action.apply(context); + this.applied = true; + } catch (Exception e) { + error = e; + } + } } @Override @@ -89,6 +103,10 @@ public StatementRuleContext errorMessage(Supplier errorFact } RuleErrorMessage errorMessage() { + if(error != null) { + return RuleErrorMessage.from(context.startLocation(), error.getMessage()); + } + return errorReport.get(); } @@ -117,4 +135,22 @@ public Requirement> requireChild(AxiomItemDefinition required) return context.requireChild(required); } + @Override + public Requirement requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return requirement(context.root().requireNamespace(name, namespaceId)); + } + + public boolean notFailed() { + return error == null; + } + + public boolean successful() { + return applied; + } + + public Collection> requirements() { + return requirements; + } + + } diff --git a/infra/axiom/src/test/resources/axiom-base-types.axiom b/infra/axiom/src/main/resources/axiom-base-types.axiom similarity index 83% rename from infra/axiom/src/test/resources/axiom-base-types.axiom rename to infra/axiom/src/main/resources/axiom-base-types.axiom index 93f34d62719..05a74eaf591 100644 --- a/infra/axiom/src/test/resources/axiom-base-types.axiom +++ b/infra/axiom/src/main/resources/axiom-base-types.axiom @@ -8,12 +8,14 @@ model axiom-base-types { - namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; + namespace "https://ns.evolveum.com/axiom/language"; version "0.1.0"; + type string; + type boolean; type uri; type int; type binary; type dateTime; - + } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index a0f5d8f300b..fe609389db0 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -1,12 +1,14 @@ model axiom-lang { + namespace "https://ns.evolveum.com/axiom/language"; + root model { documentation """ Axiom Model """; type AxiomModel; } - + type AxiomImportDeclaration { argument prefix; @@ -14,7 +16,7 @@ model axiom-lang { type AxiomIdentifier; } - item uri { + item namespace { type string; } } @@ -88,6 +90,12 @@ model axiom-lang { item since { type SemanticVersion; } + //item status { + // documentation """ + // Status of definition, could be experimental, stable, deprecated. + // """; + // type string; + //} } type AxiomIdentifierDefinition { @@ -183,8 +191,7 @@ model axiom-lang { // "Type library" (temporary) - type string; - type boolean; + type SemanticVersion { extends string; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java new file mode 100644 index 00000000000..7236a3fd77d --- /dev/null +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java @@ -0,0 +1,40 @@ +package com.evolveum.axiom.lang.test; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.api.AxiomBuiltIn; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomSchemaContext; +import com.evolveum.axiom.lang.impl.AxiomStatementSource; +import com.evolveum.axiom.lang.impl.AxiomSyntaxException; +import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.midpoint.tools.testng.AbstractUnitTest; + +public abstract class AbstractReactorTest extends AbstractUnitTest { + + private static final String COMMON_DIR_PATH = "src/test/resources/"; + + protected static AxiomSchemaContext parseFile(String name) throws AxiomSyntaxException, FileNotFoundException, IOException { + return parseInputStream(name, new FileInputStream(COMMON_DIR_PATH + name)); + } + + protected static AxiomSchemaContext parseInputStream(String name, InputStream stream) throws AxiomSyntaxException, FileNotFoundException, IOException { + return parseInputStream(name, stream, AxiomBuiltIn.Item.MODEL_DEFINITION); + } + + protected static AxiomSchemaContext parseInputStream(String name, InputStream stream, AxiomItemDefinition rootItemDefinition) throws AxiomSyntaxException, FileNotFoundException, IOException { + ModelReactorContext reactorContext =ModelReactorContext.defaultReactor(); + AxiomStatementSource statementSource = AxiomStatementSource.from(name, stream); + reactorContext.loadModelFromSource(statementSource); + return reactorContext.computeSchemaContext(); + } + + protected static AxiomStatementSource source(String name) throws AxiomSyntaxException, IOException { + InputStream stream = new FileInputStream(COMMON_DIR_PATH + name); + return AxiomStatementSource.from(name, stream); + } +} diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java new file mode 100644 index 00000000000..3cfb8dc0069 --- /dev/null +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java @@ -0,0 +1,66 @@ +/* + * 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.test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; + +import org.testng.annotations.Test; + + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.api.AxiomBuiltIn; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomSchemaContext; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; + +import com.evolveum.axiom.lang.impl.AxiomStatementSource; + +import com.evolveum.axiom.lang.impl.AxiomSyntaxException; +import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.midpoint.tools.testng.AbstractUnitTest; + +public class TestAxiomMultimodule extends AbstractReactorTest { + + private static final String DIR = "multimodule/"; + private static final String SCHEMA_ORG = DIR + "schema-org-person.axiom"; + private static final String FOAF = DIR + "foaf-person.axiom"; + private static final String TEST = DIR + "test-person.axiom"; + private static final String TEST_INVALID = DIR + "test-person.axiom.invalid"; + + + @Test + public void axiomTestImports() throws IOException, AxiomSyntaxException { + ModelReactorContext context = ModelReactorContext.defaultReactor(); + context.loadModelFromSource(source(SCHEMA_ORG)); + context.loadModelFromSource(source(FOAF)); + context.loadModelFromSource(source(TEST)); + AxiomSchemaContext schemaContext = context.computeSchemaContext(); + + AxiomItemDefinition modelDef = schemaContext.getRoot(Item.MODEL_DEFINITION.name()).get(); + assertEquals(modelDef.name(), Item.MODEL_DEFINITION.name()); + + //folowupContext.loadModelFromSource(statementSource); + AxiomSchemaContext selfparsedContext = context.computeSchemaContext(); + assertNotNull(selfparsedContext.getRoot(Item.MODEL_DEFINITION.name())); + assertTrue(selfparsedContext.getType(Type.IDENTIFIER_DEFINITION.name()).get().item(Item.ID_MEMBER.name()).get().required()); + } + + + + +} diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index a3e28068d09..47978fdff1e 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -34,21 +34,13 @@ import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; -public class TestAxiomParser extends AbstractUnitTest { +public class TestAxiomParser extends AbstractReactorTest { - private static final String COMMON_DIR_PATH = "src/test/resources/"; private static final String BASE_EXAMPLE = "base-example.axiom"; private static final String COMMON_CORE = "common-core.axiom"; private static final String SCRIPTING = "scripting.axiom"; - private static final String AXIOM_BUILTIN_TYPES = "axiom-base-types.axiom"; - private static final Lazy AXIOM_TYPES_SCHEMA = Lazy.from(() -> { - try { - InputStream stream = new FileInputStream(COMMON_DIR_PATH + AXIOM_BUILTIN_TYPES); - return AxiomStatementSource.from(AXIOM_BUILTIN_TYPES, stream); - } catch (Exception e) { - throw new IllegalStateException(e); - } - }); + + @Test public void axiomSelfDescribingTest() throws IOException, AxiomSyntaxException { @@ -62,7 +54,7 @@ public void axiomSelfDescribingTest() throws IOException, AxiomSyntaxException { // Default reactor has Axiom model already loaded ModelReactorContext folowupContext = ModelReactorContext.reactor(modelContext); //folowupContext.loadModelFromSource(statementSource); - AxiomSchemaContext selfparsedContext = bootstrapContext.computeSchemaContext(); + AxiomSchemaContext selfparsedContext = folowupContext.computeSchemaContext(); assertNotNull(selfparsedContext.getRoot(Item.MODEL_DEFINITION.name())); assertTrue(selfparsedContext.getType(Type.IDENTIFIER_DEFINITION.name()).get().item(Item.ID_MEMBER.name()).get().required()); } @@ -82,7 +74,7 @@ private void assertInstanceOf(Class clz, Object value) { @Test public void moduleHeaderTest() throws IOException, AxiomSyntaxException { AxiomSchemaContext context = parseFile(BASE_EXAMPLE); - assertNotNull(context.getType(AxiomIdentifier.axiom("Example")).get()); + assertNotNull(context.getType(AxiomIdentifier.from("https://ns.evolveum.com/example/axiom/model-header", "Example")).get()); } @Test @@ -95,21 +87,7 @@ public void scriptingTest() throws IOException, AxiomSyntaxException { AxiomSchemaContext context = parseFile(SCRIPTING); } - private AxiomSchemaContext parseFile(String name) throws AxiomSyntaxException, FileNotFoundException, IOException { - return parseInputStream(name, new FileInputStream(COMMON_DIR_PATH + name)); - } - - private AxiomSchemaContext parseInputStream(String name, InputStream stream) throws AxiomSyntaxException, FileNotFoundException, IOException { - return parseInputStream(name, stream, AxiomBuiltIn.Item.MODEL_DEFINITION); - } - private AxiomSchemaContext parseInputStream(String name, InputStream stream, AxiomItemDefinition rootItemDefinition) throws AxiomSyntaxException, FileNotFoundException, IOException { - ModelReactorContext reactorContext =ModelReactorContext.defaultReactor(); - AxiomStatementSource statementSource = AxiomStatementSource.from(name, stream); - reactorContext.loadModelFromSource(statementSource); - reactorContext.loadModelFromSource(AXIOM_TYPES_SCHEMA.get()); - return reactorContext.computeSchemaContext(); - } } diff --git a/infra/axiom/src/test/resources/multimodule/foaf-person.axiom b/infra/axiom/src/test/resources/multimodule/foaf-person.axiom new file mode 100644 index 00000000000..1c7e3330c8c --- /dev/null +++ b/infra/axiom/src/test/resources/multimodule/foaf-person.axiom @@ -0,0 +1,17 @@ +model foaf-person { + + namespace "http://xmlns.com/foaf/0.1/"; + + type Person { + item givenName { + type string; + } + item familyName { + type string; + } + item additionalName { + type string; + } + } + +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodule/schema-org-person.axiom b/infra/axiom/src/test/resources/multimodule/schema-org-person.axiom new file mode 100644 index 00000000000..270c138c8f5 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodule/schema-org-person.axiom @@ -0,0 +1,19 @@ +model foaf-person { + + namespace "https://schema.org"; + //prefix schemaorg; + + + type Person { + item givenName { + type string; + } + item familyName { + type string; + } + item additionalName { + type string; + } + } + +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodule/test-person.axiom b/infra/axiom/src/test/resources/multimodule/test-person.axiom new file mode 100644 index 00000000000..6f2700eef3f --- /dev/null +++ b/infra/axiom/src/test/resources/multimodule/test-person.axiom @@ -0,0 +1,23 @@ +model schema-org-person { + + namespace "https://example.org"; + + import foaf { + namespace "http://xmlns.com/foaf/0.1/"; + } + import schemaOrg { + namespace "https://schema.org"; + } + + type Person { + item name { + type string; + } + item foaf { + type foaf:Person; + } + item schemaorg { + type schemaOrg:Person; + } + } +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodule/test-person.axiom.invalid b/infra/axiom/src/test/resources/multimodule/test-person.axiom.invalid new file mode 100644 index 00000000000..48d580edea9 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodule/test-person.axiom.invalid @@ -0,0 +1,23 @@ +model invalid-import { + + import foafInvalid { + namespace "foaf"; + } + + import schemaOrg { + namespace "https://schema.org"; + } + + type InvalidGlobal { + item person { + type Person; + } + } + + type InvalidPrefix { + item person { + type InvalidPrefix; + } + } + +} \ No newline at end of file From 2a48766ed845396e8a103a4faef033de69671821 Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Mon, 18 May 2020 20:04:25 +0200 Subject: [PATCH 02/60] valueMetadata GUI integration - WIP --- .../midpoint/gui/api/page/PageBase.java | 4 + .../wrapper/PrismContainerValueWrapper.java | 20 +- .../wrapper/PrismObjectValueWrapper.java | 6 +- .../api/prism/wrapper/PrismValueWrapper.java | 15 +- .../column/PrismReferenceWrapperColumn.java | 2 +- .../PrismReferenceWrapperColumnPanel.java | 8 +- .../impl/factory/panel/ItemPanelContext.java | 2 +- .../factory/panel/ItemRealValueModel.java | 2 +- .../panel/PrismContainerPanelContext.java | 2 +- .../wrapper/ItemWrapperFactoryImpl.java | 24 +- .../OperationalContainerWrapperFactory.java | 2 +- .../PrismContainerWrapperFactoryImpl.java | 4 +- .../PrismObjectWrapperFactoryImpl.java | 2 + .../ValueMetadataWrapperFactoryImpl.java | 57 ++++ .../gui/impl/prism/panel/ItemPanel.java | 2 +- .../panel/MetadataContainerValuePanel.html | 57 ++++ .../panel/MetadataContainerValuePanel.java | 72 ++++++ .../prism/panel/PrismContainerValuePanel.html | 7 +- .../prism/panel/PrismContainerValuePanel.java | 60 ++--- .../impl/prism/panel/PrismPropertyPanel.java | 2 +- .../gui/impl/prism/panel/PrismValuePanel.html | 5 + .../gui/impl/prism/panel/PrismValuePanel.java | 41 ++- .../impl/prism/wrapper/ItemWrapperImpl.java | 3 +- .../PrismContainerValueWrapperImpl.java | 34 ++- .../wrapper/PrismContainerWrapperImpl.java | 6 +- .../wrapper/PrismObjectValueWrapperImpl.java | 7 + .../wrapper/PrismPropertyValueWrapper.java | 12 +- .../PrismReferenceValueWrapperImpl.java | 9 +- .../prism/wrapper/PrismValueWrapperImpl.java | 59 +++-- .../wrapper/ValueMetadataWrapperImpl.java | 244 ++++++++++++++++++ .../registry/GuiComponentRegistryImpl.java | 1 - .../FocusProjectionsTabPanel.java | 2 +- .../util/ContainerListDataProvider.java | 8 +- .../web/page/admin/server/PageTask.java | 2 +- 34 files changed, 669 insertions(+), 114 deletions(-) create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java index 378781c8ab0..4068b6e6be7 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java @@ -2695,6 +2695,10 @@ public PrismObjectWrapperFactory findObjectWrapperFact return registry.findWrapperFactory(def); } + public PrismContainerWrapperFactory findContainerWrapperFactory(PrismContainerDefinition def) { + return registry.findContainerWrapperFactory(def); + } + public VW createValueWrapper(IW parentWrapper, PV newValue, ValueStatus status, WrapperContext context) throws SchemaException { ItemWrapperFactory factory = registry.findWrapperFactory(parentWrapper); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismContainerValueWrapper.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismContainerValueWrapper.java index 715a79e2bc5..526c01a303f 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismContainerValueWrapper.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismContainerValueWrapper.java @@ -8,10 +8,7 @@ import java.util.List; -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.PrismContainerDefinition; -import com.evolveum.midpoint.prism.PrismContainerValue; -import com.evolveum.midpoint.prism.Referencable; +import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.util.exception.SchemaException; @@ -22,7 +19,7 @@ * @author katka * */ -public interface PrismContainerValueWrapper extends PrismValueWrapper>{ +public interface PrismContainerValueWrapper extends PrismValueWrapper { String getDisplayName(); String getHelpText(); @@ -31,11 +28,6 @@ public interface PrismContainerValueWrapper extends Pri void setExpanded(boolean expanded); - boolean hasMetadata(); - boolean isShowMetadata(); - - void setShowMetadata(boolean showMetadata); - boolean isSorted(); void setSorted(boolean sorted); @@ -46,9 +38,9 @@ public interface PrismContainerValueWrapper extends Pri List> getContainers(); - List> getNonContainers(); + List> getNonContainers(); - List> getItems(); + List> getItems(); PrismContainerWrapper findContainer(ItemPath path) throws SchemaException; PrismPropertyWrapper findProperty(ItemPath propertyPath) throws SchemaException; @@ -60,7 +52,6 @@ public interface PrismContainerValueWrapper extends Pri boolean isSelected(); boolean setSelected(boolean selected); //TODO why return boolean? - boolean isReadOnly(); void setReadOnly(boolean readOnly, boolean recursive); @@ -83,4 +74,7 @@ public interface PrismContainerValueWrapper extends Pri PrismContainerDefinition getDefinition(); + @Override + PrismContainerValue getNewValue(); } + diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismObjectValueWrapper.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismObjectValueWrapper.java index 5a8de9c45f2..33d02dd658b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismObjectValueWrapper.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismObjectValueWrapper.java @@ -6,6 +6,8 @@ */ package com.evolveum.midpoint.gui.api.prism.wrapper; +import com.evolveum.midpoint.prism.PrismContainerValue; +import com.evolveum.midpoint.prism.PrismObjectValue; import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; /** @@ -14,6 +16,6 @@ */ public interface PrismObjectValueWrapper extends PrismContainerValueWrapper { - - + @Override + PrismContainerValue getNewValue(); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java index 23a69128fe7..ec3005c2954 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java @@ -8,6 +8,7 @@ import java.io.Serializable; +import com.evolveum.midpoint.gui.impl.prism.wrapper.ValueMetadataWrapperImpl; import com.evolveum.midpoint.prism.ItemDefinition; import com.evolveum.midpoint.prism.PrismValue; import com.evolveum.midpoint.prism.delta.ItemDelta; @@ -19,7 +20,7 @@ * @author katka * */ -public interface PrismValueWrapper extends Serializable, DebugDumpable { +public interface PrismValueWrapper extends Serializable, DebugDumpable { T getRealValue(); void setRealValue(T realValue); @@ -27,12 +28,18 @@ public interface PrismValueWrapper extends Serializable ValueStatus getStatus(); void setStatus(ValueStatus status); - V getNewValue(); - V getOldValue(); + V getNewValue(); + V getOldValue(); IW getParent(); - > void addToDelta(D delta) throws SchemaException; + > void addToDelta(D delta) throws SchemaException; boolean isVisible(); + PrismContainerValueWrapper getValueMetadata(); + void setValueMetadata(ValueMetadataWrapperImpl valueMetadata); + + boolean isShowMetadata(); + void setShowMetadata(boolean showMetadata); + } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumn.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumn.java index a5694982a59..5e776eac525 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumn.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumn.java @@ -29,7 +29,7 @@ /** * @author skublik */ -public class PrismReferenceWrapperColumn extends AbstractItemWrapperColumn> { +public class PrismReferenceWrapperColumn extends AbstractItemWrapperColumn> { private static final long serialVersionUID = 1L; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumnPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumnPanel.java index 9e3317a0bd0..f10b5156920 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumnPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/data/column/PrismReferenceWrapperColumnPanel.java @@ -27,7 +27,7 @@ * @author katka * */ -public class PrismReferenceWrapperColumnPanel extends AbstractItemWrapperColumnPanel, PrismValueWrapper> { +public class PrismReferenceWrapperColumnPanel extends AbstractItemWrapperColumnPanel, PrismValueWrapper> { private static final long serialVersionUID = 1L; private static final Trace LOGGER = TraceManager.getTrace(PrismReferenceWrapperColumnPanel.class); @@ -37,12 +37,12 @@ public class PrismReferenceWrapperColumnPanel extends Ab } @Override - protected String createLabel(PrismValueWrapper object) { + protected String createLabel(PrismValueWrapper object) { return WebComponentUtil.getReferencedObjectDisplayNamesAndNames(object.getRealValue(), false, true); } @Override - protected Panel createValuePanel(String id, IModel> model, PrismValueWrapper object) { + protected Panel createValuePanel(String id, IModel> model, PrismValueWrapper object) { Panel panel; try { @@ -57,7 +57,7 @@ protected Panel createValuePanel(String id, IModel> mod } @Override - protected Panel createLink(String id, IModel> object) { + protected Panel createLink(String id, IModel> object) { LinkPanel linkPanel = new LinkPanel(id, new IModel() { @Override diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemPanelContext.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemPanelContext.java index d3f8970b545..3139099734f 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemPanelContext.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemPanelContext.java @@ -87,7 +87,7 @@ public ItemRealValueModel getRealValueModel() { return realValueModel; } - public > void setRealValueModel(IModel valueWrapper) { + public > void setRealValueModel(IModel valueWrapper) { this.realValueModel = new ItemRealValueModel<>(valueWrapper); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemRealValueModel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemRealValueModel.java index 148313f090f..23a0926b869 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemRealValueModel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/ItemRealValueModel.java @@ -17,7 +17,7 @@ public class ItemRealValueModel extends PropertyModel{ private static final long serialVersionUID = 1L; - public ItemRealValueModel(IModel> modelObject) { + public ItemRealValueModel(IModel> modelObject) { super(modelObject, "realValue"); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/PrismContainerPanelContext.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/PrismContainerPanelContext.java index 8d065bf2b18..7adf23bb6c4 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/PrismContainerPanelContext.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/panel/PrismContainerPanelContext.java @@ -27,7 +27,7 @@ public PrismContainerPanelContext(IModel> itemWrapper) } @Override - public > void setRealValueModel(IModel valueWrapper) { + public > void setRealValueModel(IModel valueWrapper) { super.setRealValueModel(valueWrapper); this.valueWrapperModel = (IModel>) valueWrapper; } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java index 070a244387a..0d1ec55301e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java @@ -9,9 +9,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Optional; import com.evolveum.midpoint.gui.api.factory.wrapper.ItemWrapperFactory; import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext; +import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry; +import com.evolveum.midpoint.gui.impl.prism.wrapper.ValueMetadataWrapperImpl; import com.evolveum.midpoint.model.api.ModelService; import com.evolveum.midpoint.prism.path.ItemName; @@ -154,7 +157,7 @@ private boolean skipCreateWrapper(ItemDefinition def, ItemStatus status, Wrap } protected boolean canCreateWrapper(ItemDefinition def, ItemStatus status, WrapperContext context, boolean isEmptyValue) { - if (def.isOperational()) { + if (def.isOperational() && !context.isCreateOperational()) { LOGGER.trace("Skipping creating wrapper for {}, because it is operational.", def.getItemName()); return false; } @@ -173,6 +176,7 @@ protected List createValuesWrapper(IW itemWrapper, I item, WrapperContext co if (shouldCreateEmptyValue(item, context)) { PV prismValue = createNewValue(item); VW valueWrapper = createValueWrapper(itemWrapper, prismValue, ValueStatus.ADDED, context); +// setupMetadata(valueWrapper, context); pvWrappers.add(valueWrapper); } return pvWrappers; @@ -181,6 +185,7 @@ protected List createValuesWrapper(IW itemWrapper, I item, WrapperContext co for (PV pcv : values) { if(canCreateValueWrapper(pcv)){ VW valueWrapper = createValueWrapper(itemWrapper, pcv, ValueStatus.NOT_CHANGED, context); + setupMetadata(valueWrapper, context); pvWrappers.add(valueWrapper); } } @@ -189,6 +194,21 @@ protected List createValuesWrapper(IW itemWrapper, I item, WrapperContext co } + protected void setupMetadata(VW valueWrapper, WrapperContext ctx) throws SchemaException { + PrismValue oldValue = valueWrapper.getOldValue(); + Optional metadata = oldValue.valueMetadata(); + if (!metadata.isPresent()) { + LOGGER.trace("Skipping creating metadata"); + return; + } + + ValueMetadata valueMetadata = metadata.get(); + + ValueMetadataWrapperFactoryImpl valueMetadataWrapperFactory = new ValueMetadataWrapperFactoryImpl(getRegistry()); + PrismContainerValueWrapper valueMetadataWrapper = valueMetadataWrapperFactory.createValueWrapper(null, valueMetadata, ValueStatus.NOT_CHANGED, ctx); + valueWrapper.setValueMetadata(new ValueMetadataWrapperImpl(valueMetadataWrapper)); + } + protected List getValues(I item) { return item.getValues(); } @@ -261,7 +281,7 @@ protected boolean shouldCreateEmptyValue(I item, WrapperContext context) { /** * @return the registry */ - public GuiComponentRegistryImpl getRegistry() { + public GuiComponentRegistry getRegistry() { return registry; } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/OperationalContainerWrapperFactory.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/OperationalContainerWrapperFactory.java index 53800abae53..bd2a0710517 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/OperationalContainerWrapperFactory.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/OperationalContainerWrapperFactory.java @@ -27,7 +27,7 @@ public class OperationalContainerWrapperFactory extends PrismContainerWrapperFac @Override public boolean match(ItemDefinition def) { - return QNameUtil.match(MetadataType.COMPLEX_TYPE, def.getTypeName()) || QNameUtil.match(TriggerType.COMPLEX_TYPE, def.getTypeName()); + return QNameUtil.match(TriggerType.COMPLEX_TYPE, def.getTypeName()); //QNameUtil.match(MetadataType.COMPLEX_TYPE, def.getTypeName()) || } @PostConstruct diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismContainerWrapperFactoryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismContainerWrapperFactoryImpl.java index 21e5440ae32..f0975820a2c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismContainerWrapperFactoryImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismContainerWrapperFactoryImpl.java @@ -66,7 +66,9 @@ public PrismContainerValueWrapper createValueWrapper(PrismContainerWrapper containerValueWrapper.getItems().addAll((Collection) children); containerValueWrapper.setVirtualContainerItems(context.getVirtualItemSpecification()); - parent.setVirtual(context.getVirtualItemSpecification() != null); + if (parent != null) { + parent.setVirtual(context.getVirtualItemSpecification() != null); + } return containerValueWrapper; } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismObjectWrapperFactoryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismObjectWrapperFactoryImpl.java index 0a66b7a906f..2e05ead9c5e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismObjectWrapperFactoryImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/PrismObjectWrapperFactoryImpl.java @@ -70,6 +70,7 @@ public PrismObjectWrapper createObjectWrapper(PrismObject object, ItemStat context.setShowEmpty(ItemStatus.ADDED == status); objectWrapper.setExpanded(true); PrismContainerValueWrapper valueWrapper = createValueWrapper(objectWrapper, object.getValue(), ItemStatus.ADDED == status ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, context); + setupMetadata(valueWrapper, context); objectWrapper.getValues().add(valueWrapper); registerWrapperPanel(objectWrapper); @@ -97,6 +98,7 @@ public void updateWrapper(PrismObjectWrapper wrapper, WrapperContext context) wrapper.getValue().getItems().clear(); PrismContainerValueWrapper valueWrapper = createValueWrapper(wrapper, wrapper.getObject().getValue(), ItemStatus.ADDED == wrapper.getStatus() ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, context); + setupMetadata(valueWrapper, context); wrapper.getValues().clear(); wrapper.getValues().add(valueWrapper); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java new file mode 100644 index 00000000000..00bc7fac13f --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010-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.midpoint.gui.impl.factory.wrapper; + +import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext; +import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper; +import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper; +import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry; +import com.evolveum.midpoint.prism.Containerable; +import com.evolveum.midpoint.prism.ItemDefinition; +import com.evolveum.midpoint.prism.PrismContainer; +import com.evolveum.midpoint.prism.PrismContainerValue; +import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.midpoint.web.component.prism.ValueStatus; + +import java.util.List; + +public class ValueMetadataWrapperFactoryImpl extends PrismContainerWrapperFactoryImpl { + + private GuiComponentRegistry registry; + + ValueMetadataWrapperFactoryImpl(GuiComponentRegistry registry) { + this.registry = registry; + } + + @Override + public PrismContainerValueWrapper createValueWrapper(PrismContainerWrapper parent, PrismContainerValue value, ValueStatus status, WrapperContext context) throws SchemaException { + context.setCreateOperational(true); + PrismContainerValueWrapper v = super.createValueWrapper(parent, value, status, context); + context.setCreateOperational(false); + return v; + } + + @Override + protected boolean shouldBeExpanded(PrismContainerWrapper parent, PrismContainerValue value, WrapperContext context) { + return true; + } + + @Override + protected boolean shouldCreateEmptyValue(PrismContainer item, WrapperContext context) { + return false; + } + + @Override + protected List getItemDefinitions(PrismContainerWrapper parent, PrismContainerValue value) { + return value.getComplexTypeDefinition().getDefinitions(); + } + + @Override + public GuiComponentRegistry getRegistry() { + return registry; + } +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ItemPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ItemPanel.java index df994c96141..f09d583595c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ItemPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ItemPanel.java @@ -36,7 +36,7 @@ * @author katka * */ -public abstract class ItemPanel, IW extends ItemWrapper> extends BasePanel implements RefreshableTabPanel { +public abstract class ItemPanel, IW extends ItemWrapper> extends BasePanel implements RefreshableTabPanel { private static final long serialVersionUID = 1L; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html new file mode 100644 index 00000000000..9f7f82ea62d --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html @@ -0,0 +1,57 @@ + + + + + +
+
+
+ +
+ + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+ + + diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java new file mode 100644 index 00000000000..fb6992e5505 --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010-2018 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.midpoint.gui.impl.prism.panel; + +import java.text.Collator; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; +import javax.xml.namespace.QName; + +import com.evolveum.midpoint.web.component.form.Form; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.wicket.AttributeModifier; +import org.apache.wicket.Component; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.behavior.AttributeAppender; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.*; + +import com.evolveum.midpoint.gui.api.GuiStyleConstants; +import com.evolveum.midpoint.gui.api.component.togglebutton.ToggleIconButton; +import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext; +import com.evolveum.midpoint.gui.api.prism.wrapper.*; +import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils; +import com.evolveum.midpoint.gui.impl.factory.panel.ItemPanelContext; +import com.evolveum.midpoint.gui.impl.factory.panel.PrismContainerPanelContext; +import com.evolveum.midpoint.gui.impl.prism.panel.component.ListContainersPopup; +import com.evolveum.midpoint.prism.Containerable; +import com.evolveum.midpoint.prism.PrismContainerDefinition; +import com.evolveum.midpoint.prism.PrismValue; +import com.evolveum.midpoint.schema.result.OperationResult; +import com.evolveum.midpoint.task.api.Task; +import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.midpoint.util.exception.SystemException; +import com.evolveum.midpoint.web.component.AjaxButton; +import com.evolveum.midpoint.web.component.prism.ValueStatus; +import com.evolveum.midpoint.web.component.util.VisibleBehaviour; +import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour; +import com.evolveum.midpoint.web.util.InfoTooltipBehavior; + +/** + * @author katka + * + */ +public class MetadataContainerValuePanel extends PrismContainerValuePanel> { + + public MetadataContainerValuePanel(String id, IModel> model, ItemPanelSettings settings) { + super(id, model, settings); + } + + @Override + protected void createMetadataPanel(Form form) { + + } + + @Override + protected boolean isRemoveButtonVisible() { + return false; + } + +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.html index cdaa0327134..48fc60a2f9d 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.html @@ -18,11 +18,14 @@
- + - + +
+
+
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.java index 9e9791bf2dc..dca9c0fb189 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerValuePanel.java @@ -131,7 +131,7 @@ public void onClick(AjaxRequestTarget target) { } protected LoadableDetachableModel getLabelModel() { - return getPageBase().createStringResource(getModel().getObject().getDisplayName()); + return getPageBase().createStringResource("${displayName}", getModel()); } @Override @@ -338,7 +338,7 @@ public String getObject() { private void initButtons(WebMarkupContainer header) { header.add(createExpandCollapseButton()); - header.add(createMetadataButton()); +// header.add(createMetadataButton()); header.add(createSortButton()); header.add(createAddMoreButton()); } @@ -360,29 +360,29 @@ protected Label getHelpLabel() { return help; } - private ToggleIconButton createMetadataButton() { - ToggleIconButton showMetadataButton = new ToggleIconButton(ID_SHOW_METADATA, - GuiStyleConstants.CLASS_ICON_SHOW_METADATA, GuiStyleConstants.CLASS_ICON_SHOW_METADATA) { - private static final long serialVersionUID = 1L; - - @Override - public void onClick(AjaxRequestTarget target) { - onShowMetadataClicked(target); - } - - @Override - public boolean isOn() { - return PrismContainerValuePanel.this.getModelObject().isShowMetadata(); - } - - - }; - showMetadataButton.add(new AttributeModifier("title", new StringResourceModel("PrismContainerValuePanel.showMetadata.${showMetadata}", getModel()))); - showMetadataButton.add(new VisibleBehaviour(() -> getModelObject().hasMetadata() && shouldBeButtonsShown())); - showMetadataButton.setOutputMarkupId(true); - showMetadataButton.setOutputMarkupPlaceholderTag(true); - return showMetadataButton; - } +// private ToggleIconButton createMetadataButton() { +// ToggleIconButton showMetadataButton = new ToggleIconButton(ID_SHOW_METADATA, +// GuiStyleConstants.CLASS_ICON_SHOW_METADATA, GuiStyleConstants.CLASS_ICON_SHOW_METADATA) { +// private static final long serialVersionUID = 1L; +// +// @Override +// public void onClick(AjaxRequestTarget target) { +// onShowMetadataClicked(target); +// } +// +// @Override +// public boolean isOn() { +// return PrismContainerValuePanel.this.getModelObject().isShowMetadata(); +// } +// +// +// }; +// showMetadataButton.add(new AttributeModifier("title", new StringResourceModel("PrismContainerValuePanel.showMetadata.${showMetadata}", getModel()))); +// showMetadataButton.add(new VisibleBehaviour(() -> getModelObject().hasMetadata() && shouldBeButtonsShown())); +// showMetadataButton.setOutputMarkupId(true); +// showMetadataButton.setOutputMarkupPlaceholderTag(true); +// return showMetadataButton; +// } private ToggleIconButton createSortButton() { ToggleIconButton sortPropertiesButton = new ToggleIconButton(ID_SORT_PROPERTIES, @@ -494,11 +494,11 @@ private void onSortClicked(AjaxRequestTarget target) { refreshPanel(target); } - private void onShowMetadataClicked(AjaxRequestTarget target) { - CVW wrapper = getModelObject(); - wrapper.setShowMetadata(!wrapper.isShowMetadata()); - refreshPanel(target); - } +// private void onShowMetadataClicked(AjaxRequestTarget target) { +// CVW wrapper = getModelObject(); +// wrapper.setShowMetadata(!wrapper.isShowMetadata()); +// refreshPanel(target); +// } private void refreshPanel(AjaxRequestTarget target) { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java index ae8ed7af1b1..84c8b7337c7 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java @@ -23,7 +23,7 @@ /** * @author katkav */ -public class PrismPropertyPanel extends ItemPanel, PrismPropertyWrapper> { +public class PrismPropertyPanel extends ItemPanel, PrismPropertyWrapper> { private static final long serialVersionUID = 1L; private static final Trace LOGGER = TraceManager.getTrace(PrismPropertyPanel.class); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.html index a20d1661df2..84a72a9594d 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.html @@ -22,10 +22,15 @@ +
+
+
+
+ diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java index 8979e498c5a..70b30eb5012 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java @@ -39,7 +39,7 @@ import org.apache.wicket.model.LambdaModel; import org.apache.wicket.model.PropertyModel; -public abstract class PrismValuePanel> extends BasePanel { +public abstract class PrismValuePanel> extends BasePanel { private static final transient Trace LOGGER = TraceManager.getTrace(PrismValuePanel.class); @@ -52,6 +52,8 @@ public abstract class PrismValuePanel isRemoveButtonVisible())); buttonContainer.add(removeButton); + AjaxLink showMetadataButton = new AjaxLink(ID_SHOW_METADATA) { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) { + showMetadataPerformed(PrismValuePanel.this.getModelObject(), target); + } + }; + buttonContainer.add(showMetadataButton); + showMetadataButton.add(new VisibleBehaviour(() -> getModelObject() != null && getModelObject().getValueMetadata() != null)); + addToHeader(buttonContainer); return buttonContainer; } @@ -106,7 +121,10 @@ protected void addToHeader(WebMarkupContainer headerContainer) { private WebMarkupContainer createValuePanel(Form form) { - GuiComponentFactory factory = getPageBase().getRegistry().findValuePanelFactory(getModelObject().getParent()); + GuiComponentFactory factory = null; + if (getModelObject() != null && getModelObject().getParent() != null) { + factory = getPageBase().getRegistry().findValuePanelFactory(getModelObject().getParent()); + } WebMarkupContainer valueContainer = new WebMarkupContainer(ID_VALUE_CONTAINER); valueContainer.setOutputMarkupId(true); form.add(valueContainer); @@ -152,6 +170,12 @@ private WebMarkupContainer createValuePanel(Form form) { } + protected void createMetadataPanel(Form form) { + MetadataContainerValuePanel metadataPanel = new MetadataContainerValuePanel(ID_METADATA, new PropertyModel<>(getModel(), "valueMetadata"), new ItemPanelSettingsBuilder().build()); + metadataPanel.add(new VisibleBehaviour(() -> getModelObject().getValueMetadata() != null && getModelObject().isShowMetadata())); + form.add(metadataPanel); + } + private AjaxEventBehavior createEventBehavior() { return new AjaxFormComponentUpdatingBehavior("change") { @@ -175,10 +199,10 @@ protected void onError(AjaxRequestTarget target, RuntimeException e) { private VisibleEnableBehaviour createVisibleEnableBehavior() { return new VisibleEnableBehaviour() { -// @Override -// public boolean isVisible() { -// return isVisibleValue(); -// } + @Override + public boolean isVisible() { + return true; + } @Override public boolean isEnabled() { @@ -254,6 +278,11 @@ private O getObject() { //TODO move to the ItemPanel, exception handling protected abstract void removeValue(VW valueToRemove, AjaxRequestTarget target) throws SchemaException; + private void showMetadataPerformed(VW value, AjaxRequestTarget target) { + value.setShowMetadata(!value.isShowMetadata()); + target.add(PrismValuePanel.this); + } + protected boolean isRemoveButtonVisible() { return !getModelObject().getParent().isReadOnly(); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ItemWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ItemWrapperImpl.java index e63383b8e9a..85d52758bed 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ItemWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ItemWrapperImpl.java @@ -24,7 +24,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import com.evolveum.midpoint.gui.api.page.PageBase; import com.evolveum.midpoint.gui.api.prism.ItemStatus; @@ -75,7 +74,7 @@ public abstract class ItemWrapperImpl parent, I item, ItemStatus status) { + public ItemWrapperImpl(PrismContainerValueWrapper parent, I item, ItemStatus status) { Validate.notNull(item, "Item must not be null."); Validate.notNull(status, "Item status must not be null."); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerValueWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerValueWrapperImpl.java index 643047bfbf9..365a05c0007 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerValueWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerValueWrapperImpl.java @@ -34,7 +34,7 @@ * @author katka * */ -public class PrismContainerValueWrapperImpl extends PrismValueWrapperImpl> implements PrismContainerValueWrapper { +public class PrismContainerValueWrapperImpl extends PrismValueWrapperImpl implements PrismContainerValueWrapper { private static final long serialVersionUID = 1L; @@ -135,17 +135,17 @@ public void setExpanded(boolean expanded) { this.expanded = expanded; } - @Override - public boolean hasMetadata() { - for (ItemWrapper container : items) { - if (container.getTypeName().equals(MetadataType.COMPLEX_TYPE)) { - return true; - } - } - - return false; - } - +// @Override +// public boolean hasMetadata() { +// for (ItemWrapper container : items) { +// if (container.getTypeName().equals(MetadataType.COMPLEX_TYPE)) { +// return true; +// } +// } +// +// return false; +// } +// @Override public List> getItems() { @@ -484,6 +484,16 @@ public boolean isVisible() { return ((PrismContainerWrapper) parent).isExpanded() || isHeterogenous(); } + @Override + public PrismContainerValue getNewValue() { + return super.getNewValue(); + } + + @Override + public PrismContainerValue getOldValue() { + return super.getOldValue(); + } + public PrismContainerDefinition getDefinition() { return getNewValue().getDefinition(); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerWrapperImpl.java index a4f1962521c..51589ecd271 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismContainerWrapperImpl.java @@ -349,9 +349,9 @@ public boolean isVisible(PrismContainerValueWrapper parent, ItemVisibilityHan return false; } - if (getComplexTypeDefinition().getTypeName().equals(MetadataType.COMPLEX_TYPE)) { - return (getParent() != null && getParent().isShowMetadata()); - } +// if (getComplexTypeDefinition().getTypeName().equals(MetadataType.COMPLEX_TYPE)) { +// return (getParent() != null && getParent().isShowMetadata()); +// } // pretend that object is always expanded. it is becasue all other containers are children of it // and it can influence visibility behavior on different tabs. diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismObjectValueWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismObjectValueWrapperImpl.java index 0aecb7a6ed3..7d7e4f0ef3f 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismObjectValueWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismObjectValueWrapperImpl.java @@ -10,6 +10,8 @@ import java.util.List; import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectValueWrapper; +import com.evolveum.midpoint.prism.PrismContainerValue; + import org.apache.wicket.model.StringResourceModel; import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper; @@ -57,4 +59,9 @@ public List> getContainers() public String getDisplayName() { return new StringResourceModel("prismContainer.mainPanelDisplayName").getString(); } + + @Override + public PrismContainerValue getNewValue() { + return super.getNewValue(); + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismPropertyValueWrapper.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismPropertyValueWrapper.java index b659fb3a9f2..6e5027e8a1a 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismPropertyValueWrapper.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismPropertyValueWrapper.java @@ -10,6 +10,7 @@ import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper; import com.evolveum.midpoint.prism.PrismPropertyValue; +import com.evolveum.midpoint.prism.PrismValue; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.polystring.PolyString; import com.evolveum.midpoint.util.DOMUtil; @@ -21,7 +22,7 @@ * @author katka * */ -public class PrismPropertyValueWrapper extends PrismValueWrapperImpl> { +public class PrismPropertyValueWrapper extends PrismValueWrapperImpl { /** * @param parent @@ -115,4 +116,13 @@ public String toShortString() { return getRealValue().toString(); } + @Override + public PrismPropertyValue getNewValue() { + return super.getNewValue(); + } + + @Override + public PrismPropertyValue getOldValue() { + return super.getOldValue(); + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java index 50173d8ba52..ed020736710 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java @@ -8,6 +8,7 @@ import com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper; import com.evolveum.midpoint.prism.PrismReferenceValue; +import com.evolveum.midpoint.prism.PrismValue; import com.evolveum.midpoint.prism.Referencable; import com.evolveum.midpoint.web.component.prism.ValueStatus; @@ -15,7 +16,7 @@ * @author katka * */ -public class PrismReferenceValueWrapperImpl extends PrismValueWrapperImpl { +public class PrismReferenceValueWrapperImpl extends PrismValueWrapperImpl { private static final long serialVersionUID = 1L; @@ -56,4 +57,10 @@ public boolean isLink() { public void setLink(boolean link) { isLink = link; } + + @Override + public PrismReferenceValue getNewValue() { + return super.getNewValue(); + } + } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java index fb42768de40..6c982caf562 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java @@ -7,9 +7,11 @@ package com.evolveum.midpoint.gui.impl.prism.wrapper; import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper; +import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper; import com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper; import com.evolveum.midpoint.prism.ItemDefinition; import com.evolveum.midpoint.prism.PrismValue; +import com.evolveum.midpoint.prism.ValueMetadata; import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy; import com.evolveum.midpoint.util.DOMUtil; @@ -24,36 +26,40 @@ * @author katka * */ -public abstract class PrismValueWrapperImpl implements PrismValueWrapper { +public abstract class PrismValueWrapperImpl implements PrismValueWrapper { private static final long serialVersionUID = 1L; private ItemWrapper parent; - private V oldValue; - private V newValue; + private PrismValue oldValue; + private PrismValue newValue; private ValueStatus status; + private ValueMetadataWrapperImpl valueMetadata; + private boolean showMetadata; - PrismValueWrapperImpl(ItemWrapper parent, V value, ValueStatus status) { + PrismValueWrapperImpl(ItemWrapper parent, PrismValue value, ValueStatus status) { this.parent = parent; this.newValue = value; - this.oldValue = (V) value.clone(); + if (value != null) { + this.oldValue = value.clone(); + } this.status = status; } @Override - public > void addToDelta(D delta) throws SchemaException { + public > void addToDelta(D delta) throws SchemaException { switch (status) { case ADDED: if (newValue.isEmpty()) { break; } if (parent.isSingleValue()) { - delta.addValueToReplace((V) newValue.clone()); + delta.addValueToReplace(getNewValue().clone()); } else { - delta.addValueToAdd((V) newValue.clone()); + delta.addValueToAdd(getNewValue().clone()); } break; case NOT_CHANGED: @@ -64,23 +70,23 @@ public abstract class PrismValueWrapperImpl implements if (parent.isSingleValue()) { if (newValue.isEmpty()) { - delta.addValueToDelete((V) oldValue.clone()); + delta.addValueToDelete(oldValue.clone()); } else { - delta.addValueToReplace((V) newValue.clone()); + delta.addValueToReplace(newValue.clone()); } break; } if (!newValue.isEmpty()) { - delta.addValueToAdd((V) newValue.clone()); + delta.addValueToAdd(newValue.clone()); } if (!oldValue.isEmpty()) { - delta.addValueToDelete((V) oldValue.clone()); + delta.addValueToDelete(oldValue.clone()); } break; case DELETED: if (oldValue != null && !oldValue.isEmpty()) { - delta.addValueToDelete((V) oldValue.clone()); + delta.addValueToDelete(oldValue.clone()); } break; default: @@ -106,13 +112,13 @@ public T getRealValue() { @Override - public V getNewValue() { - return newValue; + public V getNewValue() { + return (V) newValue; } @Override - public V getOldValue() { - return oldValue; + public V getOldValue() { + return (V) oldValue; } @Override @@ -142,4 +148,23 @@ public String debugDump(int indent) { public boolean isVisible() { return !ValueStatus.DELETED.equals(getStatus()); } + + @Override + public void setValueMetadata(ValueMetadataWrapperImpl valueMetadata) { + this.valueMetadata = valueMetadata; + } + + @Override + public ValueMetadataWrapperImpl getValueMetadata() { + return valueMetadata; + } + + @Override + public boolean isShowMetadata() { + return true; + } + + public void setShowMetadata(boolean showMetadata) { + this.showMetadata = showMetadata; + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java new file mode 100644 index 00000000000..ddb7e1fd03f --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2010-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.midpoint.gui.impl.prism.wrapper; + +import com.evolveum.midpoint.gui.api.prism.wrapper.*; +import com.evolveum.midpoint.prism.*; +import com.evolveum.midpoint.prism.delta.ItemDelta; +import com.evolveum.midpoint.prism.path.ItemPath; +import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.midpoint.web.component.prism.ValueStatus; +import com.evolveum.midpoint.xml.ns._public.common.common_3.VirtualContainerItemSpecificationType; + +import java.util.List; + +public class ValueMetadataWrapperImpl implements PrismContainerValueWrapper { + + private boolean sorted; + private PrismContainerValueWrapper metadataValueWrapper; + + public ValueMetadataWrapperImpl(PrismContainerValueWrapper metadataValueWrapper) { + this.metadataValueWrapper = metadataValueWrapper; + } + + @Override + public String getDisplayName() { + return getDefinition().getDisplayName(); + } + + @Override + public String getHelpText() { + return metadataValueWrapper.getHelpText(); + } + + @Override + public boolean isExpanded() { + return true; + } + + @Override + public void setExpanded(boolean expanded) { + + } + + @Override + public boolean isSorted() { + return sorted; + } + + @Override + public void setSorted(boolean sorted) { + this.sorted = sorted; + } + + @Override + public List> getChildContainers() throws SchemaException { + throw new UnsupportedOperationException("Cannot create child containers for value metadata"); + } + + @Override + public Containerable getRealValue() { + return getOldValue().getRealValue(); + } + + @Override + public void setRealValue(Containerable realValue) { + throw new UnsupportedOperationException("Cannot set real value for value metadata"); + } + + @Override + public ValueStatus getStatus() { + return ValueStatus.NOT_CHANGED; + } + + @Override + public void setStatus(ValueStatus status) { + throw new UnsupportedOperationException("Cannot set value status for value metadata"); + } + + @Override + public ValueMetadata getNewValue() { + return (ValueMetadata) metadataValueWrapper.getOldValue(); + } + + @Override + public ValueMetadata getOldValue() { + return (ValueMetadata) metadataValueWrapper.getOldValue(); + } + + @Override + public IW getParent() { + return null; + } + + @Override + public > void addToDelta(D delta) throws SchemaException { + throw new UnsupportedOperationException("Cannot compute delta for valueMetadata"); + } + + @Override + public boolean isVisible() { + return true; + } + + @Override + public PrismContainerValueWrapper getValueMetadata() { + return null; + } + + @Override + public void setValueMetadata(ValueMetadataWrapperImpl valueMetadata) { + + } + + @Override + public boolean isShowMetadata() { + return false; + } + + @Override + public void setShowMetadata(boolean showMetadata) { + + } + + @Override + public List> getContainers() { + return metadataValueWrapper.getContainers(); + } + + @Override + public List> getNonContainers() { + return metadataValueWrapper.getNonContainers(); + } + + @Override + public List> getItems() { + return metadataValueWrapper.getItems(); + } + + @Override + public PrismContainerWrapper findContainer(ItemPath path) throws SchemaException { + return metadataValueWrapper.findContainer(path); + } + + @Override + public PrismPropertyWrapper findProperty(ItemPath propertyPath) throws SchemaException { + return metadataValueWrapper.findProperty(propertyPath); + } + + @Override + public PrismReferenceWrapper findReference(ItemPath path) throws SchemaException { + return metadataValueWrapper.findReference(path); + } + + @Override + public IW findItem(ItemPath path, Class type) throws SchemaException { + return metadataValueWrapper.findItem(path, type); + } + + @Override + public ItemPath getPath() { + return null; + } + + @Override + public boolean isSelected() { + return false; + } + + @Override + public boolean setSelected(boolean selected) { + return false; + } + + @Override + public boolean isReadOnly() { + return true; + } + + @Override + public void setReadOnly(boolean readOnly, boolean recursive) { + + } + + @Override + public boolean hasChanged() { + return false; + } + + @Override + public boolean isShowEmpty() { + return false; + } + + @Override + public void setShowEmpty(boolean setShowEmpty) { + + } + + @Override + public void applyDelta(ID delta) throws SchemaException { + + } + + @Override + public PrismContainerValue getValueToAdd() throws SchemaException { + return null; + } + + @Override + public boolean isHeterogenous() { + return false; + } + + @Override + public void setHeterogenous(boolean heterogenous) { + + } + + @Override + public void setVirtualContainerItems(List virtualItems) { + + } + + @Override + public boolean isVirtual() { + return false; + } + + @Override + public PrismContainerDefinition getDefinition() { + return metadataValueWrapper.getDefinition(); + } + + @Override + public String debugDump(int indent) { + return null; + } + + +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/registry/GuiComponentRegistryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/registry/GuiComponentRegistryImpl.java index 61ef5ce6a57..1d7f1857ca1 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/registry/GuiComponentRegistryImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/registry/GuiComponentRegistryImpl.java @@ -16,7 +16,6 @@ import javax.xml.namespace.QName; import com.evolveum.midpoint.gui.api.factory.wrapper.PrismContainerWrapperFactory; -import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper; import com.evolveum.midpoint.prism.*; import org.springframework.stereotype.Component; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/FocusProjectionsTabPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/FocusProjectionsTabPanel.java index cefa473cd5e..3b5c613c1e4 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/FocusProjectionsTabPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/FocusProjectionsTabPanel.java @@ -339,7 +339,7 @@ protected Component createColumnPanel(String componentI if (object == null) { return new WebMarkupContainer(componentId); } - List> values = object.getValues(); + List> values = object.getValues(); List pendingOperations = new ArrayList(); values.forEach(value -> { pendingOperations.add(value.getRealValue()); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/util/ContainerListDataProvider.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/util/ContainerListDataProvider.java index 1258478e08a..b4816fe686b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/util/ContainerListDataProvider.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/util/ContainerListDataProvider.java @@ -6,8 +6,9 @@ */ package com.evolveum.midpoint.web.component.util; +import com.evolveum.midpoint.gui.api.factory.wrapper.ItemWrapperFactory; +import com.evolveum.midpoint.gui.api.factory.wrapper.PrismContainerWrapperFactory; import com.evolveum.midpoint.gui.api.util.WebComponentUtil; -import com.evolveum.midpoint.gui.impl.factory.wrapper.PrismContainerWrapperFactoryImpl; import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext; import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper; import com.evolveum.midpoint.prism.Containerable; @@ -80,11 +81,10 @@ public Iterator> internalIterator(long f LOGGER.trace("Query {} resulted in {} containers", type.getSimpleName(), list.size()); } - PrismContainerWrapperFactoryImpl containerFactory = new PrismContainerWrapperFactoryImpl(); - for (C object : list) { WrapperContext context = new WrapperContext(task, result); - getAvailableData().add(containerFactory.createContainerValueWrapper(null, object.asPrismContainerValue(), ValueStatus.NOT_CHANGED, context)); + PrismContainerWrapperFactory factory = getPage().findContainerWrapperFactory(object.asPrismContainerValue().getDefinition()); + getAvailableData().add(factory.createValueWrapper(null, object.asPrismContainerValue(), ValueStatus.NOT_CHANGED, context)); } } catch (Exception ex) { result.recordFatalError(getPage().createStringResource("ContainerListDataProvider.message.listContainers.fatalError").getString(), ex); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/server/PageTask.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/server/PageTask.java index fc1c8301b5e..cc65335ca9d 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/server/PageTask.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/server/PageTask.java @@ -434,7 +434,7 @@ public void yesPerformed(AjaxRequestTarget target) { return null; } - PrismValueWrapper itemValue = item.getValue(); + PrismValueWrapper itemValue = item.getValue(); if (itemValue == null) { return null; } From 6098201e57a5d09af796c4e5c27299719a16607c Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 10:08:12 +0200 Subject: [PATCH 03/60] Axiom: moved exceptions to lang.spi Signed-off-by: Tony Tkacik --- .../stmt/AxiomStatementStreamListener.java | 2 +- .../axiom/lang/impl/AxiomErrorListener.java | 2 + .../axiom/lang/impl/AxiomStatementSource.java | 1 + .../impl/AxiomStatementStreamBuilder.java | 1 + .../axiom/lang/impl/BasicStatementRule.java | 1 + .../lang/impl/IdentifierSpaceHolderImpl.java | 1 + .../axiom/lang/impl/ModelReactorContext.java | 2 +- .../axiom/lang/impl/StatementContext.java | 1 + .../axiom/lang/impl/StatementContextImpl.java | 1 + .../axiom/lang/impl/StatementRule.java | 1 + .../axiom/lang/impl/StatementRuleContext.java | 1 + .../lang/impl/StatementRuleContextImpl.java | 1 + .../{impl => spi}/AxiomSemanticException.java | 3 +- .../{impl => spi}/AxiomSyntaxException.java | 2 +- .../axiom/src/main/resources/axiom-lang.axiom | 53 ++++++++++++------- .../axiom/lang/test/AbstractReactorTest.java | 2 +- .../axiom/lang/test/TestAxiomMultimodule.java | 3 +- .../axiom/lang/test/TestAxiomParser.java | 3 +- 18 files changed, 51 insertions(+), 30 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AxiomSemanticException.java (95%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AxiomSyntaxException.java (98%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java index ad2ff098907..e5187734d7f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.impl.AxiomSyntaxException; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public interface AxiomStatementStreamListener { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomErrorListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomErrorListener.java index c8357f5d710..38f07b2c116 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomErrorListener.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomErrorListener.java @@ -18,6 +18,8 @@ import org.antlr.v4.runtime.atn.ATNConfigSet; import org.antlr.v4.runtime.dfa.DFA; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; + public class AxiomErrorListener extends BaseErrorListener { private final String source; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java index b689eec3a23..f7ab5040b75 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java @@ -27,6 +27,7 @@ import com.evolveum.axiom.lang.antlr.AxiomParser; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class AxiomStatementSource implements AxiomModelInfo, AxiomIdentifierResolver { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java index 835deb511c3..affcee04cd8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java @@ -15,6 +15,7 @@ import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; import com.evolveum.axiom.lang.api.stmt.SourceLocation; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.google.common.collect.Iterables; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 23ef4c4536f..b2982aaa32d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -14,6 +14,7 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index 906f8e6b0f9..20e4810b2e1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -10,6 +10,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 09bd476ef97..029aaf30796 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -21,7 +21,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; - +import com.evolveum.axiom.lang.spi.AxiomSemanticException; import org.jetbrains.annotations.Nullable; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java index 29c95e8a99c..424d589b5b0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java @@ -6,6 +6,7 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 21045a29827..a9719035f6f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -18,6 +18,7 @@ import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java index 61ecad414b0..6fe435ff91e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java @@ -1,6 +1,7 @@ package com.evolveum.axiom.lang.impl; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; public interface StatementRule { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java index 92f834e4d28..fd4dcf62b93 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java @@ -10,6 +10,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.impl.Requirement.Search; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; public interface StatementRuleContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index 3ae8a47f769..86d11a7b6ec 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -11,6 +11,7 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.sun.net.httpserver.Authenticator.Result; public class StatementRuleContextImpl implements StatementRuleContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSemanticException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java similarity index 95% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSemanticException.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java index 9c345456e9d..da2c932165c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSemanticException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.lang.spi; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.stmt.SourceLocation; @@ -35,7 +35,6 @@ public static void check(boolean check, SourceLocation start, String format, Obj if(!check) { throw new AxiomSemanticException(start + Strings.lenientFormat(format, arguments)); } - ; } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSyntaxException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java similarity index 98% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSyntaxException.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java index 140873ad471..ea1ec975338 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSyntaxException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java @@ -4,7 +4,7 @@ * 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.impl; +package com.evolveum.axiom.lang.spi; import java.util.Optional; diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index fe609389db0..a6eddfebf52 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -5,47 +5,48 @@ model axiom-lang { root model { documentation """ Axiom Model + + Declares a new axiom model. """; type AxiomModel; } - type AxiomImportDeclaration { - argument prefix; + type AxiomModel { + extends AxiomBaseDefinition; - item prefix { - type AxiomIdentifier; + item namespace { + type string; } - item namespace { + item version { type string; } - } - type AxiomModel { - extends AxiomBaseDefinition; - item import { type AxiomImportDeclaration; } item root { + documentation """ + Root Definition + + Root Definition defines allowed root for serialized documents + modeled by Axiom language. + """; type AxiomRootDefinition; } item type { documentation """ Type Declaration + + type statement declares a new global type, which is available + to model items. """; type AxiomTypeDefinition; } - item namespace { - type string; - } - item version { - type string; - } // TODO move to prism schema; consider renaming to objectType? item object { @@ -67,7 +68,19 @@ model axiom-lang { type PrismItemDefinition; } } - + + type AxiomImportDeclaration { + argument prefix; + + item prefix { + type AxiomIdentifier; + } + + item namespace { + type string; + } + } + type AxiomRootDefinition { extends AxiomItemDefinition; identifier name { @@ -86,7 +99,7 @@ model axiom-lang { item documentation { type string; } - + item since { type SemanticVersion; } @@ -97,7 +110,7 @@ model axiom-lang { // type string; //} } - + type AxiomIdentifierDefinition { argument key; item key { @@ -127,7 +140,7 @@ model axiom-lang { } item extends { - type AxiomTypeReference; + type AxiomTypeReference; } item identifier { @@ -196,7 +209,7 @@ model axiom-lang { type SemanticVersion { extends string; } - + // TODO move to prism schema; probably should be prism:ObjectDefinition type PrismObjectDefinition { extends AxiomTypeDefinition; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java index 7236a3fd77d..7b6d838c7e5 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java @@ -10,8 +10,8 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.impl.AxiomStatementSource; -import com.evolveum.axiom.lang.impl.AxiomSyntaxException; import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; public abstract class AbstractReactorTest extends AbstractUnitTest { diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java index 3cfb8dc0069..f493401e635 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java @@ -29,9 +29,8 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.AxiomStatementSource; - -import com.evolveum.axiom.lang.impl.AxiomSyntaxException; import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; public class TestAxiomMultimodule extends AbstractReactorTest { diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index 47978fdff1e..36109efa1ca 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -29,9 +29,8 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.AxiomStatementSource; - -import com.evolveum.axiom.lang.impl.AxiomSyntaxException; import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; public class TestAxiomParser extends AbstractReactorTest { From 4936ba34b866d13a0395827e4ebafe37dcb0ac8a Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 10:10:02 +0200 Subject: [PATCH 04/60] Axiom: moved SourceLocation to lang.spi Signed-off-by: Tony Tkacik --- .../axiom/lang/api/stmt/AxiomStatementStreamListener.java | 1 + .../java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java | 2 +- .../evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java | 2 +- .../java/com/evolveum/axiom/lang/impl/ModelReactorContext.java | 2 +- .../java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java | 2 +- .../java/com/evolveum/axiom/lang/impl/StatementContextImpl.java | 2 +- .../java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java | 2 +- .../com/evolveum/axiom/lang/spi/AxiomSemanticException.java | 1 - .../java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java | 1 - .../evolveum/axiom/lang/{api/stmt => spi}/SourceLocation.java | 2 +- 10 files changed, 8 insertions(+), 9 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{api/stmt => spi}/SourceLocation.java (94%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java index e5187734d7f..1973a797698 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java @@ -11,6 +11,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; +import com.evolveum.axiom.lang.spi.SourceLocation; public interface AxiomStatementStreamListener { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java index 24db22ec6ca..997381f79e3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java @@ -22,7 +22,7 @@ import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; +import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.base.Strings; public class AxiomAntlrVisitor extends AxiomBaseVisitor { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java index affcee04cd8..7cc6a1bac76 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java @@ -14,8 +14,8 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; +import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.collect.Iterables; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 029aaf30796..f1ebda10495 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -19,9 +19,9 @@ import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.SourceLocation; import org.jetbrains.annotations.Nullable; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java index 067a6e25cb8..d4883c1705d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java @@ -1,6 +1,6 @@ package com.evolveum.axiom.lang.impl; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; +import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.base.Strings; public class RuleErrorMessage { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index a9719035f6f..1747e47e9cb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -16,9 +16,9 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.stmt.AxiomStatement; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.SourceLocation; public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java index 37154cda505..44d7fb66d10 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java @@ -4,7 +4,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; +import com.evolveum.axiom.lang.spi.SourceLocation; public interface StatementTreeBuilder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java index da2c932165c..0d1c6ea8c0e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java @@ -1,7 +1,6 @@ package com.evolveum.axiom.lang.spi; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.google.common.base.Strings; public class AxiomSemanticException extends RuntimeException { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java index ea1ec975338..811e169ffde 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java @@ -11,7 +11,6 @@ import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.stmt.SourceLocation; import com.google.common.base.Strings; public class AxiomSyntaxException extends RuntimeException { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/SourceLocation.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java similarity index 94% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/SourceLocation.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java index 8164b9f3af4..38546da7222 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/SourceLocation.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.api.stmt; +package com.evolveum.axiom.lang.spi; public class SourceLocation { From bdf8504f2c5d8c1903c6c71849e990280196cd14 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 10:11:02 +0200 Subject: [PATCH 05/60] Axiom: moved Statement interface to Axiom SPI Signed-off-by: Tony Tkacik --- .../main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java | 2 +- .../evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java | 2 +- .../java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java | 2 +- .../com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java | 2 +- .../com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java | 2 +- .../com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java | 2 +- .../java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java | 2 +- .../com/evolveum/axiom/lang/impl/AxiomStatementSource.java | 2 +- .../evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java | 4 ++-- .../com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java | 2 +- .../java/com/evolveum/axiom/lang/impl/BasicStatementRule.java | 2 +- .../com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java | 2 +- .../evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java | 2 +- .../main/java/com/evolveum/axiom/lang/impl/Requirement.java | 2 +- .../java/com/evolveum/axiom/lang/impl/StatementContext.java | 2 +- .../com/evolveum/axiom/lang/impl/StatementContextImpl.java | 2 +- .../com/evolveum/axiom/lang/impl/StatementContextResult.java | 2 +- .../com/evolveum/axiom/lang/impl/StatementRuleContext.java | 2 +- .../evolveum/axiom/lang/impl/StatementRuleContextImpl.java | 2 +- .../evolveum/axiom/lang/{api/stmt => spi}/AxiomStatement.java | 2 +- .../lang/{api/stmt => spi}/AxiomStatementStreamListener.java | 4 +--- 21 files changed, 22 insertions(+), 24 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{api/stmt => spi}/AxiomStatement.java (97%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{api/stmt => spi}/AxiomStatementStreamListener.java (83%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 84ea9160a93..fe8f1ac9698 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -14,7 +14,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.concepts.Lazy.Supplier; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java index 9298b9a69e1..29fe8aa0a13 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java @@ -7,7 +7,7 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.Multimap; public class AbstractAxiomBaseDefinition extends AxiomStatementImpl implements AxiomBaseDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java index 997381f79e3..6294195385f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java @@ -21,7 +21,7 @@ import com.evolveum.axiom.lang.antlr.AxiomParser.PrefixContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; -import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; +import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.base.Strings; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java index 6e80dd0f8d8..da8d115b948 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java @@ -6,7 +6,7 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.Multimap; public class AxiomItemDefinitionImpl extends AbstractAxiomBaseDefinition implements AxiomItemDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index 10da0252199..14a4dcbee00 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -10,7 +10,7 @@ import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java index 4d3b2eafebb..51e5a8246ae 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java @@ -10,8 +10,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java index 9bcf42362ad..21caef367ae 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java @@ -13,7 +13,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java index f7ab5040b75..c5494d1398f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java @@ -26,7 +26,7 @@ import com.evolveum.axiom.lang.antlr.AxiomLexer; import com.evolveum.axiom.lang.antlr.AxiomParser; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; -import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; +import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class AxiomStatementSource implements AxiomModelInfo, AxiomIdentifierResolver { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java index 7cc6a1bac76..50299cabb1b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java @@ -12,8 +12,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; -import com.evolveum.axiom.lang.api.stmt.AxiomStatementStreamListener; +import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.collect.Iterables; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java index 1b2b782dc63..0dfaba47f6c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java @@ -16,7 +16,7 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.Identifiable; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Multimap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index b2982aaa32d..86f386f62b9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -13,8 +13,8 @@ import com.evolveum.axiom.lang.api.AxiomModel; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java index 3ccc9e65a13..109d4b68b87 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java @@ -5,7 +5,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; interface IdentifierSpaceHolder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index 20e4810b2e1..2eec78deb98 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -9,8 +9,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java index 478fa9becb4..a45d8b2aaf0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.base.Preconditions; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java index 424d589b5b0..bb7439aba13 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java @@ -5,8 +5,8 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 1747e47e9cb..411c7cac157 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -15,9 +15,9 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.lang.spi.SourceLocation; public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java index d973b27607a..6a795132928 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java @@ -7,7 +7,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java index fd4dcf62b93..dee4e3caa88 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java @@ -8,9 +8,9 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.impl.Requirement.Search; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatement; public interface StatementRuleContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index 86d11a7b6ec..e89989c825a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -10,8 +10,8 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.stmt.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatement; import com.sun.net.httpserver.Authenticator.Result; public class StatementRuleContextImpl implements StatementRuleContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatement.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java similarity index 97% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatement.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java index d320f89c71f..b6f287f3f74 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java @@ -4,7 +4,7 @@ * 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.stmt; +package com.evolveum.axiom.lang.spi; import java.util.Collection; import java.util.Optional; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementStreamListener.java similarity index 83% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementStreamListener.java index 1973a797698..2a1e35e7945 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/stmt/AxiomStatementStreamListener.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementStreamListener.java @@ -4,14 +4,12 @@ * 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.stmt; +package com.evolveum.axiom.lang.spi; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.evolveum.axiom.lang.spi.SourceLocation; public interface AxiomStatementStreamListener { From 81ecb7c4c94b325b1242f10b17c3b61bd3622118 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 10:15:53 +0200 Subject: [PATCH 06/60] Axiom: Moved IdentifierResolver to axiom.lang.spi Signed-off-by: Tony Tkacik --- .../java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java | 1 + .../java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java | 1 + .../java/com/evolveum/axiom/lang/impl/ModelReactorContext.java | 1 + .../axiom/lang/{impl => spi}/AxiomIdentifierResolver.java | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AxiomIdentifierResolver.java (97%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java index 6294195385f..74ff1ecb38f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java @@ -21,6 +21,7 @@ import com.evolveum.axiom.lang.antlr.AxiomParser.PrefixContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.base.Strings; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java index c5494d1398f..8f913b4525e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java @@ -26,6 +26,7 @@ import com.evolveum.axiom.lang.antlr.AxiomLexer; import com.evolveum.axiom.lang.antlr.AxiomParser; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index f1ebda10495..a53261e68ed 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -20,6 +20,7 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java similarity index 97% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomIdentifierResolver.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java index 5fe918220d3..a0cc6ec4651 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java @@ -4,7 +4,7 @@ * 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.impl; +package com.evolveum.axiom.lang.spi; import java.util.Set; From 4459d85e9e95cf9aaf626040cce0fcdb195e2876 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 10:18:46 +0200 Subject: [PATCH 07/60] Axiom: Moved Requirement to axiom.reactor Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/lang/impl/BasicStatementRule.java | 1 + .../com/evolveum/axiom/lang/impl/ModelReactorContext.java | 1 + .../com/evolveum/axiom/lang/impl/StatementContext.java | 1 + .../com/evolveum/axiom/lang/impl/StatementContextImpl.java | 3 ++- .../evolveum/axiom/lang/impl/StatementContextResult.java | 1 + .../com/evolveum/axiom/lang/impl/StatementRuleContext.java | 3 ++- .../evolveum/axiom/lang/impl/StatementRuleContextImpl.java | 1 + .../evolveum/axiom/{lang/impl => reactor}/Deffered.java | 2 +- .../evolveum/axiom/{lang/impl => reactor}/Requirement.java | 7 ++++++- 9 files changed, 16 insertions(+), 4 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/impl => reactor}/Deffered.java (95%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/impl => reactor}/Requirement.java (95%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 86f386f62b9..a6a53554574 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -15,6 +15,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.reactor.Requirement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index a53261e68ed..5af0ffb5120 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -23,6 +23,7 @@ import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.SourceLocation; +import com.evolveum.axiom.reactor.Requirement; import org.jetbrains.annotations.Nullable; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java index bb7439aba13..f29071c649e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java @@ -7,6 +7,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.reactor.Requirement; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 411c7cac157..599fdba2d3b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -19,6 +19,7 @@ import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.lang.spi.SourceLocation; +import com.evolveum.axiom.reactor.Requirement; public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { @@ -156,7 +157,7 @@ public void setValue(Object value, SourceLocation loc) { public Requirement> asRequirement() { if (result instanceof StatementContextResult) { - return new Deffered<>(result); + return Requirement.deffered(result); } return result; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java index 6a795132928..a01a8bab759 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java @@ -8,6 +8,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.reactor.Requirement; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java index dee4e3caa88..f65ce8f9049 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java @@ -8,9 +8,10 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.impl.Requirement.Search; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.reactor.Requirement; +import com.evolveum.axiom.reactor.Requirement.Search; public interface StatementRuleContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index e89989c825a..ce4d6c7f492 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -12,6 +12,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.reactor.Requirement; import com.sun.net.httpserver.Authenticator.Result; public class StatementRuleContextImpl implements StatementRuleContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Deffered.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java similarity index 95% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Deffered.java rename to infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java index 2e6bfdf74b6..5b57de5fcd1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Deffered.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.reactor; import java.util.Optional; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java similarity index 95% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java rename to infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java index a45d8b2aaf0..512b687b6ba 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/Requirement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java @@ -1,10 +1,11 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.reactor; import java.util.Optional; import java.util.function.Supplier; import org.jetbrains.annotations.Nullable; +import com.evolveum.axiom.lang.impl.RuleErrorMessage; import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.base.Preconditions; @@ -28,6 +29,10 @@ public static Requirement from(Supplier supplier) { return new Suppliable<>(supplier); } + public static Requirement deffered(Requirement original) { + return new Deffered<>(original); + } + default Requirement unsatisfiedMessage(Supplier unsatisfiedMessage) { return this; } From ac85a7ec9f8b7e2f899807d3efdc6c60684b97f5 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 10:42:59 +0200 Subject: [PATCH 08/60] Moved ANTLR specific classes to axiom.lang.antlr Signed-off-by: Tony Tkacik --- .../lang/antlr/AxiomAntlrStatementSource.java | 71 +++++++++++++++++++ .../{impl => antlr}/AxiomAntlrVisitor.java | 2 +- .../{impl => antlr}/AxiomErrorListener.java | 9 +-- .../AxiomModelStatementSource.java} | 56 ++++++--------- .../axiom/lang/impl/AxiomModelInfo.java | 14 ---- .../axiom/lang/impl/AxiomStatementImpl.java | 6 -- .../axiom/lang/impl/DelegatedRequirement.java | 7 -- .../axiom/lang/impl/ModelReactorContext.java | 11 +-- .../evolveum/axiom/reactor/Requirement.java | 1 - .../axiom/lang/test/AbstractReactorTest.java | 8 +-- .../axiom/lang/test/TestAxiomMultimodule.java | 3 +- .../axiom/lang/test/TestAxiomParser.java | 3 +- 12 files changed, 106 insertions(+), 85 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => antlr}/AxiomAntlrVisitor.java (99%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => antlr}/AxiomErrorListener.java (86%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl/AxiomStatementSource.java => antlr/AxiomModelStatementSource.java} (60%) delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomModelInfo.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DelegatedRequirement.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java new file mode 100644 index 00000000000..87f724e77fe --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -0,0 +1,71 @@ +/* + * 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.antlr; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; +import java.util.Set; + +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.antlr.AxiomLexer; +import com.evolveum.axiom.lang.antlr.AxiomParser; +import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; + +public class AxiomAntlrStatementSource { + + private final StatementContext root; + private final String sourceName; + + public static AxiomAntlrStatementSource from(String sourceName, InputStream stream) throws IOException, AxiomSyntaxException { + return from(sourceName, CharStreams.fromStream(stream)); + } + + public static StatementContext contextFrom(String sourceName, CharStream stream) { + AxiomLexer lexer = new AxiomLexer(stream); + AxiomParser parser = new AxiomParser(new CommonTokenStream(lexer)); + lexer.removeErrorListeners(); + parser.removeErrorListeners(); + AxiomErrorListener errorListener = new AxiomErrorListener(sourceName); + parser.addErrorListener(errorListener); + StatementContext statement = parser.statement(); + errorListener.validate(); + return statement; + } + + public static AxiomAntlrStatementSource from(String sourceName, CharStream stream) throws AxiomSyntaxException { + StatementContext statement = contextFrom(sourceName, stream); + return new AxiomAntlrStatementSource(sourceName, statement); + } + + protected AxiomAntlrStatementSource(String sourceName, StatementContext statement) { + this.sourceName = sourceName; + this.root = statement; + } + + public String sourceName() { + return sourceName; + } + + protected final StatementContext root() { + return root; + } + + public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomStatementStreamListener listener, + Optional> emitOnly) { + AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, statements, arguments, listener, emitOnly.orElse(null)); + visitor.visit(root); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java similarity index 99% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index 74ff1ecb38f..aba2ca4f3de 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -4,7 +4,7 @@ * 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.impl; +package com.evolveum.axiom.lang.antlr; import java.util.Optional; import java.util.Set; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomErrorListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java similarity index 86% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomErrorListener.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java index 38f07b2c116..5541095f0c4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomErrorListener.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java @@ -4,20 +4,14 @@ * 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.impl; +package com.evolveum.axiom.lang.antlr; import java.util.ArrayList; -import java.util.BitSet; import java.util.List; -import org.antlr.v4.runtime.ANTLRErrorListener; import org.antlr.v4.runtime.BaseErrorListener; -import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Recognizer; -import org.antlr.v4.runtime.atn.ATNConfigSet; -import org.antlr.v4.runtime.dfa.DFA; - import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class AxiomErrorListener extends BaseErrorListener { @@ -33,7 +27,6 @@ public AxiomErrorListener(String source) { public void syntaxError(final Recognizer recognizer, final Object offendingSymbol, final int line, final int charPositionInLine, final String msg, final RecognitionException e) { exceptions.add(new AxiomSyntaxException(source, line, charPositionInLine, msg)); - } public void validate() throws AxiomSyntaxException { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java similarity index 60% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 8f913b4525e..f6c367954b3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -4,7 +4,7 @@ * 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.impl; +package com.evolveum.axiom.lang.antlr; import java.beans.Statement; import java.io.IOException; @@ -30,66 +30,52 @@ import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -public class AxiomStatementSource implements AxiomModelInfo, AxiomIdentifierResolver { +public class AxiomModelStatementSource extends AxiomAntlrStatementSource implements AxiomIdentifierResolver { private static final String IMPORT = "import"; private static final String NAMESPACE = "namespace"; - private final StatementContext root; - private String sourceName; + + private String name; private Map imports; + private String namespace; - public static AxiomStatementSource from(InputStream stream) throws IOException, AxiomSyntaxException { + public static AxiomModelStatementSource from(InputStream stream) throws IOException, AxiomSyntaxException { return from(null, CharStreams.fromStream(stream)); } - public static AxiomStatementSource from(String sourceName, InputStream stream) throws IOException, AxiomSyntaxException { + public static AxiomModelStatementSource from(String sourceName, InputStream stream) throws IOException, AxiomSyntaxException { return from(sourceName, CharStreams.fromStream(stream)); } - public static AxiomStatementSource from(String sourceName, CharStream stream) throws AxiomSyntaxException { - - AxiomLexer lexer = new AxiomLexer(stream); - AxiomParser parser = new AxiomParser(new CommonTokenStream(lexer)); - - lexer.removeErrorListeners(); - parser.removeErrorListeners(); - AxiomErrorListener errorListener = new AxiomErrorListener(sourceName); - parser.addErrorListener(errorListener); - StatementContext statement = parser.statement(); - errorListener.validate(); - return new AxiomStatementSource(sourceName, statement, imports(statement)); + public static AxiomModelStatementSource from(String sourceName, CharStream stream) throws AxiomSyntaxException { + StatementContext statement = AxiomAntlrStatementSource.contextFrom(sourceName, stream); + String name = statement.argument().identifier().localIdentifier().getText(); + return new AxiomModelStatementSource(sourceName, statement, name, namespace(statement), imports(statement)); } - private AxiomStatementSource(String sourceName, StatementContext statement, Map imports) { - this.sourceName = sourceName; - this.root = statement; + private AxiomModelStatementSource(String sourceName, StatementContext statement, String namespace, String name, Map imports) { + super(sourceName, statement); + this.name = name; this.imports = imports; + this.namespace = namespace; } - @Override - public String getModelName() { - return root.argument().identifier().localIdentifier().getText(); - } - @Override - public String getNamespace() { - return null; + public String modelName() { + return name; } - @Override - public String getDescription() { - // TODO Auto-generated method stub - return null; + public String namespace() { + return namespace; } public void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListener listener) { stream(resolver, listener, Optional.empty()); } - private void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListener listener, + public void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListener listener, Optional> emitOnly) { - AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, resolver, BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly.orElse(null)); - visitor.visit(root); + stream(resolver, BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); } public static Map imports(AxiomParser.StatementContext root) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomModelInfo.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomModelInfo.java deleted file mode 100644 index 80f13954a47..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomModelInfo.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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.impl; - -public interface AxiomModelInfo { - - String getModelName(); - String getNamespace(); - String getDescription(); -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java index 21caef367ae..5e5211e1ef3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java @@ -6,20 +6,14 @@ */ package com.evolveum.axiom.lang.impl; -import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Optional; - import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.MultimapBuilder; import com.google.common.collect.ImmutableMap.Builder; public class AxiomStatementImpl implements AxiomStatement { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DelegatedRequirement.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DelegatedRequirement.java deleted file mode 100644 index f83c3ddd823..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DelegatedRequirement.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.evolveum.axiom.lang.impl; - -import java.util.Optional; - -import com.google.common.base.Preconditions; - - diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 5af0ffb5120..b27636d0e7d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -14,6 +14,7 @@ import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; @@ -34,19 +35,19 @@ public class ModelReactorContext implements AxiomIdentifierResolver { private static final String AXIOM_LANG_RESOURCE = "/axiom-lang.axiom"; private static final String AXIOM_BUILTIN_RESOURCE = "/axiom-base-types.axiom"; - private static final Lazy BASE_LANGUAGE_SOURCE = Lazy.from(() -> { + private static final Lazy BASE_LANGUAGE_SOURCE = Lazy.from(() -> { InputStream stream = AxiomBuiltIn.class.getResourceAsStream(AXIOM_LANG_RESOURCE); try { - return AxiomStatementSource.from(AXIOM_LANG_RESOURCE, stream); + return AxiomModelStatementSource.from(AXIOM_LANG_RESOURCE, stream); } catch (Exception e) { throw new RuntimeException(e); } }); - private static final Lazy BASE_TYPES_SOURCE = Lazy.from(() -> { + private static final Lazy BASE_TYPES_SOURCE = Lazy.from(() -> { InputStream stream = AxiomBuiltIn.class.getResourceAsStream(AXIOM_BUILTIN_RESOURCE); try { - return AxiomStatementSource.from(AXIOM_BUILTIN_RESOURCE, stream); + return AxiomModelStatementSource.from(AXIOM_BUILTIN_RESOURCE, stream); } catch (Exception e) { throw new RuntimeException(e); } @@ -184,7 +185,7 @@ public void addRules(StatementRule... rules) { } } - public void loadModelFromSource(AxiomStatementSource statementSource) { + public void loadModelFromSource(AxiomModelStatementSource statementSource) { statementSource.stream(this, new AxiomStatementStreamBuilder(this, new Root())); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java index 512b687b6ba..206cdb3a9c7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java @@ -175,7 +175,6 @@ public RuleErrorMessage errorMessage() { if(maybeDelegate instanceof Supplier && notFound != null) { return notFound.get(); } - // TODO Auto-generated method stub return super.errorMessage(); } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java index 7b6d838c7e5..2c392debc06 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java @@ -6,10 +6,10 @@ import java.io.InputStream; import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; -import com.evolveum.axiom.lang.impl.AxiomStatementSource; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; @@ -28,13 +28,13 @@ protected static AxiomSchemaContext parseInputStream(String name, InputStream st protected static AxiomSchemaContext parseInputStream(String name, InputStream stream, AxiomItemDefinition rootItemDefinition) throws AxiomSyntaxException, FileNotFoundException, IOException { ModelReactorContext reactorContext =ModelReactorContext.defaultReactor(); - AxiomStatementSource statementSource = AxiomStatementSource.from(name, stream); + AxiomModelStatementSource statementSource = AxiomModelStatementSource.from(name, stream); reactorContext.loadModelFromSource(statementSource); return reactorContext.computeSchemaContext(); } - protected static AxiomStatementSource source(String name) throws AxiomSyntaxException, IOException { + protected static AxiomModelStatementSource source(String name) throws AxiomSyntaxException, IOException { InputStream stream = new FileInputStream(COMMON_DIR_PATH + name); - return AxiomStatementSource.from(name, stream); + return AxiomModelStatementSource.from(name, stream); } } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java index f493401e635..dc185f7e832 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java @@ -21,14 +21,13 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; - -import com.evolveum.axiom.lang.impl.AxiomStatementSource; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index 36109efa1ca..9132779211c 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -21,14 +21,13 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; - -import com.evolveum.axiom.lang.impl.AxiomStatementSource; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; From d3ea298ab58e3749bdb7d4252f9f5ffa6dc92da4 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 10:48:48 +0200 Subject: [PATCH 09/60] Moved Statement, Item, Type implementations to axiom.lang.spi Signed-off-by: Tony Tkacik --- .../axiom/lang/impl/AxiomStatementFactoryContext.java | 5 ++--- .../com/evolveum/axiom/lang/impl/ModelReactorContext.java | 5 ++++- .../com/evolveum/axiom/lang/impl/StatementContextImpl.java | 3 ++- .../com/evolveum/axiom/lang/impl/StatementContextResult.java | 1 + .../lang/{impl => spi}/AbstractAxiomBaseDefinition.java | 3 +-- .../axiom/lang/{impl => spi}/AxiomItemDefinitionImpl.java | 3 +-- .../axiom/lang/{impl => spi}/AxiomStatementBuilder.java | 5 ++--- .../axiom/lang/{impl => spi}/AxiomStatementImpl.java | 5 ++--- .../axiom/lang/{impl => spi}/AxiomTypeDefinitionImpl.java | 3 +-- .../main/java/com/evolveum/axiom/reactor/Requirement.java | 3 --- 10 files changed, 16 insertions(+), 20 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AbstractAxiomBaseDefinition.java (92%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AxiomItemDefinitionImpl.java (94%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AxiomStatementBuilder.java (93%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AxiomStatementImpl.java (93%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl => spi}/AxiomTypeDefinitionImpl.java (97%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementFactoryContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementFactoryContext.java index fc3fc6a8341..351703d0ee5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementFactoryContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementFactoryContext.java @@ -6,15 +6,14 @@ */ package com.evolveum.axiom.lang.impl; -import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; +import com.evolveum.axiom.lang.spi.AxiomStatementImpl; public interface AxiomStatementFactoryContext { AxiomStatementImpl.Factory factoryFor(AxiomTypeDefinition identifier); - static AxiomStatementFactoryContext defaultFactory(AxiomStatementImpl.Factory factory) { + static AxiomStatementFactoryContext defaultFactory(AxiomStatementImpl.Factory factory) { return (identifier) -> factory; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index b27636d0e7d..7b92019fd4c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -20,10 +20,13 @@ import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomItemDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatementImpl; +import com.evolveum.axiom.lang.spi.AxiomTypeDefinitionImpl; import com.evolveum.axiom.lang.spi.SourceLocation; +import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; import com.evolveum.axiom.reactor.Requirement; import org.jetbrains.annotations.Nullable; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 599fdba2d3b..e1a15bf29e1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -15,10 +15,11 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; import com.evolveum.axiom.lang.spi.SourceLocation; +import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; import com.evolveum.axiom.reactor.Requirement; public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java index a01a8bab759..4d3d500a398 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java @@ -8,6 +8,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; import com.evolveum.axiom.reactor.Requirement; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java similarity index 92% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java index 29fe8aa0a13..5d6f99c75a2 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractAxiomBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.lang.spi; import java.util.List; @@ -7,7 +7,6 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.Multimap; public class AbstractAxiomBaseDefinition extends AxiomStatementImpl implements AxiomBaseDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java similarity index 94% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index da8d115b948..1b2fcdec30a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.lang.spi; import java.util.List; @@ -6,7 +6,6 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.Multimap; public class AxiomItemDefinitionImpl extends AbstractAxiomBaseDefinition implements AxiomItemDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementBuilder.java similarity index 93% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementBuilder.java index 51e5a8246ae..acbe6c376ed 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementBuilder.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.lang.spi; import com.evolveum.axiom.concepts.Lazy; @@ -10,8 +10,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.impl.AxiomStatementImpl.Factory; -import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementImpl.java similarity index 93% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementImpl.java index 5e5211e1ef3..b07e3b0577e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementImpl.java @@ -4,13 +4,12 @@ * 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.impl; +package com.evolveum.axiom.lang.spi; import java.util.Collection; import java.util.List; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; @@ -57,7 +56,7 @@ public String toString() { return keyword + "{value=" + value + "}"; } - interface Factory> { + public interface Factory> { I create(AxiomIdentifier type, V value, List> children, Multimap> keywordMap); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java similarity index 97% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 0dfaba47f6c..38d8d4627a5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.lang.spi; import java.util.Collection; import java.util.List; @@ -16,7 +16,6 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.Identifiable; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Multimap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java index 206cdb3a9c7..f3fa23a1398 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java @@ -3,10 +3,7 @@ import java.util.Optional; import java.util.function.Supplier; -import org.jetbrains.annotations.Nullable; - import com.evolveum.axiom.lang.impl.RuleErrorMessage; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.base.Preconditions; From 602f0d0288f265da8267a791266e27015fa001fa Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 19 May 2020 14:45:55 +0200 Subject: [PATCH 10/60] Axiom: Added abstract rule reactor Signed-off-by: Tony Tkacik --- .../{lang/api => concepts}/Identifiable.java | 2 +- .../axiom/lang/impl/BasicStatementRule.java | 8 +- .../axiom/lang/impl/ModelReactorContext.java | 77 +++++++----------- .../axiom/lang/impl/RuleContextImpl.java | 37 +++++++++ .../axiom/lang/impl/StatementContext.java | 4 +- .../axiom/lang/impl/StatementContextImpl.java | 33 ++++---- .../lang/impl/StatementContextResult.java | 4 +- .../axiom/lang/impl/StatementRuleContext.java | 8 +- .../lang/impl/StatementRuleContextImpl.java | 77 +++++++++++------- .../lang/spi/AxiomTypeDefinitionImpl.java | 2 +- .../com/evolveum/axiom/reactor/Action.java | 29 +++++++ .../evolveum/axiom/reactor/ActionState.java | 31 +++++++ .../axiom/reactor/BaseReactorContext.java | 81 +++++++++++++++++++ .../com/evolveum/axiom/reactor/Deffered.java | 10 +-- .../{Requirement.java => Depedency.java} | 40 ++++----- .../axiom/reactor/DependantAction.java | 20 +++++ .../java/com/evolveum/axiom/reactor/Rule.java | 11 +++ .../axiom/reactor/RuleReactorContext.java | 17 ++++ 18 files changed, 360 insertions(+), 131 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => concepts}/Identifiable.java (95%) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/ActionState.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java rename infra/axiom/src/main/java/com/evolveum/axiom/reactor/{Requirement.java => Depedency.java} (74%) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/Rule.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/RuleReactorContext.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/Identifiable.java b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/Identifiable.java similarity index 95% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/Identifiable.java rename to infra/axiom/src/main/java/com/evolveum/axiom/concepts/Identifiable.java index a385213325d..4ee4d2abf31 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/Identifiable.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/Identifiable.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.concepts; import java.util.Map; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index a6a53554574..c85005953fd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -15,7 +15,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Requirement; +import com.evolveum.axiom.reactor.Depedency; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -63,7 +63,7 @@ public void apply(StatementRuleContext rule) throws AxiomSemant @Override public void apply(StatementRuleContext rule) throws AxiomSemanticException { - Requirement req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES)); + Depedency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES)); req.unsatisfiedMessage(() -> rule.error("Default types not found.")); rule.apply((ctx) -> { ctx.parent().importIdentifierSpace(req.get()); @@ -86,7 +86,7 @@ public void apply(StatementRuleContext rule) throws AxiomSemant public void apply(StatementRuleContext rule) throws AxiomSemanticException { String child = rule.requiredChildValue(Item.NAMESPACE, String.class); AxiomIdentifier namespaceId = Item.NAMESPACE.name(); - Requirement req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(child)); + Depedency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(child)); req.unsatisfiedMessage(() -> rule.error("Namespace %s not found.", child)); rule.apply((ctx) -> { ctx.parent().importIdentifierSpace(req.get()); @@ -113,7 +113,7 @@ public void apply(StatementRuleContext rule) throws AxiomSemant @Override public void apply(StatementRuleContext rule) throws AxiomSemanticException { AxiomIdentifier type = rule.requireValue(); - Requirement.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); + Depedency.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); typeDef.notFound(() -> rule.error("type '%s' was not found.", type)); typeDef.unsatisfiedMessage(() -> rule.error("Referenced type %s is not complete.", type)); rule.apply(ctx -> { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 7b92019fd4c..6b1c92959b8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -2,8 +2,8 @@ import java.io.InputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -27,11 +27,12 @@ import com.evolveum.axiom.lang.spi.AxiomTypeDefinitionImpl; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; -import com.evolveum.axiom.reactor.Requirement; +import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.RuleReactorContext; import org.jetbrains.annotations.Nullable; -public class ModelReactorContext implements AxiomIdentifierResolver { +public class ModelReactorContext extends RuleReactorContext, StatementRuleContextImpl, RuleContextImpl> implements AxiomIdentifierResolver { private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); @@ -87,7 +88,7 @@ private static void defaults(ModelReactorContext reactorContext) { } - List> rules = new ArrayList<>(); + Collection rules = new ArrayList<>(); private final AxiomSchemaContext boostrapContext; private final Map exported = new HashMap<>(); @@ -99,7 +100,6 @@ private static void defaults(ModelReactorContext reactorContext) { IdentifierSpaceHolderImpl globalSpace = new IdentifierSpaceHolderImpl(Scope.GLOBAL); Map> typeFactories = new HashMap<>(); - List outstanding = new ArrayList<>(); List> roots = new ArrayList<>(); public ModelReactorContext(AxiomSchemaContext boostrapContext) { @@ -107,46 +107,22 @@ public ModelReactorContext(AxiomSchemaContext boostrapContext) { } public AxiomSchemaContext computeSchemaContext() throws AxiomSemanticException { - boolean anyCompleted = false; - do { - anyCompleted = false; - List toCheck = outstanding; - outstanding = new ArrayList<>(); - - Iterator iterator = toCheck.iterator(); - while (iterator.hasNext()) { - StatementRuleContextImpl ruleCtx = iterator.next(); - if (ruleCtx.canProcess() && ruleCtx.notFailed()) { - ruleCtx.perform(); - if(ruleCtx.successful()) { - iterator.remove(); - anyCompleted = true; - } - } - } - // We add not finished items back to outstanding - outstanding.addAll(toCheck); - } while (anyCompleted); - - if (!outstanding.isEmpty()) { - failOutstanding(outstanding); - } - + compute(); return createSchemaContext(); } - private void failOutstanding(List report) { + @Override + protected void failOutstanding(Collection> outstanding) throws AxiomSemanticException { StringBuilder messages = new StringBuilder("Can not complete models, following errors occured:\n"); - for (StatementRuleContextImpl rule : report) { + for (StatementRuleContextImpl rule : outstanding) { RuleErrorMessage exception = rule.errorMessage(); if (exception != null) { messages.append(exception.toString()).append("\n"); } - for (Requirement req : rule.requirements()) { + for (Depedency req : rule.dependencies()) { if(!req.isSatisfied()) { messages.append(req.errorMessage()).append("\n"); } - } } throw new AxiomSemanticException(messages.toString()); @@ -166,25 +142,21 @@ public void registerGlobal(AxiomIdentifier space, IdentifierSpaceKey key, Statem } - - public void addOutstanding(StatementRuleContextImpl rule) { - outstanding.add(rule); - } - void endStatement(StatementTreeBuilder cur, SourceLocation loc) throws AxiomSemanticException { if (cur instanceof StatementContextImpl) { StatementContextImpl current = (StatementContextImpl) cur; - for (StatementRule statementRule : rules) { - if (statementRule.isApplicableTo(current.definition())) { - current.addRule(statementRule); - } - } + addActionsFor(current); } } + @Override + protected void addOutstanding(StatementRuleContextImpl action) { + super.addOutstanding(action); + } + public void addRules(StatementRule... rules) { for (StatementRule statementRule : rules) { - this.rules.add(statementRule); + this.rules.add(new RuleContextImpl(statementRule)); } } @@ -253,8 +225,19 @@ private CompositeIdentifierSpace exported(IdentifierSpaceKey namespace) { return exported.computeIfAbsent(namespace, k -> new CompositeIdentifierSpace()); } - public Requirement namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { - return Requirement.orNull(exported.get(namespaceId)); + public Depedency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return Depedency.orNull(exported.get(namespaceId)); + } + + @Override + protected AxiomSemanticException createException() { + return null; + } + + @Override + protected Collection rulesFor(StatementContextImpl context) { + // TODO: Add smart filters if neccessary + return rules; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java new file mode 100644 index 00000000000..4b1b570a55d --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java @@ -0,0 +1,37 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.Collection; + +import com.evolveum.axiom.reactor.Rule; + +public class RuleContextImpl implements Rule, StatementRuleContextImpl> { + + private final StatementRule delegate; + + public RuleContextImpl(StatementRule delegate) { + super(); + this.delegate = delegate; + } + + @Override + public boolean applicableTo(StatementContextImpl context) { + return delegate.isApplicableTo(context.definition()); + } + + @Override + public Collection> applyTo(StatementContextImpl context) { + StatementRuleContextImpl actionBuilder = context.addRule(delegate); + delegate.apply(actionBuilder); + return actionBuilder.build(); + } + + @Override + public String toString() { + return delegate.toString(); + } + + public StatementRule delegate() { + return delegate; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java index f29071c649e..41388f3dcfa 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java @@ -7,7 +7,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Requirement; +import com.evolveum.axiom.reactor.Depedency; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; @@ -22,7 +22,7 @@ public interface StatementContext { Optional optionalValue(); - void replace(Requirement> statement); + void replace(Depedency> statement); StatementContext parent(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index e1a15bf29e1..4787936123c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -3,7 +3,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; import java.util.Set; import java.util.function.Supplier; @@ -20,7 +19,7 @@ import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; -import com.evolveum.axiom.reactor.Requirement; +import com.evolveum.axiom.reactor.Depedency; public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { @@ -31,7 +30,7 @@ public abstract class StatementContextImpl implements StatementContext, St private SourceLocation startLocation; private SourceLocation endLocation; private SourceLocation valueLocation; - private Requirement> result; + private Depedency> result; StatementContextImpl(AxiomItemDefinition definition, SourceLocation loc, Scope scope, Scope... rest) { @@ -114,7 +113,7 @@ public StatementContext createEffectiveChild(AxiomIdentifier axiomIdentif public void registerRule(StatementRuleContextImpl rule) { mutableResult().addRule(rule); - addOutstanding(rule); + //addOutstanding(rule); } protected void addOutstanding(StatementRuleContextImpl rule) { @@ -133,8 +132,10 @@ private Collection> children(AxiomIdentifier identif return (Collection) mutableResult().get(identifier); } - public void addRule(StatementRule statementRule) throws AxiomSemanticException { - statementRule.apply(new StatementRuleContextImpl(this,statementRule)); + public StatementRuleContextImpl addRule(StatementRule statementRule) throws AxiomSemanticException { + StatementRuleContextImpl action = new StatementRuleContextImpl(this,statementRule); + statementRule.apply(action); + return action; } @Override @@ -143,8 +144,8 @@ public Optional optionalValue() { } @Override - public void replace(Requirement> supplier) { - this.result = (Requirement) supplier; + public void replace(Depedency> supplier) { + this.result = (Depedency) supplier; } @Override @@ -156,9 +157,9 @@ public void setValue(Object value, SourceLocation loc) { this.valueLocation = loc; } - public Requirement> asRequirement() { + public Depedency> asRequirement() { if (result instanceof StatementContextResult) { - return Requirement.deffered(result); + return Depedency.deffered(result); } return result; } @@ -221,14 +222,14 @@ public V requireValue(Class type) { return null; } - public Requirement> requireChild(AxiomItemDefinition required) { - return Requirement.retriableDelegate(() -> { + public Depedency> requireChild(AxiomItemDefinition required) { + return Depedency.retriableDelegate(() -> { if(mutableResult() != null) { - return (Requirement) firstChild(required).map(StatementContextImpl::asRequirement).orElse(null); + return (Depedency) firstChild(required).map(StatementContextImpl::asRequirement).orElse(null); } Optional> maybe = result.get().first(required); - return Requirement.from(maybe); + return Depedency.from(maybe); }); } @@ -347,8 +348,8 @@ protected Root root() { return this; } - public Requirement requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { - return Requirement.retriableDelegate(() -> { + public Depedency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return Depedency.retriableDelegate(() -> { return reactor.namespace(name, namespaceId); }); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java index 4d3d500a398..5693c722c9f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java @@ -9,11 +9,11 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; -import com.evolveum.axiom.reactor.Requirement; +import com.evolveum.axiom.reactor.Depedency; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -class StatementContextResult implements Requirement> { +class StatementContextResult implements Depedency> { private V value; private final List> childrenList = new ArrayList<>(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java index f65ce8f9049..ba8aebf9ab4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java @@ -10,8 +10,8 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Requirement; -import com.evolveum.axiom.reactor.Requirement.Search; +import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.Depedency.Search; public interface StatementRuleContext { @@ -38,8 +38,8 @@ public interface Action { Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key); - Requirement> requireChild(AxiomItemDefinition required); + Depedency> requireChild(AxiomItemDefinition required); - Requirement requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); + Depedency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index ce4d6c7f492..960b8b8f616 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Supplier; @@ -12,13 +13,14 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Requirement; -import com.sun.net.httpserver.Authenticator.Result; -public class StatementRuleContextImpl implements StatementRuleContext { +import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.DependantAction; +import com.google.common.collect.ImmutableList; +public class StatementRuleContextImpl implements StatementRuleContext, DependantAction { private final StatementContextImpl context; private final StatementRule rule; - private final List> requirements = new ArrayList<>(); + private final List> dependencies = new ArrayList<>(); private Action action; private Supplier errorReport = () -> null; private boolean applied = false; @@ -29,29 +31,25 @@ public StatementRuleContextImpl(StatementContextImpl context, StatementRule rule() { - return rule; - } - @Override public Optional optionalChildValue(AxiomItemDefinition child, Class type) { return (Optional) context.firstChild(child).flatMap(v -> v.optionalValue()); } @Override - public Requirement.Search> requireGlobalItem(AxiomIdentifier space, + public Depedency.Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key) { - return requirement(Requirement.retriableDelegate(() -> { + return requirement(Depedency.retriableDelegate(() -> { StatementContextImpl maybe = context.lookup(space, key); if(maybe != null) { - return (Requirement) maybe.asRequirement(); + return (Depedency) maybe.asRequirement(); } return null; })); } - private > X requirement(X req) { - this.requirements.add(req); + private > X requirement(X req) { + this.dependencies.add(req); return req; } @@ -63,7 +61,7 @@ public StatementRuleContextImpl apply(Action action) { } public boolean canProcess() { - for (Requirement requirement : requirements) { + for (Depedency requirement : dependencies) { if (!requirement.isSatisfied()) { return false; } @@ -71,14 +69,11 @@ public boolean canProcess() { return true; } - public void perform() throws AxiomSemanticException { + @Override + public void apply() throws AxiomSemanticException { if(!applied && error == null) { - try { - this.action.apply(context); - this.applied = true; - } catch (Exception e) { - error = e; - } + this.action.apply(context); + this.applied = true; } } @@ -133,25 +128,49 @@ public RuleErrorMessage error(String format, Object... arguments) { } @Override - public Requirement> requireChild(AxiomItemDefinition required) { + public Depedency> requireChild(AxiomItemDefinition required) { return context.requireChild(required); } @Override - public Requirement requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + public Depedency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { return requirement(context.root().requireNamespace(name, namespaceId)); } - public boolean notFailed() { - return error == null; - } - + @Override public boolean successful() { return applied; } - public Collection> requirements() { - return requirements; + public Collection> requirements() { + return dependencies; + } + + @Override + public void fail(Exception e) throws AxiomSemanticException { + this.error = e; + } + + + @Override + public Collection> dependencies() { + return dependencies; + } + + @Override + public Optional error() { + return Optional.empty(); + } + + public boolean isDefined() { + return action != null; + } + + public Collection> build() { + if(action != null) { + return ImmutableList.of(this); + } + return Collections.emptyList(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 38d8d4627a5..2cee9ce2e58 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -10,11 +10,11 @@ import org.checkerframework.checker.units.qual.K; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.concepts.Identifiable; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.Identifiable; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java new file mode 100644 index 00000000000..693b269f148 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java @@ -0,0 +1,29 @@ +package com.evolveum.axiom.reactor; + +import java.util.Optional; + +public interface Action { + + void apply(); + + boolean successful(); + + /** + * Returns true if action can be applied. + * + * Return false if action application of action failed with exception, which is non-retriable. + * + * @return + */ + boolean canApply(); + + /** + * + * @param e Exception which occured during call of {@link #apply()} + * @throws E If action specific exception if failed critically and all computation should be stopped. + */ + void fail(Exception e) throws E; + + Optional error(); + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/ActionState.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/ActionState.java new file mode 100644 index 00000000000..3c3ff852ba9 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/ActionState.java @@ -0,0 +1,31 @@ +package com.evolveum.axiom.reactor; + +public enum ActionState { + NOT_READY(false, false, false), + APPLICABLE(true, false, false), + APPLIED(false, true, false), + FAILED(false, false, true); + + private ActionState(boolean satisfied, boolean applied, boolean failed) { + this.satisfied = satisfied; + this.applied = applied; + this.failed = failed; + } + + private final boolean satisfied; + private final boolean applied; + private final boolean failed; + + boolean canApply() { + return satisfied; + } + + boolean applied() { + return applied; + } + + boolean failed() { + return failed; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java new file mode 100644 index 00000000000..024d0178a29 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java @@ -0,0 +1,81 @@ +package com.evolveum.axiom.reactor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Optional; + +public abstract class BaseReactorContext> { + + + private Collection outstanding = new ArrayList<>(); + + public void compute() throws E { + boolean anyActionCompleted = false; + do { + anyActionCompleted = false; + Collection toCheck = takeOutstanding(); + Iterator iterator = toCheck.iterator(); + while (iterator.hasNext()) { + A action = iterator.next(); + if (action.canApply()) { + try { + action.apply(); + } catch (Exception e) { + fail(action, e); + } + if(action.successful()) { + iterator.remove(); + anyActionCompleted = true; + } + } + } + // We add not finished items back to outstanding + addOutstanding(toCheck); + } while (anyActionCompleted); + + if (!outstanding.isEmpty()) { + failOutstanding(outstanding); + } + } + + protected void fail(A action, Exception e) throws E { + action.fail(e); + } + + protected void failOutstanding(Collection outstanding) throws E { + E common = createException(); + for (A action : outstanding) { + if(!action.canApply()) { + addSuppresed(common, action); + + } + } + throw common; + } + + protected void addOutstanding(A action) { + outstanding.add(action); + } + + protected void addOutstanding(Collection action) { + outstanding.addAll(action); + } + + protected void addSuppresed(E common, A action) { + Optional error = action.error(); + if(error.isPresent()) { + common.addSuppressed(error.get()); + } + } + + protected abstract E createException(); + + private Collection takeOutstanding() { + Collection ret = outstanding; + outstanding = new ArrayList<>(); + return ret; + } + + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java index 5b57de5fcd1..4fe34245b00 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java @@ -4,18 +4,18 @@ import com.google.common.base.Preconditions; -class Deffered extends Requirement.Delegated { +class Deffered extends Depedency.Delegated { private Object ret; - Deffered(Requirement delegate) { + Deffered(Depedency delegate) { ret = delegate; } @Override - Requirement delegate() { - if(ret instanceof Requirement) { - return (Requirement) ret; + Depedency delegate() { + if(ret instanceof Depedency) { + return (Depedency) ret; } return null; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Depedency.java similarity index 74% rename from infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java rename to infra/axiom/src/main/java/com/evolveum/axiom/reactor/Depedency.java index f3fa23a1398..407ff2d24fb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Requirement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Depedency.java @@ -7,49 +7,49 @@ import com.google.common.base.Preconditions; -public interface Requirement { +public interface Depedency { boolean isSatisfied(); public T get(); public RuleErrorMessage errorMessage(); - public static Requirement unsatisfied() { + public static Depedency unsatisfied() { return new Unsatified<>(); } - public static Requirement immediate(T value) { + public static Depedency immediate(T value) { return new Immediate<>(value); } - public static Requirement from(Supplier supplier) { + public static Depedency from(Supplier supplier) { return new Suppliable<>(supplier); } - public static Requirement deffered(Requirement original) { + public static Depedency deffered(Depedency original) { return new Deffered<>(original); } - default Requirement unsatisfiedMessage(Supplier unsatisfiedMessage) { + default Depedency unsatisfiedMessage(Supplier unsatisfiedMessage) { return this; } - interface Search extends Requirement { + interface Search extends Depedency { - default Requirement.Search notFound(Supplier unsatisfiedMessage) { + default Depedency.Search notFound(Supplier unsatisfiedMessage) { return this; } } - public static abstract class Abstract implements Requirement { + public static abstract class Abstract implements Depedency { private Supplier errorMessage; @Override - public Requirement unsatisfiedMessage(Supplier unsatisfiedMessage) { + public Depedency unsatisfiedMessage(Supplier unsatisfiedMessage) { errorMessage = unsatisfiedMessage; return this; } @@ -122,7 +122,7 @@ public V get() { public abstract class Delegated extends Abstract { - abstract Requirement delegate(); + abstract Depedency delegate(); @Override public boolean isSatisfied() { @@ -141,20 +141,20 @@ public final class RetriableDelegate extends Delegated implements Search notFound; - public RetriableDelegate(Supplier> lookup) { + public RetriableDelegate(Supplier> lookup) { maybeDelegate = lookup; } @Override - Requirement delegate() { - if(maybeDelegate instanceof Requirement) { - return (Requirement) maybeDelegate; + Depedency delegate() { + if(maybeDelegate instanceof Depedency) { + return (Depedency) maybeDelegate; } if(maybeDelegate instanceof Supplier) { - Requirement result = ((Supplier>) maybeDelegate).get(); + Depedency result = ((Supplier>) maybeDelegate).get(); if(result != null) { maybeDelegate = result; - return (Requirement) result; + return (Depedency) result; } } @@ -177,17 +177,17 @@ public RuleErrorMessage errorMessage() { } - static Search retriableDelegate(Supplier> lookup) { + static Search retriableDelegate(Supplier> lookup) { return new RetriableDelegate(lookup); } - static Requirement from(Optional maybe) { + static Depedency from(Optional maybe) { if(maybe.isPresent()) { return immediate(maybe.get()); } return unsatisfied(); } - static Requirement orNull(T value) { + static Depedency orNull(T value) { if(value != null) { return immediate(value); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java new file mode 100644 index 00000000000..862dc0a7d3e --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java @@ -0,0 +1,20 @@ +package com.evolveum.axiom.reactor; + +import java.util.Collection; + +public interface DependantAction extends Action { + + Collection> dependencies(); + + @Override + default boolean canApply() { + for (Depedency dependency : dependencies()) { + if(!dependency.isSatisfied()) { + return false; + } + } + return true; + } + + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Rule.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Rule.java new file mode 100644 index 00000000000..64ed6831550 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Rule.java @@ -0,0 +1,11 @@ +package com.evolveum.axiom.reactor; + +import java.util.Collection; + +public interface Rule> { + + boolean applicableTo(C context); + + Collection applyTo(C context); + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/RuleReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/RuleReactorContext.java new file mode 100644 index 00000000000..4ec8f506977 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/RuleReactorContext.java @@ -0,0 +1,17 @@ +package com.evolveum.axiom.reactor; + +import java.util.Collection; + +public abstract class RuleReactorContext, R extends Rule> extends BaseReactorContext{ + + protected abstract Collection rulesFor(C context); + + protected void addActionsFor(C context) { + Collection rules = rulesFor(context); + for (R rule : rules) { + if(rule.applicableTo(context)) { + addOutstanding(rule.applyTo(context)); + } + } + } +} From 3fe33031a29cb77373bb424d3e52e3e0862ab4a9 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 20 May 2020 11:59:50 +0200 Subject: [PATCH 11/60] Axiom: Moved AxiomStreamBuilder to lang.spi Signed-off-by: Tony Tkacik --- .../lang/impl/CompositeIdentifierSpace.java | 2 +- .../lang/impl/DefaultItemDefinition.java | 46 -------------- .../lang/impl/DefaultTypeDefinition.java | 62 ------------------- .../axiom/lang/impl/ModelReactorContext.java | 27 ++++---- .../axiom/lang/impl/StatementContextImpl.java | 19 ++++-- .../axiom/lang/impl/StatementTreeBuilder.java | 22 ------- .../AxiomStreamTreeBuilder.java} | 43 +++++++------ .../axiom/lang/spi/SourceLocation.java | 5 -- 8 files changed, 54 insertions(+), 172 deletions(-) delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultItemDefinition.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultTypeDefinition.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java rename infra/axiom/src/main/java/com/evolveum/axiom/lang/{impl/AxiomStatementStreamBuilder.java => spi/AxiomStreamTreeBuilder.java} (56%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java index d36ccd83493..ae10f4afdfb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java @@ -8,7 +8,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -public class CompositeIdentifierSpace implements IdentifierSpaceHolder, NamespaceContext { +class CompositeIdentifierSpace implements IdentifierSpaceHolder, NamespaceContext { private final Set delegates = new HashSet<>(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultItemDefinition.java deleted file mode 100644 index 2df8066b9a7..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultItemDefinition.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.impl; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; - -class DefaultItemDefinition implements AxiomItemDefinition { - - private AxiomIdentifier identifier; - private AxiomTypeDefinition type; - - public DefaultItemDefinition(AxiomIdentifier identifier, AxiomTypeDefinition type) { - super(); - this.identifier = identifier; - this.type = type; - } - - @Override - public AxiomIdentifier name() { - return identifier; - } - - @Override - public String documentation() { - return null; - } - - @Override - public AxiomTypeDefinition type() { - return type; - } - - @Override - public boolean required() { - // TODO Auto-generated method stub - return false; - } - - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultTypeDefinition.java deleted file mode 100644 index 2db4cbf9f03..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/DefaultTypeDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.impl; - -import java.util.Collection; -import java.util.Map; -import java.util.Optional; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; - -class DefaultTypeDefinition implements AxiomTypeDefinition { - - private AxiomIdentifier identifier; - private Map items; - - public DefaultTypeDefinition(AxiomIdentifier identifier, Map items) { - super(); - this.identifier = identifier; - this.items = items; - } - - @Override - public AxiomIdentifier name() { - return identifier; - } - - @Override - public String documentation() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Optional argument() { - return Optional.empty(); - } - - @Override - public Optional superType() { - return Optional.empty(); - } - - @Override - public Map items() { - return items; - } - - - @Override - public Collection identifiers() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 6b1c92959b8..88c33bd1bc8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -24,6 +24,7 @@ import com.evolveum.axiom.lang.spi.AxiomItemDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatementImpl; +import com.evolveum.axiom.lang.spi.AxiomStreamTreeBuilder; import com.evolveum.axiom.lang.spi.AxiomTypeDefinitionImpl; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; @@ -142,9 +143,9 @@ public void registerGlobal(AxiomIdentifier space, IdentifierSpaceKey key, Statem } - void endStatement(StatementTreeBuilder cur, SourceLocation loc) throws AxiomSemanticException { + void endStatement(StatementContextImpl cur, SourceLocation loc) throws AxiomSemanticException { if (cur instanceof StatementContextImpl) { - StatementContextImpl current = (StatementContextImpl) cur; + StatementContextImpl current = cur; addActionsFor(current); } } @@ -161,7 +162,7 @@ public void addRules(StatementRule... rules) { } public void loadModelFromSource(AxiomModelStatementSource statementSource) { - statementSource.stream(this, new AxiomStatementStreamBuilder(this, new Root())); + statementSource.stream(this, new AxiomStreamTreeBuilder(new Root())); } @Override @@ -169,12 +170,7 @@ public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull Strin return AxiomIdentifier.axiom(localName); } - private class Root implements StatementTreeBuilder { - - @Override - public void setValue(Object value) { - // NOOP - } + private class Root implements AxiomStreamTreeBuilder.NodeBuilder { @Override public Optional childDef(AxiomIdentifier statement) { @@ -182,7 +178,7 @@ public Optional childDef(AxiomIdentifier statement) { } @Override - public StatementTreeBuilder createChildNode(AxiomIdentifier identifier, SourceLocation loc) { + public StatementContextImpl startChildNode(AxiomIdentifier identifier, SourceLocation loc) { StatementContextImpl ret = new StatementContextImpl.Root<>(ModelReactorContext.this, childDef(identifier).get(), loc); roots.add(ret); @@ -198,6 +194,12 @@ public AxiomIdentifier identifier() { public void setValue(Object value, SourceLocation loc) { } + + @Override + public void endNode(SourceLocation loc) { + // TODO Auto-generated method stub + + } } public void addStatementFactory(AxiomIdentifier statementType, Factory factory) { @@ -207,14 +209,15 @@ public void addStatementFactory(AxiomIdentifier statementType, Factory fac public Factory typeFactory(AxiomTypeDefinition statementType) { Optional current = Optional.of(statementType); do { - Factory maybe = typeFactories.get(current.get().name()); + @SuppressWarnings("unchecked") + Factory maybe = (Factory) typeFactories.get(current.get().name()); if (maybe != null) { return maybe; } current = current.get().superType(); } while (current.isPresent()); - return (Factory) AxiomStatementImpl.factory(); + return AxiomStatementImpl.factory(); } public void exportIdentifierSpace(IdentifierSpaceKey namespace, IdentifierSpaceHolder localSpace) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 4787936123c..eec9f46e293 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -17,11 +17,12 @@ import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; +import com.evolveum.axiom.lang.spi.AxiomStreamTreeBuilder; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; import com.evolveum.axiom.reactor.Depedency; -public abstract class StatementContextImpl implements StatementContext, StatementTreeBuilder, IdentifierSpaceHolder { +public abstract class StatementContextImpl implements StatementContext, AxiomStreamTreeBuilder.NodeBuilder, IdentifierSpaceHolder { private final AxiomItemDefinition definition; @@ -49,7 +50,7 @@ protected void initResult() { return parent().typeFactory(type); } - @Override + public void setValue(Object value) { mutableResult().setValue((V) value); } @@ -68,12 +69,13 @@ boolean isChildAllowed(AxiomIdentifier child) { @SuppressWarnings("rawtypes") @Override - public StatementContextImpl createChildNode(AxiomIdentifier identifier, SourceLocation loc) { + public StatementContextImpl startChildNode(AxiomIdentifier identifier, SourceLocation loc) { StatementContextImpl childCtx = new StatementContextImpl.Child(this, childDef(identifier).get(), loc); mutableResult().add(childCtx); return childCtx; } + public IdentifierSpaceHolder localSpace() { return localSpace; } @@ -105,8 +107,8 @@ public AxiomItemDefinition definition() { @Override public StatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value) { - StatementContextImpl child = createChildNode(axiomIdentifier, null); - child.setValue(value); + StatementContextImpl child = startChildNode(axiomIdentifier, null); + child.setValue(value, null); return child; } @@ -222,6 +224,12 @@ public V requireValue(Class type) { return null; } + @Override + public void endNode(SourceLocation loc) { + this.endLocation = loc; + root().reactor.endStatement(this, loc); + } + public Depedency> requireChild(AxiomItemDefinition required) { return Depedency.retriableDelegate(() -> { if(mutableResult() != null) { @@ -266,6 +274,7 @@ public void exportIdentifierSpace(IdentifierSpaceKey namespace) { public void importIdentifierSpace(NamespaceContext namespaceContext) { throw new UnsupportedOperationException("Child can not import identifier space"); } + } static class Root extends StatementContextImpl { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java deleted file mode 100644 index 44d7fb66d10..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementTreeBuilder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.evolveum.axiom.lang.impl; - -import java.util.Optional; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.spi.SourceLocation; - -public interface StatementTreeBuilder { - - void setValue(Object value); - - Optional childDef(AxiomIdentifier statement); - - AxiomIdentifier identifier(); - - void setValue(Object value, SourceLocation loc); - - StatementTreeBuilder createChildNode(AxiomIdentifier identifier, SourceLocation loc); - - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java similarity index 56% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java index 50299cabb1b..8856584c946 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementStreamBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java @@ -4,33 +4,24 @@ * 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.impl; +package com.evolveum.axiom.lang.spi; import java.util.Deque; import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; -import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.evolveum.axiom.lang.spi.SourceLocation; -import com.google.common.collect.Iterables; -public class AxiomStatementStreamBuilder implements AxiomStatementStreamListener { +public class AxiomStreamTreeBuilder implements AxiomStatementStreamListener { + private final Deque queue = new LinkedList<>(); - private final ModelReactorContext context; - private final Deque queue = new LinkedList<>(); - - public AxiomStatementStreamBuilder(ModelReactorContext context, StatementTreeBuilder root) { - this.context = context; + public AxiomStreamTreeBuilder(NodeBuilder root) { queue.add(root); } - protected StatementTreeBuilder current() { + protected NodeBuilder current() { return queue.peek(); } @@ -46,7 +37,6 @@ public void argument(String identifier, SourceLocation loc) { private void argument0(Object value, SourceLocation loc) { current().setValue(value, loc); - } @Override @@ -56,14 +46,29 @@ public void startStatement(AxiomIdentifier statement, SourceLocation loc) throws queue.offerFirst(createBuilder(childDef.get(), loc)); } - private StatementTreeBuilder createBuilder(AxiomItemDefinition item, SourceLocation loc) { - return current().createChildNode(item.name(), loc); + private NodeBuilder createBuilder(AxiomItemDefinition item, SourceLocation loc) { + return current().startChildNode(item.name(), loc); } @Override public void endStatement(SourceLocation loc) { - StatementTreeBuilder current = queue.poll(); - context.endStatement(current, loc); + NodeBuilder current = queue.poll(); + current.endNode(loc); + } + + public interface NodeBuilder { + + void endNode(SourceLocation loc); + + Optional childDef(AxiomIdentifier statement); + + AxiomIdentifier identifier(); + + void setValue(Object value, SourceLocation loc); + + NodeBuilder startChildNode(AxiomIdentifier identifier, SourceLocation loc); + + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java index 38546da7222..ef710e87ce9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java @@ -16,9 +16,6 @@ public static SourceLocation from(String source, int line, int pos) { return new SourceLocation(source, line, pos); } - - - @Override public String toString() { return sourceName + "["+ line + ":" + character + "]"; @@ -36,6 +33,4 @@ public int getChar() { return character; } - - } From ce60a05e486b8afcf99a07056dbbbf5602fe1246 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 20 May 2020 16:07:42 +0200 Subject: [PATCH 12/60] Axiom: Added support for extension statement Signed-off-by: Tony Tkacik --- .../axiom/lang/antlr/AxiomErrorListener.java | 5 +- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 4 +- ...ontext.java => AxiomStatementContext.java} | 22 +++-- .../axiom/lang/impl/AxiomStatementRule.java | 60 ++++++++++++ .../axiom/lang/impl/BasicStatementRule.java | 97 +++++++++++++------ .../axiom/lang/impl/ModelReactorContext.java | 12 +-- .../axiom/lang/impl/RuleContextImpl.java | 8 +- .../axiom/lang/impl/StatementContextImpl.java | 69 +++++++++---- .../lang/impl/StatementContextResult.java | 8 +- ...text.java => StatementFactoryContext.java} | 4 +- .../axiom/lang/impl/StatementRule.java | 14 --- .../axiom/lang/impl/StatementRuleContext.java | 45 --------- .../lang/impl/StatementRuleContextImpl.java | 72 ++++++++++---- .../axiom/lang/spi/AxiomStatement.java | 2 - .../lang/spi/AxiomStreamTreeBuilder.java | 12 +++ .../axiom/lang/spi/AxiomSyntaxException.java | 49 +++------- .../com/evolveum/axiom/reactor/Deffered.java | 10 +- .../axiom/reactor/DependantAction.java | 4 +- .../{Depedency.java => Dependency.java} | 75 ++++++++++---- .../axiom/src/main/resources/axiom-lang.axiom | 36 ++++++- .../axiom/lang/test/TestAxiomMultimodule.java | 27 +----- .../extension/declaration-order.axiom | 17 ++++ .../extension/person-extension.axiom | 19 ++++ .../multimodel/extension/test-person.axiom | 10 ++ .../ref}/foaf-person.axiom | 0 .../ref}/schema-org-person.axiom | 0 .../ref}/test-person.axiom | 0 .../ref}/test-person.axiom.invalid | 0 28 files changed, 432 insertions(+), 249 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/{StatementContext.java => AxiomStatementContext.java} (56%) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java rename infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/{AxiomStatementFactoryContext.java => StatementFactoryContext.java} (76%) delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java rename infra/axiom/src/main/java/com/evolveum/axiom/reactor/{Depedency.java => Dependency.java} (64%) create mode 100644 infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom create mode 100644 infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom create mode 100644 infra/axiom/src/test/resources/multimodel/extension/test-person.axiom rename infra/axiom/src/test/resources/{multimodule => multimodel/ref}/foaf-person.axiom (100%) rename infra/axiom/src/test/resources/{multimodule => multimodel/ref}/schema-org-person.axiom (100%) rename infra/axiom/src/test/resources/{multimodule => multimodel/ref}/test-person.axiom (100%) rename infra/axiom/src/test/resources/{multimodule => multimodel/ref}/test-person.axiom.invalid (100%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java index 5541095f0c4..21f8b5eb47f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java @@ -13,6 +13,7 @@ import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Recognizer; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; +import com.evolveum.axiom.lang.spi.SourceLocation; public class AxiomErrorListener extends BaseErrorListener { @@ -26,7 +27,7 @@ public AxiomErrorListener(String source) { @Override public void syntaxError(final Recognizer recognizer, final Object offendingSymbol, final int line, final int charPositionInLine, final String msg, final RecognitionException e) { - exceptions.add(new AxiomSyntaxException(source, line, charPositionInLine, msg)); + exceptions.add(new AxiomSyntaxException(SourceLocation.from(source, line, charPositionInLine), msg)); } public void validate() throws AxiomSyntaxException { @@ -44,6 +45,6 @@ public void validate() throws AxiomSyntaxException { sb.append(e.getFormattedMessage()); } - throw new AxiomSyntaxException(source, 0, 0, sb.toString()); + throw new AxiomSyntaxException(SourceLocation.from(source, 0, 0), sb.toString()); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index fe8f1ac9698..c70c26b0bed 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -13,7 +13,6 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.concepts.Lazy.Supplier; import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; @@ -51,6 +50,7 @@ public static class Item implements AxiomItemDefinition, AxiomStatement identifiers() { Item.ID_SPACE )); public static final Type IMPORT_DEFINITION = new Type("AxiomImportDeclaration"); + public static final Type EXTENSION_DEFINITION = new Type("AxiomExtensionDefinition"); + private final AxiomIdentifier identifier; private final AxiomTypeDefinition superType; private final Lazy argument; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementContext.java similarity index 56% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementContext.java index 41388f3dcfa..b43f52668eb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementContext.java @@ -1,30 +1,28 @@ package com.evolveum.axiom.lang.impl; +import java.util.Collection; import java.util.Optional; -import java.util.function.Supplier; - import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -public interface StatementContext { +public interface AxiomStatementContext { V requireValue() throws AxiomSemanticException; AxiomItemDefinition definition(); - StatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value); + AxiomStatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value); Optional optionalValue(); - void replace(Depedency> statement); + void replace(Dependency> statement); - StatementContext parent(); + AxiomStatementContext parent(); void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key); @@ -35,4 +33,12 @@ public interface StatementContext { void exportIdentifierSpace(IdentifierSpaceKey namespace); + void addChildren(Collection> children); + + AxiomStatementRule.Context newAction(String actionName); + + AxiomStatementRule.Context modify(AxiomStatementContext target, String actionName); + + void addEffectiveChildren(Collection> children); + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java new file mode 100644 index 00000000000..a6eb0c4bd96 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -0,0 +1,60 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.Optional; +import java.util.function.Supplier; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.reactor.Dependency; +import com.evolveum.axiom.reactor.Dependency.Search; + +public interface AxiomStatementRule { + + String name(); + + boolean isApplicableTo(AxiomItemDefinition definition); + + void apply(Context rule) throws AxiomSemanticException; + + + interface Context { + Optional optionalChildValue(AxiomItemDefinition supertypeReference, Class type); + + V requiredChildValue(AxiomItemDefinition supertypeReference, Class type) throws AxiomSemanticException; + + V requireValue() throws AxiomSemanticException; + + Context apply(Action action); + + Context errorMessage(Supplier errorFactory); + + RuleErrorMessage error(String format, Object... arguments); + + AxiomTypeDefinition typeDefinition(); + + AxiomItemDefinition itemDefinition(); + + Optional optionalValue(); + + Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key); + + Dependency> requireChild(AxiomItemDefinition required); + + Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); + + Dependency> modify(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + + Context newAction(); + + Dependency> require(AxiomStatementContext ext); + } + + public interface Action { + + void apply(AxiomStatementContext context) throws AxiomSemanticException; + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index c85005953fd..4467c381163 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -3,7 +3,6 @@ import java.util.Collection; import java.util.Optional; import java.util.Set; -import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; @@ -15,19 +14,19 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.Dependency; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -public enum BasicStatementRule implements StatementRule { +public enum BasicStatementRule implements AxiomStatementRule { REQUIRE_REQUIRED_ITEMS(all(),all()) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { + public void apply(Context rule) throws AxiomSemanticException { AxiomTypeDefinition typeDef = rule.typeDefinition(); for(AxiomItemDefinition required : typeDef.requiredItems()) { - rule.requireChild(required).unsatisfiedMessage(() -> rule.error("%s does not have required statement %s")); + //rule.requireChild(required).unsatisfiedMessage(() -> rule.error("%s does not have required statement %s", rule.itemDefinition().name() ,required.name())); rule.apply((ctx) -> {}); } } @@ -36,17 +35,49 @@ public void apply(StatementRuleContext rule) throws AxiomSemant COPY_ARGUMENT_VALUE(all(),all()) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { + public void apply(Context rule) throws AxiomSemanticException { Optional argument = rule.typeDefinition().argument(); if(argument.isPresent() && rule.optionalValue().isPresent()) { rule.apply(ctx -> ctx.createEffectiveChild(argument.get().name(), ctx.requireValue())); } } }, + + EXPAND_TYPE_REFERENCE(items(Item.TYPE_REFERENCE), types(Type.TYPE_REFERENCE)) { + @Override + public void apply(Context rule) throws AxiomSemanticException { + AxiomIdentifier type = rule.requireValue(); + Dependency.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); + typeDef.notFound(() -> rule.error("type '%s' was not found.", type)); + typeDef.unsatisfiedMessage(() -> rule.error("Referenced type %s is not complete.", type)); + rule.apply(ctx -> { + ctx.replace(typeDef); + }); + } + }, + MATERIALIZE_FROM_SUPERTYPE(items(Item.SUPERTYPE_REFERENCE),types(Type.TYPE_REFERENCE)) { + + @Override + public void apply(Context rule) throws AxiomSemanticException { + AxiomIdentifier type = rule.requireValue(); + Dependency.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); + typeDef.notFound(() -> rule.error("type '%s' was not found.", type)); + typeDef.unsatisfiedMessage(() -> rule.error("Referenced type %s is not complete.", type)); + rule.apply(ctx -> { + ctx.replace(typeDef); + AxiomStatement superType = typeDef.get(); + // Copy Identifiers + ctx.parent().addChildren(superType.children(Item.IDENTIFIER_DEFINITION.name())); + // Copy Items + }); + } + + }, + REGISTER_TO_IDENTIFIER_SPACE(all(),all()) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { + public void apply(Context rule) throws AxiomSemanticException { Collection idDefs = rule.typeDefinition().identifiers(); if(!idDefs.isEmpty()) { rule.apply(ctx -> { @@ -62,8 +93,8 @@ public void apply(StatementRuleContext rule) throws AxiomSemant IMPORT_DEFAULT_TYPES(all(), types(Type.MODEL)) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { - Depedency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES)); + public void apply(Context rule) throws AxiomSemanticException { + Dependency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES)); req.unsatisfiedMessage(() -> rule.error("Default types not found.")); rule.apply((ctx) -> { ctx.parent().importIdentifierSpace(req.get()); @@ -73,7 +104,7 @@ public void apply(StatementRuleContext rule) throws AxiomSemant EXPORT_GLOBALS_FROM_MODEL(all(), types(Type.MODEL)) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { + public void apply(Context rule) throws AxiomSemanticException { String namespace = rule.requiredChildValue(Item.NAMESPACE, String.class); rule.apply(ctx -> { ctx.exportIdentifierSpace(namespaceId(namespace)); @@ -83,19 +114,36 @@ public void apply(StatementRuleContext rule) throws AxiomSemant IMPORT_MODEL(all(),types(Type.IMPORT_DEFINITION)) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { + public void apply(Context rule) throws AxiomSemanticException { String child = rule.requiredChildValue(Item.NAMESPACE, String.class); - AxiomIdentifier namespaceId = Item.NAMESPACE.name(); - Depedency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(child)); + Dependency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(child)); req.unsatisfiedMessage(() -> rule.error("Namespace %s not found.", child)); rule.apply((ctx) -> { ctx.parent().importIdentifierSpace(req.get()); }); - } + }, + APPLY_EXTENSION(all(), types(Type.EXTENSION_DEFINITION)) { + @Override + public void apply(Context ctx) throws AxiomSemanticException { + AxiomIdentifier targetName = ctx.requiredChildValue(Item.TARGET, AxiomIdentifier.class); + Dependency> targetRef = ctx.modify(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(targetName)); + + ctx.apply(ext -> { + Context copyItems = ext.modify(targetRef.get(), "Extension: Adding items to target"); + Dependency> extDef = copyItems.require(ext); + copyItems.apply(target -> { + // Copy items to target + target.addEffectiveChildren(extDef.get().children(Item.ITEM_DEFINITION.name())); + }); + }); - + /*ctx.apply(ext -> { + Context targetAction = ext.newAction(); + targetAction. + });*/ + } }, /* @@ -103,29 +151,18 @@ public void apply(StatementRuleContext rule) throws AxiomSemant REGISTER_TYPE(items(Item.TYPE_DEFINITION), types(Type.TYPE_DEFINITION)) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { + public void apply(Context rule) throws AxiomSemanticException { AxiomIdentifier typeName = rule.requireValue(); rule.apply(ctx -> ctx.registerAsGlobalItem(typeName)); } }, */ - EXPAND_TYPE_REFERENCE(all(), types(Type.TYPE_REFERENCE)) { - @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { - AxiomIdentifier type = rule.requireValue(); - Depedency.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); - typeDef.notFound(() -> rule.error("type '%s' was not found.", type)); - typeDef.unsatisfiedMessage(() -> rule.error("Referenced type %s is not complete.", type)); - rule.apply(ctx -> { - ctx.replace(typeDef); - }); - } - }; + ; /* ADD_SUPERTYPE(items(), types(Type.TYPE_DEFINITION)) { @Override - public void apply(StatementRuleContext rule) throws AxiomSemanticException { + public void apply(Context rule) throws AxiomSemanticException { Optional superType = rule.optionalChildValue(Item.SUPERTYPE_REFERENCE, AxiomIdentifier.class); if(superType.isPresent()) { Requirement> req = rule.requireGlobalItem(Item.TYPE_DEFINITION, superType.get()); @@ -151,7 +188,7 @@ private BasicStatementRule(Set items, Set type this.types = ImmutableSet.copyOf(types); } - static IdentifierSpaceKey keyFrom(AxiomIdentifierDefinition idDef, StatementRuleContext ctx) { + static IdentifierSpaceKey keyFrom(AxiomIdentifierDefinition idDef, Context ctx) { ImmutableMap.Builder components = ImmutableMap.builder(); for(AxiomItemDefinition cmp : idDef.components()) { components.put(cmp.name(), ctx.requiredChildValue(cmp, Object.class)); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 88c33bd1bc8..736eca867e9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -28,7 +28,7 @@ import com.evolveum.axiom.lang.spi.AxiomTypeDefinitionImpl; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; -import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.RuleReactorContext; import org.jetbrains.annotations.Nullable; @@ -120,7 +120,7 @@ protected void failOutstanding(Collection> outstandi if (exception != null) { messages.append(exception.toString()).append("\n"); } - for (Depedency req : rule.dependencies()) { + for (Dependency req : rule.dependencies()) { if(!req.isSatisfied()) { messages.append(req.errorMessage()).append("\n"); } @@ -155,8 +155,8 @@ protected void addOutstanding(StatementRuleContextImpl action) { super.addOutstanding(action); } - public void addRules(StatementRule... rules) { - for (StatementRule statementRule : rules) { + public void addRules(AxiomStatementRule... rules) { + for (AxiomStatementRule statementRule : rules) { this.rules.add(new RuleContextImpl(statementRule)); } } @@ -228,8 +228,8 @@ private CompositeIdentifierSpace exported(IdentifierSpaceKey namespace) { return exported.computeIfAbsent(namespace, k -> new CompositeIdentifierSpace()); } - public Depedency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { - return Depedency.orNull(exported.get(namespaceId)); + public Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return Dependency.orNull(exported.get(namespaceId)); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java index 4b1b570a55d..80d11e54e4c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java @@ -6,9 +6,9 @@ public class RuleContextImpl implements Rule, StatementRuleContextImpl> { - private final StatementRule delegate; + private final AxiomStatementRule delegate; - public RuleContextImpl(StatementRule delegate) { + public RuleContextImpl(AxiomStatementRule delegate) { super(); this.delegate = delegate; } @@ -20,7 +20,7 @@ public boolean applicableTo(StatementContextImpl context) { @Override public Collection> applyTo(StatementContextImpl context) { - StatementRuleContextImpl actionBuilder = context.addRule(delegate); + StatementRuleContextImpl actionBuilder = context.addAction(delegate.name()); delegate.apply(actionBuilder); return actionBuilder.build(); } @@ -30,7 +30,7 @@ public String toString() { return delegate.toString(); } - public StatementRule delegate() { + public AxiomStatementRule delegate() { return delegate; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index eec9f46e293..35e915c866b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -11,6 +11,7 @@ import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.concepts.Optionals; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.impl.AxiomStatementRule.Context; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -20,9 +21,9 @@ import com.evolveum.axiom.lang.spi.AxiomStreamTreeBuilder; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; -import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.Dependency; -public abstract class StatementContextImpl implements StatementContext, AxiomStreamTreeBuilder.NodeBuilder, IdentifierSpaceHolder { +public abstract class StatementContextImpl implements AxiomStatementContext, AxiomStreamTreeBuilder.NodeBuilder, IdentifierSpaceHolder { private final AxiomItemDefinition definition; @@ -31,7 +32,7 @@ public abstract class StatementContextImpl implements StatementContext, Ax private SourceLocation startLocation; private SourceLocation endLocation; private SourceLocation valueLocation; - private Depedency> result; + private Dependency> result; StatementContextImpl(AxiomItemDefinition definition, SourceLocation loc, Scope scope, Scope... rest) { @@ -106,7 +107,7 @@ public AxiomItemDefinition definition() { } @Override - public StatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value) { + public AxiomStatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value) { StatementContextImpl child = startChildNode(axiomIdentifier, null); child.setValue(value, null); return child; @@ -115,7 +116,7 @@ public StatementContext createEffectiveChild(AxiomIdentifier axiomIdentif public void registerRule(StatementRuleContextImpl rule) { mutableResult().addRule(rule); - //addOutstanding(rule); + addOutstanding(rule); } protected void addOutstanding(StatementRuleContextImpl rule) { @@ -134,10 +135,8 @@ private Collection> children(AxiomIdentifier identif return (Collection) mutableResult().get(identifier); } - public StatementRuleContextImpl addRule(StatementRule statementRule) throws AxiomSemanticException { - StatementRuleContextImpl action = new StatementRuleContextImpl(this,statementRule); - statementRule.apply(action); - return action; + public StatementRuleContextImpl addAction(String name) throws AxiomSemanticException { + return new StatementRuleContextImpl(this,name); } @Override @@ -146,8 +145,8 @@ public Optional optionalValue() { } @Override - public void replace(Depedency> supplier) { - this.result = (Depedency) supplier; + public void replace(Dependency> supplier) { + this.result = (Dependency) supplier; } @Override @@ -159,9 +158,9 @@ public void setValue(Object value, SourceLocation loc) { this.valueLocation = loc; } - public Depedency> asRequirement() { + public Dependency> asRequirement() { if (result instanceof StatementContextResult) { - return Depedency.deffered(result); + return Dependency.deffered(result); } return result; } @@ -230,21 +229,48 @@ public void endNode(SourceLocation loc) { root().reactor.endStatement(this, loc); } - public Depedency> requireChild(AxiomItemDefinition required) { - return Depedency.retriableDelegate(() -> { + public Dependency> requireChild(AxiomItemDefinition required) { + return Dependency.retriableDelegate(() -> { if(mutableResult() != null) { - return (Depedency) firstChild(required).map(StatementContextImpl::asRequirement).orElse(null); + return (Dependency) firstChild(required).map(StatementContextImpl::asRequirement).orElse(null); } Optional> maybe = result.get().first(required); - return Depedency.from(maybe); + return Dependency.from(maybe); }); } + @Override + public Context newAction(String name) { + return addAction(name); + } + + @Override + public void addChildren(Collection> children) { + AxiomStreamTreeBuilder streamBuilder = new AxiomStreamTreeBuilder(this); + for(AxiomStatement child : children) { + streamBuilder.stream(child); + } + } + + @Override + public void addEffectiveChildren(Collection> children) { + for(AxiomStatement child :children) { + AxiomStatementContext effective = createEffectiveChild(child.keyword(), child.value()); + effective.replace(Dependency.immediate(child)); + + } + } + protected IdentifierSpaceHolder exports() { throw new IllegalStateException("Statement does not provide exports"); } + @Override + public Context modify(AxiomStatementContext target, String name) { + return (target).newAction(name); + } + static class Child extends StatementContextImpl { private StatementContextImpl parent; @@ -357,8 +383,8 @@ protected Root root() { return this; } - public Depedency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { - return Depedency.retriableDelegate(() -> { + public Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return Dependency.retriableDelegate(() -> { return reactor.namespace(name, namespaceId); }); } @@ -368,4 +394,9 @@ protected Root root() { return parent().root(); } + + public Dependency> optionalChild(AxiomItemDefinition required) { + return Dependency.optional(requireChild(required)); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java index 5693c722c9f..ca7156d97b0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java @@ -9,15 +9,15 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; -import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.Dependency; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -class StatementContextResult implements Depedency> { +class StatementContextResult implements Dependency> { private V value; private final List> childrenList = new ArrayList<>(); - private final Multimap> children = HashMultimap.create(); + private final Multimap> children = HashMultimap.create(); private AxiomStatementBuilder builder; private final List> rules = new ArrayList<>(); @@ -41,7 +41,7 @@ public V value() { return value; } - public Collection> get(AxiomIdentifier identifier) { + public Collection> get(AxiomIdentifier identifier) { return children.get(identifier); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementFactoryContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementFactoryContext.java similarity index 76% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementFactoryContext.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementFactoryContext.java index 351703d0ee5..d686799cb1f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementFactoryContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementFactoryContext.java @@ -9,11 +9,11 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.spi.AxiomStatementImpl; -public interface AxiomStatementFactoryContext { +interface StatementFactoryContext { AxiomStatementImpl.Factory factoryFor(AxiomTypeDefinition identifier); - static AxiomStatementFactoryContext defaultFactory(AxiomStatementImpl.Factory factory) { + static StatementFactoryContext defaultFactory(AxiomStatementImpl.Factory factory) { return (identifier) -> factory; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java deleted file mode 100644 index 6fe435ff91e..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRule.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.evolveum.axiom.lang.impl; - -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.spi.AxiomSemanticException; - -public interface StatementRule { - - String name(); - - boolean isApplicableTo(AxiomItemDefinition definition); - - void apply(StatementRuleContext rule) throws AxiomSemanticException; - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java deleted file mode 100644 index ba8aebf9ab4..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContext.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.evolveum.axiom.lang.impl; - -import java.util.Optional; -import java.util.function.Supplier; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Depedency; -import com.evolveum.axiom.reactor.Depedency.Search; - -public interface StatementRuleContext { - - Optional optionalChildValue(AxiomItemDefinition supertypeReference, Class type); - - V requiredChildValue(AxiomItemDefinition supertypeReference, Class type) throws AxiomSemanticException; - - V requireValue() throws AxiomSemanticException; - - StatementRuleContext apply(StatementRuleContext.Action action); - - StatementRuleContext errorMessage(Supplier errorFactory); - - RuleErrorMessage error(String format, Object... arguments); - - public interface Action { - - void apply(StatementContext context) throws AxiomSemanticException; - } - - AxiomTypeDefinition typeDefinition(); - - Optional optionalValue(); - - Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key); - - Depedency> requireChild(AxiomItemDefinition required); - - Depedency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index 960b8b8f616..7b557ed1d39 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -11,22 +11,23 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.impl.AxiomStatementRule.Context; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Depedency; +import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.DependantAction; import com.google.common.collect.ImmutableList; -public class StatementRuleContextImpl implements StatementRuleContext, DependantAction { +public class StatementRuleContextImpl implements AxiomStatementRule.Context, DependantAction { private final StatementContextImpl context; - private final StatementRule rule; - private final List> dependencies = new ArrayList<>(); - private Action action; + private final String rule; + private final List> dependencies = new ArrayList<>(); + private AxiomStatementRule.Action action; private Supplier errorReport = () -> null; private boolean applied = false; private Exception error; - public StatementRuleContextImpl(StatementContextImpl context, StatementRule rule) { + public StatementRuleContextImpl(StatementContextImpl context, String rule) { this.context = context; this.rule = rule; } @@ -37,31 +38,31 @@ public Optional optionalChildValue(AxiomItemDefinition child, Class ty } @Override - public Depedency.Search> requireGlobalItem(AxiomIdentifier space, + public Dependency.Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key) { - return requirement(Depedency.retriableDelegate(() -> { + return requirement(Dependency.retriableDelegate(() -> { StatementContextImpl maybe = context.lookup(space, key); if(maybe != null) { - return (Depedency) maybe.asRequirement(); + return (Dependency) maybe.asRequirement(); } return null; })); } - private > X requirement(X req) { + private > X requirement(X req) { this.dependencies.add(req); return req; } @Override - public StatementRuleContextImpl apply(Action action) { + public StatementRuleContextImpl apply(AxiomStatementRule.Action action) { this.action = action; context.registerRule(this); return this; } public boolean canProcess() { - for (Depedency requirement : dependencies) { + for (Dependency requirement : dependencies) { if (!requirement.isSatisfied()) { return false; } @@ -80,7 +81,7 @@ public void apply() throws AxiomSemanticException { @Override public V requiredChildValue(AxiomItemDefinition supertypeReference, Class type) throws AxiomSemanticException { - StatementContext ctx = context.firstChild(supertypeReference).get(); + AxiomStatementContext ctx = context.firstChild(supertypeReference).get(); return (V) ctx.requireValue(type); } @@ -94,7 +95,7 @@ public boolean isApplied() { } @Override - public StatementRuleContext errorMessage(Supplier errorFactory) { + public AxiomStatementRule.Context errorMessage(Supplier errorFactory) { this.errorReport = errorFactory; return this; } @@ -128,12 +129,16 @@ public RuleErrorMessage error(String format, Object... arguments) { } @Override - public Depedency> requireChild(AxiomItemDefinition required) { - return context.requireChild(required); + public Dependency> requireChild(AxiomItemDefinition required) { + return requirement(context.requireChild(required)); + } + + public Dependency> optionalChild(AxiomItemDefinition required) { + return requirement(context.optionalChild(required)); } @Override - public Depedency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + public Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { return requirement(context.root().requireNamespace(name, namespaceId)); } @@ -142,7 +147,7 @@ public boolean successful() { return applied; } - public Collection> requirements() { + public Collection> requirements() { return dependencies; } @@ -153,7 +158,7 @@ public void fail(Exception e) throws AxiomSemanticException { @Override - public Collection> dependencies() { + public Collection> dependencies() { return dependencies; } @@ -173,5 +178,34 @@ public Collection> build() { return Collections.emptyList(); } + @Override + public AxiomItemDefinition itemDefinition() { + return context.definition(); + } + + @Override + public Dependency> modify(AxiomIdentifier space, IdentifierSpaceKey key) { + return requirement(Dependency.retriableDelegate(() -> { + StatementContextImpl maybe = context.lookup(space, key); + if(maybe != null) { + return Dependency.immediate(maybe); + } + return null; + })); + } + + @Override + public Dependency> require(AxiomStatementContext ext) { + return requirement((Dependency) impl(ext).asRequirement()); + } + + private StatementContextImpl impl(AxiomStatementContext ext) { + return (StatementContextImpl) ext; + } + + @Override + public Context newAction() { + return new StatementRuleContextImpl(context, rule); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java index b6f287f3f74..1bc849964ba 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java @@ -12,8 +12,6 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.google.common.collect.Collections2; -import com.google.common.collect.Iterables; public interface AxiomStatement { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java index 8856584c946..b1bd44592ff 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java @@ -71,4 +71,16 @@ public interface NodeBuilder { } + public void stream(AxiomStatement statement) { + startStatement(statement.keyword(), null); + if(statement.value() != null) { + argument0(statement.value(), null); + } + for( AxiomStatement child : statement.children()) { + stream(child); + } + endStatement(null); + + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java index 811e169ffde..4e2b845d1c2 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java @@ -10,56 +10,33 @@ import org.jetbrains.annotations.Nullable; -import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.base.Strings; public class AxiomSyntaxException extends RuntimeException { - private final String source; - private final int line; - private final int charPositionInLine; + private final SourceLocation source; - public AxiomSyntaxException(@Nullable final String source, final int line, - final int charPositionInLine, final String message) { - this(source, line, charPositionInLine, message, null); - } - - public AxiomSyntaxException(@Nullable final String source, final int line, - final int charPositionInLine, final String message, @Nullable final Throwable cause) { + public AxiomSyntaxException(@Nullable final SourceLocation source, String message, @Nullable final Throwable cause) { super(message, cause); this.source = source; - this.line = line; - this.charPositionInLine = charPositionInLine; - } - - public final Optional getSource() { - return Optional.ofNullable(source); } - public final int getLine() { - return line; + public AxiomSyntaxException(SourceLocation source2, String message) { + this(source2, message, null); } - public final int getCharPositionInLine() { - return charPositionInLine; + public final Optional getSource() { + return Optional.ofNullable(source); } public String getFormattedMessage() { - final StringBuilder sb = new StringBuilder(getMessage()); + final StringBuilder sb = new StringBuilder(); if (source != null) { - sb.append(" in source "); sb.append(source); } - if (line != 0) { - sb.append(" on line "); - sb.append(line); - if (charPositionInLine != 0) { - sb.append(" character "); - sb.append(charPositionInLine); - } - } - return sb.toString(); + + return sb.append(getMessage()).toString(); } @Override @@ -67,15 +44,11 @@ public String toString() { return this.getClass().getName() + ": " + getFormattedMessage(); } - public static void check(boolean test, String source, int line, int posInLine, String format, Object... args) { + public static void check(boolean test, SourceLocation source, String format, Object... args) { if(!test) { - throw new AxiomSyntaxException(source, line, posInLine, Strings.lenientFormat(format, args)); + throw new AxiomSyntaxException(source, Strings.lenientFormat(format, args)); } - } - public static void check(boolean present, SourceLocation loc, String format, Object... args) { - check(present, loc.getSource(), loc.getLine(), loc.getChar(),format, args); - } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java index 4fe34245b00..bb6dbb2904f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java @@ -4,18 +4,18 @@ import com.google.common.base.Preconditions; -class Deffered extends Depedency.Delegated { +class Deffered extends Dependency.Delegated { private Object ret; - Deffered(Depedency delegate) { + Deffered(Dependency delegate) { ret = delegate; } @Override - Depedency delegate() { - if(ret instanceof Depedency) { - return (Depedency) ret; + Dependency delegate() { + if(ret instanceof Dependency) { + return (Dependency) ret; } return null; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java index 862dc0a7d3e..dc366ff9462 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java @@ -4,11 +4,11 @@ public interface DependantAction extends Action { - Collection> dependencies(); + Collection> dependencies(); @Override default boolean canApply() { - for (Depedency dependency : dependencies()) { + for (Dependency dependency : dependencies()) { if(!dependency.isSatisfied()) { return false; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Depedency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java similarity index 64% rename from infra/axiom/src/main/java/com/evolveum/axiom/reactor/Depedency.java rename to infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java index 407ff2d24fb..392a98a2867 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Depedency.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java @@ -7,49 +7,55 @@ import com.google.common.base.Preconditions; -public interface Depedency { +public interface Dependency { + default boolean isRequired() { + return true; + } boolean isSatisfied(); public T get(); public RuleErrorMessage errorMessage(); - public static Depedency unsatisfied() { + public static Dependency unsatisfied() { return new Unsatified<>(); } - public static Depedency immediate(T value) { + public static Dependency immediate(T value) { return new Immediate<>(value); } - public static Depedency from(Supplier supplier) { + public static Dependency optional(Dependency dependency) { + return new OptionalDep(dependency); + } + + public static Dependency from(Supplier supplier) { return new Suppliable<>(supplier); } - public static Depedency deffered(Depedency original) { + public static Dependency deffered(Dependency original) { return new Deffered<>(original); } - default Depedency unsatisfiedMessage(Supplier unsatisfiedMessage) { + default Dependency unsatisfiedMessage(Supplier unsatisfiedMessage) { return this; } - interface Search extends Depedency { + interface Search extends Dependency { - default Depedency.Search notFound(Supplier unsatisfiedMessage) { + default Dependency.Search notFound(Supplier unsatisfiedMessage) { return this; } } - - public static abstract class Abstract implements Depedency { + public static abstract class Abstract implements Dependency { private Supplier errorMessage; @Override - public Depedency unsatisfiedMessage(Supplier unsatisfiedMessage) { + public Dependency unsatisfiedMessage(Supplier unsatisfiedMessage) { errorMessage = unsatisfiedMessage; return this; } @@ -122,13 +128,18 @@ public V get() { public abstract class Delegated extends Abstract { - abstract Depedency delegate(); + abstract Dependency delegate(); @Override public boolean isSatisfied() { return delegate().isSatisfied(); } + @Override + public boolean isRequired() { + return delegate().isRequired(); + } + @Override public T get() { Preconditions.checkState(isSatisfied(), "Requirement was not satisfied"); @@ -136,25 +147,46 @@ public T get() { } } + public final class OptionalDep extends Delegated { + + private final Dependency delegate; + + public OptionalDep(Dependency delegate) { + super(); + this.delegate = delegate; + } + + @Override + public boolean isRequired() { + return false; + } + + @Override + Dependency delegate() { + return delegate; + } + + } + public final class RetriableDelegate extends Delegated implements Search { private Object maybeDelegate; private Supplier notFound; - public RetriableDelegate(Supplier> lookup) { + public RetriableDelegate(Supplier> lookup) { maybeDelegate = lookup; } @Override - Depedency delegate() { - if(maybeDelegate instanceof Depedency) { - return (Depedency) maybeDelegate; + Dependency delegate() { + if(maybeDelegate instanceof Dependency) { + return (Dependency) maybeDelegate; } if(maybeDelegate instanceof Supplier) { - Depedency result = ((Supplier>) maybeDelegate).get(); + Dependency result = ((Supplier>) maybeDelegate).get(); if(result != null) { maybeDelegate = result; - return (Depedency) result; + return (Dependency) result; } } @@ -177,20 +209,21 @@ public RuleErrorMessage errorMessage() { } - static Search retriableDelegate(Supplier> lookup) { + static Search retriableDelegate(Supplier> lookup) { return new RetriableDelegate(lookup); } - static Depedency from(Optional maybe) { + static Dependency from(Optional maybe) { if(maybe.isPresent()) { return immediate(maybe.get()); } return unsatisfied(); } - static Depedency orNull(T value) { + static Dependency orNull(T value) { if(value != null) { return immediate(value); } return null; } + } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index a6eddfebf52..2784ebd3fbc 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -37,16 +37,26 @@ model axiom-lang { } item type { + type AxiomTypeDefinition; documentation """ Type Declaration type statement declares a new global type, which is available to model items. """; - type AxiomTypeDefinition; } + item mixin { + type AxiomMixinDefinition; + documentation """ + Mixin Declaration, declares a new global mixin, aset of reusable item + definitions, which can be used in type definitions. + """; + } + item extension { + type AxiomExtensionDefinition; + } // TODO move to prism schema; consider renaming to objectType? item object { @@ -143,6 +153,10 @@ model axiom-lang { type AxiomTypeReference; } + item uses { + type AxiomTypeReference; + } + item identifier { type AxiomIdentifierDefinition; } @@ -200,7 +214,25 @@ model axiom-lang { } } - type AxiomTypeReference; + type AxiomTypeReference { + //type AxiomIdentifier; + //reference { + // scope global; + // space AxiomTypeDefinition; + // argument name; + //} + } + + type AxiomMixinDefinition { + extends AxiomTypeDefinition; + } + + type AxiomExtensionDefinition { + extends AxiomMixinDefinition; + item target { + type AxiomTypeReference; + } + } // "Type library" (temporary) diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java index dc185f7e832..a35a9caf581 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java @@ -7,40 +7,24 @@ package com.evolveum.axiom.lang.test; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; -import java.util.Optional; - import org.testng.annotations.Test; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; -import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.evolveum.midpoint.tools.testng.AbstractUnitTest; public class TestAxiomMultimodule extends AbstractReactorTest { - private static final String DIR = "multimodule/"; + private static final String DIR = "multimodel/ref/"; private static final String SCHEMA_ORG = DIR + "schema-org-person.axiom"; private static final String FOAF = DIR + "foaf-person.axiom"; private static final String TEST = DIR + "test-person.axiom"; private static final String TEST_INVALID = DIR + "test-person.axiom.invalid"; - @Test public void axiomTestImports() throws IOException, AxiomSyntaxException { ModelReactorContext context = ModelReactorContext.defaultReactor(); @@ -52,13 +36,6 @@ public void axiomTestImports() throws IOException, AxiomSyntaxException { AxiomItemDefinition modelDef = schemaContext.getRoot(Item.MODEL_DEFINITION.name()).get(); assertEquals(modelDef.name(), Item.MODEL_DEFINITION.name()); - //folowupContext.loadModelFromSource(statementSource); - AxiomSchemaContext selfparsedContext = context.computeSchemaContext(); - assertNotNull(selfparsedContext.getRoot(Item.MODEL_DEFINITION.name())); - assertTrue(selfparsedContext.getType(Type.IDENTIFIER_DEFINITION.name()).get().item(Item.ID_MEMBER.name()).get().required()); - } - - - + } } diff --git a/infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom b/infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom new file mode 100644 index 00000000000..fd1d7c581ab --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom @@ -0,0 +1,17 @@ +model test-person { + + namespace "https://example.org"; + + type Person { + item name { + type string; + } + } + + extension PersonExtension { + target Person; + item fullName { + type string; + } + } +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom b/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom new file mode 100644 index 00000000000..5523388e417 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom @@ -0,0 +1,19 @@ +model schema-org-person { + + namespace "https://schema.org"; + + import base { + namespace "https://example.org"; + } + + extension SchemaOrgPerson { + target base:Person; + + item honorificPrefix { + type string; + } + item honorificSuffix { + type string; + } + } +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodel/extension/test-person.axiom b/infra/axiom/src/test/resources/multimodel/extension/test-person.axiom new file mode 100644 index 00000000000..4e6c8e0baa3 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/extension/test-person.axiom @@ -0,0 +1,10 @@ +model test-person { + + namespace "https://example.org"; + + type Person { + item name { + type string; + } + } +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodule/foaf-person.axiom b/infra/axiom/src/test/resources/multimodel/ref/foaf-person.axiom similarity index 100% rename from infra/axiom/src/test/resources/multimodule/foaf-person.axiom rename to infra/axiom/src/test/resources/multimodel/ref/foaf-person.axiom diff --git a/infra/axiom/src/test/resources/multimodule/schema-org-person.axiom b/infra/axiom/src/test/resources/multimodel/ref/schema-org-person.axiom similarity index 100% rename from infra/axiom/src/test/resources/multimodule/schema-org-person.axiom rename to infra/axiom/src/test/resources/multimodel/ref/schema-org-person.axiom diff --git a/infra/axiom/src/test/resources/multimodule/test-person.axiom b/infra/axiom/src/test/resources/multimodel/ref/test-person.axiom similarity index 100% rename from infra/axiom/src/test/resources/multimodule/test-person.axiom rename to infra/axiom/src/test/resources/multimodel/ref/test-person.axiom diff --git a/infra/axiom/src/test/resources/multimodule/test-person.axiom.invalid b/infra/axiom/src/test/resources/multimodel/ref/test-person.axiom.invalid similarity index 100% rename from infra/axiom/src/test/resources/multimodule/test-person.axiom.invalid rename to infra/axiom/src/test/resources/multimodel/ref/test-person.axiom.invalid From e33135d5e0b91b3a5e031d0fafebad5a97ee92fc Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 21 May 2020 09:31:54 +0200 Subject: [PATCH 13/60] Axiom: Axiom supports language extensions. Signed-off-by: Tony Tkacik --- .../lang/antlr/AxiomModelStatementSource.java | 7 +- .../axiom/lang/impl/ModelReactorContext.java | 6 +- .../axiom/lang/test/TestAxiomExtension.java | 103 ++++++++++++++++++ .../extension/language-extension-use.axiom | 25 +++++ .../extension/language-extension.axiom | 16 +++ 5 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java create mode 100644 infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom create mode 100644 infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index f6c367954b3..8cec3503659 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -6,7 +6,6 @@ */ package com.evolveum.axiom.lang.antlr; -import java.beans.Statement; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; @@ -14,16 +13,12 @@ import java.util.Optional; import java.util.Set; -import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.TokenStream; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.antlr.AxiomLexer; import com.evolveum.axiom.lang.antlr.AxiomParser; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; @@ -75,7 +70,7 @@ public void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListene public void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListener listener, Optional> emitOnly) { - stream(resolver, BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); + stream(resolver.or(this), BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); } public static Map imports(AxiomParser.StatementContext root) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 736eca867e9..feb8575624b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -30,6 +30,7 @@ import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.RuleReactorContext; +import com.google.common.base.Strings; import org.jetbrains.annotations.Nullable; @@ -167,7 +168,10 @@ public void loadModelFromSource(AxiomModelStatementSource statementSource) { @Override public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName) { - return AxiomIdentifier.axiom(localName); + if(Strings.isNullOrEmpty(prefix)) { + return AxiomIdentifier.axiom(localName); + } + return null; } private class Root implements AxiomStreamTreeBuilder.NodeBuilder { diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java new file mode 100644 index 00000000000..5e7984cda2f --- /dev/null +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -0,0 +1,103 @@ +/* + * 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.test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.io.IOException; +import java.util.Collection; +import java.util.Optional; + +import org.testng.annotations.Test; + + +import com.evolveum.axiom.lang.api.AxiomSchemaContext; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; +import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomStatement; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; + +public class TestAxiomExtension extends AbstractReactorTest { + + private static final AxiomIdentifier PERSON = AxiomIdentifier.from("https://example.org", "Person"); + private static final AxiomIdentifier STORAGE = AxiomIdentifier.from("https://example.org/extension", "type"); + + private static final AxiomIdentifier PERSON_EXTENSION = AxiomIdentifier.from("https://schema.org", "SchemaOrgPerson"); + private static final String DIR = "multimodel/extension/"; + private static final String SCHEMA_ORG = DIR + "person-extension.axiom"; + private static final String BASE = DIR + "test-person.axiom"; + private static final String ORDER = DIR + "declaration-order.axiom"; + private static final String LANG_EXT = DIR + "language-extension.axiom"; + private static final String LANG_EXT_USE = DIR + "language-extension-use.axiom"; + + @Test + public void axiomTestExtension() throws IOException, AxiomSyntaxException { + ModelReactorContext context = ModelReactorContext.defaultReactor(); + context.loadModelFromSource(source(SCHEMA_ORG)); + context.loadModelFromSource(source(BASE)); + AxiomSchemaContext schemaContext = context.computeSchemaContext(); + + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + assertTrue(!langExtDef.identifiers().isEmpty()); + + Optional personDef = schemaContext.getType(PERSON); + assertTrue(personDef.isPresent()); + Optional extPersonDef = schemaContext.getType(PERSON_EXTENSION); + assertTrue(extPersonDef.isPresent()); + + for(AxiomIdentifier item : extPersonDef.get().items().keySet()) { + assertTrue(personDef.get().item(item).isPresent()); + } + } + + @Test + public void axiomTestOrder() throws IOException, AxiomSyntaxException { + ModelReactorContext context = ModelReactorContext.defaultReactor(); + context.loadModelFromSource(source(ORDER)); + AxiomSchemaContext schemaContext = context.computeSchemaContext(); + + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + assertTrue(!langExtDef.identifiers().isEmpty()); + + Optional personDef = schemaContext.getType(PERSON); + assertTrue(personDef.isPresent()); + assertEquals(2, personDef.get().items().entrySet().size()); + } + + @Test + public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxException { + ModelReactorContext context = ModelReactorContext.defaultReactor(); + context.loadModelFromSource(source(LANG_EXT)); + AxiomSchemaContext schemaContext = context.computeSchemaContext(); + + AxiomTypeDefinition typeDef = schemaContext.getType(Type.TYPE_DEFINITION.name()).get(); + assertNotNull(typeDef.item(STORAGE).get()); + + + ModelReactorContext extendedLanguage = ModelReactorContext.reactor(schemaContext); + extendedLanguage.loadModelFromSource(source(LANG_EXT)); + extendedLanguage.loadModelFromSource(source(LANG_EXT_USE)); + + schemaContext = extendedLanguage.computeSchemaContext(); + + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + assertTrue(!langExtDef.identifiers().isEmpty()); + + Optional personDef = schemaContext.getType(PERSON); + assertTrue(personDef.isPresent()); + Collection> extension = ((AxiomStatement) personDef.get()).children(STORAGE); + assertFalse(extension.isEmpty(), "Extension statements should be available."); + + assertEquals(2, personDef.get().items().entrySet().size()); + } + +} diff --git a/infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom b/infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom new file mode 100644 index 00000000000..82c20a7f609 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom @@ -0,0 +1,25 @@ +model language-extension-use { + + namespace "https://example.org"; + + import storage { + namespace "https://example.org/extension"; + } + + type Address { + item street { + type string; + } + storage:type embedded; + } + + type Person { + item name { + type string; + } + item address { + type Address; + } + storage:type table; + } +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom b/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom new file mode 100644 index 00000000000..d1f7cd96107 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom @@ -0,0 +1,16 @@ +model language-extension { + + namespace "https://example.org/extension"; + + import axiom { + namespace "https://ns.evolveum.com/axiom/language"; + } + + extension Storage { + target axiom:AxiomTypeDefinition; + + item type { + type string; + } + } +} \ No newline at end of file From 871ce98f74ebaa0b8a13923bce9df1e0439d223b Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Thu, 21 May 2020 09:48:30 +0200 Subject: [PATCH 14/60] valueMetadata integration --- .../api/prism/wrapper/PrismValueWrapper.java | 2 + .../wrapper/ItemWrapperFactoryImpl.java | 2 +- .../ValueMetadataWrapperFactoryImpl.java | 13 ++ .../prism/panel/ExpressionPropertyPanel.java | 3 +- .../gui/impl/prism/panel/ItemPanel.java | 4 +- .../prism/panel/MetadataContainerPanel.html | 33 +++++ .../prism/panel/MetadataContainerPanel.java | 123 ++++++++++++++++++ .../panel/MetadataContainerValuePanel.html | 47 ++----- .../panel/MetadataContainerValuePanel.java | 84 +++++++++++- .../impl/prism/panel/PrismContainerPanel.java | 3 +- .../impl/prism/panel/PrismPropertyPanel.java | 3 +- .../impl/prism/panel/PrismReferencePanel.java | 3 +- .../gui/impl/prism/panel/PrismValuePanel.java | 2 +- .../ResourceAttributeDefinitionPanel.java | 5 +- .../PrismReferenceValueWrapperImpl.java | 22 ++++ .../prism/wrapper/PrismValueWrapperImpl.java | 10 +- .../wrapper/ValueMetadataWrapperImpl.java | 8 +- .../midpoint/web/component/TabbedPanel.html | 7 +- 18 files changed, 318 insertions(+), 56 deletions(-) create mode 100755 gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.html create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.java diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java index ec3005c2954..20746194a1e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/prism/wrapper/PrismValueWrapper.java @@ -42,4 +42,6 @@ public interface PrismValueWrapper extends Serializable, DebugDumpable { boolean isShowMetadata(); void setShowMetadata(boolean showMetadata); + String toShortString(); + } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java index 0d1ec55301e..cfd25c285f8 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ItemWrapperFactoryImpl.java @@ -195,7 +195,7 @@ protected List createValuesWrapper(IW itemWrapper, I item, WrapperContext co } protected void setupMetadata(VW valueWrapper, WrapperContext ctx) throws SchemaException { - PrismValue oldValue = valueWrapper.getOldValue(); + PrismValue oldValue = valueWrapper.getNewValue(); Optional metadata = oldValue.valueMetadata(); if (!metadata.isPresent()) { LOGGER.trace("Skipping creating metadata"); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java index 00bc7fac13f..099aaa3824a 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/factory/wrapper/ValueMetadataWrapperFactoryImpl.java @@ -7,6 +7,8 @@ package com.evolveum.midpoint.gui.impl.factory.wrapper; import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext; +import com.evolveum.midpoint.gui.api.prism.ItemStatus; +import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper; import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper; import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper; import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry; @@ -54,4 +56,15 @@ protected List getItemDefinitions(PrismContainerWrappe public GuiComponentRegistry getRegistry() { return registry; } + + @Override + protected ItemWrapper createChildWrapper(ItemDefinition def, PrismContainerValueWrapper containerValueWrapper, WrapperContext context) throws SchemaException { + ItemWrapper child = super.createChildWrapper(def, containerValueWrapper, context); + //TODO ugly hack. find out something smarter + if (ItemStatus.ADDED == child.getStatus()) { + return null; + } + + return child; + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ExpressionPropertyPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ExpressionPropertyPanel.java index 9435485fc6f..b62e180bb42 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ExpressionPropertyPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ExpressionPropertyPanel.java @@ -19,7 +19,6 @@ import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.html.list.ListItem; -import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext; @@ -53,7 +52,7 @@ public ExpressionPropertyPanel(String id, IModel getHeaderVisibility())); add(headerPanel); @@ -84,7 +84,7 @@ protected boolean getHeaderVisibility() { return getParent().findParent(AbstractItemWrapperColumnPanel.class) == null; } - protected abstract Panel createHeaderPanel(); + protected abstract Component createHeaderPanel(); protected ListView createValuesPanel() { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.html new file mode 100755 index 00000000000..388871d5e3b --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.html @@ -0,0 +1,33 @@ + + + + + + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+ +
+
+ + diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.java new file mode 100644 index 00000000000..52aab3e2a4a --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerPanel.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2010-2018 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.midpoint.gui.impl.prism.panel; + +import com.evolveum.midpoint.gui.api.model.ReadOnlyModel; +import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper; + +import com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper; + +import com.evolveum.midpoint.gui.impl.factory.panel.ItemRealValueModel; + +import com.evolveum.midpoint.web.component.util.VisibleBehaviour; + +import org.apache.wicket.AttributeModifier; +import org.apache.wicket.Component; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.model.IModel; + +import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper; +import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper; +import com.evolveum.midpoint.prism.Containerable; +import com.evolveum.midpoint.prism.PrismValue; +import com.evolveum.midpoint.util.exception.SchemaException; + +import org.apache.wicket.model.PropertyModel; + +/** + * @author katka + * + */ +public class MetadataContainerPanel extends ItemPanel, PrismContainerWrapper>{ + + private static final long serialVersionUID = 1L; + + private static final String ID_HEADER = "header"; + private static final String ID_PANEL = "panel"; + + private static final String ID_NON_CONTAINERS = "nonContainers"; + private static final String ID_CONTAINERS = "containers"; + private static final String ID_CONTAINER = "container"; + private static final String ID_LABEL = "label"; + private static final String ID_VALUES = "values"; + private static final String ID_VALUE = "value"; + + /** + * @param id + * @param model + */ + public MetadataContainerPanel(String id, IModel> model, ItemPanelSettings settings) { + super(id, model, settings); + } + + @Override + protected void onInitialize() { + super.onInitialize(); + + } + + @Override + protected Component createHeaderPanel() { + return new Label(ID_HEADER, new PropertyModel<>(getModel(), "displayName")); + } + + @Override + protected boolean getHeaderVisibility() { + return true; + } + + @Override + protected Component createValuePanel(ListItem> item) { + + WebMarkupContainer valuePanel = new WebMarkupContainer(ID_PANEL); + item.add(valuePanel); + ListView nonContainers = new ListView(ID_NON_CONTAINERS, new PropertyModel<>(item.getModel(), "nonContainers")) { + + @Override + protected void populateItem(ListItem listItem) { + listItem.add(new Label(ID_LABEL, new PropertyModel<>(listItem.getModel(), "displayName"))); + + ListView values = new ListView(ID_VALUES, new PropertyModel<>(listItem.getModel(), "values")) { + + @Override + protected void populateItem(ListItem listItem) { + Label value = new Label(ID_VALUE, new ReadOnlyModel<>(() -> { + + return listItem.getModelObject().toShortString(); + })); + listItem.add(value); + } + }; + + values.add(new VisibleBehaviour(() -> listItem.getModelObject() != null && !listItem.getModelObject().isEmpty())); + listItem.add(values); + } + }; + valuePanel.add(nonContainers); + + ListView> containers = new ListView<>(ID_CONTAINERS, new PropertyModel<>(item.getModel(), "containers")) { + + @Override + protected void populateItem(ListItem> listItem) { + listItem.add(new MetadataContainerPanel(ID_CONTAINER, listItem.getModel(), getSettings().copy())); + } + }; + valuePanel.add(containers); + + return valuePanel; + + } + + @Override + protected PV createNewValue(PrismContainerWrapper itemWrapper) { + return (PV) itemWrapper.getItem().createNewValue(); + } +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html index 9f7f82ea62d..aaee0083f1e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.html @@ -9,48 +9,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ + + + + + -
-
-
-
-
-
+ + +
-
- -
-
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java index fb6992e5505..a920b3923ff 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/MetadataContainerValuePanel.java @@ -6,14 +6,21 @@ */ package com.evolveum.midpoint.gui.impl.prism.panel; +import java.awt.*; import java.text.Collator; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Locale; import javax.xml.namespace.QName; +import com.evolveum.midpoint.gui.api.component.tabs.PanelTab; +import com.evolveum.midpoint.gui.impl.prism.wrapper.ValueMetadataWrapperImpl; +import com.evolveum.midpoint.web.component.TabbedPanel; import com.evolveum.midpoint.web.component.form.Form; +import com.evolveum.midpoint.web.component.prism.ItemVisibility; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.wicket.AttributeModifier; @@ -21,6 +28,7 @@ import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.behavior.AttributeAppender; +import org.apache.wicket.extensions.markup.html.tabs.ITab; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.list.ListItem; @@ -53,17 +61,89 @@ * @author katka * */ -public class MetadataContainerValuePanel extends PrismContainerValuePanel> { +public class MetadataContainerValuePanel extends PrismValuePanel, ValueMetadataWrapperImpl> { + + private static final String ID_CONTAINER = "container"; - public MetadataContainerValuePanel(String id, IModel> model, ItemPanelSettings settings) { + public MetadataContainerValuePanel(String id, IModel model, ItemPanelSettings settings) { super(id, model, settings); } + + @Override + protected Component createDefaultPanel(String id) { + + if (getModelObject() == null) { + return new WebMarkupContainer(id); + } + + ListView containers = new ListView(id, new PropertyModel<>(getModel(), "containers")) { + + @Override + protected void populateItem(ListItem listItem) { + listItem.add(new MetadataContainerPanel(ID_CONTAINER, listItem.getModel(), getSettings().copy())); + } + }; + + add(containers); + + return containers; + } + + @Override + protected PV createNewValue(PrismContainerWrapper itemWrapper) { + return null; + } + + @Override + protected void removeValue(ValueMetadataWrapperImpl valueToRemove, AjaxRequestTarget target) throws SchemaException { + + } + + private List createTabs() { + List tabs = new ArrayList<>(); + + for (PrismContainerWrapper w : getModelObject().getContainers()) { + tabs.add(new PanelTab(createStringResource(w.getDisplayName())) { + @Override + public WebMarkupContainer createPanel(String panelId) { + ItemPanelSettings settings = getSettings().copy(); + settings.setHeaderVisible(false); + return new MetadataContainerPanel<>(panelId, Model.of(w), settings); + } + }); + } + + if (CollectionUtils.isNotEmpty(getModelObject().getNonContainers())) { + tabs.add(new PanelTab(createStringResource(getModelObject().getDisplayName())) { + @Override + public WebMarkupContainer createPanel(String panelId) { + ItemPanelSettings s = getSettings().copy(); + s.setVisibilityHandler(wrapper -> { + if (wrapper instanceof PrismContainerWrapper) { + return ItemVisibility.HIDDEN; + } + return ItemVisibility.AUTO; + }); + return new PrismContainerValuePanel<>(panelId, getModel(), s) { + + }; + } + }); + } + return tabs; + } + @Override protected void createMetadataPanel(Form form) { } + @Override + protected PC createPanelCtx(IModel> wrapper) { + return (PC) new PrismContainerPanelContext(wrapper); + } + @Override protected boolean isRemoveButtonVisible() { return false; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerPanel.java index cb475ed5b9a..ef8e0da87e5 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismContainerPanel.java @@ -14,7 +14,6 @@ import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.html.list.ListItem; -import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper; @@ -54,7 +53,7 @@ protected void onInitialize() { } @Override - protected Panel createHeaderPanel() { + protected Component createHeaderPanel() { return new PrismContainerHeaderPanel(ID_HEADER, getModel()) { @Override protected void onExpandClick(AjaxRequestTarget target) { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java index 84c8b7337c7..94b14552588 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismPropertyPanel.java @@ -17,7 +17,6 @@ import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.html.list.ListItem; -import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; /** @@ -39,7 +38,7 @@ public PrismPropertyPanel(String id, IModel> model, Item } @Override - protected Panel createHeaderPanel() { + protected Component createHeaderPanel() { return new PrismPropertyHeaderPanel(ID_HEADER, getModel()) { @Override protected void refreshPanel(AjaxRequestTarget target) { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismReferencePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismReferencePanel.java index d2386a2ba50..33978de33c0 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismReferencePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismReferencePanel.java @@ -15,7 +15,6 @@ import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.html.list.ListItem; -import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import com.evolveum.midpoint.prism.Referencable; @@ -38,7 +37,7 @@ public PrismReferencePanel(String id, IModel> model, It } @Override - protected Panel createHeaderPanel() { + protected Component createHeaderPanel() { return new PrismReferenceHeaderPanel(ID_HEADER, getModel()) { @Override protected void refreshPanel(AjaxRequestTarget target) { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java index 70b30eb5012..7731d66b32f 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/PrismValuePanel.java @@ -171,7 +171,7 @@ private WebMarkupContainer createValuePanel(Form form) { } protected void createMetadataPanel(Form form) { - MetadataContainerValuePanel metadataPanel = new MetadataContainerValuePanel(ID_METADATA, new PropertyModel<>(getModel(), "valueMetadata"), new ItemPanelSettingsBuilder().build()); + MetadataContainerValuePanel metadataPanel = new MetadataContainerValuePanel(ID_METADATA, new PropertyModel<>(getModel(), "valueMetadata"), new ItemPanelSettingsBuilder().editabilityHandler(wrapper -> false).build()); metadataPanel.add(new VisibleBehaviour(() -> getModelObject().getValueMetadata() != null && getModelObject().isShowMetadata())); form.add(metadataPanel); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ResourceAttributeDefinitionPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ResourceAttributeDefinitionPanel.java index 7f5bb5ea8d7..9f94a2bb4dd 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ResourceAttributeDefinitionPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/panel/ResourceAttributeDefinitionPanel.java @@ -8,7 +8,8 @@ package com.evolveum.midpoint.gui.impl.prism.panel; import com.evolveum.midpoint.gui.api.prism.wrapper.ResourceAttributeWrapper; -import org.apache.wicket.markup.html.panel.Panel; + +import org.apache.wicket.Component; import org.apache.wicket.model.IModel; import com.evolveum.midpoint.util.logging.Trace; @@ -34,7 +35,7 @@ public ResourceAttributeDefinitionPanel(String id, IModel(ID_HEADER, getResourceAttributeDefinitionModel()); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java index ed020736710..1a50307f394 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismReferenceValueWrapperImpl.java @@ -7,11 +7,15 @@ package com.evolveum.midpoint.gui.impl.prism.wrapper; import com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper; +import com.evolveum.midpoint.gui.api.util.WebComponentUtil; import com.evolveum.midpoint.prism.PrismReferenceValue; import com.evolveum.midpoint.prism.PrismValue; import com.evolveum.midpoint.prism.Referencable; +import com.evolveum.midpoint.util.PrettyPrinter; import com.evolveum.midpoint.web.component.prism.ValueStatus; +import javax.xml.namespace.QName; + /** * @author katka * @@ -63,4 +67,22 @@ public PrismReferenceValue getNewValue() { return super.getNewValue(); } + @Override + public String toShortString() { + T referencable = getRealValue(); + if (referencable == null) { + return ""; + } + + return getRefName(referencable) + " (" + getTargetType(referencable) + ")"; + } + + private String getRefName(T referencable) { + return referencable.getTargetName() != null ? WebComponentUtil.getOrigStringFromPoly(referencable.getTargetName()) : referencable.getOid(); + } + + private String getTargetType(T referencable) { + QName type = referencable.getType(); + return type != null ? type.getLocalPart() : ""; + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java index 6c982caf562..08427b28b27 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/PrismValueWrapperImpl.java @@ -161,10 +161,18 @@ public ValueMetadataWrapperImpl getValueMetadata() { @Override public boolean isShowMetadata() { - return true; + return showMetadata; } public void setShowMetadata(boolean showMetadata) { this.showMetadata = showMetadata; } + + @Override + public String toShortString() { + if (getRealValue() == null) { + return ""; + } + return getRealValue().toString(); + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java index ddb7e1fd03f..5ac365e8f46 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/wrapper/ValueMetadataWrapperImpl.java @@ -27,6 +27,9 @@ public ValueMetadataWrapperImpl(PrismContainerValueWrapper metada @Override public String getDisplayName() { + if (getDefinition() == null) { + return "MetadataMock"; + } return getDefinition().getDisplayName(); } @@ -240,5 +243,8 @@ public String debugDump(int indent) { return null; } - + @Override + public String toShortString() { + return ""; + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/TabbedPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/TabbedPanel.html index 36f1ce19d10..e79f1ccc3ab 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/TabbedPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/TabbedPanel.html @@ -7,7 +7,12 @@ --> From d258fe82cc877057ad0d936246242d2e444fe491 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 21 May 2020 10:01:50 +0200 Subject: [PATCH 15/60] Axiom: fixed checkstyle Signed-off-by: Tony Tkacik --- .../axiom/lang/antlr/AxiomAntlrStatementSource.java | 2 -- .../com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java | 6 ------ .../axiom/lang/antlr/AxiomModelStatementSource.java | 1 - .../main/java/com/evolveum/axiom/lang/api/AxiomModel.java | 2 ++ 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index 87f724e77fe..9f004cdce71 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -16,8 +16,6 @@ import org.antlr.v4.runtime.CommonTokenStream; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.antlr.AxiomLexer; -import com.evolveum.axiom.lang.antlr.AxiomParser; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index aba2ca4f3de..55e89071386 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -11,20 +11,14 @@ import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.RuleNode; - import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.antlr.AxiomBaseVisitor; import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; -import com.evolveum.axiom.lang.antlr.AxiomParser.PrefixContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.SourceLocation; -import com.google.common.base.Strings; public class AxiomAntlrVisitor extends AxiomBaseVisitor { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 8cec3503659..9f4362cf5db 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -19,7 +19,6 @@ import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.antlr.AxiomParser; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java index fb7da6f0a06..441eeb9593a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java @@ -8,4 +8,6 @@ public interface AxiomModel { AxiomIdentifier IMPORTED_NAMESPACE = AxiomIdentifier.axiom("ImportedNamespace"); String BUILTIN_TYPES = "https://ns.evolveum.com/axiom/language"; + String name(); + String namespace(); } From d919536acdb7537dafb898fb47c2d933e742ba12 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 21 May 2020 11:33:00 +0200 Subject: [PATCH 16/60] Axiom: Introduced AxiomItem and AxiomItemValue in axiom.api Signed-off-by: Tony Tkacik --- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 20 +++++++++---- .../evolveum/axiom/lang/api/AxiomItem.java | 20 +++++++++++++ .../axiom/lang/api/AxiomItemDefinition.java | 11 ++++++-- .../axiom/lang/api/AxiomItemValue.java | 28 +++++++++++++++++++ ...inition.java => AxiomNamedDefinition.java} | 2 +- .../axiom/lang/api/AxiomTypeDefinition.java | 24 +++++++++++----- .../axiom/lang/impl/BasicStatementRule.java | 2 +- .../axiom/lang/impl/StatementContextImpl.java | 4 +-- .../lang/spi/AbstractAxiomBaseDefinition.java | 4 +-- .../lang/spi/AxiomItemDefinitionImpl.java | 11 ++++++++ .../lang/spi/AxiomTypeDefinitionImpl.java | 8 +++--- .../axiom/src/main/resources/axiom-lang.axiom | 2 +- .../axiom/lang/test/TestAxiomExtension.java | 16 +++++------ .../axiom/lang/test/TestAxiomParser.java | 2 +- 14 files changed, 120 insertions(+), 34 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java rename infra/axiom/src/main/java/com/evolveum/axiom/lang/api/{AxiomBaseDefinition.java => AxiomNamedDefinition.java} (89%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index c70c26b0bed..2adb1fbf436 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -84,6 +84,16 @@ public boolean required() { return required; } + @Override + public int minOccurs() { + return 0; + } + + @Override + public int maxOccurs() { + return Integer.MAX_VALUE; + } + @Override public String toString() { return AxiomItemDefinition.toString(this); @@ -137,7 +147,7 @@ public static class Type implements AxiomTypeDefinition { Item.ITEM_DEFINITION )) { @Override - public Collection identifiers() { + public Collection identifierDefinitions() { return TYPE_IDENTIFIER_DEFINITION.get(); } }; @@ -154,7 +164,7 @@ public Collection identifiers() { )) { @Override - public Collection identifiers() { + public Collection identifierDefinitions() { return ITEM_IDENTIFIER_DEFINITION.get(); } }; @@ -163,7 +173,7 @@ public Collection identifiers() { new Type("AxiomRootDefinition", ITEM_DEFINITION, () -> itemDefs()) { @Override - public Collection identifiers() { + public Collection identifierDefinitions() { return ROOT_IDENTIFIER_DEFINITION.get(); } }; @@ -232,7 +242,7 @@ public Optional superType() { } @Override - public Map items() { + public Map itemDefinitions() { return items.get(); } @@ -246,7 +256,7 @@ private static Map itemDefs(AxiomItemDefin } @Override - public Collection identifiers() { + public Collection identifierDefinitions() { return Collections.emptyList(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java new file mode 100644 index 00000000000..a1619605719 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java @@ -0,0 +1,20 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Collection; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; + +public interface AxiomItem { + + AxiomIdentifier name(); + Optional definition(); + + Collection> values(); + + default AxiomItemValue onlyValue() { + return Iterables.getOnlyElement(values()); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java index d37cc6cee47..b1e78d2004d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java @@ -9,12 +9,18 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.base.MoreObjects; -public interface AxiomItemDefinition extends AxiomBaseDefinition { +public interface AxiomItemDefinition extends AxiomNamedDefinition { AxiomIdentifier ROOT_SPACE = AxiomIdentifier.axiom("AxiomRootDefinition"); AxiomTypeDefinition type(); - boolean required(); + + default boolean required() { + return minOccurs() > 0; + } + + int minOccurs(); + int maxOccurs(); static String toString(AxiomItemDefinition def) { return MoreObjects.toStringHelper(AxiomItemDefinition.class) @@ -22,4 +28,5 @@ static String toString(AxiomItemDefinition def) { .add("type", def.type()) .toString(); } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java new file mode 100644 index 00000000000..69db2849773 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java @@ -0,0 +1,28 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.function.Supplier; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.google.common.collect.Collections2; + + +public interface AxiomItemValue extends Supplier { + + Optional definition(); + + default Collection> items() { + return Collections.emptyList(); + } + + default Collection> items(AxiomIdentifier name) { + return Collections2.filter(items(), value -> name.equals(value.name())); + } + + + @Override + V get(); + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomNamedDefinition.java similarity index 89% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBaseDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomNamedDefinition.java index 628f31b3ec4..4e6854067a9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomNamedDefinition.java @@ -8,7 +8,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; -public interface AxiomBaseDefinition { +public interface AxiomNamedDefinition { AxiomIdentifier name(); String documentation(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java index bbaea4573c5..230e2cbda68 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java @@ -14,26 +14,36 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.collect.ImmutableMap; -public interface AxiomTypeDefinition extends AxiomBaseDefinition { +public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomItemValue { public final AxiomIdentifier IDENTIFIER_MEMBER = AxiomIdentifier.axiom("name"); public final AxiomIdentifier IDENTIFIER_SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition"); + @Override + default AxiomTypeDefinition get() { + return this; + } + + @Override + default Optional definition() { + return Optional.empty(); + } + Optional argument(); Optional superType(); - Map items(); + Map itemDefinitions(); - Collection identifiers(); + Collection identifierDefinitions(); - default Optional item(AxiomIdentifier child) { - AxiomItemDefinition maybe = items().get(child); + default Optional itemDefinition(AxiomIdentifier child) { + AxiomItemDefinition maybe = itemDefinitions().get(child); if(maybe != null) { return Optional.of(maybe); } if(superType().isPresent()) { - return superType().get().item(child); + return superType().get().itemDefinition(child); } return Optional.empty(); } @@ -43,7 +53,7 @@ static IdentifierSpaceKey identifier(AxiomIdentifier name) { } default Collection requiredItems() { - return items().values().stream().filter(AxiomItemDefinition::required).collect(Collectors.toList()); + return itemDefinitions().values().stream().filter(AxiomItemDefinition::required).collect(Collectors.toList()); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 4467c381163..c450b2d1c84 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -78,7 +78,7 @@ public void apply(Context rule) throws AxiomSemanticException { @Override public void apply(Context rule) throws AxiomSemanticException { - Collection idDefs = rule.typeDefinition().identifiers(); + Collection idDefs = rule.typeDefinition().identifierDefinitions(); if(!idDefs.isEmpty()) { rule.apply(ctx -> { for (AxiomIdentifierDefinition idDef : idDefs) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 35e915c866b..5ac07225cad 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -64,7 +64,7 @@ private StatementContextResult mutableResult() { } boolean isChildAllowed(AxiomIdentifier child) { - return definition.type().item(child).isPresent(); + return definition.type().itemDefinition(child).isPresent(); } @@ -88,7 +88,7 @@ public String toString() { @Override public Optional childDef(AxiomIdentifier child) { - return definition.type().item(child); + return definition.type().itemDefinition(child); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java index 5d6f99c75a2..6354f37ee31 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java @@ -3,13 +3,13 @@ import java.util.List; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomBaseDefinition; +import com.evolveum.axiom.lang.api.AxiomNamedDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.google.common.collect.Multimap; -public class AbstractAxiomBaseDefinition extends AxiomStatementImpl implements AxiomBaseDefinition { +public class AbstractAxiomBaseDefinition extends AxiomStatementImpl implements AxiomNamedDefinition { public static final Factory FACTORY = AbstractAxiomBaseDefinition::new ; private AxiomIdentifier name; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 1b2fcdec30a..5cabddf6f01 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -32,6 +32,17 @@ public boolean required() { return minOccurs > 0; } + @Override + public int minOccurs() { + return 0; + } + + @Override + public int maxOccurs() { + // FIXME: Return real value + return Integer.MAX_VALUE; + } + @Override public String toString() { return AxiomItemDefinition.toString(this); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 2cee9ce2e58..c91e0e3f340 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -39,11 +39,11 @@ public AxiomTypeDefinitionImpl(AxiomIdentifier keyword, AxiomIdentifier value, L items = builder.build(); superType = first(SUPERTYPE_REFERENCE.name(), AxiomTypeDefinition.class); argument = firstValue(ARGUMENT.name(), AxiomIdentifier.class) - .flatMap((AxiomIdentifier k) -> item(k)); + .flatMap((AxiomIdentifier k) -> itemDefinition(k)); identifiers = children(Item.IDENTIFIER_DEFINITION.name()).stream().map(idDef -> { Set members = idDef.children(Item.ID_MEMBER.name()).stream() - .map(k -> item((AxiomIdentifier) k.value()).get()).collect(Collectors.toSet()); + .map(k -> itemDefinition((AxiomIdentifier) k.value()).get()).collect(Collectors.toSet()); AxiomIdentifier space = idDef.firstValue(ID_SPACE.name(), AxiomIdentifier.class).get(); AxiomIdentifierDefinition.Scope scope = AxiomIdentifierDefinition.scope(idDef.firstValue(ID_SCOPE.name(), AxiomIdentifier.class).get().getLocalName()); return AxiomIdentifierDefinition.from(space, scope, members); @@ -64,12 +64,12 @@ public Optional superType() { } @Override - public Map items() { + public Map itemDefinitions() { return items; } @Override - public Collection identifiers() { + public Collection identifierDefinitions() { return identifiers; } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 2784ebd3fbc..13e81603274 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -49,7 +49,7 @@ model axiom-lang { item mixin { type AxiomMixinDefinition; documentation """ - Mixin Declaration, declares a new global mixin, aset of reusable item + Mixin Declaration, declares a new global mixin, aset of reusable item definitions, which can be used in type definitions. """; } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index 5e7984cda2f..afdc9f175bb 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -47,15 +47,15 @@ public void axiomTestExtension() throws IOException, AxiomSyntaxException { AxiomSchemaContext schemaContext = context.computeSchemaContext(); AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); - assertTrue(!langExtDef.identifiers().isEmpty()); + assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); Optional extPersonDef = schemaContext.getType(PERSON_EXTENSION); assertTrue(extPersonDef.isPresent()); - for(AxiomIdentifier item : extPersonDef.get().items().keySet()) { - assertTrue(personDef.get().item(item).isPresent()); + for(AxiomIdentifier item : extPersonDef.get().itemDefinitions().keySet()) { + assertTrue(personDef.get().itemDefinition(item).isPresent()); } } @@ -66,11 +66,11 @@ public void axiomTestOrder() throws IOException, AxiomSyntaxException { AxiomSchemaContext schemaContext = context.computeSchemaContext(); AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); - assertTrue(!langExtDef.identifiers().isEmpty()); + assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); - assertEquals(2, personDef.get().items().entrySet().size()); + assertEquals(2, personDef.get().itemDefinitions().entrySet().size()); } @Test @@ -80,7 +80,7 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio AxiomSchemaContext schemaContext = context.computeSchemaContext(); AxiomTypeDefinition typeDef = schemaContext.getType(Type.TYPE_DEFINITION.name()).get(); - assertNotNull(typeDef.item(STORAGE).get()); + assertNotNull(typeDef.itemDefinition(STORAGE).get()); ModelReactorContext extendedLanguage = ModelReactorContext.reactor(schemaContext); @@ -90,14 +90,14 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio schemaContext = extendedLanguage.computeSchemaContext(); AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); - assertTrue(!langExtDef.identifiers().isEmpty()); + assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); Collection> extension = ((AxiomStatement) personDef.get()).children(STORAGE); assertFalse(extension.isEmpty(), "Extension statements should be available."); - assertEquals(2, personDef.get().items().entrySet().size()); + assertEquals(2, personDef.get().itemDefinitions().entrySet().size()); } } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index 9132779211c..cd7dfa9613a 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -54,7 +54,7 @@ public void axiomSelfDescribingTest() throws IOException, AxiomSyntaxException { //folowupContext.loadModelFromSource(statementSource); AxiomSchemaContext selfparsedContext = folowupContext.computeSchemaContext(); assertNotNull(selfparsedContext.getRoot(Item.MODEL_DEFINITION.name())); - assertTrue(selfparsedContext.getType(Type.IDENTIFIER_DEFINITION.name()).get().item(Item.ID_MEMBER.name()).get().required()); + assertTrue(selfparsedContext.getType(Type.IDENTIFIER_DEFINITION.name()).get().itemDefinition(Item.ID_MEMBER.name()).get().required()); } From aae76b6376718464213c6950c6a4a33ad10f7459 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 21 May 2020 12:14:38 +0200 Subject: [PATCH 17/60] Axiom: Renamed reactor context to reflect Item & Value terminology Signed-off-by: Tony Tkacik --- .../evolveum/axiom/lang/api/AxiomItem.java | 1 + .../axiom/lang/api/AxiomItemFactory.java | 9 ++++ .../axiom/lang/api/AxiomItemValue.java | 4 +- .../axiom/lang/api/AxiomItemValueBuilder.java | 51 +++++++++++++++++++ .../axiom/lang/api/AxiomItemValueFactory.java | 9 ++++ .../axiom/lang/api/AxiomTypeDefinition.java | 5 +- .../axiom/lang/impl/StatementContextImpl.java | 14 ++--- ...t.java => StatementResultContextImpl.java} | 4 +- .../lang/spi/AxiomTypeDefinitionImpl.java | 4 -- 9 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java rename infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/{StatementContextResult.java => StatementResultContextImpl.java} (91%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java index a1619605719..03401b6e040 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java @@ -17,4 +17,5 @@ default AxiomItemValue onlyValue() { return Iterables.getOnlyElement(values()); } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java new file mode 100644 index 00000000000..69131b6268a --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java @@ -0,0 +1,9 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Collection; + +public interface AxiomItemFactory { + + AxiomItem create(AxiomItemDefinition def, Collection> axiomItem); + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java index 69db2849773..dc5c840c478 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java @@ -21,8 +21,10 @@ default Collection> items(AxiomIdentifier name) { return Collections2.filter(items(), value -> name.equals(value.name())); } - @Override V get(); + interface Factory> { + T create(AxiomTypeDefinition def, V value, Collection> items); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java new file mode 100644 index 00000000000..a56f3467022 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java @@ -0,0 +1,51 @@ +package com.evolveum.axiom.lang.api; + +import com.evolveum.axiom.concepts.Lazy; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.function.Supplier; + +import javax.annotation.concurrent.NotThreadSafe; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; + +@NotThreadSafe +public class AxiomItemValueBuilder> implements Lazy.Supplier { + + private final AxiomTypeDefinition type; + + private final AxiomItemValueFactory factory; + private Map>> children = new LinkedHashMap<>(); + private V value; + + public AxiomItemValueBuilder(AxiomTypeDefinition type, AxiomItemValueFactory factory) { + this.type = type; + this.factory = factory; + } + + public V getValue() { + return value; + } + + public void setValue(V value) { + this.value = value; + } + + public void add(AxiomIdentifier name, Supplier> child) { + children.put(name, child); + } + + @Override + public T get() { + Builder> builder = ImmutableMap.builder(); + for(Entry>> entry : children.entrySet()) { + builder.put(entry.getKey(), entry.getValue().get()); + } + return factory.create(type, value, builder.build().values()); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java new file mode 100644 index 00000000000..e19da1881c8 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java @@ -0,0 +1,9 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Collection; + +public interface AxiomItemValueFactory> { + + T create(AxiomTypeDefinition def, V value, Collection> items); +} + diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java index 230e2cbda68..80bc9c7e3d5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java @@ -14,11 +14,12 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.collect.ImmutableMap; -public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomItemValue { +public interface AxiomTypeDefinition extends AxiomNamedDefinition { public final AxiomIdentifier IDENTIFIER_MEMBER = AxiomIdentifier.axiom("name"); public final AxiomIdentifier IDENTIFIER_SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition"); + /* @Override default AxiomTypeDefinition get() { return this; @@ -27,7 +28,7 @@ default AxiomTypeDefinition get() { @Override default Optional definition() { return Optional.empty(); - } + }*/ Optional argument(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java index 5ac07225cad..10d0045b627 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java @@ -44,7 +44,7 @@ public abstract class StatementContextImpl implements AxiomStatementContext builder = new AxiomStatementBuilder<>(definition.name(), typeFactory(definition.type())); - this.result = new StatementContextResult<>(definition, builder); + this.result = new StatementResultContextImpl<>(definition, builder); } protected Factory> typeFactory(AxiomTypeDefinition type) { @@ -56,9 +56,9 @@ public void setValue(Object value) { mutableResult().setValue((V) value); } - private StatementContextResult mutableResult() { - if(result instanceof StatementContextResult) { - return (StatementContextResult) result; + private StatementResultContextImpl mutableResult() { + if(result instanceof StatementResultContextImpl) { + return (StatementResultContextImpl) result; } return null; } @@ -159,7 +159,7 @@ public void setValue(Object value, SourceLocation loc) { } public Dependency> asRequirement() { - if (result instanceof StatementContextResult) { + if (result instanceof StatementResultContextImpl) { return Dependency.deffered(result); } return result; @@ -217,8 +217,8 @@ private void registerLocalParent(AxiomIdentifier space, IdentifierSpaceKey key) @Override public V requireValue(Class type) { - if(result instanceof StatementContextResult) { - return type.cast(((StatementContextResult) result).value()); + if(result instanceof StatementResultContextImpl) { + return type.cast(((StatementResultContextImpl) result).value()); } return null; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementResultContextImpl.java similarity index 91% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementResultContextImpl.java index ca7156d97b0..0758eb9c9ac 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextResult.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementResultContextImpl.java @@ -13,7 +13,7 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -class StatementContextResult implements Dependency> { +class StatementResultContextImpl implements Dependency> { private V value; private final List> childrenList = new ArrayList<>(); @@ -22,7 +22,7 @@ class StatementContextResult implements Dependency> { private final List> rules = new ArrayList<>(); - public StatementContextResult(AxiomItemDefinition definition, AxiomStatementBuilder builder) { + public StatementResultContextImpl(AxiomItemDefinition definition, AxiomStatementBuilder builder) { super(); this.builder = builder; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index c91e0e3f340..ddade1fa76d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -7,17 +7,13 @@ import java.util.Set; import java.util.stream.Collectors; -import org.checkerframework.checker.units.qual.K; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.concepts.Identifiable; -import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Multimap; import static com.evolveum.axiom.lang.api.AxiomBuiltIn.Item.*; From 3ae8c901651a17ab8c371a94417172f223cadf7f Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Sat, 23 May 2020 09:33:03 +0200 Subject: [PATCH 18/60] Axiom: Reworked language reactor to use concepts as Item & Value Language reactor used different concept for computation (statement) before, which had different structural behaviour than Item & Value which were exported as result. This difference was removed, additional concept (statement) was removed. Signed-off-by: Tony Tkacik --- .../lang/antlr/AxiomAntlrStatementSource.java | 4 +- .../axiom/lang/antlr/AxiomAntlrVisitor.java | 44 +- .../lang/antlr/AxiomModelStatementSource.java | 6 +- .../axiom/lang/api/AbstractAxiomItem.java | 25 ++ .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 30 +- .../lang/api/AxiomIdentifierDefinition.java | 16 +- .../api/AxiomIdentifierDefinitionImpl.java | 8 +- .../evolveum/axiom/lang/api/AxiomItem.java | 9 +- .../axiom/lang/api/AxiomItemDefinition.java | 16 +- .../axiom/lang/api/AxiomItemImpl.java | 26 ++ .../axiom/lang/api/AxiomItemStream.java | 14 + .../axiom/lang/api/AxiomItemValue.java | 18 +- .../axiom/lang/api/AxiomItemValueBuilder.java | 24 +- .../axiom/lang/api/AxiomItemValueFactory.java | 6 +- .../axiom/lang/api/AxiomTypeDefinition.java | 8 +- .../axiom/lang/api/CompactAxiomItem.java | 42 ++ .../axiom/lang/api/SimpleItemValue.java | 28 ++ .../axiom/lang/impl/AbstractContext.java | 74 ++++ .../axiom/lang/impl/AxiomItemContext.java | 11 + .../axiom/lang/impl/AxiomRootContext.java | 11 + .../lang/impl/AxiomSchemaContextImpl.java | 10 +- .../lang/impl/AxiomStatementContext.java | 44 -- .../axiom/lang/impl/AxiomStatementRule.java | 67 ++- .../axiom/lang/impl/AxiomValueContext.java | 68 +++ .../axiom/lang/impl/BasicStatementRule.java | 215 ++++++---- .../lang/impl/CompositeIdentifierSpace.java | 21 +- .../lang/impl/IdentifierSpaceHolder.java | 8 +- .../lang/impl/IdentifierSpaceHolderImpl.java | 27 +- .../evolveum/axiom/lang/impl/ItemContext.java | 91 ++++ .../axiom/lang/impl/ItemValueImpl.java | 60 +++ .../axiom/lang/impl/ModelReactorContext.java | 105 ++--- .../axiom/lang/impl/RuleContextImpl.java | 10 +- .../axiom/lang/impl/SourceContext.java | 96 +++++ .../axiom/lang/impl/StatementContextImpl.java | 402 ------------------ .../lang/impl/StatementFactoryContext.java | 20 - .../lang/impl/StatementResultContextImpl.java | 77 ---- .../lang/impl/StatementRuleContextImpl.java | 127 +++--- .../axiom/lang/impl/ValueContext.java | 227 ++++++++++ .../lang/spi/AbstractAxiomBaseDefinition.java | 34 -- .../lang/spi/AbstractBaseDefinition.java | 33 ++ .../spi/AxiomIdentifierDefinitionImpl.java | 58 +++ .../lang/spi/AxiomItemDefinitionImpl.java | 37 +- .../lang/spi/AxiomItemStreamTreeBuilder.java | 107 +++++ .../axiom/lang/spi/AxiomStatement.java | 45 -- .../axiom/lang/spi/AxiomStatementBuilder.java | 67 --- .../axiom/lang/spi/AxiomStatementImpl.java | 77 ---- .../spi/AxiomStatementStreamListener.java | 20 - .../lang/spi/AxiomStreamTreeBuilder.java | 86 ---- .../lang/spi/AxiomTypeDefinitionImpl.java | 76 ++-- .../axiom/lang/spi/SourceLocation.java | 4 + .../com/evolveum/axiom/reactor/Action.java | 12 +- .../axiom/reactor/DependantAction.java | 7 +- .../evolveum/axiom/reactor/Dependency.java | 55 ++- .../axiom/src/main/resources/axiom-lang.axiom | 2 +- .../axiom/lang/test/TestAxiomExtension.java | 8 +- 55 files changed, 1540 insertions(+), 1283 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AbstractAxiomItem.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleItemValue.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomRootContext.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementContext.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementFactoryContext.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementResultContextImpl.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementBuilder.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementImpl.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementStreamListener.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index 9f004cdce71..7f364170ab3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -17,8 +17,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.api.AxiomItemStream; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class AxiomAntlrStatementSource { @@ -60,7 +60,7 @@ protected final StatementContext root() { return root; } - public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomStatementStreamListener listener, + public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Listener listener, Optional> emitOnly) { AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, statements, arguments, listener, emitOnly.orElse(null)); visitor.visit(root); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index 55e89071386..2e6c603a1e4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -16,19 +16,19 @@ import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; +import com.evolveum.axiom.lang.api.AxiomItemStream; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.SourceLocation; public class AxiomAntlrVisitor extends AxiomBaseVisitor { private final AxiomIdentifierResolver statements; private final AxiomIdentifierResolver arguments; - private final AxiomStatementStreamListener delegate; + private final AxiomItemStream.Listener delegate; private final Optional> limit; private final String sourceName; - public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomStatementStreamListener delegate, + public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Listener delegate, Set limit) { this.sourceName = name; this.statements = statements; @@ -51,14 +51,36 @@ private String nullableText(ParserRuleContext prefix) { public T visitStatement(StatementContext ctx) { AxiomIdentifier identifier = statementIdentifier(ctx.identifier()); if(canEmit(identifier)) { - delegate.startStatement(identifier, sourceLocation(ctx.identifier().start)); + SourceLocation start = sourceLocation(ctx.identifier().start); + delegate.startItem(identifier, start); + + ArgumentContext argument = ctx.argument(); + final Object value; + final SourceLocation valueStart; + if(argument != null) { + value = convert(argument); + valueStart = sourceLocation(argument.start); + } else { + value = null; + valueStart = start; + } + delegate.startValue(value, valueStart); T ret = super.visitStatement(ctx); - delegate.endStatement(sourceLocation(ctx.stop)); + delegate.endValue(sourceLocation(ctx.stop)); + delegate.endItem(sourceLocation(ctx.stop)); return ret; } return defaultResult(); } + private Object convert(ArgumentContext ctx) { + if (ctx.identifier() != null) { + return (convert(ctx.identifier())); + } else { + return (convert(ctx.string())); + } + } + private boolean canEmit(AxiomIdentifier identifier) { if (limit.isPresent()) { return limit.get().contains(identifier); @@ -68,11 +90,7 @@ private boolean canEmit(AxiomIdentifier identifier) { @Override public T visitArgument(ArgumentContext ctx) { - if (ctx.identifier() != null) { - delegate.argument(convert(ctx.identifier()), sourceLocation(ctx.start)); - } else { - delegate.argument(convert(ctx.string()), sourceLocation(ctx.start)); - } + return defaultResult(); } @@ -86,12 +104,6 @@ private AxiomIdentifier argumentIdentifier(IdentifierContext identifier) { return arguments.resolveIdentifier(prefix, localName); } - - - private int sourceLine(ParserRuleContext node) { - return node.start.getLine(); - } - private SourceLocation sourceLocation(Token start) { return SourceLocation.from(sourceName, start.getLine(), start.getCharPositionInLine()); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 9f4362cf5db..365fc2713ca 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -20,8 +20,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.api.AxiomItemStream; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.AxiomStatementStreamListener; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class AxiomModelStatementSource extends AxiomAntlrStatementSource implements AxiomIdentifierResolver { @@ -63,11 +63,11 @@ public String namespace() { return namespace; } - public void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListener listener) { + public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Listener listener) { stream(resolver, listener, Optional.empty()); } - public void stream(AxiomIdentifierResolver resolver, AxiomStatementStreamListener listener, + public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Listener listener, Optional> emitOnly) { stream(resolver.or(this), BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AbstractAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AbstractAxiomItem.java new file mode 100644 index 00000000000..42a9085ca31 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AbstractAxiomItem.java @@ -0,0 +1,25 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Optional; + +import com.evolveum.axiom.api.AxiomIdentifier; + +public abstract class AbstractAxiomItem implements AxiomItem { + + + private final AxiomItemDefinition definition; + + public AbstractAxiomItem(AxiomItemDefinition definition) { + this.definition = definition; + } + + @Override + public Optional definition() { + return Optional.of(definition); + } + + @Override + public AxiomIdentifier name() { + return definition.name(); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 2adb1fbf436..e85311840aa 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -13,7 +13,6 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableSet; @@ -28,7 +27,7 @@ private AxiomBuiltIn() { throw new UnsupportedOperationException("Utility class"); } - public static class Item implements AxiomItemDefinition, AxiomStatement { + 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); @@ -63,6 +62,11 @@ private Item(String identifier, AxiomTypeDefinition type, boolean required) { this.required = required; } + @Override + public Optional type() { + return Optional.of(type); + } + @Override public AxiomIdentifier name() { return identifier; @@ -75,7 +79,7 @@ public String documentation() { @Override - public AxiomTypeDefinition type() { + public AxiomTypeDefinition typeDefinition() { return type; } @@ -100,22 +104,8 @@ public String toString() { } @Override - public Collection> children() { - return null; - } - - @Override - public Collection> children(AxiomIdentifier name) { - return null; - } - - @Override - public AxiomIdentifier keyword() { - return null; - } - @Override - public AxiomIdentifier value() { - return identifier; + public AxiomItemDefinition get() { + return this; } } @@ -179,7 +169,7 @@ public Collection identifierDefinitions() { }; protected static final Lazy> ITEM_IDENTIFIER_DEFINITION = Lazy.from(()-> - ImmutableSet.of(AxiomIdentifierDefinition.local(ITEM_DEFINITION.name(), Item.NAME))); + ImmutableSet.of(AxiomIdentifierDefinition.parent(ITEM_DEFINITION.name(), Item.NAME))); protected static final Lazy> ROOT_IDENTIFIER_DEFINITION = Lazy.from(()-> ImmutableSet.of(AxiomIdentifierDefinition.global(AxiomItemDefinition.ROOT_SPACE, Item.NAME))); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java index d1985875020..7db0007aff8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java @@ -1,13 +1,17 @@ package com.evolveum.axiom.lang.api; import java.util.Collection; -import java.util.Optional; import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.collect.ImmutableSet; -public interface AxiomIdentifierDefinition { +public interface AxiomIdentifierDefinition extends AxiomItemValue { + + @Override + default AxiomIdentifierDefinition get() { + return this; + } Collection components(); @@ -17,6 +21,7 @@ public interface AxiomIdentifierDefinition { enum Scope { GLOBAL, + PARENT, LOCAL } @@ -32,6 +37,9 @@ static Scope scope(String scope) { if(Scope.GLOBAL.name().equalsIgnoreCase(scope)) { return Scope.GLOBAL; } + if(Scope.PARENT.name().equalsIgnoreCase(scope)) { + return Scope.PARENT; + } if(Scope.LOCAL.name().equalsIgnoreCase(scope)) { return Scope.LOCAL; } @@ -42,4 +50,8 @@ static AxiomIdentifierDefinition from(AxiomIdentifier space, Scope scope, Set type() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java index 03401b6e040..7d03297a256 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java @@ -1,9 +1,9 @@ package com.evolveum.axiom.lang.api; import java.util.Collection; +import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.google.common.base.Optional; import com.google.common.collect.Iterables; public interface AxiomItem { @@ -17,5 +17,12 @@ default AxiomItemValue onlyValue() { return Iterables.getOnlyElement(values()); } + static AxiomItem of(AxiomItemDefinition def, V value) { + return CompactAxiomItem.of(def, value); + } + + static AxiomItem from(AxiomItemDefinition def, Collection> values) { + return AxiomItemImpl.from(def, values); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java index b1e78d2004d..7d7084fe85d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java @@ -8,12 +8,20 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableMap; -public interface AxiomItemDefinition extends AxiomNamedDefinition { +public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomItemValue { AxiomIdentifier ROOT_SPACE = AxiomIdentifier.axiom("AxiomRootDefinition"); + AxiomIdentifier SPACE = AxiomIdentifier.axiom("AxiomItemDefinition"); + AxiomIdentifier NAME = AxiomIdentifier.axiom("name"); - AxiomTypeDefinition type(); + @Override + default AxiomItemDefinition get() { + return this; + } + + AxiomTypeDefinition typeDefinition(); default boolean required() { return minOccurs() > 0; @@ -29,4 +37,8 @@ static String toString(AxiomItemDefinition def) { .toString(); } + static IdentifierSpaceKey identifier(AxiomIdentifier name) { + return IdentifierSpaceKey.from(ImmutableMap.of(NAME, name)); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java new file mode 100644 index 00000000000..765abc850a6 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java @@ -0,0 +1,26 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Collection; + +import com.google.common.collect.ImmutableList; + +class AxiomItemImpl extends AbstractAxiomItem { + + Collection> values; + + + private AxiomItemImpl(AxiomItemDefinition definition, Collection> val) { + super(definition); + this.values = ImmutableList.copyOf(val); + } + + static AxiomItem from(AxiomItemDefinition definition, Collection> values) { + return new AxiomItemImpl<>(definition, values); + } + + @Override + public Collection> values() { + return values; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java new file mode 100644 index 00000000000..e42949d602c --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java @@ -0,0 +1,14 @@ +package com.evolveum.axiom.lang.api; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.spi.SourceLocation; + +public interface AxiomItemStream { + + interface Listener { + void startItem(AxiomIdentifier item, SourceLocation loc); + void startValue(Object value, SourceLocation loc); + void endValue(SourceLocation loc); + void endItem(SourceLocation loc); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java index dc5c840c478..29b40321e79 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java @@ -6,25 +6,31 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; -import com.google.common.collect.Collections2; public interface AxiomItemValue extends Supplier { - Optional definition(); + Optional type(); default Collection> items() { return Collections.emptyList(); } - default Collection> items(AxiomIdentifier name) { - return Collections2.filter(items(), value -> name.equals(value.name())); + @SuppressWarnings({ "rawtypes", "unchecked" }) + default Optional> item(AxiomItemDefinition def) { + return (Optional) item(def.name()); + } + + @SuppressWarnings("unchecked") + default Optional> item(AxiomIdentifier name) { + return items().stream().filter(value -> name.equals(value.name())).findFirst().map(v -> (AxiomItem) v); } @Override V get(); - interface Factory> { - T create(AxiomTypeDefinition def, V value, Collection> items); + static AxiomItemValue from(AxiomTypeDefinition typeDefinition, V value) { + return new SimpleItemValue(typeDefinition, value); } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java index a56f3467022..c2e9045f3e1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java @@ -5,20 +5,18 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Function; import java.util.function.Supplier; -import javax.annotation.concurrent.NotThreadSafe; - import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -@NotThreadSafe public class AxiomItemValueBuilder> implements Lazy.Supplier { private final AxiomTypeDefinition type; - private final AxiomItemValueFactory factory; + private AxiomItemValueFactory factory; private Map>> children = new LinkedHashMap<>(); private V value; @@ -39,13 +37,29 @@ public void add(AxiomIdentifier name, Supplier> child) { children.put(name, child); } + public Supplier> get(AxiomIdentifier name) { + return children.get(name); + } + + public Supplier> get(AxiomIdentifier name, Function>> child) { + return children.computeIfAbsent(name, child); + } + @Override public T get() { Builder> builder = ImmutableMap.builder(); for(Entry>> entry : children.entrySet()) { builder.put(entry.getKey(), entry.getValue().get()); } - return factory.create(type, value, builder.build().values()); + return factory.create(type, value, builder.build()); + } + + public static > AxiomItemValueBuilder create(AxiomTypeDefinition type, AxiomItemValueFactory factory) { + return new AxiomItemValueBuilder<>(type, factory); + } + + public void setFactory(AxiomItemValueFactory factoryFor) { + this.factory = factoryFor; } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java index e19da1881c8..93fb5d8baa4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java @@ -1,9 +1,11 @@ package com.evolveum.axiom.lang.api; -import java.util.Collection; +import java.util.Map; + +import com.evolveum.axiom.api.AxiomIdentifier; public interface AxiomItemValueFactory> { - T create(AxiomTypeDefinition def, V value, Collection> items); + T create(AxiomTypeDefinition def, V value, Map> items); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java index 80bc9c7e3d5..6f21808bd27 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java @@ -14,21 +14,21 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.collect.ImmutableMap; -public interface AxiomTypeDefinition extends AxiomNamedDefinition { +public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomItemValue { public final AxiomIdentifier IDENTIFIER_MEMBER = AxiomIdentifier.axiom("name"); public final AxiomIdentifier IDENTIFIER_SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition"); - /* + @Override default AxiomTypeDefinition get() { return this; } @Override - default Optional definition() { + default Optional type() { return Optional.empty(); - }*/ + } Optional argument(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java new file mode 100644 index 00000000000..cd300a09322 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java @@ -0,0 +1,42 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Collection; +import java.util.Optional; + +import com.google.common.collect.ImmutableSet; + +class CompactAxiomItem extends AbstractAxiomItem implements AxiomItemValue { + + private final V value; + + @Override + public Optional type() { + return definition().map(AxiomItemDefinition::typeDefinition); + } + + private CompactAxiomItem(AxiomItemDefinition definition, V value) { + super(definition); + this.value = value; + } + + public static AxiomItem of(AxiomItemDefinition def, V value) { + return new CompactAxiomItem(def, value); + } + + @Override + public V get() { + return value; + } + + @Override + public Collection> values() { + return ImmutableSet.of(this); + } + + @Override + public AxiomItemValue onlyValue() { + return this; + } + + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleItemValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleItemValue.java new file mode 100644 index 00000000000..4d07e341a13 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleItemValue.java @@ -0,0 +1,28 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Optional; + +class SimpleItemValue implements AxiomItemValue { + + private final AxiomTypeDefinition type; + private final T value; + + + + SimpleItemValue(AxiomTypeDefinition type, T value) { + super(); + this.type = type; + this.value = value; + } + + @Override + public Optional type() { + return Optional.ofNullable(type); + } + + @Override + public T get() { + return value; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java new file mode 100644 index 00000000000..faacde90e30 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java @@ -0,0 +1,74 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.Map; +import java.util.Optional; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.spi.SourceLocation; + +abstract class AbstractContext

> implements IdentifierSpaceHolder { + + private final P parent; + private SourceLocation start; + + private final IdentifierSpaceHolder localSpace; + + public AbstractContext(P context, SourceLocation loc, Scope scope) { + this(context,loc, new IdentifierSpaceHolderImpl(scope)); + } + + public AbstractContext(P context, SourceLocation loc, IdentifierSpaceHolder space) { + parent = context; + start = loc; + localSpace = space; + } + + public P parent() { + return parent; + } + protected abstract Optional childDef(AxiomIdentifier id); + + + protected SourceContext rootImpl() { + return parent.rootImpl(); + } + + public SourceLocation startLocation() { + return start; + } + + + @Override + public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + ValueContext maybe = localSpace.lookup(space, key); + if(maybe != null) { + return maybe; + } + return parent().lookup(space, key); + } + + @Override + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + switch (scope) { + case GLOBAL: + rootImpl().register(space, scope, key, context); + break; + case PARENT: + parent().register(space, Scope.LOCAL, key, context); + break; + case LOCAL: + localSpace.register(space, scope, key, context); + break; + default: + throw new IllegalStateException("Unsupported scope"); + } + } + + @Override + public Map> space(AxiomIdentifier space) { + return localSpace.space(space); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java new file mode 100644 index 00000000000..ca571fb4294 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java @@ -0,0 +1,11 @@ +package com.evolveum.axiom.lang.impl; + +public interface AxiomItemContext { + + AxiomValueContext addValue(T value); + + AxiomValueContext parent(); + + T onlyValue(); + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomRootContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomRootContext.java new file mode 100644 index 00000000000..0130a69e195 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomRootContext.java @@ -0,0 +1,11 @@ +package com.evolveum.axiom.lang.impl; + +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; + +public interface AxiomRootContext { + + void importIdentifierSpace(NamespaceContext namespaceContext); + + void exportIdentifierSpace(IdentifierSpaceKey namespaceId); + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index 14a4dcbee00..547bea72415 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -7,10 +7,10 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; @@ -18,9 +18,9 @@ public class AxiomSchemaContextImpl implements AxiomSchemaContext { private Map roots; private Map types; - private Map>> globals; + private Map>> globals; - public AxiomSchemaContextImpl(Map>> globalMap) { + public AxiomSchemaContextImpl(Map>> globalMap) { this.globals = globalMap; this.roots = Maps.transformValues(globalMap.get(AxiomItemDefinition.ROOT_SPACE), AxiomItemDefinition.class::cast); this.types = Maps.transformValues(globalMap.get(AxiomTypeDefinition.IDENTIFIER_SPACE), AxiomTypeDefinition.class::cast); @@ -51,8 +51,8 @@ private static IdentifierSpaceKey nameKey(AxiomIdentifier type) { } public static AxiomSchemaContextImpl boostrapContext() { - Map> root = ImmutableMap.of(nameKey(AxiomBuiltIn.Item.MODEL_DEFINITION.name()), AxiomBuiltIn.Item.MODEL_DEFINITION); - Map>> global + Map> root = ImmutableMap.of(nameKey(AxiomBuiltIn.Item.MODEL_DEFINITION.name()), AxiomBuiltIn.Item.MODEL_DEFINITION); + Map>> global = ImmutableMap.of(AxiomItemDefinition.ROOT_SPACE, root, AxiomTypeDefinition.IDENTIFIER_SPACE, ImmutableMap.of()); return new AxiomSchemaContextImpl(global); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementContext.java deleted file mode 100644 index b43f52668eb..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementContext.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.evolveum.axiom.lang.impl; - -import java.util.Collection; -import java.util.Optional; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.reactor.Dependency; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; - -public interface AxiomStatementContext { - - V requireValue() throws AxiomSemanticException; - - AxiomItemDefinition definition(); - - AxiomStatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value); - - Optional optionalValue(); - - void replace(Dependency> statement); - - AxiomStatementContext parent(); - - void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key); - - V requireValue(Class type); - - - void importIdentifierSpace(NamespaceContext namespaceContext); - - void exportIdentifierSpace(IdentifierSpaceKey namespace); - - void addChildren(Collection> children); - - AxiomStatementRule.Context newAction(String actionName); - - AxiomStatementRule.Context modify(AxiomStatementContext target, String actionName); - - void addEffectiveChildren(Collection> children); - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index a6eb0c4bd96..9df55cd29f7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -1,16 +1,13 @@ package com.evolveum.axiom.lang.impl; -import java.util.Optional; -import java.util.function.Supplier; - import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.reactor.Dependency; -import com.evolveum.axiom.reactor.Dependency.Search; public interface AxiomStatementRule { @@ -18,43 +15,77 @@ public interface AxiomStatementRule { boolean isApplicableTo(AxiomItemDefinition definition); - void apply(Context rule) throws AxiomSemanticException; + void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException; + + + interface Lookup { + default AxiomTypeDefinition typeDefinition() { + return itemDefinition().typeDefinition(); + } + + AxiomItemDefinition itemDefinition(); + + Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); + + Dependency> child(AxiomItemDefinition namespace, Class valueType); + + Dependency> modify(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + + Dependency.Search> global(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + + Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey itemName); + + Dependency finalValue(); + + V currentValue(); + + boolean isMutable(); - interface Context { - Optional optionalChildValue(AxiomItemDefinition supertypeReference, Class type); + } + + interface ActionBuilder { + + + AxiomSemanticException error(String message, Object... arguments); + + ActionBuilder apply(Action action); + + Dependency> require(AxiomValueContext ext); + + + + > X require(X req); + + /* Optional optionalChildValue(AxiomItemDefinition supertypeReference, Class type); V requiredChildValue(AxiomItemDefinition supertypeReference, Class type) throws AxiomSemanticException; V requireValue() throws AxiomSemanticException; - Context apply(Action action); + Context errorMessage(Supplier errorFactory); RuleErrorMessage error(String format, Object... arguments); - AxiomTypeDefinition typeDefinition(); - AxiomItemDefinition itemDefinition(); Optional optionalValue(); - Search> requireGlobalItem(AxiomIdentifier space, IdentifierSpaceKey key); + Search> requireGlobal(AxiomIdentifier space, IdentifierSpaceKey key); - Dependency> requireChild(AxiomItemDefinition required); + Dependency> requireChild(AxiomItemDefinition required); Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); - Dependency> modify(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); - - Context newAction(); + Dependency> modify(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); - Dependency> require(AxiomStatementContext ext); + Dependency> require(AxiomValueContext ext);*/ } public interface Action { - void apply(AxiomStatementContext context) throws AxiomSemanticException; + void apply(AxiomValueContext context) throws AxiomSemanticException; } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java new file mode 100644 index 00000000000..32fc7d5de64 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java @@ -0,0 +1,68 @@ +package com.evolveum.axiom.lang.impl; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; + +public interface AxiomValueContext { + + void replace(AxiomItemValue axiomItemValue); + + default AxiomItemContext childItem(AxiomItemDefinition def) { + return childItem(def.name()); + } + + AxiomItemContext childItem(AxiomIdentifier name); + + V currentValue(); + + AxiomItemContext parent(); + + void mergeItem(AxiomItem axiomItem); + + void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key); + + AxiomRootContext root(); + + ActionBuilder newAction(String name); + + default AxiomValueContext parentValue() { + return parent().parent(); + } + + void replaceValue(V object); + + /*V requireValue() throws AxiomSemanticException; + + AxiomItemDefinition definition(); + + AxiomValueContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value); + + Optional optionalValue(); + + void replace(Dependency> statement); + + AxiomValueContext parent(); + + void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key); + + V requireValue(Class type); + + + void importIdentifierSpace(NamespaceContext namespaceContext); + + void exportIdentifierSpace(IdentifierSpaceKey namespace); + + void mergeItem(AxiomItem children); + + AxiomStatementRule.Context newAction(String actionName); + + AxiomStatementRule.Context modify(AxiomValueContext target, String actionName); + + void mergeEffectiveItemValues(AxiomItem axiomItem); */ + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index c450b2d1c84..832e2c7c97c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -1,150 +1,189 @@ package com.evolveum.axiom.lang.impl; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import java.util.Set; - import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; +import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; import com.evolveum.axiom.lang.api.AxiomModel; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.reactor.Dependency; +import com.evolveum.axiom.reactor.Dependency.Search; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; public enum BasicStatementRule implements AxiomStatementRule { - +/* REQUIRE_REQUIRED_ITEMS(all(),all()) { @Override public void apply(Context rule) throws AxiomSemanticException { - AxiomTypeDefinition typeDef = rule.typeDefinition(); + AxiomTypeDefinition typeDef = action.typeDefinition(); for(AxiomItemDefinition required : typeDef.requiredItems()) { - //rule.requireChild(required).unsatisfiedMessage(() -> rule.error("%s does not have required statement %s", rule.itemDefinition().name() ,required.name())); - rule.apply((ctx) -> {}); + //action.requireChild(required).unsatisfiedMessage(() -> action.error("%s does not have required statement %s", action.itemDefinition().name() ,required.name())); + action.apply((ctx) -> {}); + } + } + },*/ + + MOVE_ARGUMENT_VALUE(all(),all()) { + @Override + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + if(context.isMutable()) { + Optional argument = context.typeDefinition().argument(); + if(argument.isPresent() && context.currentValue() != null) { + action.apply(ctx -> { + ctx.childItem(argument.get()).addValue(ctx.currentValue()); + ctx.replaceValue(null); + }); + } } } }, - COPY_ARGUMENT_VALUE(all(),all()) { + REGISTER_TO_IDENTIFIER_SPACE(all(),all()){ @Override - public void apply(Context rule) throws AxiomSemanticException { - Optional argument = rule.typeDefinition().argument(); - if(argument.isPresent() && rule.optionalValue().isPresent()) { - rule.apply(ctx -> ctx.createEffectiveChild(argument.get().name(), ctx.requireValue())); + public boolean isApplicableTo(AxiomItemDefinition definition) { + return !definition.typeDefinition().identifierDefinitions().isEmpty(); + } + + @Override + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Collection idDefs = context.typeDefinition().identifierDefinitions(); + Map>>> identReq = new HashMap<>(); + for(AxiomIdentifierDefinition idDef : idDefs) { + Map>> components = new HashMap<>(); + for(AxiomItemDefinition cmp : idDef.components()) { + components.put(cmp.name(), action.require(context.child(cmp, Object.class)) + .map(v -> v.onlyValue()) + .unsatisfied(()-> action.error("Item '%s' is required by identifier, but not defined.", cmp.name()))); + } + identReq.put(idDef, components); } + action.apply(ctx -> { + for (AxiomIdentifierDefinition idDef : idDefs) { + IdentifierSpaceKey key = keyFrom(identReq.get(idDef)); + ctx.register(idDef.space(), idDef.scope(), key); + } + }); } - }, + }, EXPAND_TYPE_REFERENCE(items(Item.TYPE_REFERENCE), types(Type.TYPE_REFERENCE)) { @Override - public void apply(Context rule) throws AxiomSemanticException { - AxiomIdentifier type = rule.requireValue(); - Dependency.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); - typeDef.notFound(() -> rule.error("type '%s' was not found.", type)); - typeDef.unsatisfiedMessage(() -> rule.error("Referenced type %s is not complete.", type)); - rule.apply(ctx -> { - ctx.replace(typeDef); + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + AxiomIdentifier type = context.currentValue(); + Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); + typeDef.notFound(() -> action.error("type '%s' was not found.", type)); + typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); + action.apply(ctx -> { + ctx.replace(typeDef.get()); }); } }, - MATERIALIZE_FROM_SUPERTYPE(items(Item.SUPERTYPE_REFERENCE),types(Type.TYPE_REFERENCE)) { + EXPAND_IDENTIFIER_ITEM(items(Item.ID_MEMBER), all()) { @Override - public void apply(Context rule) throws AxiomSemanticException { - AxiomIdentifier type = rule.requireValue(); - Dependency.Search> typeDef = rule.requireGlobalItem(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)); - typeDef.notFound(() -> rule.error("type '%s' was not found.", type)); - typeDef.unsatisfiedMessage(() -> rule.error("Referenced type %s is not complete.", type)); - rule.apply(ctx -> { - ctx.replace(typeDef); - AxiomStatement superType = typeDef.get(); - // Copy Identifiers - ctx.parent().addChildren(superType.children(Item.IDENTIFIER_DEFINITION.name())); - // Copy Items - }); + public boolean isApplicableTo(AxiomItemDefinition definition) { + return Item.ID_MEMBER.name().equals(definition.name()); } - }, + @Override + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + AxiomIdentifier itemName = context.currentValue(); + Search> itemDef = action.require(context.namespaceValue(AxiomItemDefinition.SPACE, AxiomItemDefinition.identifier(itemName))) + .notFound(() -> action.error("item '%s' was not found", itemName)); + action.apply((val) -> { + val.replace(itemDef.get()); + }); + } - REGISTER_TO_IDENTIFIER_SPACE(all(),all()) { + }, + MATERIALIZE_FROM_SUPERTYPE(items(Item.SUPERTYPE_REFERENCE),types(Type.TYPE_REFERENCE)) { @Override - public void apply(Context rule) throws AxiomSemanticException { - Collection idDefs = rule.typeDefinition().identifierDefinitions(); - if(!idDefs.isEmpty()) { - rule.apply(ctx -> { - for (AxiomIdentifierDefinition idDef : idDefs) { - IdentifierSpaceKey key = keyFrom(idDef, rule); - ctx.register(idDef.space(), idDef.scope(), key); - } - - }); - } + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + AxiomIdentifier type = context.currentValue(); + Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); + typeDef.notFound(() -> action.error("type '%s' was not found.", type)); + typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); + action.apply(ctx -> { + ctx.replace(typeDef.get()); + AxiomItemValue superType = typeDef.get(); + // Copy Identifiers + Optional> identifiers = superType.item(Item.IDENTIFIER_DEFINITION); + if(identifiers.isPresent()) { + ctx.parentValue().mergeItem(identifiers.get()); + }// Copy Items + Optional> items = superType.item(Item.ITEM_DEFINITION); + if(items.isPresent()) { + ctx.parentValue().mergeItem(items.get()); + } + }); } + }, + IMPORT_DEFAULT_TYPES(all(), types(Type.MODEL)) { @Override - public void apply(Context rule) throws AxiomSemanticException { - Dependency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES)); - req.unsatisfiedMessage(() -> rule.error("Default types not found.")); - rule.apply((ctx) -> { - ctx.parent().importIdentifierSpace(req.get()); + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Dependency req = action.require(context.namespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES))); + req.unsatisfied(() -> action.error("Default types not found.")); + action.apply((ctx) -> { + ctx.root().importIdentifierSpace(req.get()); }); } }, EXPORT_GLOBALS_FROM_MODEL(all(), types(Type.MODEL)) { @Override - public void apply(Context rule) throws AxiomSemanticException { - String namespace = rule.requiredChildValue(Item.NAMESPACE, String.class); - rule.apply(ctx -> { - ctx.exportIdentifierSpace(namespaceId(namespace)); + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Dependency namespace = action.require(context.child(Item.NAMESPACE, String.class).map(v -> v.onlyValue().get())); + action.apply(ctx -> { + ctx.root().exportIdentifierSpace(namespaceId(namespace.get())); }); } }, IMPORT_MODEL(all(),types(Type.IMPORT_DEFINITION)) { @Override - public void apply(Context rule) throws AxiomSemanticException { - String child = rule.requiredChildValue(Item.NAMESPACE, String.class); - Dependency req = rule.requireNamespace(Item.NAMESPACE.name(), namespaceId(child)); - req.unsatisfiedMessage(() -> rule.error("Namespace %s not found.", child)); - rule.apply((ctx) -> { - ctx.parent().importIdentifierSpace(req.get()); + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Dependency namespace = action.require(context.child(Item.NAMESPACE, String.class) + .map(item -> item.onlyValue()) + .flatMap(uri -> context.namespace(Item.NAMESPACE.name(), namespaceId(uri.get())) + .unsatisfied(() -> action.error("Namespace %s not found.", uri.get())) + )); + action.apply((ctx) -> { + ctx.root().importIdentifierSpace(namespace.get()); }); } }, APPLY_EXTENSION(all(), types(Type.EXTENSION_DEFINITION)) { @Override - public void apply(Context ctx) throws AxiomSemanticException { - AxiomIdentifier targetName = ctx.requiredChildValue(Item.TARGET, AxiomIdentifier.class); - Dependency> targetRef = ctx.modify(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(targetName)); - - ctx.apply(ext -> { - Context copyItems = ext.modify(targetRef.get(), "Extension: Adding items to target"); - Dependency> extDef = copyItems.require(ext); - copyItems.apply(target -> { - // Copy items to target - target.addEffectiveChildren(extDef.get().children(Item.ITEM_DEFINITION.name())); - }); + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Dependency> targetRef = action.require(context.child(Item.TARGET, AxiomIdentifier.class) + .flatMap(item -> + context.modify(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(item.onlyValue().get())) + .unsatisfied(() -> action.error("Target %s not found.",item.onlyValue().get())) + )); + Dependency> itemDef = action.require(context.child(Item.ITEM_DEFINITION, Object.class)); + action.apply(ext -> { + targetRef.get().mergeItem(itemDef.get()); }); - - /*ctx.apply(ext -> { - Context targetAction = ext.newAction(); - targetAction. - });*/ } - }, /* * Not needed - registration is handled by identifier statement @@ -152,8 +191,8 @@ public void apply(Context ctx) throws AxiomSemanticException { @Override public void apply(Context rule) throws AxiomSemanticException { - AxiomIdentifier typeName = rule.requireValue(); - rule.apply(ctx -> ctx.registerAsGlobalItem(typeName)); + AxiomIdentifier typeName = action.requireValue(); + action.apply(ctx -> ctx.registerAsGlobalItem(typeName)); } }, */ @@ -163,15 +202,15 @@ public void apply(Context rule) throws AxiomSemanticException { @Override public void apply(Context rule) throws AxiomSemanticException { - Optional superType = rule.optionalChildValue(Item.SUPERTYPE_REFERENCE, AxiomIdentifier.class); + Optional superType = action.optionalChildValue(Item.SUPERTYPE_REFERENCE, AxiomIdentifier.class); if(superType.isPresent()) { - Requirement> req = rule.requireGlobalItem(Item.TYPE_DEFINITION, superType.get()); - rule.apply((ctx) -> { + Requirement> req = action.requireGlobalItem(Item.TYPE_DEFINITION, superType.get()); + action.apply((ctx) -> { //ctx.builder().add(Item.SUPERTYPE_REFERENCE, req.get()); }); - rule.errorMessage(() -> { + action.errorMessage(() -> { if(!req.isSatisfied()) { - return rule.error("Supertype %s is not defined", superType.get()); + return action.error("Supertype %s is not defined", superType.get()); } return null; }); @@ -188,10 +227,10 @@ private BasicStatementRule(Set items, Set type this.types = ImmutableSet.copyOf(types); } - static IdentifierSpaceKey keyFrom(AxiomIdentifierDefinition idDef, Context ctx) { + static IdentifierSpaceKey keyFrom(Map>> ctx) { ImmutableMap.Builder components = ImmutableMap.builder(); - for(AxiomItemDefinition cmp : idDef.components()) { - components.put(cmp.name(), ctx.requiredChildValue(cmp, Object.class)); + for(Entry>> entry : ctx.entrySet()) { + components.put(entry.getKey(), entry.getValue().get().get()); } return IdentifierSpaceKey.from(components.build()); } @@ -199,7 +238,7 @@ static IdentifierSpaceKey keyFrom(AxiomIdentifierDefinition idDef, Context types(AxiomTypeDefinition... types) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java index ae10f4afdfb..fb5efd77449 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java @@ -11,11 +11,22 @@ class CompositeIdentifierSpace implements IdentifierSpaceHolder, NamespaceContext { private final Set delegates = new HashSet<>(); + private final IdentifierSpaceHolderImpl export = new IdentifierSpaceHolderImpl(Scope.GLOBAL); + + + + public IdentifierSpaceHolderImpl getExport() { + return export; + } + + public CompositeIdentifierSpace() { + delegates.add(export); + } @Override - public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { for (IdentifierSpaceHolder delegate : delegates) { - StatementContextImpl maybe = delegate.lookup(space, key); + ValueContext maybe = delegate.lookup(space, key); if(maybe != null) { return maybe; } @@ -24,12 +35,12 @@ public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey } @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl context) { - throw new UnsupportedOperationException(); + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + export.register(space, scope, key, context); } @Override - public Map> space(AxiomIdentifier space) { + public Map> space(AxiomIdentifier space) { throw new UnsupportedOperationException(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java index 109d4b68b87..f70d59c7e19 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java @@ -5,13 +5,13 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.spi.AxiomStatement; + interface IdentifierSpaceHolder { - void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl context); + void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context); - public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key); + public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key); - Map> space(AxiomIdentifier space); + Map> space(AxiomIdentifier space); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index 2eec78deb98..e6daa6d57f4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -9,8 +9,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.api.AxiomItemValue; import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; @@ -18,45 +18,44 @@ public class IdentifierSpaceHolderImpl implements IdentifierSpaceHolder { Set allowedScopes; - Map>> space = new HashMap<>(); + Map>> space = new HashMap<>(); public IdentifierSpaceHolderImpl(Scope first, Scope... rest) { allowedScopes = EnumSet.of(first, rest); } @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl item) { + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext item) { Preconditions.checkArgument(allowedScopes.contains(scope), "Scope " + scope + " is not allowed");// TODO // Auto-generated // method stub - StatementContextImpl previous = space(space).putIfAbsent(key, item); + ValueContext previous = space(space).putIfAbsent(key, item); if (previous != null) { throw new AxiomSemanticException(item.startLocation() + Strings.lenientFormat("%s identifier space: Item %s is already defined at %s", space, - item.optionalValue().get(), previous.startLocation())); + item, previous.startLocation())); } } @Override - public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { return space(space).get(key); } @Override - public Map> space(AxiomIdentifier spaceId) { + public Map> space(AxiomIdentifier spaceId) { return space.computeIfAbsent(spaceId, k -> new HashMap<>()); } - Map>> build() { - ImmutableMap.Builder>> roots = ImmutableMap + Map>> build() { + ImmutableMap.Builder>> roots = ImmutableMap .builder(); - for (Entry>> entry : space.entrySet()) { - ImmutableMap.Builder> space = ImmutableMap.builder(); - for (Entry> item : entry.getValue().entrySet()) { - space.put(item.getKey(), item.getValue().asLazy().get()); + for (Entry>> entry : space.entrySet()) { + ImmutableMap.Builder> space = ImmutableMap.builder(); + for (Entry> item : entry.getValue().entrySet()) { + space.put(item.getKey(), item.getValue().get()); } roots.put(entry.getKey(), space.build()); - } return roots.build(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java new file mode 100644 index 00000000000..919840344e4 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -0,0 +1,91 @@ +package com.evolveum.axiom.lang.impl; + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.function.Supplier; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder; +import com.evolveum.axiom.lang.spi.SourceLocation; +import com.evolveum.axiom.reactor.Dependency; +import com.google.common.base.Preconditions; +import com.google.common.collect.Collections2; + +public class ItemContext extends AbstractContext> implements AxiomItemContext, Supplier>, Dependency>, AxiomItemStreamTreeBuilder.ItemBuilder { + + private final AxiomIdentifier name; + Collection>> values = new ArrayList<>(); + private final AxiomItemDefinition definition; + + public ItemContext(ValueContext sourceContext, AxiomIdentifier name, AxiomItemDefinition definition, SourceLocation loc) { + super(sourceContext, loc, sourceContext); + this.name = name; + this.definition = definition; + } + + @Override + public AxiomIdentifier name() { + return name; + } + + @Override + public ValueContext startValue(Object value, SourceLocation loc) { + ValueContext valueCtx = new ValueContext<>(this, (V) value, loc); + values.add(valueCtx); + return valueCtx; + } + + @Override + public void endNode(SourceLocation loc) { + //root().applyRules(this); + } + + public AxiomTypeDefinition type() { + return definition.typeDefinition(); + } + + @Override + protected Optional childDef(AxiomIdentifier id) { + return type().itemDefinition(id); + } + + @Override + public boolean isSatisfied() { + return Dependency.allSatisfied(values); + } + + @Override + public AxiomItem get() { + return AxiomItem.from(definition, Collections2.transform(values, v -> v.get())); + } + + @Override + public Exception errorMessage() { + return null; + } + + public AxiomItemDefinition definition() { + return definition; + } + + @Override + public AxiomValueContext addValue(V value) { + ValueContext ret = startValue(value, SourceLocation.runtime()); + ret.endValue(SourceLocation.runtime()); + //values.add(Dependency.immediate(AxiomItemValue.from(definition.typeDefinition(), value))); + return ret; + } + + @Override + public V onlyValue() { + Preconditions.checkState(values.size() == 1); + return values.iterator().next().get().get(); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java new file mode 100644 index 00000000000..4788398bade --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -0,0 +1,60 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.Collection; +import java.util.Map; +import java.util.Optional; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; + +public class ItemValueImpl implements AxiomItemValue { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private static final AxiomItemValueFactory FACTORY = ItemValueImpl::new; + private final AxiomTypeDefinition type; + private final V value; + private final Map> items; + + + + public ItemValueImpl(AxiomTypeDefinition type, V value, Map> items) { + super(); + this.type = type; + this.value = value; + this.items = items; + } + + @SuppressWarnings("unchecked") + public static AxiomItemValueFactory> factory() { + return FACTORY; + } + + @Override + public Optional type() { + return Optional.ofNullable(type); + } + + @Override + public V get() { + return value; + } + + @Override + public Optional> item(AxiomItemDefinition def) { + return AxiomItemValue.super.item(def); + } + + @Override + public Optional> item(AxiomIdentifier name) { + return Optional.ofNullable((AxiomItem) items.get(name)); + } + + @Override + public Collection> items() { + return items.values(); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index feb8575624b..1717a4da506 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -14,27 +14,29 @@ import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomItemValueFactory; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.spi.AxiomIdentifierDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomItemDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatementImpl; -import com.evolveum.axiom.lang.spi.AxiomStreamTreeBuilder; +import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder; import com.evolveum.axiom.lang.spi.AxiomTypeDefinitionImpl; -import com.evolveum.axiom.lang.spi.SourceLocation; -import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.RuleReactorContext; import com.google.common.base.Strings; import org.jetbrains.annotations.Nullable; -public class ModelReactorContext extends RuleReactorContext, StatementRuleContextImpl, RuleContextImpl> implements AxiomIdentifierResolver { +public class ModelReactorContext extends + RuleReactorContext, StatementRuleContextImpl, RuleContextImpl> + implements AxiomIdentifierResolver { private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); @@ -85,6 +87,8 @@ private static void defaults(ModelReactorContext reactorContext) { reactorContext.addRules(BasicStatementRule.values()); reactorContext.addStatementFactory(Type.TYPE_DEFINITION.name(), AxiomTypeDefinitionImpl.FACTORY); reactorContext.addStatementFactory(Type.ITEM_DEFINITION.name(), AxiomItemDefinitionImpl.FACTORY); + reactorContext.addStatementFactory(Type.IDENTIFIER_DEFINITION.name(), AxiomIdentifierDefinitionImpl.FACTORY); + reactorContext.loadModelFromSource(BASE_LANGUAGE_SOURCE.get()); reactorContext.loadModelFromSource(BASE_TYPES_SOURCE.get()); @@ -95,14 +99,12 @@ private static void defaults(ModelReactorContext reactorContext) { private final AxiomSchemaContext boostrapContext; private final Map exported = new HashMap<>(); - - - Map> globalItems = new HashMap<>(); + Map> globalItems = new HashMap<>(); IdentifierSpaceHolderImpl globalSpace = new IdentifierSpaceHolderImpl(Scope.GLOBAL); - Map> typeFactories = new HashMap<>(); - List> roots = new ArrayList<>(); + Map> typeFactories = new HashMap<>(); + List> roots = new ArrayList<>(); public ModelReactorContext(AxiomSchemaContext boostrapContext) { this.boostrapContext = boostrapContext; @@ -117,13 +119,14 @@ public AxiomSchemaContext computeSchemaContext() throws AxiomSemanticException { protected void failOutstanding(Collection> outstanding) throws AxiomSemanticException { StringBuilder messages = new StringBuilder("Can not complete models, following errors occured:\n"); for (StatementRuleContextImpl rule : outstanding) { - RuleErrorMessage exception = rule.errorMessage(); + Exception exception = rule.errorMessage(); + messages.append("Rule: ").append(rule.name()).append("\n"); if (exception != null) { - messages.append(exception.toString()).append("\n"); + messages.append(exception.getMessage()).append("\n"); } for (Dependency req : rule.dependencies()) { - if(!req.isSatisfied()) { - messages.append(req.errorMessage()).append("\n"); + if (!req.isSatisfied() && req.errorMessage() != null) { + messages.append(req.errorMessage().getMessage()).append("\n"); } } } @@ -135,22 +138,10 @@ private AxiomSchemaContext createSchemaContext() { return new AxiomSchemaContextImpl(globalSpace.build()); } - public IdentifierSpaceHolderImpl space() { return globalSpace; } - public void registerGlobal(AxiomIdentifier space, IdentifierSpaceKey key, StatementContextImpl item) { - - } - - void endStatement(StatementContextImpl cur, SourceLocation loc) throws AxiomSemanticException { - if (cur instanceof StatementContextImpl) { - StatementContextImpl current = cur; - addActionsFor(current); - } - } - @Override protected void addOutstanding(StatementRuleContextImpl action) { super.addOutstanding(action); @@ -163,65 +154,34 @@ public void addRules(AxiomStatementRule... rules) { } public void loadModelFromSource(AxiomModelStatementSource statementSource) { - statementSource.stream(this, new AxiomStreamTreeBuilder(new Root())); + SourceContext sourceCtx = new SourceContext(this, statementSource, new CompositeIdentifierSpace()); + statementSource.stream(this, new AxiomItemStreamTreeBuilder(sourceCtx)); } @Override public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName) { - if(Strings.isNullOrEmpty(prefix)) { + if (Strings.isNullOrEmpty(prefix)) { return AxiomIdentifier.axiom(localName); } return null; } - private class Root implements AxiomStreamTreeBuilder.NodeBuilder { - - @Override - public Optional childDef(AxiomIdentifier statement) { - return boostrapContext.getRoot(statement); - } - - @Override - public StatementContextImpl startChildNode(AxiomIdentifier identifier, SourceLocation loc) { - StatementContextImpl ret = new StatementContextImpl.Root<>(ModelReactorContext.this, - childDef(identifier).get(), loc); - roots.add(ret); - return ret; - } - - @Override - public AxiomIdentifier identifier() { - return ROOT; - } - - @Override - public void setValue(Object value, SourceLocation loc) { - - } - - @Override - public void endNode(SourceLocation loc) { - // TODO Auto-generated method stub - - } - } - - public void addStatementFactory(AxiomIdentifier statementType, Factory factory) { + public void addStatementFactory(AxiomIdentifier statementType, AxiomItemValueFactory factory) { typeFactories.put(statementType, factory); } - public Factory typeFactory(AxiomTypeDefinition statementType) { + public AxiomItemValueFactory> typeFactory(AxiomTypeDefinition statementType) { Optional current = Optional.of(statementType); do { @SuppressWarnings("unchecked") - Factory maybe = (Factory) typeFactories.get(current.get().name()); + AxiomItemValueFactory maybe = (AxiomItemValueFactory) typeFactories.get(current.get().name()); if (maybe != null) { - return maybe; + return (AxiomItemValueFactory) maybe; } current = current.get().superType(); } while (current.isPresent()); - return AxiomStatementImpl.factory(); + return ItemValueImpl.factory(); } public void exportIdentifierSpace(IdentifierSpaceKey namespace, IdentifierSpaceHolder localSpace) { @@ -242,10 +202,21 @@ protected AxiomSemanticException createException() { } @Override - protected Collection rulesFor(StatementContextImpl context) { + protected Collection rulesFor(ValueContext context) { // TODO: Add smart filters if neccessary return rules; } + public Optional rootDefinition(AxiomIdentifier statement) { + return boostrapContext.getRoot(statement); + } + + public void applyRuleDefinitions(ValueContext valueContext) { + addActionsFor(valueContext); + } + + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + globalSpace.register(space, scope, key, context); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java index 80d11e54e4c..5924cd6edde 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java @@ -4,7 +4,7 @@ import com.evolveum.axiom.reactor.Rule; -public class RuleContextImpl implements Rule, StatementRuleContextImpl> { +public class RuleContextImpl implements Rule, StatementRuleContextImpl> { private final AxiomStatementRule delegate; @@ -14,14 +14,14 @@ public RuleContextImpl(AxiomStatementRule delegate) { } @Override - public boolean applicableTo(StatementContextImpl context) { - return delegate.isApplicableTo(context.definition()); + public boolean applicableTo(ValueContext context) { + return delegate.isApplicableTo(context.parent().definition()); } @Override - public Collection> applyTo(StatementContextImpl context) { + public Collection> applyTo(ValueContext context) { StatementRuleContextImpl actionBuilder = context.addAction(delegate.name()); - delegate.apply(actionBuilder); + delegate.apply(actionBuilder, actionBuilder); return actionBuilder.build(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java new file mode 100644 index 00000000000..045effa995a --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -0,0 +1,96 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder; +import com.evolveum.axiom.lang.spi.SourceLocation; +import com.evolveum.axiom.reactor.Dependency; +import com.google.common.base.Preconditions; + +class SourceContext extends ValueContext implements AxiomRootContext, AxiomItemStreamTreeBuilder.ValueBuilder { + + private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); + + private final ModelReactorContext context; + private final AxiomModelStatementSource source; + private final Map items = new HashMap(); + private final CompositeIdentifierSpace globalSpace; + + public SourceContext(ModelReactorContext context, AxiomModelStatementSource source, CompositeIdentifierSpace space) { + super(SourceLocation.runtime(), space); + this.context = context; + this.source = source; + this.globalSpace = space; + } + + @Override + public AxiomIdentifier name() { + return ROOT; + } + + @Override + public ItemContext startItem(AxiomIdentifier identifier, SourceLocation loc) { + return items.computeIfAbsent(identifier, id -> createItem(id, loc)); + } + + @Override + public Optional childDef(AxiomIdentifier statement) { + return context.rootDefinition(statement); + } + + @Override + protected SourceContext rootImpl() { + return this; + } + + @Override + public void endValue(SourceLocation loc) { + // NOOP + } + + @Override + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + globalSpace.register(space, scope, key, context); + this.context.register(space, scope, key, context); + } + + @Override + public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + return globalSpace.lookup(space, key); + } + + public AxiomItemValueFactory> factoryFor(AxiomTypeDefinition type) { + return context.typeFactory(type); + } + + public void applyRuleDefinitions(ValueContext valueContext) { + context.applyRuleDefinitions(valueContext); + } + + public Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return Dependency.retriableDelegate(() -> { + return context.namespace(name, namespaceId); + }); + } + + @Override + public void importIdentifierSpace(NamespaceContext namespaceContext) { + Preconditions.checkArgument(namespaceContext instanceof IdentifierSpaceHolder); + globalSpace.add((IdentifierSpaceHolder) namespaceContext); + } + + @Override + public void exportIdentifierSpace(IdentifierSpaceKey namespaceId) { + context.exportIdentifierSpace(namespaceId, globalSpace.getExport()); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java deleted file mode 100644 index 10d0045b627..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementContextImpl.java +++ /dev/null @@ -1,402 +0,0 @@ -package com.evolveum.axiom.lang.impl; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.function.Supplier; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.concepts.Optionals; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.impl.AxiomStatementRule.Context; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; -import com.evolveum.axiom.lang.spi.AxiomStreamTreeBuilder; -import com.evolveum.axiom.lang.spi.SourceLocation; -import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; -import com.evolveum.axiom.reactor.Dependency; - -public abstract class StatementContextImpl implements AxiomStatementContext, AxiomStreamTreeBuilder.NodeBuilder, IdentifierSpaceHolder { - - private final AxiomItemDefinition definition; - - private final IdentifierSpaceHolder localSpace; - - private SourceLocation startLocation; - private SourceLocation endLocation; - private SourceLocation valueLocation; - private Dependency> result; - - - StatementContextImpl(AxiomItemDefinition definition, SourceLocation loc, Scope scope, Scope... rest) { - this.definition = definition; - this.startLocation = loc; - this.localSpace = new IdentifierSpaceHolderImpl(scope, rest); - } - - - protected void initResult() { - AxiomStatementBuilder builder = new AxiomStatementBuilder<>(definition.name(), typeFactory(definition.type())); - this.result = new StatementResultContextImpl<>(definition, builder); - } - - protected Factory> typeFactory(AxiomTypeDefinition type) { - return parent().typeFactory(type); - } - - - public void setValue(Object value) { - mutableResult().setValue((V) value); - } - - private StatementResultContextImpl mutableResult() { - if(result instanceof StatementResultContextImpl) { - return (StatementResultContextImpl) result; - } - return null; - } - - boolean isChildAllowed(AxiomIdentifier child) { - return definition.type().itemDefinition(child).isPresent(); - } - - - @SuppressWarnings("rawtypes") - @Override - public StatementContextImpl startChildNode(AxiomIdentifier identifier, SourceLocation loc) { - StatementContextImpl childCtx = new StatementContextImpl.Child(this, childDef(identifier).get(), loc); - mutableResult().add(childCtx); - return childCtx; - } - - - public IdentifierSpaceHolder localSpace() { - return localSpace; - } - - @Override - public String toString() { - return "Context(" + definition.name() + ")"; - } - - @Override - public Optional childDef(AxiomIdentifier child) { - return definition.type().itemDefinition(child); - } - - @Override - public AxiomIdentifier identifier() { - return definition.name(); - } - - @Override - public V requireValue() throws AxiomSemanticException { - return AxiomSemanticException.checkNotNull(mutableResult().value(), definition, "must have argument specified."); - } - - @Override - public AxiomItemDefinition definition() { - return definition; - } - - @Override - public AxiomStatementContext createEffectiveChild(AxiomIdentifier axiomIdentifier, V value) { - StatementContextImpl child = startChildNode(axiomIdentifier, null); - child.setValue(value, null); - return child; - } - - - public void registerRule(StatementRuleContextImpl rule) { - mutableResult().addRule(rule); - addOutstanding(rule); - } - - protected void addOutstanding(StatementRuleContextImpl rule) { - parent().addOutstanding(rule); - } - - public SourceLocation startLocation() { - return startLocation; - } - - public Optional> firstChild(AxiomItemDefinition child) { - return Optionals.first(children(child.name())); - } - - private Collection> children(AxiomIdentifier identifier) { - return (Collection) mutableResult().get(identifier); - } - - public StatementRuleContextImpl addAction(String name) throws AxiomSemanticException { - return new StatementRuleContextImpl(this,name); - } - - @Override - public Optional optionalValue() { - return Optional.ofNullable(mutableResult().value()); - } - - @Override - public void replace(Dependency> supplier) { - this.result = (Dependency) supplier; - } - - @Override - abstract public StatementContextImpl parent(); - - @Override - public void setValue(Object value, SourceLocation loc) { - setValue(value); - this.valueLocation = loc; - } - - public Dependency> asRequirement() { - if (result instanceof StatementResultContextImpl) { - return Dependency.deffered(result); - } - return result; - } - - public Supplier> asLazy() { - return Lazy.from(() -> result.get()); - } - - public boolean isSatisfied() { - return result.isSatisfied(); - } - - - @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key) { - register(space, scope, key, this); - } - - @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, StatementContextImpl context) { - switch (scope) { - case GLOBAL: - parentNs().register(space, scope, key, context); - break; - case LOCAL: - localSpace.register(space, scope, key, context); - break; - default: - throw new IllegalStateException("Unsupported scope"); - } - } - - abstract IdentifierSpaceHolder parentNs(); - - @Override - public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { - StatementContextImpl maybe = localSpace.lookup(space, key); - if(maybe != null) { - return maybe; - } - return parentNs().lookup(space, key); - - } - - @Override - public Map> space(AxiomIdentifier space) { - return localSpace.space(space); - } - - private void registerLocalParent(AxiomIdentifier space, IdentifierSpaceKey key) { - // TODO Auto-generated method stub - - } - - @Override - public V requireValue(Class type) { - if(result instanceof StatementResultContextImpl) { - return type.cast(((StatementResultContextImpl) result).value()); - } - return null; - } - - @Override - public void endNode(SourceLocation loc) { - this.endLocation = loc; - root().reactor.endStatement(this, loc); - } - - public Dependency> requireChild(AxiomItemDefinition required) { - return Dependency.retriableDelegate(() -> { - if(mutableResult() != null) { - return (Dependency) firstChild(required).map(StatementContextImpl::asRequirement).orElse(null); - } - Optional> maybe = result.get().first(required); - - return Dependency.from(maybe); - }); - } - - @Override - public Context newAction(String name) { - return addAction(name); - } - - @Override - public void addChildren(Collection> children) { - AxiomStreamTreeBuilder streamBuilder = new AxiomStreamTreeBuilder(this); - for(AxiomStatement child : children) { - streamBuilder.stream(child); - } - } - - @Override - public void addEffectiveChildren(Collection> children) { - for(AxiomStatement child :children) { - AxiomStatementContext effective = createEffectiveChild(child.keyword(), child.value()); - effective.replace(Dependency.immediate(child)); - - } - } - - protected IdentifierSpaceHolder exports() { - throw new IllegalStateException("Statement does not provide exports"); - } - - @Override - public Context modify(AxiomStatementContext target, String name) { - return (target).newAction(name); - } - - static class Child extends StatementContextImpl { - - private StatementContextImpl parent; - - public Child(StatementContextImpl parent, AxiomItemDefinition definition, SourceLocation loc) { - super(definition, loc, Scope.LOCAL); - this.parent = parent; - initResult(); - } - - @Override - public StatementContextImpl parent() { - return parent; - } - - @Override - IdentifierSpaceHolder parentNs() { - return parent; - } - - @Override - public void exportIdentifierSpace(IdentifierSpaceKey namespace) { - throw new UnsupportedOperationException("Child can not export identifier space"); - } - - @Override - public void importIdentifierSpace(NamespaceContext namespaceContext) { - throw new UnsupportedOperationException("Child can not import identifier space"); - } - - } - - static class Root extends StatementContextImpl { - - private static final AxiomIdentifier IMPORTED_MODEL = AxiomIdentifier.axiom("ImportedModel"); - private final ModelReactorContext reactor; - private Set imports; - - public Root(ModelReactorContext reactor, AxiomItemDefinition definition, - SourceLocation loc) { - super(definition, loc, Scope.GLOBAL, Scope.LOCAL); - this.reactor = reactor; - this.imports = new HashSet<>(); - initResult(); - } - - @Override - protected IdentifierSpaceHolder parentNs() { - throw new UnsupportedOperationException(); - } - - @Override - protected void addOutstanding(StatementRuleContextImpl rule) { - reactor.addOutstanding(rule); - } - - @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, - StatementContextImpl context) { - if (Scope.GLOBAL.equals(scope)) { - reactor.space().register(space, scope, key, context); - } - localSpace().register(space, scope, key, context); - } - - @Override - public StatementContextImpl lookup(AxiomIdentifier space, IdentifierSpaceKey key) { - StatementContextImpl maybe = localSpace().lookup(space, key); - if(maybe != null) { - return maybe; - } - for(IdentifierSpaceHolder model : imports) { - maybe = model.lookup(space, key); - if(maybe != null) { - return maybe; - } - } - return null; - } - - @Override - protected Factory> typeFactory(AxiomTypeDefinition type) { - return reactor.typeFactory(type); - } - - @Override - public StatementContextImpl parent() { - return this; - } - - @Override - protected IdentifierSpaceHolder exports() { - return localSpace(); - } - - @Override - public void exportIdentifierSpace(IdentifierSpaceKey namespace) { - reactor.exportIdentifierSpace(namespace, localSpace()); - } - - @Override - public void importIdentifierSpace(NamespaceContext namespaceContext) { - if(namespaceContext instanceof IdentifierSpaceHolder) { - imports.add((IdentifierSpaceHolder) namespaceContext); - } - } - - @Override - protected Root root() { - return this; - } - - public Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { - return Dependency.retriableDelegate(() -> { - return reactor.namespace(name, namespaceId); - }); - } - } - - protected Root root() { - return parent().root(); - } - - - public Dependency> optionalChild(AxiomItemDefinition required) { - return Dependency.optional(requireChild(required)); - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementFactoryContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementFactoryContext.java deleted file mode 100644 index d686799cb1f..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementFactoryContext.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.impl; - -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.spi.AxiomStatementImpl; - -interface StatementFactoryContext { - - AxiomStatementImpl.Factory factoryFor(AxiomTypeDefinition identifier); - - static StatementFactoryContext defaultFactory(AxiomStatementImpl.Factory factory) { - return (identifier) -> factory; - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementResultContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementResultContextImpl.java deleted file mode 100644 index 0758eb9c9ac..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementResultContextImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.evolveum.axiom.lang.impl; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.function.Supplier; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.spi.AxiomStatement; -import com.evolveum.axiom.lang.spi.AxiomStatementBuilder; -import com.evolveum.axiom.reactor.Dependency; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - -class StatementResultContextImpl implements Dependency> { - - private V value; - private final List> childrenList = new ArrayList<>(); - private final Multimap> children = HashMultimap.create(); - private AxiomStatementBuilder builder; - - private final List> rules = new ArrayList<>(); - - public StatementResultContextImpl(AxiomItemDefinition definition, AxiomStatementBuilder builder) { - super(); - this.builder = builder; - } - - public void setValue(V value) { - this.value = value; - this.builder.setValue(value); - } - - public void add(StatementContextImpl childCtx) { - childrenList.add(childCtx); - children.put(childCtx.identifier(), childCtx); - builder.add(childCtx.identifier(), childCtx.asLazy()); - } - public V value() { - return value; - } - - public Collection> get(AxiomIdentifier identifier) { - return children.get(identifier); - } - - @Override - public boolean isSatisfied() { - for (StatementRuleContextImpl rule : rules) { - if(!rule.isApplied()) { - return false; - } - } - for (StatementContextImpl rule : childrenList) { - if(!rule.isSatisfied()) { - return false; - } - } - return true; - } - - @Override - public AxiomStatement get() { - return builder.get(); - } - - public void addRule(StatementRuleContextImpl rule) { - this.rules.add(rule); - } - - @Override - public RuleErrorMessage errorMessage() { - // TODO Auto-generated method stub - return null; - } -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index 7b557ed1d39..86e31e448e1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -8,48 +8,55 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.impl.AxiomStatementRule.Context; import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.DependantAction; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; -public class StatementRuleContextImpl implements AxiomStatementRule.Context, DependantAction { +public class StatementRuleContextImpl implements AxiomStatementRule.Lookup, AxiomStatementRule.ActionBuilder, DependantAction { - private final StatementContextImpl context; + private final ValueContext context; private final String rule; private final List> dependencies = new ArrayList<>(); private AxiomStatementRule.Action action; - private Supplier errorReport = () -> null; + private Supplier errorReport = () -> null; private boolean applied = false; private Exception error; - public StatementRuleContextImpl(StatementContextImpl context, String rule) { + public StatementRuleContextImpl(ValueContext context, String rule) { this.context = context; this.rule = rule; } - @Override - public Optional optionalChildValue(AxiomItemDefinition child, Class type) { - return (Optional) context.firstChild(child).flatMap(v -> v.optionalValue()); + public Dependency.Search> global(AxiomIdentifier space, + IdentifierSpaceKey key) { + return Dependency.retriableDelegate(() -> { + ValueContext maybe = context.lookup(space, key); + if(maybe != null) { + return (Dependency) maybe; + } + return null; + }); } @Override - public Dependency.Search> requireGlobalItem(AxiomIdentifier space, + public Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey key) { - return requirement(Dependency.retriableDelegate(() -> { - StatementContextImpl maybe = context.lookup(space, key); + return Dependency.retriableDelegate(() -> { + ValueContext maybe = context.lookup(space, key); if(maybe != null) { - return (Dependency) maybe.asRequirement(); + return (Dependency) maybe; } return null; - })); + }); } - private > X requirement(X req) { + @Override + public > X require(X req) { this.dependencies.add(req); return req; } @@ -57,7 +64,7 @@ private > X requirement(X req) { @Override public StatementRuleContextImpl apply(AxiomStatementRule.Action action) { this.action = action; - context.registerRule(this); + context.dependsOnAction(this); return this; } @@ -78,31 +85,15 @@ public void apply() throws AxiomSemanticException { } } - @Override - public V requiredChildValue(AxiomItemDefinition supertypeReference, Class type) - throws AxiomSemanticException { - AxiomStatementContext ctx = context.firstChild(supertypeReference).get(); - return (V) ctx.requireValue(type); - } - - @Override - public V requireValue() throws AxiomSemanticException { - return context.requireValue(); - } - public boolean isApplied() { return applied; } - @Override - public AxiomStatementRule.Context errorMessage(Supplier errorFactory) { - this.errorReport = errorFactory; - return this; - } - RuleErrorMessage errorMessage() { + @Override + public Exception errorMessage() { if(error != null) { - return RuleErrorMessage.from(context.startLocation(), error.getMessage()); + return error; } return errorReport.get(); @@ -114,32 +105,8 @@ public String toString() { } @Override - public AxiomTypeDefinition typeDefinition() { - return context.definition().type(); - } - - @Override - public Optional optionalValue() { - return context.optionalValue(); - } - - @Override - public RuleErrorMessage error(String format, Object... arguments) { - return RuleErrorMessage.from(context.startLocation(), format, arguments); - } - - @Override - public Dependency> requireChild(AxiomItemDefinition required) { - return requirement(context.requireChild(required)); - } - - public Dependency> optionalChild(AxiomItemDefinition required) { - return requirement(context.optionalChild(required)); - } - - @Override - public Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { - return requirement(context.root().requireNamespace(name, namespaceId)); + public Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return (context.rootImpl().requireNamespace(name, namespaceId)); } @Override @@ -180,13 +147,13 @@ public Collection> build() { @Override public AxiomItemDefinition itemDefinition() { - return context.definition(); + return context.parent().definition(); } @Override - public Dependency> modify(AxiomIdentifier space, IdentifierSpaceKey key) { - return requirement(Dependency.retriableDelegate(() -> { - StatementContextImpl maybe = context.lookup(space, key); + public Dependency> modify(AxiomIdentifier space, IdentifierSpaceKey key) { + return (Dependency.retriableDelegate(() -> { + ValueContext maybe = context.lookup(space, key); if(maybe != null) { return Dependency.immediate(maybe); } @@ -195,17 +162,33 @@ public Dependency> modify(AxiomIdentifier space, Identi } @Override - public Dependency> require(AxiomStatementContext ext) { - return requirement((Dependency) impl(ext).asRequirement()); + public Dependency> require(AxiomValueContext ext) { + return require((Dependency>) ext); } - private StatementContextImpl impl(AxiomStatementContext ext) { - return (StatementContextImpl) ext; + @Override + public boolean isMutable() { + return context.isMutable(); } @Override - public Context newAction() { - return new StatementRuleContextImpl(context, rule); + public AxiomSemanticException error(String message, Object... arguments) { + return new AxiomSemanticException(context.startLocation() + Strings.lenientFormat(message, arguments)); + } + @Override + public Dependency> child(AxiomItemDefinition namespace, Class valueType) { + return (context.requireChild(namespace.name())); + } + @Override + public V currentValue() { + return context.currentValue(); + } + @Override + public Dependency finalValue() { + return context.map(v -> v.get()); + } + public String name() { + return rule; } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java new file mode 100644 index 00000000000..4c5cc35cf07 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -0,0 +1,227 @@ +package com.evolveum.axiom.lang.impl; + +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomItemValueBuilder; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; +import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; +import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder.ValueBuilder; +import com.evolveum.axiom.reactor.Dependency; +import com.google.common.base.Preconditions; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Optional; +import java.util.function.Supplier; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.spi.SourceLocation; + +public class ValueContext extends AbstractContext> implements AxiomValueContext, ValueBuilder, Dependency> { + + private Dependency> result; + Collection> dependencies = new HashSet<>(); + + public ValueContext(SourceLocation loc, IdentifierSpaceHolder space) { + super(null, loc, space); + result = new Result(null,null); + } + + public ValueContext(ItemContext itemContext, V value, SourceLocation loc) { + super(itemContext, loc, AxiomIdentifierDefinition.Scope.LOCAL); + result = new Result(parent().type(), value); + } + + @Override + public AxiomIdentifier name() { + return parent().name(); + } + + @Override + public Optional childDef(AxiomIdentifier statement) { + return parent().type().itemDefinition(statement); + } + + @Override + public ItemContext startItem(AxiomIdentifier identifier, SourceLocation loc) { + return mutable().getOrCreateItem(identifier, loc); + } + + @Override + public void endValue(SourceLocation loc) { + rootImpl().applyRuleDefinitions(this); + } + + protected Result mutable() { + Preconditions.checkState(result instanceof ValueContext.Result); + return (Result) result; + } + + @Override + public boolean isSatisfied() { + return result.isSatisfied(); + } + + @Override + public AxiomItemValue get() { + return result.get(); + } + + @Override + public Exception errorMessage() { + return null; + } + + private ItemContext mutableItem(Supplier> supplier) { + Preconditions.checkState(supplier instanceof ItemContext); + return (ItemContext) supplier; + } + + public AxiomItemDefinition itemDefinition() { + return parent().definition(); + } + + public StatementRuleContextImpl addAction(String name) { + return new StatementRuleContextImpl<>(this, name); + } + + protected ItemContext createItem(AxiomIdentifier id, SourceLocation loc) { + return new ItemContext<>(this, id ,childDef(id).get(), loc); + } + + private class Result implements Dependency> { + + AxiomTypeDefinition type; + AxiomItemValueBuilder> builder; + private V value; + + public Result(AxiomTypeDefinition type, V value) { + this.type = type; + this.value = value; + builder = AxiomItemValueBuilder.create(type, null); + } + + ItemContext getOrCreateItem(AxiomIdentifier identifier, SourceLocation loc) { + return mutableItem(builder.get(identifier, id -> { + ItemContext item = createItem(id, loc); + addDependency(item); + return item; + })); + } + + Dependency> getItem(AxiomIdentifier item) { + Supplier> maybeItem = builder.get(item); + if(maybeItem == null) { + return null; + } + if(maybeItem instanceof Dependency) { + return (Dependency) maybeItem; + } + return Dependency.immediate((AxiomItem) maybeItem.get()); + } + + + + @Override + public boolean isSatisfied() { + return Dependency.allSatisfied(dependencies); + } + + @Override + public AxiomItemValue get() { + builder.setValue(value); + builder.setFactory(rootImpl().factoryFor(type)); + return builder.get(); + } + + @Override + public Exception errorMessage() { + return null; + } + + } + + void addDependency(Dependency action) { + dependencies.add(action); + } + + @Override + public void replace(AxiomItemValue axiomItemValue) { + this.result = Dependency.immediate((AxiomItemValue) axiomItemValue); + } + + @Override + public AxiomItemContext childItem(AxiomIdentifier name) { + return (AxiomItemContext) mutable().getOrCreateItem(name, SourceLocation.runtime()); + } + + @Override + public V currentValue() { + if(result instanceof ValueContext.Result) { + return ((ValueContext.Result) result).value; + } + return get().get(); + } + + @Override + public void mergeItem(AxiomItem axiomItem) { + ItemContext item = startItem(axiomItem.name(), SourceLocation.runtime()); + for(AxiomItemValue value : axiomItem.values()) { + ValueContext valueCtx = item.startValue(value.get(),SourceLocation.runtime()); + valueCtx.replace(value); + valueCtx.endValue(SourceLocation.runtime()); + } + item.endNode(SourceLocation.runtime()); + } + + @Override + public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key) { + register(space, scope, key, this); + } + + + + @Override + public ActionBuilder newAction(String name) { + return new StatementRuleContextImpl(this, name); + } + + @Override + public AxiomRootContext root() { + return parent().rootImpl(); + } + + public void dependsOnAction(StatementRuleContextImpl action) { + addDependency(action); + } + + public Dependency> requireChild(AxiomIdentifier item) { + return Dependency.retriableDelegate(() -> { + if(result instanceof ValueContext.Result) { + return ((ValueContext.Result) result).getItem(item); + } + return Dependency.from(result.get().item(item)); + + }); + } + + @Override + public void replaceValue(V object) { + mutable().value = object; + } + + public boolean isMutable() { + return result instanceof ValueContext.Result; + } + + @Override + public String toString() { + return "value("+ parent().name() +";" + result +")"; + } + + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java deleted file mode 100644 index 6354f37ee31..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractAxiomBaseDefinition.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.evolveum.axiom.lang.spi; - -import java.util.List; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomNamedDefinition; -import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.google.common.collect.Multimap; - -public class AbstractAxiomBaseDefinition extends AxiomStatementImpl implements AxiomNamedDefinition { - - public static final Factory FACTORY = AbstractAxiomBaseDefinition::new ; - private AxiomIdentifier name; - private String documentation; - - public AbstractAxiomBaseDefinition(AxiomIdentifier keyword, AxiomIdentifier value, List> children, - Multimap> keywordMap) { - super(keyword, value, children, keywordMap); - name = firstValue(AxiomBuiltIn.Item.NAME.name(), AxiomIdentifier.class).get(); - } - - @Override - public AxiomIdentifier name() { - return name; - } - - @Override - public String documentation() { - return documentation; - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java new file mode 100644 index 00000000000..e8012a5265c --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java @@ -0,0 +1,33 @@ +package com.evolveum.axiom.lang.spi; + +import java.util.Map; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomNamedDefinition; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.lang.impl.ItemValueImpl; + +public class AbstractBaseDefinition extends ItemValueImpl implements AxiomNamedDefinition { + + private final AxiomIdentifier name; + private final String documentation; + + public AbstractBaseDefinition(AxiomTypeDefinition type, V value, Map> items) { + super(type, value, items); + name = (AxiomIdentifier) item(Item.NAME).get().onlyValue().get(); + documentation = item(Item.DOCUMENTATION).map(i -> i.onlyValue().get().toString()).orElse(null); // + } + + @Override + public AxiomIdentifier name() { + return name; + } + + @Override + public String documentation() { + return documentation; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java new file mode 100644 index 00000000000..c613afd4514 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -0,0 +1,58 @@ +package com.evolveum.axiom.lang.spi; + +import java.util.Collection; +import java.util.Map; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; +import com.evolveum.axiom.lang.impl.ItemValueImpl; +import com.google.common.collect.ImmutableList; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; + +public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { + + public static final AxiomItemValueFactory FACTORY = AxiomIdentifierDefinitionImpl::new ; + + + private final Scope scope; + private final Collection components; + + private final AxiomIdentifier space; + + public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomIdentifierDefinition value, Map> items) { + super(axiomItemDefinition, value, items); + this.scope = AxiomIdentifierDefinition.scope(this.item(Item.ID_SCOPE.name()).get().onlyValue().get().getLocalName()); + this.space = this.item(Item.ID_SPACE.name()).get().onlyValue().get(); + + ImmutableList.Builder components = ImmutableList.builder(); + for (AxiomItemValue val : this.item(Item.ID_MEMBER.name()).get().values()) { + components.add(val.get()); + } + this.components = components.build(); + } + + @Override + public AxiomIdentifierDefinition get() { + return this; + } + + @Override + public Collection components() { + return components; + } + + @Override + public Scope scope() { + return scope; + } + + @Override + public AxiomIdentifier space() { + return space; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 5cabddf6f01..526cae74036 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -1,40 +1,45 @@ package com.evolveum.axiom.lang.spi; -import java.util.List; +import java.util.Map; +import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomBuiltIn; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; +import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.google.common.collect.Multimap; -public class AxiomItemDefinitionImpl extends AbstractAxiomBaseDefinition implements AxiomItemDefinition { +public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { - public static final Factory FACTORY = AxiomItemDefinitionImpl::new ; + public static final AxiomItemValueFactory FACTORY = AxiomItemDefinitionImpl::new ; private final AxiomTypeDefinition type; - private int minOccurs; - - public AxiomItemDefinitionImpl(AxiomIdentifier keyword, AxiomIdentifier value, List> children, - Multimap> keywordMap) { - super(keyword, value, children, keywordMap); - type = first(AxiomBuiltIn.Item.TYPE_DEFINITION.name(), AxiomTypeDefinition.class) - .orElseThrow(() -> new IllegalStateException("No 'type' declaration in " + super.toString())); - minOccurs = firstValue(AxiomBuiltIn.Item.MIN_OCCURS.name(), String.class).map(Integer::parseInt).orElse(0); + private final Optional> minOccurs; + + public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomItemDefinition value, Map> items) { + super(axiomItemDefinition, value, items); + this.type = this.item(Item.TYPE_REFERENCE.name()).get().onlyValue().get(); + minOccurs = this.item(Item.MIN_OCCURS.name()); + } + + @Override + public AxiomItemDefinition get() { + return this; } @Override - public AxiomTypeDefinition type() { + public AxiomTypeDefinition typeDefinition() { return type; } @Override public boolean required() { - return minOccurs > 0; + return minOccurs() > 0; } @Override public int minOccurs() { - return 0; + return minOccurs.map(i -> Integer.parseInt(i.onlyValue().get())).orElse(0); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java new file mode 100644 index 00000000000..6faabd78881 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java @@ -0,0 +1,107 @@ +/* + * 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.spi; + +import java.util.Deque; +import java.util.LinkedList; +import java.util.Optional; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemStream; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.google.common.base.Preconditions; + + +public class AxiomItemStreamTreeBuilder implements AxiomItemStream.Listener { + + private final Deque queue = new LinkedList<>(); + + public AxiomItemStreamTreeBuilder(ValueBuilder root) { + queue.add(root); + } + + protected V offer(V builder) { + queue.offerFirst(builder); + return builder; + } + + protected Builder current() { + return queue.peek(); + } + + protected Builder poll() { + return queue.poll(); + } + + private ItemBuilder item(Builder node) { + Preconditions.checkState(node instanceof ItemBuilder); + return (ItemBuilder) node; + } + + private ValueBuilder value(Builder node) { + Preconditions.checkState(node instanceof ValueBuilder); + return (ValueBuilder) node; + } + + @Override + public void startValue(Object value, SourceLocation loc) { + queue.offerFirst(item(current()).startValue(value, loc)); + } + + @Override + public void endValue(SourceLocation loc) { + value(poll()).endValue(loc); + } + + @Override + public void startItem(AxiomIdentifier item, SourceLocation loc) { + Optional childDef = value(current()).childDef(item); + AxiomSyntaxException.check(childDef.isPresent(), loc , "Item %s not allowed in %s", item, current().name()); + offer(value(current()).startItem(item, loc)); + } + + @Override + public void endItem(SourceLocation loc) { + item(poll()).endNode(loc); + } + + private interface Builder { + AxiomIdentifier name(); + } + + public interface ItemBuilder extends Builder { + ValueBuilder startValue(Object value, SourceLocation loc); + void endNode(SourceLocation loc); + + } + + public interface ValueBuilder extends Builder { + Optional childDef(AxiomIdentifier statement); + ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc); + void endValue(SourceLocation loc); + } + + public void stream(AxiomItem itemDef) { + for(AxiomItemValue value : itemDef.values()) { + startItem(itemDef.name(), null); + stream(value); + endItem(null); + + } + } + + private void stream(AxiomItemValue value) { + Object valueMapped = value.get(); + startValue(valueMapped, null); + for(AxiomItem item : value.items()) { + stream(item); + } + endValue(null); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java deleted file mode 100644 index 1bc849964ba..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatement.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.spi; - -import java.util.Collection; -import java.util.Optional; -import java.util.stream.Collectors; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; - -public interface AxiomStatement { - - AxiomIdentifier keyword(); - V value(); - - Collection> children(); - - Collection> children(AxiomIdentifier name); - - default Collection children(AxiomIdentifier name, Class type) { - return children(name).stream().filter(type::isInstance).map(type::cast).collect(Collectors.toList()); - } - - default Optional first(AxiomIdentifier axiomIdentifier, Class class1) { - return children(axiomIdentifier).stream().filter(class1::isInstance).findFirst().map(class1::cast); - } - - default Optional> first(AxiomItemDefinition item) { - return first(item.name()); - } - - default Optional> first(AxiomIdentifier name) { - return children(name).stream().findFirst(); - } - - default Optional firstValue(AxiomIdentifier name, Class type) { - return children(name).stream().filter(s -> type.isInstance(s.value())).map(s -> type.cast(s.value())).findFirst(); - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementBuilder.java deleted file mode 100644 index acbe6c376ed..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.evolveum.axiom.lang.spi; - -import com.evolveum.axiom.concepts.Lazy; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; - -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.spi.AxiomStatementImpl.Factory; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; - -public class AxiomStatementBuilder implements Lazy.Supplier> { - - private final AxiomIdentifier identifier; - private final AxiomStatementImpl.Factory> factory; - private T value; - - public AxiomStatementBuilder(AxiomIdentifier identifier, Factory> factory) { - this.identifier = identifier; - this.factory = factory; - } - - public AxiomStatementBuilder(AxiomIdentifier identifier) { - this(identifier, AxiomStatementImpl.factory()); - } - - - public T getValue() { - return value; - } - - public void setValue(T value) { - this.value = value; - } - - private List>> childList = new ArrayList<>(); - private Multimap>> children = HashMultimap.create(); - - public void add(AxiomItemDefinition item, Supplier> statement) { - add(item.name(), statement); - } - - public void add(AxiomIdentifier type, Supplier> statement) { - childList.add(statement); - children.put(type, statement); - } - - @Override - public AxiomStatement get() { - return factory.create(identifier, value, buildChildList(), buildChildMap()); - } - - private Multimap> buildChildMap() { - return Multimaps.transformValues(children, (v) -> v.get()); - } - - private List> buildChildList() { - return Lists.transform(childList, (v) -> v.get()); - } -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementImpl.java deleted file mode 100644 index b07e3b0577e..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.spi; - -import java.util.Collection; -import java.util.List; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; -import com.google.common.collect.ImmutableMap.Builder; - -public class AxiomStatementImpl implements AxiomStatement { - - private final AxiomIdentifier keyword; - private final V value; - private final List> children; - private final Multimap> keywordMap; - - public AxiomStatementImpl(AxiomIdentifier keyword, V value, List> children, - Multimap> keywordMap) { - super(); - this.keyword = keyword; - this.value = value; - this.children = ImmutableList.copyOf(children); - this.keywordMap = ImmutableMultimap.copyOf(keywordMap); - } - - @Override - public Collection> children(AxiomIdentifier type) { - return keywordMap.get(type); - } - - @Override - public Collection> children() { - return children; - } - - @Override - public AxiomIdentifier keyword() { - return keyword; - } - - @Override - public V value() { - return value; - } - - @Override - public String toString() { - return keyword + "{value=" + value + "}"; - } - - public interface Factory> { - - I create(AxiomIdentifier type, V value, List> children, - Multimap> keywordMap); - - } - - protected void putAll(Builder builder, - Collection children) { - for (AxiomItemDefinition definition : children) { - builder.put(definition.name(), definition); - } - } - - public static > Factory factory() { - return (Factory) AxiomStatementImpl::new; - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementStreamListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementStreamListener.java deleted file mode 100644 index 2a1e35e7945..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStatementStreamListener.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.spi; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import com.evolveum.axiom.api.AxiomIdentifier; - -public interface AxiomStatementStreamListener { - - void endStatement( @Nullable SourceLocation sourceLocation); - void startStatement(@NotNull AxiomIdentifier identifier, @Nullable SourceLocation sourceLocation) throws AxiomSyntaxException; - void argument(@NotNull AxiomIdentifier convert, @Nullable SourceLocation sourceLocation); - void argument(@NotNull String convert, @Nullable SourceLocation sourceLocation); -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java deleted file mode 100644 index b1bd44592ff..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomStreamTreeBuilder.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.spi; - -import java.util.Deque; -import java.util.LinkedList; -import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; - - -public class AxiomStreamTreeBuilder implements AxiomStatementStreamListener { - - private final Deque queue = new LinkedList<>(); - - public AxiomStreamTreeBuilder(NodeBuilder root) { - queue.add(root); - } - - protected NodeBuilder current() { - return queue.peek(); - } - - @Override - public void argument(AxiomIdentifier identifier, SourceLocation loc) { - argument0(identifier, loc); - } - - @Override - public void argument(String identifier, SourceLocation loc) { - argument0(identifier, loc); - } - - private void argument0(Object value, SourceLocation loc) { - current().setValue(value, loc); - } - - @Override - public void startStatement(AxiomIdentifier statement, SourceLocation loc) throws AxiomSyntaxException { - Optional childDef = current().childDef(statement); - AxiomSyntaxException.check(childDef.isPresent(), loc , "Statement %s not allowed in %s", statement, current().identifier()); - queue.offerFirst(createBuilder(childDef.get(), loc)); - } - - private NodeBuilder createBuilder(AxiomItemDefinition item, SourceLocation loc) { - return current().startChildNode(item.name(), loc); - } - - @Override - public void endStatement(SourceLocation loc) { - NodeBuilder current = queue.poll(); - current.endNode(loc); - } - - public interface NodeBuilder { - - void endNode(SourceLocation loc); - - Optional childDef(AxiomIdentifier statement); - - AxiomIdentifier identifier(); - - void setValue(Object value, SourceLocation loc); - - NodeBuilder startChildNode(AxiomIdentifier identifier, SourceLocation loc); - - - } - - public void stream(AxiomStatement statement) { - startStatement(statement.keyword(), null); - if(statement.value() != null) { - argument0(statement.value(), null); - } - for( AxiomStatement child : statement.children()) { - stream(child); - } - endStatement(null); - - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index ddade1fa76d..4a7b17e7503 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -1,49 +1,59 @@ package com.evolveum.axiom.lang.spi; import java.util.Collection; -import java.util.List; +import java.util.Collections; import java.util.Map; import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - - import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; +import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomItemValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Multimap; +import com.google.common.collect.ImmutableMap.Builder; -import static com.evolveum.axiom.lang.api.AxiomBuiltIn.Item.*; +public class AxiomTypeDefinitionImpl extends AbstractBaseDefinition implements AxiomTypeDefinition { -public class AxiomTypeDefinitionImpl extends AbstractAxiomBaseDefinition implements AxiomTypeDefinition { + public static final AxiomItemValueFactory FACTORY =AxiomTypeDefinitionImpl::new; - public static final Factory FACTORY =AxiomTypeDefinitionImpl::new; - private final Map items; + private final Map itemDefinitions; private final Optional superType; - private Optional argument; - private Collection identifiers; + private final Optional argument; + private final Collection identifiers; + + public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition value, Map> keywordMap) { + super(def, null, keywordMap); - public AxiomTypeDefinitionImpl(AxiomIdentifier keyword, AxiomIdentifier value, List> children, - Multimap> keywordMap) { - super(keyword, value, children, keywordMap); + //super(keyword, value, children, keywordMap); ImmutableMap.Builder builder = ImmutableMap.builder(); - putAll(builder, children(ITEM_DEFINITION.name(), AxiomItemDefinition.class)); - items = builder.build(); - superType = first(SUPERTYPE_REFERENCE.name(), AxiomTypeDefinition.class); - argument = firstValue(ARGUMENT.name(), AxiomIdentifier.class) - .flatMap((AxiomIdentifier k) -> itemDefinition(k)); - - identifiers = children(Item.IDENTIFIER_DEFINITION.name()).stream().map(idDef -> { - Set members = idDef.children(Item.ID_MEMBER.name()).stream() - .map(k -> itemDefinition((AxiomIdentifier) k.value()).get()).collect(Collectors.toSet()); - AxiomIdentifier space = idDef.firstValue(ID_SPACE.name(), AxiomIdentifier.class).get(); - AxiomIdentifierDefinition.Scope scope = AxiomIdentifierDefinition.scope(idDef.firstValue(ID_SCOPE.name(), AxiomIdentifier.class).get().getLocalName()); - return AxiomIdentifierDefinition.from(space, scope, members); - }).collect(Collectors.toList()); + Optional> itemDef = item(Item.ITEM_DEFINITION.name()); + if(itemDef.isPresent()) { + supplyAll(builder, itemDef.get().values()); + } + itemDefinitions = builder.build(); + + superType = this.item(Item.SUPERTYPE_REFERENCE.name()).map(v -> v.onlyValue().get()); + + argument = this.item(Item.ARGUMENT.name()).flatMap(v -> itemDefinition(v.onlyValue().get())); + identifiers = upcast(this.item(Item.IDENTIFIER_DEFINITION.name()).map(v -> v.values()).orElse(Collections.emptyList())); + } + + @Override + public AxiomTypeDefinition get() { + return this; + } + + private > Collection upcast(Collection> itemValue) { + return (Collection) itemValue; + } + + @Override + public Optional> item(AxiomIdentifier name) { + return super.item(name); } @Override @@ -61,7 +71,7 @@ public Optional superType() { @Override public Map itemDefinitions() { - return items; + return itemDefinitions; } @Override @@ -69,4 +79,12 @@ public Collection identifierDefinitions() { return identifiers; } + private void supplyAll(Builder builder, + Collection> values) { + for(AxiomItemValue v : values) { + AxiomItemDefinition val = v.get(); + builder.put(val.name(), val); + } + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java index ef710e87ce9..bfaca9d8e89 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java @@ -33,4 +33,8 @@ public int getChar() { return character; } + public static SourceLocation runtime() { + return SourceLocation.from("IN-MEMORY", 0, 0); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java index 693b269f148..8f4f00d130a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Action.java @@ -2,10 +2,20 @@ import java.util.Optional; -public interface Action { +public interface Action extends Dependency { void apply(); + @Override + default boolean isSatisfied() { + return successful(); + } + + @Override + default Void get() { + return null; + } + boolean successful(); /** diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java index dc366ff9462..5c6cd773c22 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DependantAction.java @@ -8,12 +8,7 @@ public interface DependantAction extends Action { @Override default boolean canApply() { - for (Dependency dependency : dependencies()) { - if(!dependency.isSatisfied()) { - return false; - } - } - return true; + return Dependency.allSatisfied(dependencies()); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java index 392a98a2867..e37b5fc1593 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java @@ -1,9 +1,10 @@ package com.evolveum.axiom.reactor; +import java.util.Collection; import java.util.Optional; +import java.util.function.Function; import java.util.function.Supplier; -import com.evolveum.axiom.lang.impl.RuleErrorMessage; import com.google.common.base.Preconditions; @@ -15,7 +16,7 @@ default boolean isRequired() { boolean isSatisfied(); public T get(); - public RuleErrorMessage errorMessage(); + public Exception errorMessage(); public static Dependency unsatisfied() { return new Unsatified<>(); @@ -37,13 +38,13 @@ public static Dependency deffered(Dependency original) { return new Deffered<>(original); } - default Dependency unsatisfiedMessage(Supplier unsatisfiedMessage) { + default Dependency unsatisfied(Supplier unsatisfiedMessage) { return this; } interface Search extends Dependency { - default Dependency.Search notFound(Supplier unsatisfiedMessage) { + default Dependency.Search notFound(Supplier unsatisfiedMessage) { return this; } @@ -52,17 +53,17 @@ default Dependency.Search notFound(Supplier unsatisfiedMess public static abstract class Abstract implements Dependency { - private Supplier errorMessage; + private Supplier errorMessage; @Override - public Dependency unsatisfiedMessage(Supplier unsatisfiedMessage) { + public Dependency unsatisfied(Supplier unsatisfiedMessage) { errorMessage = unsatisfiedMessage; return this; } @Override - public RuleErrorMessage errorMessage() { + public Exception errorMessage() { if(errorMessage != null) { return errorMessage.get(); } @@ -171,7 +172,7 @@ Dependency delegate() { public final class RetriableDelegate extends Delegated implements Search { private Object maybeDelegate; - private Supplier notFound; + private Supplier notFound; public RetriableDelegate(Supplier> lookup) { maybeDelegate = lookup; @@ -190,21 +191,25 @@ Dependency delegate() { } } - return unsatisfied(); + return Dependency.unsatisfied(); } @Override - public Search notFound(Supplier unsatisfiedMessage) { + public Search notFound(Supplier unsatisfiedMessage) { notFound = unsatisfiedMessage; return this; } @Override - public RuleErrorMessage errorMessage() { + public Exception errorMessage() { if(maybeDelegate instanceof Supplier && notFound != null) { return notFound.get(); } - return super.errorMessage(); + Exception maybeFound = super.errorMessage(); + if(maybeFound == null && maybeDelegate instanceof Dependency) { + maybeFound = ((Dependency)maybeDelegate).errorMessage(); + } + return maybeFound; } } @@ -225,5 +230,31 @@ static Dependency orNull(T value) { } return null; } + static boolean allSatisfied(Collection> outstanding) { + for (Dependency dependency : outstanding) { + if(!dependency.isSatisfied()) { + return false; + } + } + return true; + } + + default Dependency map(Function map) { + return new Suppliable(() -> { + if(isSatisfied()) { + return map.apply(get()); + } + return null; + }); + } + + default Dependency flatMap(Function> map) { + return new RetriableDelegate(() -> { + if(isSatisfied()) { + return map.apply(get()); + } + return null; + }); + } } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 13e81603274..0911a54d50a 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -194,7 +194,7 @@ model axiom-lang { identifier name { space AxiomItemDefinition; - scope local; + scope parent; } item type { diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index afdc9f175bb..9125c157dc5 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -12,7 +12,6 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; -import java.util.Collection; import java.util.Optional; import org.testng.annotations.Test; @@ -22,8 +21,8 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; +import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.impl.ModelReactorContext; -import com.evolveum.axiom.lang.spi.AxiomStatement; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class TestAxiomExtension extends AbstractReactorTest { @@ -94,8 +93,9 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); - Collection> extension = ((AxiomStatement) personDef.get()).children(STORAGE); - assertFalse(extension.isEmpty(), "Extension statements should be available."); + + AxiomItem extension = personDef.get().item(STORAGE).get(); + assertFalse(extension.values().isEmpty(), "Extension statements should be available."); assertEquals(2, personDef.get().itemDefinitions().entrySet().size()); } From fc218997527bb0319bfcf37f5c3f1c3e4570970f Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Sat, 23 May 2020 09:51:30 +0200 Subject: [PATCH 19/60] Axiom: register modification to target Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index 86e31e448e1..fe9fcd51e78 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -155,6 +155,7 @@ public Dependency> modify(AxiomIdentifier space, Identifier return (Dependency.retriableDelegate(() -> { ValueContext maybe = context.lookup(space, key); if(maybe != null) { + maybe.addDependency(StatementRuleContextImpl.this); return Dependency.immediate(maybe); } return null; From eb7d929fe994f89957d4611dbb646d7d601d776b Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 25 May 2020 09:28:33 +0200 Subject: [PATCH 20/60] Axiom: fixed tests failing to duplicate defitions Signed-off-by: Tony Tkacik --- .../java/com/evolveum/axiom/lang/impl/ValueContext.java | 9 ++++++--- infra/axiom/src/test/resources/base-example.axiom | 5 ----- infra/axiom/src/test/resources/common-core.axiom | 7 ++++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 4c5cc35cf07..975eb671887 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -12,7 +12,6 @@ import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; - import java.util.Collection; import java.util.HashSet; import java.util.Optional; @@ -24,6 +23,7 @@ public class ValueContext extends AbstractContext> implements AxiomValueContext, ValueBuilder, Dependency> { private Dependency> result; + V originalValue; Collection> dependencies = new HashSet<>(); public ValueContext(SourceLocation loc, IdentifierSpaceHolder space) { @@ -33,6 +33,7 @@ public ValueContext(SourceLocation loc, IdentifierSpaceHolder space) { public ValueContext(ItemContext itemContext, V value, SourceLocation loc) { super(itemContext, loc, AxiomIdentifierDefinition.Scope.LOCAL); + originalValue = value; result = new Result(parent().type(), value); } @@ -220,8 +221,10 @@ public boolean isMutable() { @Override public String toString() { - return "value("+ parent().name() +";" + result +")"; + return new StringBuffer().append(parent().definition().name().getLocalName()) + .append(" ") + .append(originalValue != null ? originalValue : "") + .toString(); } - } diff --git a/infra/axiom/src/test/resources/base-example.axiom b/infra/axiom/src/test/resources/base-example.axiom index 3906c3f40d5..805d98cabbe 100644 --- a/infra/axiom/src/test/resources/base-example.axiom +++ b/infra/axiom/src/test/resources/base-example.axiom @@ -50,11 +50,6 @@ model model-header { } } - object { - name User2; - itemName user; - } - // Alternative representation of a prism object definition // (doesn't interfere with item { type ... } in structured types) object { diff --git a/infra/axiom/src/test/resources/common-core.axiom b/infra/axiom/src/test/resources/common-core.axiom index a188f4aa56b..61f10d21fea 100644 --- a/infra/axiom/src/test/resources/common-core.axiom +++ b/infra/axiom/src/test/resources/common-core.axiom @@ -1192,7 +1192,7 @@ model common-core { type ReferentialIntegrity; // ??? - type Extension; + // type Extension; // common-3 type OperationResult; @@ -1205,7 +1205,8 @@ model common-core { type Activation; // should exist because of "container XXX" - type Trigger; - type Assignment; + // Already defined + // type Trigger; + // type Assignment; } From 94fc8a93bb3114c74cc0923c1fa48831b406f74b Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 25 May 2020 09:43:35 +0200 Subject: [PATCH 21/60] Axiom: introduced originalValue in reactor context Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/lang/impl/AxiomStatementRule.java | 2 ++ .../com/evolveum/axiom/lang/impl/BasicStatementRule.java | 7 +++---- .../evolveum/axiom/lang/impl/StatementRuleContextImpl.java | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index 9df55cd29f7..58f320d9d93 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -39,6 +39,8 @@ default AxiomTypeDefinition typeDefinition() { V currentValue(); + V originalValue(); + boolean isMutable(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 832e2c7c97c..b2abd57db56 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -41,7 +41,7 @@ public void apply(Context rule) throws AxiomSemanticException { public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { if(context.isMutable()) { Optional argument = context.typeDefinition().argument(); - if(argument.isPresent() && context.currentValue() != null) { + if(argument.isPresent() && context.originalValue() != null) { action.apply(ctx -> { ctx.childItem(argument.get()).addValue(ctx.currentValue()); ctx.replaceValue(null); @@ -83,7 +83,7 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { - AxiomIdentifier type = context.currentValue(); + AxiomIdentifier type = context.originalValue(); Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); typeDef.notFound(() -> action.error("type '%s' was not found.", type)); typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); @@ -108,13 +108,12 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { - AxiomIdentifier type = context.currentValue(); + AxiomIdentifier type = context.originalValue(); Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); typeDef.notFound(() -> action.error("type '%s' was not found.", type)); typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java index fe9fcd51e78..355206e3636 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java @@ -192,4 +192,8 @@ public String name() { return rule; } + @Override + public V originalValue() { + return context.originalValue; + } } From 04b6770f2197edb508feefc1117c2d6b88ed41f7 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 25 May 2020 10:56:29 +0200 Subject: [PATCH 22/60] Axiom: Added prism language extensions Signed-off-by: Tony Tkacik --- .../axiom/lang/api/IdentifierSpaceKey.java | 1 + .../axiom/lang/impl/BasicStatementRule.java | 53 +- .../axiom/src/main/resources/axiom-lang.axiom | 54 - .../test/resources/prism/common-core.axiom | 1220 +++++++++++++++++ .../test/resources/prism/common-core.prism | 1216 ++++++++++++++++ .../src/test/resources/prism/prism.axiom | 79 ++ 6 files changed, 2536 insertions(+), 87 deletions(-) create mode 100644 infra/axiom/src/test/resources/prism/common-core.axiom create mode 100644 infra/axiom/src/test/resources/prism/common-core.prism create mode 100644 infra/axiom/src/test/resources/prism/prism.axiom diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java index 7fe6d301e42..6d8826c6a52 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java @@ -56,4 +56,5 @@ public String toString() { public static IdentifierSpaceKey of(AxiomIdentifier key, Object value) { return from(ImmutableMap.of(key, value)); } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index b2abd57db56..28c5d38d27d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -24,7 +24,7 @@ public enum BasicStatementRule implements AxiomStatementRule { -/* + /* REQUIRE_REQUIRED_ITEMS(all(),all()) { @Override public void apply(Context rule) throws AxiomSemanticException { @@ -117,21 +117,13 @@ public void apply(Lookup context, ActionBuilder> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); typeDef.notFound(() -> action.error("type '%s' was not found.", type)); typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); - action.apply(ctx -> { - ctx.replace(typeDef.get()); - AxiomItemValue superType = typeDef.get(); - // Copy Identifiers - Optional> identifiers = superType.item(Item.IDENTIFIER_DEFINITION); - if(identifiers.isPresent()) { - ctx.parentValue().mergeItem(identifiers.get()); - }// Copy Items - Optional> items = superType.item(Item.ITEM_DEFINITION); - if(items.isPresent()) { - ctx.parentValue().mergeItem(items.get()); - } + action.apply(superTypeValue -> { + superTypeValue.replace(typeDef.get()); + addFromType(typeDef.get(), superTypeValue.parentValue()); }); } + }, IMPORT_DEFAULT_TYPES(all(), types(Type.MODEL)) { @@ -169,6 +161,7 @@ public void apply(Lookup context, ActionBuilder rule) throws AxiomSemanticException { }, */ ; -/* - ADD_SUPERTYPE(items(), types(Type.TYPE_DEFINITION)) { - - @Override - public void apply(Context rule) throws AxiomSemanticException { - Optional superType = action.optionalChildValue(Item.SUPERTYPE_REFERENCE, AxiomIdentifier.class); - if(superType.isPresent()) { - Requirement> req = action.requireGlobalItem(Item.TYPE_DEFINITION, superType.get()); - action.apply((ctx) -> { - //ctx.builder().add(Item.SUPERTYPE_REFERENCE, req.get()); - }); - action.errorMessage(() -> { - if(!req.isSatisfied()) { - return action.error("Supertype %s is not defined", superType.get()); - } - return null; - }); - } - } - };*/ private final Set items; private final Set types; @@ -264,4 +237,18 @@ private static ImmutableSet all() { private static IdentifierSpaceKey namespaceId(String uri) { return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); } + + public static void addFromType(AxiomItemValue source, AxiomValueContext target) { + AxiomItemValue superType = source; + // FIXME: Add namespace change if necessary + // Copy Identifiers + Optional> identifiers = superType.item(Item.IDENTIFIER_DEFINITION); + if(identifiers.isPresent()) { + target.mergeItem(identifiers.get()); + }// Copy Items + Optional> items = superType.item(Item.ITEM_DEFINITION); + if(items.isPresent()) { + target.mergeItem(items.get()); + } + } } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 0911a54d50a..c9834ab3328 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -57,26 +57,6 @@ model axiom-lang { item extension { type AxiomExtensionDefinition; } - - // TODO move to prism schema; consider renaming to objectType? - item object { - type PrismObjectDefinition; - } - - // TODO move to prism schema; consider renaming to containerType? - item container { - type PrismContainerDefinition; - } - - // TODO move to prism schema; consider renaming to referenceType? - item reference { - type PrismReferenceDefinition; - } - - // TODO move to prism schema - item item { - type PrismItemDefinition; - } } type AxiomImportDeclaration { @@ -161,21 +141,6 @@ model axiom-lang { type AxiomIdentifierDefinition; } - // TODO move to prism schema - item object { - type boolean; - } - - // TODO move to prism schema - item container { - type boolean; - } - - // TODO move to prism schema - item objectReference { - type boolean; - } - // TODO reconsider this - strictly speaking this is part of "global type+item definition combo" item itemName { type AxiomIdentifier; @@ -242,23 +207,4 @@ model axiom-lang { extends string; } - // TODO move to prism schema; probably should be prism:ObjectDefinition - type PrismObjectDefinition { - extends AxiomTypeDefinition; - } - - // TODO move to prism schema; probably should be prism:ContainerDefinition - type PrismContainerDefinition { - extends AxiomTypeDefinition; - } - - // TODO move to prism schema; probably should be prism:ReferenceDefinition - type PrismReferenceDefinition { - extends AxiomTypeDefinition; - } - - // TODO move to prism schema; probably should be prism:ItemDefinition - type PrismItemDefinition { - extends AxiomItemDefinition; - } } diff --git a/infra/axiom/src/test/resources/prism/common-core.axiom b/infra/axiom/src/test/resources/prism/common-core.axiom new file mode 100644 index 00000000000..83b95e6c0b4 --- /dev/null +++ b/infra/axiom/src/test/resources/prism/common-core.axiom @@ -0,0 +1,1220 @@ +// 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. + +// This is "common-core.axiom" file containing core definitions from the common-3 namespace. +// Due to its size the common-3 schema is distributed across multiple files. + +model common-core { + + namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; + version "3.0.0"; + + import prism { + namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; + } + + type Object { + prism:object; + itemName object; + documentation """ + Common supertype for all identity objects. Defines basic properties + that each object must have to live in our system (identifier, name). + + All objects are identified by OID. The OID is an immutable identifier + (usually UUID). Except the OID all the objects have human-readable name. + The name is usually unique for each object type, but this is not a + strict requirement. + + Note: object type is fixed, it cannot be changed. The object retains its + type from the time it was created to the end of its life. + """; + item name { + type PolyString; + documentation """ + Human-readable, mutable name of the object. It + may also be an identifier (login name, group name). + It is usually unique in the respective context of + interpretation. E.g. the name of the UserType subtype + is usually unique in the whole system. + The name of the ShadowType subtype is usually unique in the + scope of resource (target system) that it belongs to. + + The name may not be human-readable in a sense to display + to a common end-user. It is intended to be displayed to + IDM system administrator. Therefore it may contain quite + a "ugly" structures such as LDAP DN or URL. + + Name is mutable. It is considered to be ordinary property + of the object. Therefore it can be changed by invoking + usual modifyObject operations. However, change of the name + may have side effects (rename process). + + Although name is specified as optional by this schema, it + is in fact mandatory for most object types. The reason for + specifying the name as optional is that the name may be + generated by the system instead of supplied by the clients. + However, all objects stored in the repository must have a name. + """; + // ObjectType.name + // 0 + // true + } + + // Note: the description property is referenced from various contexts (e.g. Object and Assignment). + // To avoid duplication we use global property definition. + // item description; // TODO make this work + + // The same is true for documentation. + // item documentation; // TODO make this work + + item subtype { + type string; + maxOccurs unbounded; + documentation """ + Type of the object. It is used to distinguish what a specific object + represents. Whether it is a different kind of organizational unit, project, + team, or different kind of user, etc. + """; + // ObjectType.subtype + // 15 + } + + item fetchResult { + type OperationResult; + documentation """ + Result of the operation that fetched this instance of the object. + It is mostly used to indicate that the object is not complete or + there is some problem with the object. This is used instead of + exception if the object is part of larger structures (lists as in + list/search operations or composite objects). If not present then + the "SUCCESS" state is assumed. + + This field is TRANSIENT. It must only be used in runtime. It should + never be stored in the repository. + """; + // a:operational + } + + // item extension; // TODO make this work + + item trigger { + type Trigger; + maxOccurs unbounded; + documentation """ + Triggers for this object. They drive invocations of corresponding trigger handlers + at specified time. + """; + // a:operational + } + + item parentOrg { // TODO or should we use 'Ref' suffix i.e. 'parentOrgRef'? + type ObjectReference; + maxOccurs unbounded; + documentation """ + Set of the orgs (organizational units, projects, teams) that the object relates to. + This usually means that the object belongs to them but it may have other meanings as well + (e.g. user manages an organizational unit). + """; + // tns:OrgType + // OrgType.parentOrganization + // 240 + // + } + + item tenant { + type ObjectReference; + documentation """ + Reference to the tenant to which this object belongs. It is a computed value set automatically + by midPoint. It is determined from the organizational structure. Even though this value is + computed it is also stored in the repository due to performance reasons. + """; + // tns:OrgType + // OrgType.tenant + // 250 + // true + } + + item lifecycleState { + type string; + documentation """ + Lifecycle state of the object. This property defines whether the + object represents a draft, proposed definition, whether it is active, + deprecated, and so on. + + There are few pre-defined lifecycle states. But custom lifecycle states + may also be defined. Pre-defined lifecycle states are: + + - draft: Definition of the new object in progress. The object is + NOT active. The definition may change at any moment. It is + not ready yet. + - proposed: Definition of a new object is ready for use, but there + is still a review process to be applied (e.g. approval). + The object is NOT active. However the definition should + not change in this state. + - active: Active and working definition. Ready to be used without + any unusual limitations. + - deprecated: Active definition which is being phased out. The + definition is still fully operational. But it should not + be used for new assignments. E.g. it should not be requested, + it should not be approved, etc. + - archived: Inactive historical definition. It is no longer used. + It is maintained only for historical, auditing and + sentimental reasons. + - failed: Unexpected error has occurred during object lifecycle. Result + of that event is that the object is rendered inactive. + The situation cannot be automatically remedied. Manual action + is needed. + """; + // ObjectType.lifecycleState + // 20 + since "3.5"; + // + } + + item operationExecution { + type OperationExecution; + maxOccurs unbounded; + documentation """ + Description of recent operations executed on this object (or related objects, e.g. shadows + in case of a focal object). The number of operations to be kept here is configurable. + """; + since "3.6"; + // true + } + + item lensContext { + type LensContext; + documentation """ + Model context describing executed operation. + """; + since "4.0"; + // true + } + + item policySituation { + type uri; + maxOccurs unbounded; + documentation """ + The policy situation(s) of this object. The situations are result of + evaluation of the policy rules. This property is recorded for each object + and can be used for reporting, diagnostics, target selection in certification + campaigns, etc. + """; + since "3.5"; + // true + } + + item policyException { + type PolicyException; + maxOccurs unbounded; + documentation """ + Recorded exception from a policy rule. The exceptions that are approved are + recoded here to avoid re-evaluating and re-approving them all the time. + This is EXPERIMENTAL functionality. It is likely to change in the near future. + """; + since "3.5"; + // true + } + + item diagnosticInformation { + type DiagnosticInformation; + maxOccurs unbounded; + documentation """ + Diagnostic information attached to this object. + """; + since "4.0"; + // true + } + + // Note that oid and version are not defined here. These are intrinsic parts of prism objects + // so they do not have to be mentioned in the schema. + // TODO: is this OK? See also related questions in ObjectReference type. + } + + type AssignmentHolder { + extends Object; + itemName assignmentHolder; + documentation """ + Abstract supertype for all object types that can have assignments. + """; + + item assignment { + type Assignment; + maxOccurs unbounded; + documentation """ + Set of object's assignments. + Assignments define the privileges and "features" that this object should have, that + this object is entitled to. Typical assignment will point to a role or define + a construction of an account. + + Assignments represent what the object SHOULD HAVE. The assignments represent a policy, + a desired state of things (cf. linkRef). + """; + // FocusType.assignmentKey + } + + item iteration { + type int; // TODO + documentation """ + Iteration number. Starts with 0. It is used to iteratively find unique identifier + for the object. + """; + // true + } + + item iterationToken { + type string; + documentation """ + Iteration token. String value that is usually a suffix to the identifier based + on iteration number. E.g. ".007". It is used to iteratively find unique identifier + for the object. + """; + // true + } + + item archetype { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to all applicable archetypes, including "indirect" archetypes such as archetype supertypes. + Contains references to active archetypes only. + + Note: the value of this reference is only updated when object is recomputed. + Therefore if a role definition changes then all the affected objects must be recomputed + for this reference to be consistent. + + This is an operational property. It is set and managed by the system. It is used + for efficient use of archetypes. + """; + // tns:ArchetypeType + // true + // AssignmentHolderType.archetypeRef + since "4.0"; + } + + item roleMembership { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to abstract roles (roles, orgs, services) that this focus currently belongs to - directly + or indirectly. This reference points to all the roles in the role hierarchy. It only points to + the roles that were evaluated as active during last recompute (conditions were true, validity + constraints not violated). + + Note: the value of this reference is only updated when a focal object is recomputed. + Therefore if a role definition changes then all the affected focal objects must be recomputed + for this reference to be consistent. + + Roles mentioned here are those that are NOT obtained via delegation, i.e. "deputy" relations. + Relations acquired by delegation are listed in delegatedRef item. + + This is an operational property. It is set and managed by the system. It is used + for efficient search of all current role members, e.g. for the purpose of displaying this + information in the GUI. + """; + // tns:AbstractRoleType + // true + // FocusType.roleMembershipRef + } + + item delegated { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to objects (abstract roles as well as users) obtained via delegation. + If A1 is a deputy of A, its delegatedRef contains a union of A, A.roleMembershipRef and + A.delegatedRef. + + This is an operational property. It is set and managed by the system. It is used + for efficient search of all current role members, e.g. for the purpose of displaying this + information in the GUI. + """; + // tns:FocusType + // true + since "3.5"; + } + + item roleInfluence { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to abstract roles (roles and orgs) that this focus may directly belong to. + This reference only points to the next role in the hierarchy. However, it is backed by + a "closure" index in the repository subsystem. Therefore it can efficiently support tree-like + queries. This reference points to the roles for whose the condition is not true. + Therefore it does not reliably show + who actually has a role. It shows potential role members - all the object that are possibly + influenced when a role definition changes. + + This is an operational property. It is set and managed by the system. It is used + for efficient search of all possible role members, e.g. for the purpose of recomputing + all role members after the role definition is changed. + + TODO. NOT IMPLEMENTED YET. EXPERIMENTAL. UNSTABLE. + """; + // tns:AbstractRoleType + // true + } + } + + type Focus { + extends AssignmentHolder; + itemName focus; + documentation """ + Abstract supertype for all object types that can be focus of full midPoint computation. + This basically means objects that have projections. But focal objects also have + activation, they may have personas, etc. + """; + item link { + type ObjectReference; + maxOccurs unbounded; + documentation """ + Set of shadows (projections) linked to this focal object. + E.g. a set of accounts linked to a user. This is the set of + shadows that belongs to the focal object in a sense + that these shadows represents the focal object on the resource. + E.g. The set of accounts that represent the same midPoint user (the + same physical person, they are "analogous"). + + Links define what the object HAS. The links reflect real state of things + (cf. assignment). + """; + // tns:ShadowType + } + + item persona { + type ObjectReference; + maxOccurs unbounded; + documentation """ + Set of personas linked to this focal object. + E.g. a set of virtual identities linked to a user. This is the set of + "secondary" focal objects that belongs to this focal object in a sense + that the current focal object is in control over the linked focal objects. + E.g. this reference can be used to link user object which specified a physical + person with his virtual identities (personas) that specify his identity as an + employee, system administrator, customer, etc. + The default meaning is that the personas are "analogous", i.e. the represent + different facets of the same physical person. However, this meaning may be + theoretically overridden by using various relation parameters in this reference. + + This reference define what the object HAS. The links reflect real state of + things (cf. assignment). + """; + // tns:FocusType + since "3.6"; + } + + item activation { + type Activation; + } + + item jpegPhoto { + type binary; + documentation """ + Photo corresponding to the user / org / role / service. + """; + // FocusType.jpegPhoto + } + + item costCenter { + type string; + documentation """ + The name, identifier or code of the cost center to which the object belongs. + + Please note that organization objects (OrgType) also have a costCenter property. + Therefore it is usual that if a user belongs to an organization the costCenter from + the organization is used. Therefore this property is usually used only for users that + do not belong to any organization or for users that have different cost center than + the one defined by the organization. + """; + // FocusType.costCenter + // 420 + } + + item locality { + type PolyString; + documentation """ + Primary locality of the object, the place where + the (e.g.) user usually works, the country, city or + building that he belongs to. The specific meaning + and form of this property is deployment-specific. + """; + // FocusType.locality + // 450 + } + + item preferredLanguage { + type string; + documentation """ + Indicates user's preferred language, usually for the purpose of localizing + user interfaces. The format is IETF language tag defined in BCP 47, where + underscore is used as a subtag separator. This is usually a ISO 639-1 two-letter + language code optionally followed by ISO 3166-1 two letter country code + separated by underscore. The languages that do not have country-specific + variants are usually specified by using a two-letter country code ("sk", + "cs", "tr"). Languages with country-specific variants have country-specific + subtags ("pt_BR", "zn_CN"). + If no value is specified in this property then system default locale is assumed. + + Examples: + - en_US + - sk + - cs + - pt_BR + """; + // FocusType.preferredLanguage + // 200 + // + } + + item locale { + type string; + documentation """ + Defines user's preference in displaying currency, dates and other items + related to location and culture. The format is IETF language tag defined in BCP 47, where + underscore is used as a subtag separator. This is usually a ISO 639-1 two-letter + language code optionally followed by ISO 3166-1 two letter country code + separated by underscore. The languages that do not have country-specific + variants are usually specified by using a two-letter country code ("sk", + "cs", "tr"). Languages with country-specific variants have country-specific + subtags ("pt_BR", "zn_CN"). + If not specified then system default locale is assumed. + + Examples: + - en_US + - sk + - cs + - pt_BR + """; + // FocusType.locale + // 210 + // + } + + item timezone { + type string; + documentation """ + User's preferred timezone. It is specified in the "tz database" (a.k.a "Olson") + format. If not specified then system default timezone is assumed. + + Examples: + - Europe/Bratislava + """; + // FocusType.timezone + // 220 + // + } + + item emailAddress { + type string; + documentation """ + E-Mail address of the user, org. unit, etc. This is the address + supposed to be used for communication with the + user, org. unit, etc. E.g. IDM system may send notifications + to the e-mail address. It is NOT supposed to be + full-featured e-mail address data structure + e.g. for the purpose of complex address-book application. + """; + // FocusType.emailAddress + // 300 + } + + item telephoneNumber { + type string; + documentation """ + Primary telephone number of the user, org. unit, etc. + """; + // FocusType.telephoneNumber + // 310 + } + + item credentials { + type Credentials; + documentation """ + The set of focus's credentials (such as passwords). + """; + // FocusType.credentials + } + } + + type User { + extends Focus; + documentation """ + User object represents a physical user of the system. + It differs from the account, as "account" represents a data structure in a target system while + "user" represents data structure in midPoint. One user typically has many accounts. + Properties of User object typically describe the user as a physical person. + Therefore the user object defines handful of properties that are commonly used to describe users + in the IDM solutions (employees, customers, partners, etc.) Custom extensions are possible by utilizing + the "extension" container. + """; + + item fullName { + type PolyString; + documentation """ + Full name of the user with all the decorations, + middle name initials, honorific title and any + other structure that is usual in the cultural + environment that the system operates in. This + element is intended to be displayed to + a common user of the system. + + Examples: + - cpt. Jack Sparrow + - William "Bootstrap" Turner + - James W. Random, PhD. + - Vladimir Iljic Lenin + - Josip Broz Tito + - Chuck Norris + """; + // UserType.fullName + // 100 + // true + } + + item givenName { + type PolyString; + documentation """ + Given name of the user. It is usually the first + name of the user, but the order of names may + differ in various cultural environments. This + element will always contain the name that was + given to the user at birth or was chosen + by the user. + + Examples: + - Jack + - Chuck + """; + // UserType.givenName + // 110 + // true + } + + item familyName { + type PolyString; + documentation """ + Family name of the user. It is usually the last + name of the user, but the order of names may + differ in various cultural environments. This + element will always contain the name that was + inherited from the family or was assigned + to a user by some other means. + + Examples: + - Sparrow + - Norris + """; + // UserType.familyName + // 120 + // true + } + + item additionalName { + type PolyString; + documentation """ + Middle name, patronymic, matronymic or any other name of a person. It is usually the + middle component of the name, however that may be culture-dependent. + + Examples: + - Walker + - John + - Iljic + """; + // UserType.additionalName + // 130 + } + + item nickName { + type PolyString; + documentation """ + Familiar or otherwise informal way to address a person. + + Examples: + - Bootstrap + - Bobby< + + The meaning of this property is to take part in the formatted full + name of the person, e.g. William "Bootstrap" Turner. It is not intended + to be used as a username or login name. This value is usually changeable + by the user itself and it defines how the user wants other to address him. + Therefore it is not ideal for use as an identifier. + """; + // UserType.nickname + // 140 + } + + item honorificPrefix { + type PolyString; + documentation """ + Honorific titles that go before the name. + Examples: + - cpt. + - Ing. + - Sir + + This property is single-valued. If more + than one title is applicable, they have to be represented in + a single string (concatenated) form in the correct order. + """; + // UserType.honorificPrefix + // 150 + } + + item honorificSuffix { + type PolyString; + documentation """ + Honorific titles that go after the name. + + Examples: + - PhD. + - KBE + + This property is single-valued. If more + than one title is applicable, they have to be represented in + a single string (concatenated) form in the correct order. + """; + // UserType.honorificSuffix + // 160 + } + + item title { + type PolyString; + documentation """ + User's title defining a work position or a primary role in the + organization. + Examples: + - CEO + - Security Officer + - Assistant + """; + // UserType.title + // 170 + } + + item employeeNumber { + type string; + documentation """ + Unique, business-oriented identifier of the employee. + Typically used as correlation identifier and for + auditing purposes. Should be immutable, but the + specific properties and usage are deployment-specific. + """; + // UserType.employeeNumber + // 400 + } + + item employeeType { + type string; + maxOccurs unbounded; + documentation """ + Employee type specification such as internal employee, + external or partner. The specific values are + deployment-specific. However it is generally assumed that this + will be enumeration of several type names or codes that define + "classes" of users. + + Even though this property is named "employeeType" due to the historical + reasons it is used in a more generic way to mean general type of user. + Therefore it can be used to distinguish employees from customers, etc. + + DEPRECATED: Use ObjectType.subtype + """; + // UserType.employeeType + // 410 + // true + // 3.8 + } + item organization { + type PolyString; + maxOccurs unbounded; + documentation """ + Name or (preferably) immutable identifier of organization that the user belongs to. + The format is deployment-specific. This property together with organizationalUnit + may be used to provide easy-to-use data about organizational membership of the user. + + This is multi-valued property to allow membership of a user to several + organizations. Please note that midPoint does not maintain ordering in + multi-value properties therefore this is not usable to model a complex + organization hierarchies. Use OrgType instead. + """; + // UserType.organization + // 430 + } + + item organizationalUnit { + type PolyString; + maxOccurs unbounded; + documentation """ + Name or (preferably) immutable identifier of organizational unit that the user belongs to. + The format is deployment-specific. This property together with organization + may be used to provide easy-to-use data about organizational membership of the user. + + This is multi-valued property to allow membership of a user to several + organizational units. Please note that midPoint does not maintain ordering in + multi-value properties therefore this is not usable to model a complex + organization hierarchies. Use OrgType instead. + """; + // UserType.organizationalUnit + // 440 + } + item adminGuiConfiguration { + type AdminGuiConfiguration; + documentation """ + Specifies the admin GUI configuration that should be used + by this user. + """; + since "3.5"; + // AdminGuiConfigurationType.adminGuiConfiguration + } + } + + type ObjectReference { + prism:objectReference; + documentation """ + Reference to an object. It contains OID of the object that it + refers to. + """; + + // item description; // TODO make this work + + // item documentation; // TODO make this work + + item filter { + type SearchFilter; // TODO namespace of "query-3" + documentation """ + Filter that can be used to dynamically lookup the reference OID e.g. during imports. + It must not be used for normal operations. The filter may be stored in the repository + to avoid data loss. But even if it is stored it will not be used beyond initial + import or unless explicitly requested (e.g. by setting resolutionTime). + + Note: The filter will NOT be used if the OID in the reference is set. The OID always takes + precedence. + """; + } + + item resolutionTime { + type EvaluationTime; + // TODO defaultValue "import"; + documentation """ + Definition of the "time" when the reference will be resolved. Resolving the reference means using + the filter to get object(s) or OID(s). + + Import-time resolution means that the reference will be resolved once when the file is imported. + OID will be recorded in the reference and then only the OID will be used to follow the reference. + This is a very efficient method and it is the default. + + Run-time resolution means that the reference will be resolved every time that the reference is + evaluated. This is less efficient but it provides great flexibility as the filter may contain + expressions and therefore the reference target may dynamically change. + """; + } + + item referentialIntegrity { + type ReferentialIntegrity; + // TODO defaultValue "default"; + documentation """ + Definition of the behavior related to non-existence of object with specified target OID. + (Currently supported only at selected places in midPoint.) + """; + since "4.1"; + } + + item targetName { + type PolyString; + documentation """ + Cached name of the target object. + This is a ephemeral value. It is not stored in the repository. + It may be computed at object retrieval time or it may not be present at all. + This is NOT an authoritative information. Setting it or changing it will + not influence the reference meaning. OID is the only authoritative linking + mechanism. + """; + } + + // TODO what about (attributes) oid, type, and relation? + // Should they be listed here even if they are defined in PrismReferenceValue? + // But if not, why should we list filter, resolution time, referential integrity here, + // as they are also defined in PrismReferenceValue. + } + + mixin Description { + item description { + type string; + documentation """ + Free-form textual description of the object. It is supposed to describe + the object or a construct that it is attached to. + + This information may be presented to midPoint users, even to ordinary end users. + For example role description may be presented to users when they are selecting + roles to request. Therefore the description should be written in a language that + the users can understand. + + Description is assumed to be a plan, non-formatted text. + Amount of white space is considered insignificant. E.g. leading and trailing + white space may be skipped, multiple spaces can be collapsed to one and so on. + """; + // ObjectType.description + // 10 + } + } + + mixin Documentation { + item documentation { + type string; + documentation """ + Technical documentation for a particular object or construct. + + The purpose of this element is to document system configuration and behavior. + The documentation will not be presented to end users. In fact, it will probably + not be presented at all in midPoint user interface. This documentation element + is supposed to be a part of the technical documentation of midPoint deployment. + The tools than generate deployment configuration will look for these elements + and combine them to compiled documentation document. + + AsciiDoc formatting is assumed for this element. Any leading or trailing + whitespace is skipped. Indentation equivalent to he indentation of the first + non-blank line of text is also skipped. + """; + // ObjectType.documentation + // 11 + } + } + + // Example of short version of container definition. + prism:container { + name Assignment; + itemName assignment; + + // item description; // TODO make this work + // item documentation; // TODO make this work + // item extension; // TODO make this work + + // ... + } + + prism:container { + name Extension; + itemName extension; + documentation """ + Extension container that provides generic extensibility mechanism. + Almost any extension property can be placed in this container. + This mechanism is used to extend objects with new properties. + The extension is treated exactly the same as other object + properties by the code (storage, modifications, etc), except + that the system may not be able to understand their meaning. + """; + // ObjectType.extension + // 1000 + } + + prism:object GenericObject { + extends Focus; + itemName genericObject; + documentation """ + Generic object for storing unknown (unexpected) object types. + + The generic object should be used if there is a need to + store a custom object (e.g KangarooType) at deployment-time. + The properties of such custom objects are to be placed in the + extension part of this object. The schema is not checked or + enforced for this type of objects if technically possible. + """; + item objectType { + type uri; // TODO + // deprecated + } + } + + prism:container Trigger { + itemName trigger; + documentation """ + Defines triggers for an object. Trigger is an action that should take place + at specified time or under some other condition. + """; + item timestamp { + type dateTime; // TODO + documentation """ + The time when a trigger needs to be activated. + """; + } + item handlerUri { + type uri; // TODO + documentation """ + Handler URI indirectly specifies which class is responsible to handle the task. The handler will + to be used to handle trigger activation. + """; + } + item originDescription { + type string; + documentation """ + Short description of trigger origin, e.g. name of the mapping. + Used for diagnostic purposes. + """; + // true + since "4.0"; + } + item extension { // TODO + type Extension; + documentation """ + Extension container used to provide additional situation-specific information to the trigger. + """; + } + } + + prism:container Metadata { + itemName metadata; + documentation """ + Meta-data about data creation, modification, etc. + It may apply to objects but also parts of the object (e.g. assignments). + + Meta-data only apply to successful operations. That is obvious for create, but it also applies + to modify. For obvious reasons there are no metadata about delete. + We keep no metadata about reading. That would be a huge performance hit. + + Meta-data only describe the last operation of its kind. E.g. there is a record of last + modification, last approval, etc. There is no history. The last operation overwrites data + about the previous operation. + + These data are informational only. They should not be used for security purposes (use auditing + subsystem for that). But presence of metadata simplifies system administration and may provide + some basic information "at the glance" which may be later confirmed by the audit logs. + + Meta-data are also supposed to be searchable. Therefore they may be used to quickly find + "candidate" objects for a closer examination. + """; + // true + // + // Metadata + + item requestTimestamp { + type dateTime; + documentation """ + The timestamp of "create" operation request. It is set once and should never be changed. + + In case of "background" processes to create object (e.g. create with approval) + this should be the timestamp when the process started. I.e. the timestamp when + the operation was requested. + """; + // MetadataType.requestTimestamp + // true + since "3.5"; + // + } + + item requestor { + type ObjectReference; + documentation """ + Reference to the user that requested the "create" operation for this object or assignment. + """; + // MetadataType.requestorRef + // true + // tns:UserType + // + } + + item requestorComment { + type string; + documentation """ + Comment of the user that requested the "create" operation for this object or assignment. + """; + // MetadataType.requestorComment + // true + since "3.7"; + } + + item createTimestamp { + type dateTime; + documentation """ + The timestamp of data creation. It is set once and should never be changed. + + In case of "background" processes to create object (e.g. create with approval) + this should be the timestamp when the process ended. I.e. the timestamp when + the operation was executed. + """; + // MetadataType.createTimestamp + // true + // true + since "3.5"; + } + + item creator { + type ObjectReference; + maxOccurs unbounded; + documentation """ + Reference to the user that approved the creation of the data (if there was such a user). + This is multi-value reference therefore multiple approvers may be recorded. However the order and + hierarchy of the approvers is lost. + """; + // MetadataType.createApproverRef + // true + // true + // tns:UserType + } + + item createApproverComment { + type string; + maxOccurs unbounded; + documentation """ + Comments of the approvers during the creation of the data. Note that these comments are in no + particular order, so basically it is not known who entered which comment. + """; + // MetadataType.createApprovalComment + // true + since "3.7"; + } + + item createApprovalTimestamp { + type dateTime; + documentation """ + The timestamp of creation approval. + """; + // MetadataType.createApprovalTimestamp + // true + since "3.5"; + } + + item createChannel { + type uri; + documentation """ + Channel in which the object was created. + """; + // MetadataType.createChannel + // true + // true + } + + item createTask { + type ObjectReference; + documentation """ + Reference to the task that created the object (if it was a persistent one). + """; + // MetadataType.createTaskRef + // true + // tns:TaskType + since "3.7"; + } + + item modifyTimestamp { + type dateTime; + // MetadataType.modifyTimestamp + // true + // true + } + + item modifier { + type ObjectReference; + // MetadataType.modifierRef + // true + // true + // tns:UserType + } + + item modifyApprover { + type ObjectReference; + maxOccurs unbounded; + // MetadataType.modifyApproverRef + // true + // true + // tns:UserType + } + + item modifyApprovalComment { + type string; + maxOccurs unbounded; + // MetadataType.modifyApprovalComment + // true + since "3.7"; + } + + item modifyChannel { + type uri; + // MetadataType.modifyChannel + // true + // true + } + + item modifyTask { + type ObjectReference; + // MetadataType.modifyTaskRef + // true + // tns:TaskType + since "3.7"; + } + + item lastProvisioningTimestamp { + type dateTime; + // MetadataType.lastProvisioningTimestamp + // true + since "3.6.1"; + } + + item certificationFinishedTimestamp { + type dateTime; + // MetadataType.certificationFinishedTimestamp + // true + since "3.7"; + } + + item certificationOutcome { + type string; + // MetadataType.certificationOutcome + // true + since "3.7"; + } + + item certifier { + type ObjectReference; + // MetadataType.certifierRef + // true + // tns:UserType + since "3.7"; + } + + item certifierComment { + type string; + maxOccurs unbounded; + // MetadataType.certifierComment + // true + since "3.7"; + } + + item originMappingName { + type string; + // MetadataType.originMappingName + // true + since "3.7"; + } + } + + // axiom + + // types-3 + type PolyString; + + // query-3 + type SearchFilter; + type EvaluationTime; + type ReferentialIntegrity; + + // ??? + // type Extension; + + // common-3 + type OperationResult; + type OperationExecution; + type LensContext; + type PolicyException; + type DiagnosticInformation; + type Credentials; + type AdminGuiConfiguration; + type Activation; + + // should exist because of "container XXX" + // Already defined + // type Trigger; + // type Assignment; + +} diff --git a/infra/axiom/src/test/resources/prism/common-core.prism b/infra/axiom/src/test/resources/prism/common-core.prism new file mode 100644 index 00000000000..f8b4f02e6f3 --- /dev/null +++ b/infra/axiom/src/test/resources/prism/common-core.prism @@ -0,0 +1,1216 @@ +// 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. + +// This is "common-core.axiom" file containing core definitions from the common-3 namespace. +// Due to its size the common-3 schema is distributed across multiple files. + +prism:model common-core { + + namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; + version "3.0.0"; + + import prism { + namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; + } + + type Object { + object; + itemName object; + documentation """ + Common supertype for all identity objects. Defines basic properties + that each object must have to live in our system (identifier, name). + + All objects are identified by OID. The OID is an immutable identifier + (usually UUID). Except the OID all the objects have human-readable name. + The name is usually unique for each object type, but this is not a + strict requirement. + + Note: object type is fixed, it cannot be changed. The object retains its + type from the time it was created to the end of its life. + """; + item name { + type PolyString; + documentation """ + Human-readable, mutable name of the object. It + may also be an identifier (login name, group name). + It is usually unique in the respective context of + interpretation. E.g. the name of the UserType subtype + is usually unique in the whole system. + The name of the ShadowType subtype is usually unique in the + scope of resource (target system) that it belongs to. + + The name may not be human-readable in a sense to display + to a common end-user. It is intended to be displayed to + IDM system administrator. Therefore it may contain quite + a "ugly" structures such as LDAP DN or URL. + + Name is mutable. It is considered to be ordinary property + of the object. Therefore it can be changed by invoking + usual modifyObject operations. However, change of the name + may have side effects (rename process). + + Although name is specified as optional by this schema, it + is in fact mandatory for most object types. The reason for + specifying the name as optional is that the name may be + generated by the system instead of supplied by the clients. + However, all objects stored in the repository must have a name. + """; + // ObjectType.name + // 0 + // true + } + + // Note: the description property is referenced from various contexts (e.g. Object and Assignment). + // To avoid duplication we use global property definition. + // item description; // TODO make this work + + // The same is true for documentation. + // item documentation; // TODO make this work + + item subtype { + type string; + maxOccurs unbounded; + documentation """ + Type of the object. It is used to distinguish what a specific object + represents. Whether it is a different kind of organizational unit, project, + team, or different kind of user, etc. + """; + // ObjectType.subtype + // 15 + } + + item fetchResult { + type OperationResult; + documentation """ + Result of the operation that fetched this instance of the object. + It is mostly used to indicate that the object is not complete or + there is some problem with the object. This is used instead of + exception if the object is part of larger structures (lists as in + list/search operations or composite objects). If not present then + the "SUCCESS" state is assumed. + + This field is TRANSIENT. It must only be used in runtime. It should + never be stored in the repository. + """; + // a:operational + } + + // item extension; // TODO make this work + + item trigger { + type Trigger; + maxOccurs unbounded; + documentation """ + Triggers for this object. They drive invocations of corresponding trigger handlers + at specified time. + """; + // a:operational + } + + item parentOrg { // TODO or should we use 'Ref' suffix i.e. 'parentOrgRef'? + type ObjectReference; + maxOccurs unbounded; + documentation """ + Set of the orgs (organizational units, projects, teams) that the object relates to. + This usually means that the object belongs to them but it may have other meanings as well + (e.g. user manages an organizational unit). + """; + // tns:OrgType + // OrgType.parentOrganization + // 240 + // + } + + item tenant { + type ObjectReference; + documentation """ + Reference to the tenant to which this object belongs. It is a computed value set automatically + by midPoint. It is determined from the organizational structure. Even though this value is + computed it is also stored in the repository due to performance reasons. + """; + // tns:OrgType + // OrgType.tenant + // 250 + // true + } + + item lifecycleState { + type string; + documentation """ + Lifecycle state of the object. This property defines whether the + object represents a draft, proposed definition, whether it is active, + deprecated, and so on. + + There are few pre-defined lifecycle states. But custom lifecycle states + may also be defined. Pre-defined lifecycle states are: + + - draft: Definition of the new object in progress. The object is + NOT active. The definition may change at any moment. It is + not ready yet. + - proposed: Definition of a new object is ready for use, but there + is still a review process to be applied (e.g. approval). + The object is NOT active. However the definition should + not change in this state. + - active: Active and working definition. Ready to be used without + any unusual limitations. + - deprecated: Active definition which is being phased out. The + definition is still fully operational. But it should not + be used for new assignments. E.g. it should not be requested, + it should not be approved, etc. + - archived: Inactive historical definition. It is no longer used. + It is maintained only for historical, auditing and + sentimental reasons. + - failed: Unexpected error has occurred during object lifecycle. Result + of that event is that the object is rendered inactive. + The situation cannot be automatically remedied. Manual action + is needed. + """; + // ObjectType.lifecycleState + // 20 + since "3.5"; + // + } + + item operationExecution { + type OperationExecution; + maxOccurs unbounded; + documentation """ + Description of recent operations executed on this object (or related objects, e.g. shadows + in case of a focal object). The number of operations to be kept here is configurable. + """; + since "3.6"; + // true + } + + item lensContext { + type LensContext; + documentation """ + Model context describing executed operation. + """; + since "4.0"; + // true + } + + item policySituation { + type uri; + maxOccurs unbounded; + documentation """ + The policy situation(s) of this object. The situations are result of + evaluation of the policy rules. This property is recorded for each object + and can be used for reporting, diagnostics, target selection in certification + campaigns, etc. + """; + since "3.5"; + // true + } + + item policyException { + type PolicyException; + maxOccurs unbounded; + documentation """ + Recorded exception from a policy rule. The exceptions that are approved are + recoded here to avoid re-evaluating and re-approving them all the time. + This is EXPERIMENTAL functionality. It is likely to change in the near future. + """; + since "3.5"; + // true + } + + item diagnosticInformation { + type DiagnosticInformation; + maxOccurs unbounded; + documentation """ + Diagnostic information attached to this object. + """; + since "4.0"; + // true + } + + // Note that oid and version are not defined here. These are intrinsic parts of prism objects + // so they do not have to be mentioned in the schema. + // TODO: is this OK? See also related questions in ObjectReference type. + } + + type AssignmentHolder { + extends Object; + itemName assignmentHolder; + documentation """ + Abstract supertype for all object types that can have assignments. + """; + + item assignment { + type Assignment; + maxOccurs unbounded; + documentation """ + Set of object's assignments. + Assignments define the privileges and "features" that this object should have, that + this object is entitled to. Typical assignment will point to a role or define + a construction of an account. + + Assignments represent what the object SHOULD HAVE. The assignments represent a policy, + a desired state of things (cf. linkRef). + """; + // FocusType.assignmentKey + } + + item iteration { + type int; // TODO + documentation """ + Iteration number. Starts with 0. It is used to iteratively find unique identifier + for the object. + """; + // true + } + + item iterationToken { + type string; + documentation """ + Iteration token. String value that is usually a suffix to the identifier based + on iteration number. E.g. ".007". It is used to iteratively find unique identifier + for the object. + """; + // true + } + + item archetype { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to all applicable archetypes, including "indirect" archetypes such as archetype supertypes. + Contains references to active archetypes only. + + Note: the value of this reference is only updated when object is recomputed. + Therefore if a role definition changes then all the affected objects must be recomputed + for this reference to be consistent. + + This is an operational property. It is set and managed by the system. It is used + for efficient use of archetypes. + """; + // tns:ArchetypeType + // true + // AssignmentHolderType.archetypeRef + since "4.0"; + } + + item roleMembership { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to abstract roles (roles, orgs, services) that this focus currently belongs to - directly + or indirectly. This reference points to all the roles in the role hierarchy. It only points to + the roles that were evaluated as active during last recompute (conditions were true, validity + constraints not violated). + + Note: the value of this reference is only updated when a focal object is recomputed. + Therefore if a role definition changes then all the affected focal objects must be recomputed + for this reference to be consistent. + + Roles mentioned here are those that are NOT obtained via delegation, i.e. "deputy" relations. + Relations acquired by delegation are listed in delegatedRef item. + + This is an operational property. It is set and managed by the system. It is used + for efficient search of all current role members, e.g. for the purpose of displaying this + information in the GUI. + """; + // tns:AbstractRoleType + // true + // FocusType.roleMembershipRef + } + + item delegated { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to objects (abstract roles as well as users) obtained via delegation. + If A1 is a deputy of A, its delegatedRef contains a union of A, A.roleMembershipRef and + A.delegatedRef. + + This is an operational property. It is set and managed by the system. It is used + for efficient search of all current role members, e.g. for the purpose of displaying this + information in the GUI. + """; + // tns:FocusType + // true + since "3.5"; + } + + item roleInfluence { + type ObjectReference; + maxOccurs unbounded; + documentation """ + References to abstract roles (roles and orgs) that this focus may directly belong to. + This reference only points to the next role in the hierarchy. However, it is backed by + a "closure" index in the repository subsystem. Therefore it can efficiently support tree-like + queries. This reference points to the roles for whose the condition is not true. + Therefore it does not reliably show + who actually has a role. It shows potential role members - all the object that are possibly + influenced when a role definition changes. + + This is an operational property. It is set and managed by the system. It is used + for efficient search of all possible role members, e.g. for the purpose of recomputing + all role members after the role definition is changed. + + TODO. NOT IMPLEMENTED YET. EXPERIMENTAL. UNSTABLE. + """; + // tns:AbstractRoleType + // true + } + } + + type Focus { + extends AssignmentHolder; + itemName focus; + documentation """ + Abstract supertype for all object types that can be focus of full midPoint computation. + This basically means objects that have projections. But focal objects also have + activation, they may have personas, etc. + """; + item link { + type ObjectReference; + maxOccurs unbounded; + documentation """ + Set of shadows (projections) linked to this focal object. + E.g. a set of accounts linked to a user. This is the set of + shadows that belongs to the focal object in a sense + that these shadows represents the focal object on the resource. + E.g. The set of accounts that represent the same midPoint user (the + same physical person, they are "analogous"). + + Links define what the object HAS. The links reflect real state of things + (cf. assignment). + """; + // tns:ShadowType + } + + item persona { + type ObjectReference; + maxOccurs unbounded; + documentation """ + Set of personas linked to this focal object. + E.g. a set of virtual identities linked to a user. This is the set of + "secondary" focal objects that belongs to this focal object in a sense + that the current focal object is in control over the linked focal objects. + E.g. this reference can be used to link user object which specified a physical + person with his virtual identities (personas) that specify his identity as an + employee, system administrator, customer, etc. + The default meaning is that the personas are "analogous", i.e. the represent + different facets of the same physical person. However, this meaning may be + theoretically overridden by using various relation parameters in this reference. + + This reference define what the object HAS. The links reflect real state of + things (cf. assignment). + """; + // tns:FocusType + since "3.6"; + } + + item activation { + type Activation; + } + + item jpegPhoto { + type binary; + documentation """ + Photo corresponding to the user / org / role / service. + """; + // FocusType.jpegPhoto + } + + item costCenter { + type string; + documentation """ + The name, identifier or code of the cost center to which the object belongs. + + Please note that organization objects (OrgType) also have a costCenter property. + Therefore it is usual that if a user belongs to an organization the costCenter from + the organization is used. Therefore this property is usually used only for users that + do not belong to any organization or for users that have different cost center than + the one defined by the organization. + """; + // FocusType.costCenter + // 420 + } + + item locality { + type PolyString; + documentation """ + Primary locality of the object, the place where + the (e.g.) user usually works, the country, city or + building that he belongs to. The specific meaning + and form of this property is deployment-specific. + """; + // FocusType.locality + // 450 + } + + item preferredLanguage { + type string; + documentation """ + Indicates user's preferred language, usually for the purpose of localizing + user interfaces. The format is IETF language tag defined in BCP 47, where + underscore is used as a subtag separator. This is usually a ISO 639-1 two-letter + language code optionally followed by ISO 3166-1 two letter country code + separated by underscore. The languages that do not have country-specific + variants are usually specified by using a two-letter country code ("sk", + "cs", "tr"). Languages with country-specific variants have country-specific + subtags ("pt_BR", "zn_CN"). + If no value is specified in this property then system default locale is assumed. + + Examples: + - en_US + - sk + - cs + - pt_BR + """; + // FocusType.preferredLanguage + // 200 + // + } + + item locale { + type string; + documentation """ + Defines user's preference in displaying currency, dates and other items + related to location and culture. The format is IETF language tag defined in BCP 47, where + underscore is used as a subtag separator. This is usually a ISO 639-1 two-letter + language code optionally followed by ISO 3166-1 two letter country code + separated by underscore. The languages that do not have country-specific + variants are usually specified by using a two-letter country code ("sk", + "cs", "tr"). Languages with country-specific variants have country-specific + subtags ("pt_BR", "zn_CN"). + If not specified then system default locale is assumed. + + Examples: + - en_US + - sk + - cs + - pt_BR + """; + // FocusType.locale + // 210 + // + } + + item timezone { + type string; + documentation """ + User's preferred timezone. It is specified in the "tz database" (a.k.a "Olson") + format. If not specified then system default timezone is assumed. + + Examples: + - Europe/Bratislava + """; + // FocusType.timezone + // 220 + // + } + + item emailAddress { + type string; + documentation """ + E-Mail address of the user, org. unit, etc. This is the address + supposed to be used for communication with the + user, org. unit, etc. E.g. IDM system may send notifications + to the e-mail address. It is NOT supposed to be + full-featured e-mail address data structure + e.g. for the purpose of complex address-book application. + """; + // FocusType.emailAddress + // 300 + } + + item telephoneNumber { + type string; + documentation """ + Primary telephone number of the user, org. unit, etc. + """; + // FocusType.telephoneNumber + // 310 + } + + item credentials { + type Credentials; + documentation """ + The set of focus's credentials (such as passwords). + """; + // FocusType.credentials + } + } + + type User { + extends Focus; + documentation """ + User object represents a physical user of the system. + It differs from the account, as "account" represents a data structure in a target system while + "user" represents data structure in midPoint. One user typically has many accounts. + Properties of User object typically describe the user as a physical person. + Therefore the user object defines handful of properties that are commonly used to describe users + in the IDM solutions (employees, customers, partners, etc.) Custom extensions are possible by utilizing + the "extension" container. + """; + + item fullName { + type PolyString; + documentation """ + Full name of the user with all the decorations, + middle name initials, honorific title and any + other structure that is usual in the cultural + environment that the system operates in. This + element is intended to be displayed to + a common user of the system. + + Examples: + - cpt. Jack Sparrow + - William "Bootstrap" Turner + - James W. Random, PhD. + - Vladimir Iljic Lenin + - Josip Broz Tito + - Chuck Norris + """; + // UserType.fullName + // 100 + // true + } + + item givenName { + type PolyString; + documentation """ + Given name of the user. It is usually the first + name of the user, but the order of names may + differ in various cultural environments. This + element will always contain the name that was + given to the user at birth or was chosen + by the user. + + Examples: + - Jack + - Chuck + """; + // UserType.givenName + // 110 + // true + } + + item familyName { + type PolyString; + documentation """ + Family name of the user. It is usually the last + name of the user, but the order of names may + differ in various cultural environments. This + element will always contain the name that was + inherited from the family or was assigned + to a user by some other means. + + Examples: + - Sparrow + - Norris + """; + // UserType.familyName + // 120 + // true + } + + item additionalName { + type PolyString; + documentation """ + Middle name, patronymic, matronymic or any other name of a person. It is usually the + middle component of the name, however that may be culture-dependent. + + Examples: + - Walker + - John + - Iljic + """; + // UserType.additionalName + // 130 + } + + item nickName { + type PolyString; + documentation """ + Familiar or otherwise informal way to address a person. + + Examples: + - Bootstrap + - Bobby< + + The meaning of this property is to take part in the formatted full + name of the person, e.g. William "Bootstrap" Turner. It is not intended + to be used as a username or login name. This value is usually changeable + by the user itself and it defines how the user wants other to address him. + Therefore it is not ideal for use as an identifier. + """; + // UserType.nickname + // 140 + } + + item honorificPrefix { + type PolyString; + documentation """ + Honorific titles that go before the name. + Examples: + - cpt. + - Ing. + - Sir + + This property is single-valued. If more + than one title is applicable, they have to be represented in + a single string (concatenated) form in the correct order. + """; + // UserType.honorificPrefix + // 150 + } + + item honorificSuffix { + type PolyString; + documentation """ + Honorific titles that go after the name. + + Examples: + - PhD. + - KBE + + This property is single-valued. If more + than one title is applicable, they have to be represented in + a single string (concatenated) form in the correct order. + """; + // UserType.honorificSuffix + // 160 + } + + item title { + type PolyString; + documentation """ + User's title defining a work position or a primary role in the + organization. + Examples: + - CEO + - Security Officer + - Assistant + """; + // UserType.title + // 170 + } + + item employeeNumber { + type string; + documentation """ + Unique, business-oriented identifier of the employee. + Typically used as correlation identifier and for + auditing purposes. Should be immutable, but the + specific properties and usage are deployment-specific. + """; + // UserType.employeeNumber + // 400 + } + + item employeeType { + type string; + maxOccurs unbounded; + documentation """ + Employee type specification such as internal employee, + external or partner. The specific values are + deployment-specific. However it is generally assumed that this + will be enumeration of several type names or codes that define + "classes" of users. + + Even though this property is named "employeeType" due to the historical + reasons it is used in a more generic way to mean general type of user. + Therefore it can be used to distinguish employees from customers, etc. + + DEPRECATED: Use ObjectType.subtype + """; + // UserType.employeeType + // 410 + // true + // 3.8 + } + item organization { + type PolyString; + maxOccurs unbounded; + documentation """ + Name or (preferably) immutable identifier of organization that the user belongs to. + The format is deployment-specific. This property together with organizationalUnit + may be used to provide easy-to-use data about organizational membership of the user. + + This is multi-valued property to allow membership of a user to several + organizations. Please note that midPoint does not maintain ordering in + multi-value properties therefore this is not usable to model a complex + organization hierarchies. Use OrgType instead. + """; + // UserType.organization + // 430 + } + + item organizationalUnit { + type PolyString; + maxOccurs unbounded; + documentation """ + Name or (preferably) immutable identifier of organizational unit that the user belongs to. + The format is deployment-specific. This property together with organization + may be used to provide easy-to-use data about organizational membership of the user. + + This is multi-valued property to allow membership of a user to several + organizational units. Please note that midPoint does not maintain ordering in + multi-value properties therefore this is not usable to model a complex + organization hierarchies. Use OrgType instead. + """; + // UserType.organizationalUnit + // 440 + } + item adminGuiConfiguration { + type AdminGuiConfiguration; + documentation """ + Specifies the admin GUI configuration that should be used + by this user. + """; + since "3.5"; + // AdminGuiConfigurationType.adminGuiConfiguration + } + } + + type ObjectReference { + objectReference; + documentation """ + Reference to an object. It contains OID of the object that it + refers to. + """; + + // item description; // TODO make this work + + // item documentation; // TODO make this work + + item filter { + type SearchFilter; // TODO namespace of "query-3" + documentation """ + Filter that can be used to dynamically lookup the reference OID e.g. during imports. + It must not be used for normal operations. The filter may be stored in the repository + to avoid data loss. But even if it is stored it will not be used beyond initial + import or unless explicitly requested (e.g. by setting resolutionTime). + + Note: The filter will NOT be used if the OID in the reference is set. The OID always takes + precedence. + """; + } + + item resolutionTime { + type EvaluationTime; + // TODO defaultValue "import"; + documentation """ + Definition of the "time" when the reference will be resolved. Resolving the reference means using + the filter to get object(s) or OID(s). + + Import-time resolution means that the reference will be resolved once when the file is imported. + OID will be recorded in the reference and then only the OID will be used to follow the reference. + This is a very efficient method and it is the default. + + Run-time resolution means that the reference will be resolved every time that the reference is + evaluated. This is less efficient but it provides great flexibility as the filter may contain + expressions and therefore the reference target may dynamically change. + """; + } + + item referentialIntegrity { + type ReferentialIntegrity; + // TODO defaultValue "default"; + documentation """ + Definition of the behavior related to non-existence of object with specified target OID. + (Currently supported only at selected places in midPoint.) + """; + since "4.1"; + } + + item targetName { + type PolyString; + documentation """ + Cached name of the target object. + This is a ephemeral value. It is not stored in the repository. + It may be computed at object retrieval time or it may not be present at all. + This is NOT an authoritative information. Setting it or changing it will + not influence the reference meaning. OID is the only authoritative linking + mechanism. + """; + } + + // TODO what about (attributes) oid, type, and relation? + // Should they be listed here even if they are defined in PrismReferenceValue? + // But if not, why should we list filter, resolution time, referential integrity here, + // as they are also defined in PrismReferenceValue. + } + + item description { + type string; + documentation """ + Free-form textual description of the object. It is supposed to describe + the object or a construct that it is attached to. + + This information may be presented to midPoint users, even to ordinary end users. + For example role description may be presented to users when they are selecting + roles to request. Therefore the description should be written in a language that + the users can understand. + + Description is assumed to be a plan, non-formatted text. + Amount of white space is considered insignificant. E.g. leading and trailing + white space may be skipped, multiple spaces can be collapsed to one and so on. + """; + // ObjectType.description + // 10 + } + + item documentation { + type string; + documentation """ + Technical documentation for a particular object or construct. + + The purpose of this element is to document system configuration and behavior. + The documentation will not be presented to end users. In fact, it will probably + not be presented at all in midPoint user interface. This documentation element + is supposed to be a part of the technical documentation of midPoint deployment. + The tools than generate deployment configuration will look for these elements + and combine them to compiled documentation document. + + AsciiDoc formatting is assumed for this element. Any leading or trailing + whitespace is skipped. Indentation equivalent to he indentation of the first + non-blank line of text is also skipped. + """; + // ObjectType.documentation + // 11 + } + + // Example of short version of container definition. + container { + name Assignment; + itemName assignment; + + // item description; // TODO make this work + // item documentation; // TODO make this work + // item extension; // TODO make this work + + // ... + } + + container { + name Extension; + itemName extension; + documentation """ + Extension container that provides generic extensibility mechanism. + Almost any extension property can be placed in this container. + This mechanism is used to extend objects with new properties. + The extension is treated exactly the same as other object + properties by the code (storage, modifications, etc), except + that the system may not be able to understand their meaning. + """; + // ObjectType.extension + // 1000 + } + + object GenericObject { + extends Focus; + itemName genericObject; + documentation """ + Generic object for storing unknown (unexpected) object types. + + The generic object should be used if there is a need to + store a custom object (e.g KangarooType) at deployment-time. + The properties of such custom objects are to be placed in the + extension part of this object. The schema is not checked or + enforced for this type of objects if technically possible. + """; + item objectType { + type uri; // TODO + // deprecated + } + } + + container Trigger { + itemName trigger; + documentation """ + Defines triggers for an object. Trigger is an action that should take place + at specified time or under some other condition. + """; + item timestamp { + type dateTime; // TODO + documentation """ + The time when a trigger needs to be activated. + """; + } + item handlerUri { + type uri; // TODO + documentation """ + Handler URI indirectly specifies which class is responsible to handle the task. The handler will + to be used to handle trigger activation. + """; + } + item originDescription { + type string; + documentation """ + Short description of trigger origin, e.g. name of the mapping. + Used for diagnostic purposes. + """; + // true + since "4.0"; + } + item extension { // TODO + type Extension; + documentation """ + Extension container used to provide additional situation-specific information to the trigger. + """; + } + } + + container Metadata { + itemName metadata; + documentation """ + Meta-data about data creation, modification, etc. + It may apply to objects but also parts of the object (e.g. assignments). + + Meta-data only apply to successful operations. That is obvious for create, but it also applies + to modify. For obvious reasons there are no metadata about delete. + We keep no metadata about reading. That would be a huge performance hit. + + Meta-data only describe the last operation of its kind. E.g. there is a record of last + modification, last approval, etc. There is no history. The last operation overwrites data + about the previous operation. + + These data are informational only. They should not be used for security purposes (use auditing + subsystem for that). But presence of metadata simplifies system administration and may provide + some basic information "at the glance" which may be later confirmed by the audit logs. + + Meta-data are also supposed to be searchable. Therefore they may be used to quickly find + "candidate" objects for a closer examination. + """; + // true + // + // Metadata + + item requestTimestamp { + type dateTime; + documentation """ + The timestamp of "create" operation request. It is set once and should never be changed. + + In case of "background" processes to create object (e.g. create with approval) + this should be the timestamp when the process started. I.e. the timestamp when + the operation was requested. + """; + // MetadataType.requestTimestamp + // true + since "3.5"; + // + } + + item requestor { + type ObjectReference; + documentation """ + Reference to the user that requested the "create" operation for this object or assignment. + """; + // MetadataType.requestorRef + // true + // tns:UserType + // + } + + item requestorComment { + type string; + documentation """ + Comment of the user that requested the "create" operation for this object or assignment. + """; + // MetadataType.requestorComment + // true + since "3.7"; + } + + item createTimestamp { + type dateTime; + documentation """ + The timestamp of data creation. It is set once and should never be changed. + + In case of "background" processes to create object (e.g. create with approval) + this should be the timestamp when the process ended. I.e. the timestamp when + the operation was executed. + """; + // MetadataType.createTimestamp + // true + // true + since "3.5"; + } + + item creator { + type ObjectReference; + maxOccurs unbounded; + documentation """ + Reference to the user that approved the creation of the data (if there was such a user). + This is multi-value reference therefore multiple approvers may be recorded. However the order and + hierarchy of the approvers is lost. + """; + // MetadataType.createApproverRef + // true + // true + // tns:UserType + } + + item createApproverComment { + type string; + maxOccurs unbounded; + documentation """ + Comments of the approvers during the creation of the data. Note that these comments are in no + particular order, so basically it is not known who entered which comment. + """; + // MetadataType.createApprovalComment + // true + since "3.7"; + } + + item createApprovalTimestamp { + type dateTime; + documentation """ + The timestamp of creation approval. + """; + // MetadataType.createApprovalTimestamp + // true + since "3.5"; + } + + item createChannel { + type uri; + documentation """ + Channel in which the object was created. + """; + // MetadataType.createChannel + // true + // true + } + + item createTask { + type ObjectReference; + documentation """ + Reference to the task that created the object (if it was a persistent one). + """; + // MetadataType.createTaskRef + // true + // tns:TaskType + since "3.7"; + } + + item modifyTimestamp { + type dateTime; + // MetadataType.modifyTimestamp + // true + // true + } + + item modifier { + type ObjectReference; + // MetadataType.modifierRef + // true + // true + // tns:UserType + } + + item modifyApprover { + type ObjectReference; + maxOccurs unbounded; + // MetadataType.modifyApproverRef + // true + // true + // tns:UserType + } + + item modifyApprovalComment { + type string; + maxOccurs unbounded; + // MetadataType.modifyApprovalComment + // true + since "3.7"; + } + + item modifyChannel { + type uri; + // MetadataType.modifyChannel + // true + // true + } + + item modifyTask { + type ObjectReference; + // MetadataType.modifyTaskRef + // true + // tns:TaskType + since "3.7"; + } + + item lastProvisioningTimestamp { + type dateTime; + // MetadataType.lastProvisioningTimestamp + // true + since "3.6.1"; + } + + item certificationFinishedTimestamp { + type dateTime; + // MetadataType.certificationFinishedTimestamp + // true + since "3.7"; + } + + item certificationOutcome { + type string; + // MetadataType.certificationOutcome + // true + since "3.7"; + } + + item certifier { + type ObjectReference; + // MetadataType.certifierRef + // true + // tns:UserType + since "3.7"; + } + + item certifierComment { + type string; + maxOccurs unbounded; + // MetadataType.certifierComment + // true + since "3.7"; + } + + item originMappingName { + type string; + // MetadataType.originMappingName + // true + since "3.7"; + } + } + + // axiom + + // types-3 + type PolyString; + + // query-3 + type SearchFilter; + type EvaluationTime; + type ReferentialIntegrity; + + // ??? + // type Extension; + + // common-3 + type OperationResult; + type OperationExecution; + type LensContext; + type PolicyException; + type DiagnosticInformation; + type Credentials; + type AdminGuiConfiguration; + type Activation; + + // should exist because of "container XXX" + // Already defined + // type Trigger; + // type Assignment; + +} diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom new file mode 100644 index 00000000000..9b87afeab98 --- /dev/null +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -0,0 +1,79 @@ +model prism { + + namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; + + import axiom { + namespace "https://ns.evolveum.com/axiom/language"; + } + + root model { + documentation """ + Axiom Model + + Declares a new axiom model. + """; + type PrismModel; + } + + type PrismModel { + extends axiom:AxiomModel; + + + } + + extension PrismDefinition { + target axiom:AxiomModel; + // TODO move to prism schema; consider renaming to objectType? + item object { + type PrismObjectDefinition; + } + + // TODO move to prism schema; consider renaming to containerType? + item container { + type PrismContainerDefinition; + } + + // TODO move to prism schema; consider renaming to referenceType? + item reference { + type PrismReferenceDefinition; + } + } + + extension PrismTypeDefinitionAnnotation { + target axiom:AxiomTypeDefinition; + // TODO move to prism schema + item object { + type boolean; + } + + // TODO move to prism schema + item container { + type boolean; + } + // TODO move to prism schema + item objectReference { + type boolean; + } + } + + type PrismTypeDefinition { + extends axiom:AxiomTypeDefinition; + } + + type PrismObjectDefinition { + extends PrismTypeDefinition; + } + + type PrismContainerDefinition { + extends PrismTypeDefinition; + } + + type PrismReferenceDefinition { + extends PrismTypeDefinition; + } + + type PrismItemDefinition { + extends PrismTypeDefinition; + } + +} From a9a6280ac02012ff886b1faa9fa757e354980137 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 25 May 2020 13:31:03 +0200 Subject: [PATCH 23/60] Axiom: Moved Lookup to separate class Signed-off-by: Tony Tkacik --- .../evolveum/axiom/api/AxiomIdentifier.java | 10 +- .../lang/antlr/AbstractAxiomAntlrVisitor.java | 133 ++++++++++++++++++ .../lang/antlr/AxiomAntlrStatementSource.java | 2 +- .../axiom/lang/antlr/AxiomAntlrVisitor.java | 114 ++------------- .../axiom/lang/antlr/AxiomAntlrVisitor2.java | 39 +++++ .../lang/antlr/AxiomModelStatementSource.java | 4 +- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 6 + .../evolveum/axiom/lang/api/AxiomItem.java | 5 + .../axiom/lang/api/AxiomItemDefinition.java | 24 ++++ .../axiom/lang/api/AxiomItemStream.java | 11 +- .../lang/api/DelegatedItemDefinition.java | 72 ++++++++++ .../axiom/lang/impl/AxiomStatementRule.java | 2 + .../axiom/lang/impl/BasicStatementRule.java | 33 +++-- .../axiom/lang/impl/ModelReactorContext.java | 8 +- .../axiom/lang/impl/RuleContextImpl.java | 8 +- ...eContextImpl.java => ValueActionImpl.java} | 77 ++-------- .../axiom/lang/impl/ValueContext.java | 109 +++++++++++++- .../spi/AxiomIdentifierDefinitionImpl.java | 2 +- .../lang/spi/AxiomItemStreamTreeBuilder.java | 22 +-- .../axiom/lang/test/TestAxiomPrism.java | 50 +++++++ .../axiom/lang/test/TestTypeDerivation.java | 50 +++++++ .../multimodel/derived/base-person.axiom | 10 ++ .../multimodel/derived/derived-person.axiom | 19 +++ 23 files changed, 585 insertions(+), 225 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java rename infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/{StatementRuleContextImpl.java => ValueActionImpl.java} (53%) create mode 100644 infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java create mode 100644 infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java create mode 100644 infra/axiom/src/test/resources/multimodel/derived/base-person.axiom create mode 100644 infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java index f878f024c1a..2cb43befb49 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java @@ -6,8 +6,6 @@ */ package com.evolveum.axiom.api; -import java.util.Objects; - import com.google.common.base.Preconditions; public class AxiomIdentifier { @@ -21,11 +19,11 @@ public AxiomIdentifier(String namespace, String localName) { this.localName = Preconditions.checkNotNull(localName, "localName"); } - public String getNamespace() { + public String namespace() { return namespace; } - public String getLocalName() { + public String localName() { return localName; } @@ -71,4 +69,8 @@ public static AxiomIdentifier from(String namespace, String localName) { return new AxiomIdentifier(namespace, localName); } + public boolean sameNamespace(AxiomIdentifier other) { + return this.namespace().equals(other.namespace()); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java new file mode 100644 index 00000000000..3cf4725cd8a --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java @@ -0,0 +1,133 @@ +/* + * 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.antlr; + +import java.util.Optional; +import java.util.Set; + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.Token; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; +import com.evolveum.axiom.lang.api.AxiomItemStream; +import com.evolveum.axiom.lang.spi.SourceLocation; + +public abstract class AbstractAxiomAntlrVisitor extends AxiomBaseVisitor { + + private final Optional> limit; + private final String sourceName; + + public AbstractAxiomAntlrVisitor(String name, Set limit) { + this.sourceName = name; + this.limit = Optional.ofNullable(limit); + } + + private AxiomIdentifier statementIdentifier(IdentifierContext identifier) { + String prefix = nullableText(identifier.prefix()); + String localName = identifier.localIdentifier().getText(); + return resolveItemName(prefix, localName); + } + + + protected abstract AxiomItemStream.Target delegate(); + protected abstract AxiomIdentifier resolveItemName(String prefix, String localName); + protected abstract AxiomIdentifier resolveArgument(String prefix, String localName); + + private String nullableText(ParserRuleContext prefix) { + return prefix != null ? prefix.getText() : null; + } + + @Override + public final T visitStatement(StatementContext ctx) { + AxiomIdentifier identifier = statementIdentifier(ctx.identifier()); + if(canEmit(identifier)) { + SourceLocation start = sourceLocation(ctx.identifier().start); + delegate().startItem(identifier, start); + + ArgumentContext argument = ctx.argument(); + final Object value; + final SourceLocation valueStart; + if(argument != null) { + value = convert(argument); + valueStart = sourceLocation(argument.start); + } else { + value = null; + valueStart = start; + } + delegate().startValue(value, valueStart); + T ret = super.visitStatement(ctx); + delegate().endValue(sourceLocation(ctx.stop)); + delegate().endItem(sourceLocation(ctx.stop)); + return ret; + } + return defaultResult(); + } + + private Object convert(ArgumentContext ctx) { + if (ctx.identifier() != null) { + return (convert(ctx.identifier())); + } else { + return (convert(ctx.string())); + } + } + + private boolean canEmit(AxiomIdentifier identifier) { + if (limit.isPresent()) { + return limit.get().contains(identifier); + } + return true; + } + + @Override + public final T visitArgument(ArgumentContext ctx) { + + return defaultResult(); + } + + private AxiomIdentifier convert(IdentifierContext argument) { + return argumentIdentifier(argument); + } + + private AxiomIdentifier argumentIdentifier(IdentifierContext identifier) { + String prefix = nullableText(identifier.prefix()); + String localName = identifier.localIdentifier().getText(); + return resolveArgument(prefix, localName); + } + + + private SourceLocation sourceLocation(Token start) { + return SourceLocation.from(sourceName, start.getLine(), start.getCharPositionInLine()); + } + + static String convert(StringContext string) { + if(string.singleQuoteString() != null) { + return convertSingleQuote(string.singleQuoteString().getText()); + } + if(string.doubleQuoteString() != null) { + return covertDoubleQuote(string.doubleQuoteString().getText()); + } + return convertMultiline(string.multilineString().getText()); + } + + private static String convertSingleQuote(String text) { + int stop = text.length(); + return text.substring(1, stop - 1); + } + + private static String covertDoubleQuote(String text) { + int stop = text.length(); + return text.substring(1, stop - 1); + } + + private static String convertMultiline(String text) { + return text.replace("\"\"\"", ""); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index 7f364170ab3..545394284e1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -60,7 +60,7 @@ protected final StatementContext root() { return root; } - public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Listener listener, + public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Target listener, Optional> emitOnly) { AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, statements, arguments, listener, emitOnly.orElse(null)); visitor.visit(root); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index 2e6c603a1e4..a2ce03b78cd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -6,130 +6,40 @@ */ package com.evolveum.axiom.lang.antlr; -import java.util.Optional; import java.util.Set; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.Token; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; -import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; -import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; -import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; import com.evolveum.axiom.lang.api.AxiomItemStream; +import com.evolveum.axiom.lang.api.AxiomItemStream.Target; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.SourceLocation; -public class AxiomAntlrVisitor extends AxiomBaseVisitor { +public class AxiomAntlrVisitor extends AbstractAxiomAntlrVisitor { private final AxiomIdentifierResolver statements; private final AxiomIdentifierResolver arguments; - private final AxiomItemStream.Listener delegate; - private final Optional> limit; - private final String sourceName; + private final AxiomItemStream.Target delegate; - public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Listener delegate, + public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Target delegate, Set limit) { - this.sourceName = name; + super(name, limit); this.statements = statements; this.arguments = arguments; this.delegate = delegate; - this.limit = Optional.ofNullable(limit); - } - - private AxiomIdentifier statementIdentifier(IdentifierContext identifier) { - String prefix = nullableText(identifier.prefix()); - String localName = identifier.localIdentifier().getText(); - return statements.resolveIdentifier(prefix, localName); - } - - private String nullableText(ParserRuleContext prefix) { - return prefix != null ? prefix.getText() : null; - } - - @Override - public T visitStatement(StatementContext ctx) { - AxiomIdentifier identifier = statementIdentifier(ctx.identifier()); - if(canEmit(identifier)) { - SourceLocation start = sourceLocation(ctx.identifier().start); - delegate.startItem(identifier, start); - - ArgumentContext argument = ctx.argument(); - final Object value; - final SourceLocation valueStart; - if(argument != null) { - value = convert(argument); - valueStart = sourceLocation(argument.start); - } else { - value = null; - valueStart = start; - } - delegate.startValue(value, valueStart); - T ret = super.visitStatement(ctx); - delegate.endValue(sourceLocation(ctx.stop)); - delegate.endItem(sourceLocation(ctx.stop)); - return ret; - } - return defaultResult(); - } - - private Object convert(ArgumentContext ctx) { - if (ctx.identifier() != null) { - return (convert(ctx.identifier())); - } else { - return (convert(ctx.string())); - } - } - - private boolean canEmit(AxiomIdentifier identifier) { - if (limit.isPresent()) { - return limit.get().contains(identifier); - } - return true; } @Override - public T visitArgument(ArgumentContext ctx) { - - return defaultResult(); - } - - private AxiomIdentifier convert(IdentifierContext argument) { - return argumentIdentifier(argument); - } - - private AxiomIdentifier argumentIdentifier(IdentifierContext identifier) { - String prefix = nullableText(identifier.prefix()); - String localName = identifier.localIdentifier().getText(); + protected AxiomIdentifier resolveArgument(String prefix, String localName) { return arguments.resolveIdentifier(prefix, localName); } - private SourceLocation sourceLocation(Token start) { - return SourceLocation.from(sourceName, start.getLine(), start.getCharPositionInLine()); - } - - static String convert(StringContext string) { - if(string.singleQuoteString() != null) { - return convertSingleQuote(string.singleQuoteString().getText()); - } - if(string.doubleQuoteString() != null) { - return covertDoubleQuote(string.doubleQuoteString().getText()); - } - return convertMultiline(string.multilineString().getText()); - } - - private static String convertSingleQuote(String text) { - int stop = text.length(); - return text.substring(1, stop - 1); - } - - private static String covertDoubleQuote(String text) { - int stop = text.length(); - return text.substring(1, stop - 1); + @Override + protected AxiomIdentifier resolveItemName(String prefix, String localName) { + return statements.resolveIdentifier(prefix, localName); } - private static String convertMultiline(String text) { - return text.replace("\"\"\"", ""); + @Override + protected Target delegate() { + return delegate; } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java new file mode 100644 index 00000000000..80314bef755 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java @@ -0,0 +1,39 @@ +/* + * 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.antlr; + +import java.util.Set; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItemStream; +import com.evolveum.axiom.lang.api.AxiomItemStream.Target; + +public class AxiomAntlrVisitor2 extends AbstractAxiomAntlrVisitor { + + private final AxiomItemStream.TargetWithResolver delegate; + + public AxiomAntlrVisitor2(String name, AxiomItemStream.TargetWithResolver delegate, + Set limit) { + super(name, limit); + this.delegate = delegate; + } + + @Override + protected AxiomIdentifier resolveArgument(String prefix, String localName) { + return delegate.valueResolver().resolveIdentifier(prefix, localName); + } + + @Override + protected AxiomIdentifier resolveItemName(String prefix, String localName) { + return delegate.itemResolver().resolveIdentifier(prefix, localName); + } + + @Override + protected Target delegate() { + return delegate; + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 365fc2713ca..43eb47626c7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -63,11 +63,11 @@ public String namespace() { return namespace; } - public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Listener listener) { + public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Target listener) { stream(resolver, listener, Optional.empty()); } - public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Listener listener, + public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Target listener, Optional> emitOnly) { stream(resolver.or(this), BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index e85311840aa..30afd80eabd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -261,6 +261,12 @@ public Optional argument() { return Optional.empty(); } + @Override + public String toString() { + // TODO Auto-generated method stub + return "typedef " + name(); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java index 7d03297a256..c156b6550ce 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java @@ -1,6 +1,7 @@ package com.evolveum.axiom.lang.api; import java.util.Collection; +import java.util.Collections; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; @@ -25,4 +26,8 @@ static AxiomItem from(AxiomItemDefinition def, Collection AxiomItem from(AxiomItemDefinition def, AxiomItemValue value) { + return AxiomItemImpl.from(def, Collections.singleton(value)); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java index 7d7084fe85d..1f1d08495c7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java @@ -37,8 +37,32 @@ static String toString(AxiomItemDefinition def) { .toString(); } + static AxiomItemDefinition derived(AxiomIdentifier name , AxiomItemDefinition source) { + return new DelegatedItemDefinition() { + + @Override + protected AxiomItemDefinition delegate() { + return source; + } + + @Override + public AxiomIdentifier name() { + return name; + } + }; + } + static IdentifierSpaceKey identifier(AxiomIdentifier name) { return IdentifierSpaceKey.from(ImmutableMap.of(NAME, name)); } + interface Derived extends AxiomItemDefinition { + + AxiomItemDefinition original(); + + } + + default AxiomItemDefinition derived(AxiomIdentifier name) { + return derived(name, this); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java index e42949d602c..712c9a5c3af 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java @@ -1,14 +1,23 @@ package com.evolveum.axiom.lang.api; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.SourceLocation; public interface AxiomItemStream { - interface Listener { + interface Target { void startItem(AxiomIdentifier item, SourceLocation loc); void startValue(Object value, SourceLocation loc); void endValue(SourceLocation loc); void endItem(SourceLocation loc); } + + interface TargetWithResolver extends Target { + + AxiomIdentifierResolver itemResolver(); + AxiomIdentifierResolver valueResolver(); + + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java new file mode 100644 index 00000000000..e4ffe3f63d2 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java @@ -0,0 +1,72 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Collection; +import java.util.Optional; + +import com.evolveum.axiom.api.AxiomIdentifier; + +abstract class DelegatedItemDefinition implements AxiomItemDefinition { + + protected abstract AxiomItemDefinition delegate(); + + @Override + public Optional type() { + return delegate().type(); + } + + @Override + public Collection> items() { + return delegate().items(); + } + + @Override + public AxiomIdentifier name() { + return delegate().name(); + } + + @Override + public String documentation() { + return delegate().documentation(); + } + + @Override + public Optional> item(AxiomItemDefinition def) { + return delegate().item(def); + } + + @Override + public Optional> item(AxiomIdentifier name) { + return delegate().item(name); + } + + @Override + public AxiomItemDefinition get() { + return this; + } + + @Override + public AxiomTypeDefinition typeDefinition() { + return delegate().typeDefinition(); + } + + @Override + public boolean required() { + return delegate().required(); + } + + @Override + public int minOccurs() { + return delegate().minOccurs(); + } + + @Override + public int maxOccurs() { + return delegate().maxOccurs(); + } + + @Override + public String toString() { + return AxiomItemDefinition.toString(this); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index 58f320d9d93..6fa978895d4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -43,7 +43,9 @@ default AxiomTypeDefinition typeDefinition() { boolean isMutable(); + Lookup parentValue(); + AxiomSemanticException error(String message, Object... arguments); } interface ActionBuilder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 28c5d38d27d..d60e2d71264 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -7,6 +7,7 @@ import java.util.Optional; import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; @@ -19,6 +20,8 @@ import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.Dependency.Search; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -66,8 +69,8 @@ public void apply(Lookup context, ActionBuilder>> components = new HashMap<>(); for(AxiomItemDefinition cmp : idDef.components()) { components.put(cmp.name(), action.require(context.child(cmp, Object.class)) - .map(v -> v.onlyValue()) - .unsatisfied(()-> action.error("Item '%s' is required by identifier, but not defined.", cmp.name()))); + .unsatisfied(()-> context.error("Item '%s' is required by identifier, but not defined.", cmp.name())) + .map(v -> v.onlyValue())); } identReq.put(idDef, components); } @@ -109,17 +112,20 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { AxiomIdentifier type = context.originalValue(); + Dependency> typeName = action.require(context.parentValue().child(Item.NAME, AxiomIdentifier.class)) + .unsatisfied(() -> action.error("type does not have name defined")); Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); + typeDef.notFound(() -> action.error("type '%s' was not found.", type)); typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); action.apply(superTypeValue -> { superTypeValue.replace(typeDef.get()); - addFromType(typeDef.get(), superTypeValue.parentValue()); + addFromType(typeDef.get(), superTypeValue.parentValue(), typeName.get().onlyValue().get().namespace()); }); } @@ -238,17 +244,26 @@ private static IdentifierSpaceKey namespaceId(String uri) { return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); } - public static void addFromType(AxiomItemValue source, AxiomValueContext target) { - AxiomItemValue superType = source; + public static void addFromType(AxiomItemValue source, AxiomValueContext target, String targetNamespace) { + AxiomTypeDefinition superType = (AxiomTypeDefinition) source.get(); + Preconditions.checkState(!(superType instanceof AxiomBuiltIn.Type)); // FIXME: Add namespace change if necessary // Copy Identifiers Optional> identifiers = superType.item(Item.IDENTIFIER_DEFINITION); if(identifiers.isPresent()) { target.mergeItem(identifiers.get()); }// Copy Items - Optional> items = superType.item(Item.ITEM_DEFINITION); - if(items.isPresent()) { - target.mergeItem(items.get()); + Collection itemDefs = ImmutableList.copyOf(superType.itemDefinitions().values()); + + for (AxiomItemDefinition item : superType.itemDefinitions().values()) { + final AxiomIdentifier derivedName; + if (!item.name().namespace().equals(targetNamespace) && item.name().sameNamespace(superType.name())) { + derivedName = AxiomIdentifier.from(targetNamespace, item.name().localName()); + } else { + derivedName = item.name(); + } + AxiomItemDefinition derived = item.derived(derivedName); + target.mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, derived)); } } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 1717a4da506..c9c65776459 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -35,7 +35,7 @@ import org.jetbrains.annotations.Nullable; public class ModelReactorContext extends - RuleReactorContext, StatementRuleContextImpl, RuleContextImpl> + RuleReactorContext, ValueActionImpl, RuleContextImpl> implements AxiomIdentifierResolver { private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); @@ -116,9 +116,9 @@ public AxiomSchemaContext computeSchemaContext() throws AxiomSemanticException { } @Override - protected void failOutstanding(Collection> outstanding) throws AxiomSemanticException { + protected void failOutstanding(Collection> outstanding) throws AxiomSemanticException { StringBuilder messages = new StringBuilder("Can not complete models, following errors occured:\n"); - for (StatementRuleContextImpl rule : outstanding) { + for (ValueActionImpl rule : outstanding) { Exception exception = rule.errorMessage(); messages.append("Rule: ").append(rule.name()).append("\n"); if (exception != null) { @@ -143,7 +143,7 @@ public IdentifierSpaceHolderImpl space() { } @Override - protected void addOutstanding(StatementRuleContextImpl action) { + protected void addOutstanding(ValueActionImpl action) { super.addOutstanding(action); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java index 5924cd6edde..7950b5cf1ce 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleContextImpl.java @@ -4,7 +4,7 @@ import com.evolveum.axiom.reactor.Rule; -public class RuleContextImpl implements Rule, StatementRuleContextImpl> { +public class RuleContextImpl implements Rule, ValueActionImpl> { private final AxiomStatementRule delegate; @@ -19,9 +19,9 @@ public boolean applicableTo(ValueContext context) { } @Override - public Collection> applyTo(ValueContext context) { - StatementRuleContextImpl actionBuilder = context.addAction(delegate.name()); - delegate.apply(actionBuilder, actionBuilder); + public Collection> applyTo(ValueContext context) { + ValueActionImpl actionBuilder = context.addAction(delegate.name()); + delegate.apply(context.getLookup(), actionBuilder); return actionBuilder.build(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java similarity index 53% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java index 355206e3636..175a7de0ee3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/StatementRuleContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java @@ -7,17 +7,13 @@ import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemValue; -import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.DependantAction; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; -public class StatementRuleContextImpl implements AxiomStatementRule.Lookup, AxiomStatementRule.ActionBuilder, DependantAction { +public class ValueActionImpl implements AxiomStatementRule.ActionBuilder, DependantAction { private final ValueContext context; private final String rule; @@ -27,33 +23,12 @@ public class StatementRuleContextImpl implements AxiomStatementRule.Lookup private boolean applied = false; private Exception error; - public StatementRuleContextImpl(ValueContext context, String rule) { + public ValueActionImpl(ValueContext context, String rule) { this.context = context; this.rule = rule; } - @Override - public Dependency.Search> global(AxiomIdentifier space, - IdentifierSpaceKey key) { - return Dependency.retriableDelegate(() -> { - ValueContext maybe = context.lookup(space, key); - if(maybe != null) { - return (Dependency) maybe; - } - return null; - }); - } - @Override - public Dependency.Search> namespaceValue(AxiomIdentifier space, - IdentifierSpaceKey key) { - return Dependency.retriableDelegate(() -> { - ValueContext maybe = context.lookup(space, key); - if(maybe != null) { - return (Dependency) maybe; - } - return null; - }); - } + @Override public > X require(X req) { @@ -62,7 +37,7 @@ public > X require(X req) { } @Override - public StatementRuleContextImpl apply(AxiomStatementRule.Action action) { + public ValueActionImpl apply(AxiomStatementRule.Action action) { this.action = action; context.dependsOnAction(this); return this; @@ -104,10 +79,6 @@ public String toString() { return context.toString() + ":" + rule; } - @Override - public Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { - return (context.rootImpl().requireNamespace(name, namespaceId)); - } @Override public boolean successful() { @@ -138,62 +109,30 @@ public boolean isDefined() { return action != null; } - public Collection> build() { + public Collection> build() { if(action != null) { return ImmutableList.of(this); } return Collections.emptyList(); } - @Override - public AxiomItemDefinition itemDefinition() { - return context.parent().definition(); - } - @Override - public Dependency> modify(AxiomIdentifier space, IdentifierSpaceKey key) { - return (Dependency.retriableDelegate(() -> { - ValueContext maybe = context.lookup(space, key); - if(maybe != null) { - maybe.addDependency(StatementRuleContextImpl.this); - return Dependency.immediate(maybe); - } - return null; - })); - } @Override public Dependency> require(AxiomValueContext ext) { return require((Dependency>) ext); } - @Override - public boolean isMutable() { - return context.isMutable(); - } + @Override public AxiomSemanticException error(String message, Object... arguments) { return new AxiomSemanticException(context.startLocation() + Strings.lenientFormat(message, arguments)); } - @Override - public Dependency> child(AxiomItemDefinition namespace, Class valueType) { - return (context.requireChild(namespace.name())); - } - @Override - public V currentValue() { - return context.currentValue(); - } - @Override - public Dependency finalValue() { - return context.map(v -> v.get()); - } + public String name() { return rule; } - @Override - public V originalValue() { - return context.originalValue; - } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 975eb671887..373160bc2f6 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -9,26 +9,32 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; +import com.evolveum.axiom.lang.impl.AxiomStatementRule.Lookup; import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + import java.util.Collection; import java.util.HashSet; import java.util.Optional; import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.SourceLocation; public class ValueContext extends AbstractContext> implements AxiomValueContext, ValueBuilder, Dependency> { private Dependency> result; - V originalValue; - Collection> dependencies = new HashSet<>(); + private final LookupImpl lookup = new LookupImpl(); + private final V originalValue; + private final Collection> dependencies = new HashSet<>(); public ValueContext(SourceLocation loc, IdentifierSpaceHolder space) { super(null, loc, space); result = new Result(null,null); + originalValue = null; } public ValueContext(ItemContext itemContext, V value, SourceLocation loc) { @@ -42,6 +48,10 @@ public AxiomIdentifier name() { return parent().name(); } + public LookupImpl getLookup() { + return lookup; + } + @Override public Optional childDef(AxiomIdentifier statement) { return parent().type().itemDefinition(statement); @@ -86,8 +96,8 @@ public AxiomItemDefinition itemDefinition() { return parent().definition(); } - public StatementRuleContextImpl addAction(String name) { - return new StatementRuleContextImpl<>(this, name); + public ValueActionImpl addAction(String name) { + return new ValueActionImpl<>(this, name); } protected ItemContext createItem(AxiomIdentifier id, SourceLocation loc) { @@ -188,7 +198,7 @@ public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key) @Override public ActionBuilder newAction(String name) { - return new StatementRuleContextImpl(this, name); + return new ValueActionImpl(this, name); } @Override @@ -196,7 +206,7 @@ public AxiomRootContext root() { return parent().rootImpl(); } - public void dependsOnAction(StatementRuleContextImpl action) { + public void dependsOnAction(ValueActionImpl action) { addDependency(action); } @@ -221,10 +231,95 @@ public boolean isMutable() { @Override public String toString() { - return new StringBuffer().append(parent().definition().name().getLocalName()) + return new StringBuffer().append(parent().definition().name().localName()) .append(" ") .append(originalValue != null ? originalValue : "") .toString(); } + private class LookupImpl implements Lookup { + + @Override + public AxiomItemDefinition itemDefinition() { + return parent().definition(); + } + + @Override + public Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + return rootImpl().requireNamespace(name, namespaceId); + } + + @Override + public Dependency> child(AxiomItemDefinition name, Class valueType) { + return requireChild(name.name()); + } + + @Override + public Dependency> modify(AxiomIdentifier space, IdentifierSpaceKey key) { + return (Dependency.retriableDelegate(() -> { + ValueContext maybe = lookup(space, key); + if(maybe != null) { + //maybe.addDependency(this); + return Dependency.immediate(maybe); + } + return null; + })); + } + + @Override + public Dependency.Search> global(AxiomIdentifier space, + IdentifierSpaceKey key) { + return Dependency.retriableDelegate(() -> { + ValueContext maybe = lookup(space, key); + if(maybe != null) { + return (Dependency) maybe; + } + return null; + }); + } + + + @Override + public Dependency.Search> namespaceValue(AxiomIdentifier space, + IdentifierSpaceKey key) { + return Dependency.retriableDelegate(() -> { + ValueContext maybe = lookup(space, key); + if(maybe != null) { + return (Dependency) maybe; + } + return null; + }); + } + + @Override + public Dependency finalValue() { + return map(v -> v.get()); + } + + @Override + public V currentValue() { + return ValueContext.this.currentValue(); + } + + @Override + public V originalValue() { + return originalValue; + } + + @Override + public boolean isMutable() { + return ValueContext.this.isMutable(); + } + + @Override + public Lookup parentValue() { + return parent().parent().getLookup(); + } + + @Override + public AxiomSemanticException error(String message, Object... arguments) { + return new AxiomSemanticException(startLocation() + " " + Strings.lenientFormat(message, arguments)); + } + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index c613afd4514..ca51b3ae288 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -25,7 +25,7 @@ public class AxiomIdentifierDefinitionImpl extends ItemValueImpl> items) { super(axiomItemDefinition, value, items); - this.scope = AxiomIdentifierDefinition.scope(this.item(Item.ID_SCOPE.name()).get().onlyValue().get().getLocalName()); + this.scope = AxiomIdentifierDefinition.scope(this.item(Item.ID_SCOPE.name()).get().onlyValue().get().localName()); this.space = this.item(Item.ID_SPACE.name()).get().onlyValue().get(); ImmutableList.Builder components = ImmutableList.builder(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java index 6faabd78881..c37afa12e30 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java @@ -10,14 +10,12 @@ import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemStream; -import com.evolveum.axiom.lang.api.AxiomItemValue; import com.google.common.base.Preconditions; -public class AxiomItemStreamTreeBuilder implements AxiomItemStream.Listener { +public class AxiomItemStreamTreeBuilder implements AxiomItemStream.Target { private final Deque queue = new LinkedList<>(); @@ -86,22 +84,4 @@ public interface ValueBuilder extends Builder { void endValue(SourceLocation loc); } - public void stream(AxiomItem itemDef) { - for(AxiomItemValue value : itemDef.values()) { - startItem(itemDef.name(), null); - stream(value); - endItem(null); - - } - } - - private void stream(AxiomItemValue value) { - Object valueMapped = value.get(); - startValue(valueMapped, null); - for(AxiomItem item : value.items()) { - stream(item); - } - endValue(null); - } - } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java new file mode 100644 index 00000000000..f892365f3d5 --- /dev/null +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java @@ -0,0 +1,50 @@ +/* + * 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.test; + +import static org.testng.Assert.assertNotNull; + +import java.io.IOException; +import org.testng.annotations.Test; + + +import com.evolveum.axiom.lang.api.AxiomSchemaContext; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; + +public class TestAxiomPrism extends AbstractReactorTest { + + private static final AxiomIdentifier PERSON = AxiomIdentifier.from("https://example.org", "Person"); + private static final AxiomIdentifier STORAGE = AxiomIdentifier.from("https://example.org/extension", "type"); + + private static final AxiomIdentifier PERSON_EXTENSION = AxiomIdentifier.from("https://schema.org", "SchemaOrgPerson"); + private static final String DIR = "prism/"; + private static final String PRISM = DIR + "prism.axiom"; + private static final String COMMON_CORE = DIR + "common-core.axiom"; + + private ModelReactorContext prismReactor() throws AxiomSyntaxException, IOException { + ModelReactorContext context = ModelReactorContext.defaultReactor(); + context.loadModelFromSource(source(PRISM)); + AxiomSchemaContext schemaContext = context.computeSchemaContext(); + + ModelReactorContext extendedLanguage = ModelReactorContext.reactor(schemaContext); + extendedLanguage.loadModelFromSource(source(PRISM)); + return extendedLanguage; + } + + @Test + public void axiomTestPrismInAxiom() throws IOException, AxiomSyntaxException { + + ModelReactorContext extendedLanguage = prismReactor(); + extendedLanguage.loadModelFromSource(source(COMMON_CORE)); + AxiomSchemaContext schemaContext = extendedLanguage.computeSchemaContext(); + + assertNotNull(schemaContext); + } + +} diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java new file mode 100644 index 00000000000..b2891abb87a --- /dev/null +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -0,0 +1,50 @@ +/* + * 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.test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.io.IOException; +import java.util.Optional; + +import org.testng.annotations.Test; + + +import com.evolveum.axiom.lang.api.AxiomSchemaContext; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; + +public class TestTypeDerivation extends AbstractReactorTest { + + private static final AxiomIdentifier DERIVED_PERSON = AxiomIdentifier.from("https://example.org/derived", "Person"); + private static final String DIR = "multimodel/derived/"; + private static final String BASE = DIR + "base-person.axiom"; + private static final String DERIVED = DIR + "derived-person.axiom"; + + @Test + public void axiomTestExtension() throws IOException, AxiomSyntaxException { + ModelReactorContext context = ModelReactorContext.defaultReactor(); + context.loadModelFromSource(source(BASE)); + context.loadModelFromSource(source(DERIVED)); + AxiomSchemaContext schemaContext = context.computeSchemaContext(); + + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + assertTrue(!langExtDef.identifierDefinitions().isEmpty()); + + Optional personDef = schemaContext.getType(DERIVED_PERSON); + assertTrue(personDef.isPresent()); + + for (AxiomItemDefinition idDef : personDef.get().itemDefinitions().values()) { + assertEquals(idDef.name().namespace(), DERIVED_PERSON.namespace(), idDef.name().localName() + " should have namespace example.org/derived"); + } + } +} diff --git a/infra/axiom/src/test/resources/multimodel/derived/base-person.axiom b/infra/axiom/src/test/resources/multimodel/derived/base-person.axiom new file mode 100644 index 00000000000..78eb8f6dfc1 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/derived/base-person.axiom @@ -0,0 +1,10 @@ +model base-person { + + namespace "https://example.org/base"; + + type Person { + item name { + type string; + } + } +} \ No newline at end of file diff --git a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom new file mode 100644 index 00000000000..6a2a563dc79 --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom @@ -0,0 +1,19 @@ +model derived-person { + + namespace "https://example.org/derived"; + + import base { + namespace "https://example.org/base"; + } + + type Person { + extends base:Person; + + item firstName { + type string; + } + item lastName { + type string; + } + } +} \ No newline at end of file From 95fe7f1df5a5bac9d0ae8e4bedc940f36af77db3 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 25 May 2020 13:34:45 +0200 Subject: [PATCH 24/60] Axiom: moved common-core and scripting test to separate test Signed-off-by: Tony Tkacik --- .../axiom/lang/test/TestAxiomParser.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index cd7dfa9613a..5ae1ff2006c 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -10,19 +10,12 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.util.Optional; import org.testng.annotations.Test; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; -import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; @@ -30,7 +23,6 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.evolveum.midpoint.tools.testng.AbstractUnitTest; public class TestAxiomParser extends AbstractReactorTest { @@ -69,23 +61,4 @@ private void assertInstanceOf(Class clz, Object value) { assertTrue(clz.isInstance(value)); } - @Test - public void moduleHeaderTest() throws IOException, AxiomSyntaxException { - AxiomSchemaContext context = parseFile(BASE_EXAMPLE); - assertNotNull(context.getType(AxiomIdentifier.from("https://ns.evolveum.com/example/axiom/model-header", "Example")).get()); - } - - @Test - public void commonCoreTest() throws IOException, AxiomSyntaxException { - AxiomSchemaContext context = parseFile(COMMON_CORE); - } - - @Test - public void scriptingTest() throws IOException, AxiomSyntaxException { - AxiomSchemaContext context = parseFile(SCRIPTING); - } - - - - } From 752f231cbbdb82cb1e253397d0d6aeed641275ad Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 26 May 2020 11:57:37 +0200 Subject: [PATCH 25/60] Axiom: Make namespace inheritance configurable Signed-off-by: Tony Tkacik --- .../evolveum/axiom/api/AxiomIdentifier.java | 22 + .../lang/antlr/AbstractAxiomAntlrVisitor.java | 2 +- .../lang/antlr/AxiomAntlrStatementSource.java | 5 + .../lang/antlr/AxiomModelStatementSource.java | 7 +- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 15 +- .../evolveum/axiom/lang/api/AxiomItem.java | 1 + .../axiom/lang/api/AxiomItemDefinition.java | 36 +- .../axiom/lang/api/AxiomTypeDefinition.java | 34 +- .../lang/api/DelegatedItemDefinition.java | 9 + .../axiom/lang/impl/BasicStatementRule.java | 38 +- .../evolveum/axiom/lang/impl/ItemContext.java | 15 +- .../axiom/lang/impl/ModelReactorContext.java | 7 +- .../axiom/lang/impl/SourceContext.java | 32 +- .../axiom/lang/impl/ValueContext.java | 53 +- .../lang/spi/AxiomItemDefinitionImpl.java | 16 +- .../lang/spi/AxiomTypeDefinitionImpl.java | 8 +- .../axiom/src/main/resources/axiom-lang.axiom | 10 + .../axiom/lang/test/TestAxiomParser.java | 1 - .../axiom/lang/test/TestAxiomPrism.java | 11 + .../axiom/lang/test/TestTypeDerivation.java | 10 +- .../src/test/resources/common-core.axiom | 1212 ----------------- .../test/resources/prism/common-core.prism | 70 +- .../src/test/resources/prism/prism.axiom | 21 +- 23 files changed, 322 insertions(+), 1313 deletions(-) delete mode 100644 infra/axiom/src/test/resources/common-core.axiom diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java index 2cb43befb49..a3c03867c70 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java @@ -6,7 +6,10 @@ */ package com.evolveum.axiom.api; +import org.jetbrains.annotations.NotNull; + import com.google.common.base.Preconditions; +import com.google.common.base.Strings; public class AxiomIdentifier { @@ -58,6 +61,9 @@ public boolean equals(Object obj) { @Override public String toString() { + if(Strings.isNullOrEmpty(namespace)) { + return localName; + } return "(" + namespace + ")" +localName; } @@ -73,4 +79,20 @@ public boolean sameNamespace(AxiomIdentifier other) { return this.namespace().equals(other.namespace()); } + public AxiomIdentifier localName(String name) { + return AxiomIdentifier.from(namespace, name); + } + + public AxiomIdentifier namespace(String targetNamespace) { + return AxiomIdentifier.from(targetNamespace, localName); + } + + public AxiomIdentifier defaultNamespace() { + return AxiomIdentifier.from("", localName); + } + + public static AxiomIdentifier local(@NotNull String localName) { + return from("", localName); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java index 3cf4725cd8a..d1de47ac96c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java @@ -41,7 +41,7 @@ private AxiomIdentifier statementIdentifier(IdentifierContext identifier) { protected abstract AxiomIdentifier resolveArgument(String prefix, String localName); private String nullableText(ParserRuleContext prefix) { - return prefix != null ? prefix.getText() : null; + return prefix != null ? prefix.getText() : ""; } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index 545394284e1..35447bd25ac 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -60,6 +60,11 @@ protected final StatementContext root() { return root; } + public final void stream(AxiomItemStream.TargetWithResolver target, Optional> emitOnly) { + AxiomAntlrVisitor2 visitor = new AxiomAntlrVisitor2<>(sourceName, target, emitOnly.orElse(null)); + visitor.visit(root); + } + public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Target listener, Optional> emitOnly) { AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, statements, arguments, listener, emitOnly.orElse(null)); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 43eb47626c7..6cf53605841 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -63,15 +63,16 @@ public String namespace() { return namespace; } - public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Target listener) { - stream(resolver, listener, Optional.empty()); - } public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Target listener, Optional> emitOnly) { stream(resolver.or(this), BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); } + public Map imports() { + return imports; + } + public static Map imports(AxiomParser.StatementContext root) { Map prefixMap = new HashMap<>(); root.statement().stream().filter(s -> IMPORT.equals(s.identifier().getText())).forEach(c -> { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 30afd80eabd..547fd40c27d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -42,6 +42,7 @@ public static class Item implements AxiomItemDefinition { 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); + public static final AxiomItemDefinition OPERATIONAL = new Item("operational", Type.IDENTIFIER, true); public static final AxiomItemDefinition IDENTIFIER_DEFINITION = new Item("identifier", Type.IDENTIFIER_DEFINITION, true); @@ -93,6 +94,11 @@ public int minOccurs() { return 0; } + @Override + public boolean operational() { + return false; + } + @Override public int maxOccurs() { return Integer.MAX_VALUE; @@ -107,6 +113,12 @@ public String toString() { public AxiomItemDefinition get() { return this; } + + @Override + public AxiomTypeDefinition definingType() { + // TODO Auto-generated method stub + return null; + } } public static class Type implements AxiomTypeDefinition { @@ -150,7 +162,8 @@ public Collection identifierDefinitions() { new Type("AxiomItemDefinition", BASE_DEFINITION, () -> itemDefs( Item.TYPE_REFERENCE, Item.MIN_OCCURS, - Item.MAX_OCCURS + Item.MAX_OCCURS, + Item.OPERATIONAL )) { @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java index c156b6550ce..3783bcb4a80 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java @@ -30,4 +30,5 @@ static AxiomItem from(AxiomItemDefinition def, AxiomItemValue value) { return AxiomItemImpl.from(def, Collections.singleton(value)); } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java index 1f1d08495c7..e2a8464df11 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java @@ -23,10 +23,18 @@ default AxiomItemDefinition get() { AxiomTypeDefinition typeDefinition(); + boolean operational(); + + default boolean inherited() { + return true; + } + default boolean required() { return minOccurs() > 0; } + AxiomTypeDefinition definingType(); + int minOccurs(); int maxOccurs(); @@ -56,7 +64,13 @@ static IdentifierSpaceKey identifier(AxiomIdentifier name) { return IdentifierSpaceKey.from(ImmutableMap.of(NAME, name)); } - interface Derived extends AxiomItemDefinition { + interface Inherited extends AxiomItemDefinition { + + AxiomItemDefinition original(); + + } + + interface Extended extends AxiomItemDefinition { AxiomItemDefinition original(); @@ -65,4 +79,24 @@ interface Derived extends AxiomItemDefinition { default AxiomItemDefinition derived(AxiomIdentifier name) { return derived(name, this); } + + default AxiomItemDefinition notInherited() { + return new DelegatedItemDefinition() { + + @Override + public boolean operational() { + return false; + } + + @Override + public boolean inherited() { + return false; + } + + @Override + protected AxiomItemDefinition delegate() { + return AxiomItemDefinition.this; + } + }; + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java index 6f21808bd27..3cde7a1469a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java @@ -12,6 +12,7 @@ import java.util.stream.Collectors; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.meta.Inheritance; import com.google.common.collect.ImmutableMap; public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomItemValue { @@ -40,13 +41,13 @@ default Optional type() { default Optional itemDefinition(AxiomIdentifier child) { AxiomItemDefinition maybe = itemDefinitions().get(child); - if(maybe != null) { - return Optional.of(maybe); + if(maybe == null) { + maybe = itemDefinitions().get(Inheritance.adapt(name(), child)); } - if(superType().isPresent()) { - return superType().get().itemDefinition(child); + if(maybe == null && child.namespace().isEmpty()) { + maybe = itemDefinitions().get(name().localName(child.localName())); } - return Optional.empty(); + return Optional.ofNullable(maybe).or(() -> superType().flatMap(s -> s.itemDefinition(child))); } static IdentifierSpaceKey identifier(AxiomIdentifier name) { @@ -57,4 +58,27 @@ default Collection requiredItems() { return itemDefinitions().values().stream().filter(AxiomItemDefinition::required).collect(Collectors.toList()); } + default Optional itemDefinition(AxiomIdentifier parentItem, AxiomIdentifier name) { + return itemDefinition(Inheritance.adapt(parentItem, name)); + } + + default boolean isSubtypeOf(AxiomTypeDefinition type) { + return isSubtypeOf(type.name()); + } + + default boolean isSupertypeOf(AxiomTypeDefinition other) { + return other.isSubtypeOf(this); + } + + default boolean isSubtypeOf(AxiomIdentifier other) { + Optional current = Optional.of(this); + while(current.isPresent()) { + if(current.get().name().equals(other)) { + return true; + } + current = current.get().superType(); + } + return false; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java index e4ffe3f63d2..4fdde7e3931 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java @@ -9,6 +9,11 @@ abstract class DelegatedItemDefinition implements AxiomItemDefinition { protected abstract AxiomItemDefinition delegate(); + @Override + public boolean operational() { + return false; + } + @Override public Optional type() { return delegate().type(); @@ -69,4 +74,8 @@ public String toString() { return AxiomItemDefinition.toString(this); } + @Override + public AxiomTypeDefinition definingType() { + return delegate().definingType(); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index d60e2d71264..c7e4a3bf8ed 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -7,6 +7,7 @@ import java.util.Optional; import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; @@ -125,7 +126,7 @@ public void apply(Lookup context, ActionBuilder action.error("Referenced type %s is not complete.", type)); action.apply(superTypeValue -> { superTypeValue.replace(typeDef.get()); - addFromType(typeDef.get(), superTypeValue.parentValue(), typeName.get().onlyValue().get().namespace()); + addFromType(typeDef.get(), superTypeValue.parentValue(), typeName.get().onlyValue().get()); }); } @@ -177,9 +178,11 @@ public void apply(Lookup context, ActionBuilder action.error("Target %s not found.",item.onlyValue().get())) )); - Dependency> itemDef = action.require(context.child(Item.ITEM_DEFINITION, Object.class)); + Dependency> itemDef = action.require(context.child(Item.ITEM_DEFINITION, AxiomItemDefinition.class)); action.apply(ext -> { - targetRef.get().mergeItem(itemDef.get()); + for(AxiomItemValue item : itemDef.get().values()) { + targetRef.get().mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, item.get().notInherited())); + } }); } }, @@ -215,8 +218,18 @@ static IdentifierSpaceKey keyFrom(Map types(AxiomTypeDefinition... types) { @@ -244,7 +257,7 @@ private static IdentifierSpaceKey namespaceId(String uri) { return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); } - public static void addFromType(AxiomItemValue source, AxiomValueContext target, String targetNamespace) { + public static void addFromType(AxiomItemValue source, AxiomValueContext target, AxiomIdentifier targetName) { AxiomTypeDefinition superType = (AxiomTypeDefinition) source.get(); Preconditions.checkState(!(superType instanceof AxiomBuiltIn.Type)); // FIXME: Add namespace change if necessary @@ -254,16 +267,13 @@ public static void addFromType(AxiomItemValue source, AxiomValueContext ta target.mergeItem(identifiers.get()); }// Copy Items Collection itemDefs = ImmutableList.copyOf(superType.itemDefinitions().values()); - for (AxiomItemDefinition item : superType.itemDefinitions().values()) { - final AxiomIdentifier derivedName; - if (!item.name().namespace().equals(targetNamespace) && item.name().sameNamespace(superType.name())) { - derivedName = AxiomIdentifier.from(targetNamespace, item.name().localName()); - } else { - derivedName = item.name(); + if(item.inherited()) { + final AxiomIdentifier derivedName = Inheritance.adapt(targetName, item); + item = item.derived(derivedName); } - AxiomItemDefinition derived = item.derived(derivedName); - target.mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, derived)); + target.mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, item)); } } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 919840344e4..26f22ff1cf0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -11,13 +11,14 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemValue; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder; +import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ItemBuilder; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; -public class ItemContext extends AbstractContext> implements AxiomItemContext, Supplier>, Dependency>, AxiomItemStreamTreeBuilder.ItemBuilder { +public class ItemContext extends AbstractContext> implements AxiomItemContext, Supplier>, Dependency>, ItemBuilder { private final AxiomIdentifier name; Collection>> values = new ArrayList<>(); @@ -88,4 +89,14 @@ public V onlyValue() { return values.iterator().next().get().get(); } + @Override + public AxiomIdentifierResolver itemResolver() { + return rootImpl().itemResolver(); + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return rootImpl().valueResolver(); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index c9c65776459..20365b4b975 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -26,7 +26,6 @@ import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomItemDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder; import com.evolveum.axiom.lang.spi.AxiomTypeDefinitionImpl; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.RuleReactorContext; @@ -153,9 +152,9 @@ public void addRules(AxiomStatementRule... rules) { } } - public void loadModelFromSource(AxiomModelStatementSource statementSource) { - SourceContext sourceCtx = new SourceContext(this, statementSource, new CompositeIdentifierSpace()); - statementSource.stream(this, new AxiomItemStreamTreeBuilder(sourceCtx)); + public void loadModelFromSource(AxiomModelStatementSource source) { + SourceContext sourceCtx = new SourceContext(this, source, source.imports(), new CompositeIdentifierSpace()); + source.stream(new ItemStreamContextBuilder(sourceCtx), Optional.empty()); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 045effa995a..8f66a30b50a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -12,12 +12,14 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ValueBuilder; import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; -class SourceContext extends ValueContext implements AxiomRootContext, AxiomItemStreamTreeBuilder.ValueBuilder { +class SourceContext extends ValueContext implements AxiomRootContext, ValueBuilder { private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); @@ -25,12 +27,14 @@ class SourceContext extends ValueContext implements AxiomRootContext, Axio private final AxiomModelStatementSource source; private final Map items = new HashMap(); private final CompositeIdentifierSpace globalSpace; + private Map imports; - public SourceContext(ModelReactorContext context, AxiomModelStatementSource source, CompositeIdentifierSpace space) { + public SourceContext(ModelReactorContext context, AxiomModelStatementSource source, Map imports, CompositeIdentifierSpace space) { super(SourceLocation.runtime(), space); this.context = context; this.source = source; this.globalSpace = space; + this.imports = imports; } @Override @@ -93,4 +97,26 @@ public void importIdentifierSpace(NamespaceContext namespaceContext) { public void exportIdentifierSpace(IdentifierSpaceKey namespaceId) { context.exportIdentifierSpace(namespaceId, globalSpace.getExport()); } + + @Override + public AxiomIdentifierResolver itemResolver() { + return (prefix, localName) -> { + if(Strings.isNullOrEmpty(prefix)) { + AxiomIdentifier axiomNs = AxiomIdentifier.axiom(localName); + if(childDef(axiomNs).isPresent()) { + return axiomNs; + } + } + String namespace = imports.get(prefix); + return AxiomIdentifier.from(namespace, localName); + }; + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return AxiomIdentifierResolver.BUILTIN_TYPES.or((prefix, localName) -> { + String namespace = imports.get(prefix); + return AxiomIdentifier.from(namespace, localName); + }); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 373160bc2f6..78943a4e305 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -10,7 +10,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; import com.evolveum.axiom.lang.impl.AxiomStatementRule.Lookup; -import com.evolveum.axiom.lang.spi.AxiomItemStreamTreeBuilder.ValueBuilder; +import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -21,6 +21,8 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.meta.Inheritance; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.SourceLocation; @@ -59,7 +61,7 @@ public Optional childDef(AxiomIdentifier statement) { @Override public ItemContext startItem(AxiomIdentifier identifier, SourceLocation loc) { - return mutable().getOrCreateItem(identifier, loc); + return mutable().getOrCreateItem(Inheritance.adapt(parent().name(), identifier), loc); } @Override @@ -135,8 +137,6 @@ Dependency> getItem(AxiomIdentifier item) { return Dependency.immediate((AxiomItem) maybeItem.get()); } - - @Override public boolean isSatisfied() { return Dependency.allSatisfied(dependencies); @@ -167,7 +167,7 @@ public void replace(AxiomItemValue axiomItemValue) { @Override public AxiomItemContext childItem(AxiomIdentifier name) { - return (AxiomItemContext) mutable().getOrCreateItem(name, SourceLocation.runtime()); + return (AxiomItemContext) mutable().getOrCreateItem(Inheritance.adapt(parent().name(), name), SourceLocation.runtime()); } @Override @@ -249,9 +249,20 @@ public Dependency namespace(AxiomIdentifier name, IdentifierSp return rootImpl().requireNamespace(name, namespaceId); } + Optional resolveChildDef(AxiomItemDefinition name) { + Optional exactDef = childDef(name.name()); + if(exactDef.isPresent()) { + Optional localDef = childDef(parent().name().localName(name.name().localName())); + if(localDef.isPresent() && localDef.get() instanceof AxiomItemDefinition.Inherited) { + return localDef; + } + } + return exactDef; + } + @Override - public Dependency> child(AxiomItemDefinition name, Class valueType) { - return requireChild(name.name()); + public Dependency> child(AxiomItemDefinition definition, Class valueType) { + return requireChild(Inheritance.adapt(parent().name(), definition)); } @Override @@ -278,7 +289,6 @@ public Dependency.Search> global(AxiomIdentifier space, }); } - @Override public Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey key) { @@ -322,4 +332,31 @@ public AxiomSemanticException error(String message, Object... arguments) { } } + @Override + public AxiomIdentifierResolver itemResolver() { + return (prefix, localName) -> { + if(Strings.isNullOrEmpty(prefix)) { + AxiomIdentifier localNs = AxiomIdentifier.local(localName); + Optional childDef = childDef(localNs); + if(childDef.isPresent()) { + return Inheritance.adapt(parent().name(), childDef.get()); + } + ItemContext parent = parent(); + while(parent != null) { + AxiomIdentifier parentNs = AxiomIdentifier.from(parent.name().namespace(), localName); + if(childDef(parentNs).isPresent()) { + return parentNs; + } + parent = parent.parent().parent(); + } + } + return rootImpl().itemResolver().resolveIdentifier(prefix, localName); + }; + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return rootImpl().valueResolver(); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 526cae74036..c3898397373 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -13,15 +13,25 @@ public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { public static final AxiomItemValueFactory FACTORY = AxiomItemDefinitionImpl::new ; - private final AxiomTypeDefinition type; + private final AxiomTypeDefinition valueType; private final Optional> minOccurs; public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomItemDefinition value, Map> items) { super(axiomItemDefinition, value, items); - this.type = this.item(Item.TYPE_REFERENCE.name()).get().onlyValue().get(); + this.valueType = this.item(Item.TYPE_REFERENCE.name()).get().onlyValue().get(); minOccurs = this.item(Item.MIN_OCCURS.name()); } + @Override + public AxiomTypeDefinition definingType() { + return null; + } + + @Override + public boolean operational() { + return false; + } + @Override public AxiomItemDefinition get() { return this; @@ -29,7 +39,7 @@ public AxiomItemDefinition get() { @Override public AxiomTypeDefinition typeDefinition() { - return type; + return valueType; } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 4a7b17e7503..c4236ab3c04 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; @@ -32,7 +33,7 @@ public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition valu ImmutableMap.Builder builder = ImmutableMap.builder(); Optional> itemDef = item(Item.ITEM_DEFINITION.name()); if(itemDef.isPresent()) { - supplyAll(builder, itemDef.get().values()); + supplyAll(name(),builder, itemDef.get().values()); } itemDefinitions = builder.build(); @@ -79,11 +80,12 @@ public Collection identifierDefinitions() { return identifiers; } - private void supplyAll(Builder builder, + private void supplyAll(AxiomIdentifier type, Builder builder, Collection> values) { for(AxiomItemValue v : values) { AxiomItemDefinition val = v.get(); - builder.put(val.name(), val); + AxiomIdentifier name = Inheritance.adapt(type, val.name()); + builder.put(name, val); } } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index c9834ab3328..69c407bcca3 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -171,6 +171,16 @@ model axiom-lang { item maxOccurs { type string; } + + item operational { + type boolean; + operational true; + } + + item inherited { + type boolean; + operational true; + } } type AxiomReference { diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index 5ae1ff2006c..7ea5f732e9f 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -56,7 +56,6 @@ private void assertTypedefBasetype(Optional optional) { assertEquals(typeDef.superType().get().name(), Type.BASE_DEFINITION.name()); } - private void assertInstanceOf(Class clz, Object value) { assertTrue(clz.isInstance(value)); } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java index f892365f3d5..9e2647c7f14 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java @@ -26,6 +26,7 @@ public class TestAxiomPrism extends AbstractReactorTest { private static final String DIR = "prism/"; private static final String PRISM = DIR + "prism.axiom"; private static final String COMMON_CORE = DIR + "common-core.axiom"; + private static final String COMMON_CORE_PRISM = DIR + "common-core.prism"; private ModelReactorContext prismReactor() throws AxiomSyntaxException, IOException { ModelReactorContext context = ModelReactorContext.defaultReactor(); @@ -47,4 +48,14 @@ public void axiomTestPrismInAxiom() throws IOException, AxiomSyntaxException { assertNotNull(schemaContext); } + @Test + public void axiomTestPrismInPrism() throws IOException, AxiomSyntaxException { + + ModelReactorContext extendedLanguage = prismReactor(); + extendedLanguage.loadModelFromSource(source(COMMON_CORE_PRISM)); + AxiomSchemaContext schemaContext = extendedLanguage.computeSchemaContext(); + + assertNotNull(schemaContext); + } + } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index b2891abb87a..0bc1dffe4ad 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -10,6 +10,7 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; +import java.util.Map.Entry; import java.util.Optional; import org.testng.annotations.Test; @@ -18,6 +19,7 @@ import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.impl.ModelReactorContext; @@ -31,7 +33,7 @@ public class TestTypeDerivation extends AbstractReactorTest { private static final String DERIVED = DIR + "derived-person.axiom"; @Test - public void axiomTestExtension() throws IOException, AxiomSyntaxException { + public void axiomTestInheritance() throws IOException, AxiomSyntaxException { ModelReactorContext context = ModelReactorContext.defaultReactor(); context.loadModelFromSource(source(BASE)); context.loadModelFromSource(source(DERIVED)); @@ -42,9 +44,9 @@ public void axiomTestExtension() throws IOException, AxiomSyntaxException { Optional personDef = schemaContext.getType(DERIVED_PERSON); assertTrue(personDef.isPresent()); - - for (AxiomItemDefinition idDef : personDef.get().itemDefinitions().values()) { - assertEquals(idDef.name().namespace(), DERIVED_PERSON.namespace(), idDef.name().localName() + " should have namespace example.org/derived"); + for (Entry idDef : personDef.get().itemDefinitions().entrySet()) { + AxiomItemDefinition item = idDef.getValue(); + assertEquals(idDef.getKey(), Inheritance.adapt(DERIVED_PERSON, item), " should have different namespace"); } } } diff --git a/infra/axiom/src/test/resources/common-core.axiom b/infra/axiom/src/test/resources/common-core.axiom deleted file mode 100644 index 61f10d21fea..00000000000 --- a/infra/axiom/src/test/resources/common-core.axiom +++ /dev/null @@ -1,1212 +0,0 @@ -// 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. - -// This is "common-core.axiom" file containing core definitions from the common-3 namespace. -// Due to its size the common-3 schema is distributed across multiple files. - -model common-core { - - namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; - version "3.0.0"; - - type Object { - object; - itemName object; - documentation """ - Common supertype for all identity objects. Defines basic properties - that each object must have to live in our system (identifier, name). - - All objects are identified by OID. The OID is an immutable identifier - (usually UUID). Except the OID all the objects have human-readable name. - The name is usually unique for each object type, but this is not a - strict requirement. - - Note: object type is fixed, it cannot be changed. The object retains its - type from the time it was created to the end of its life. - """; - item name { - type PolyString; - documentation """ - Human-readable, mutable name of the object. It - may also be an identifier (login name, group name). - It is usually unique in the respective context of - interpretation. E.g. the name of the UserType subtype - is usually unique in the whole system. - The name of the ShadowType subtype is usually unique in the - scope of resource (target system) that it belongs to. - - The name may not be human-readable in a sense to display - to a common end-user. It is intended to be displayed to - IDM system administrator. Therefore it may contain quite - a "ugly" structures such as LDAP DN or URL. - - Name is mutable. It is considered to be ordinary property - of the object. Therefore it can be changed by invoking - usual modifyObject operations. However, change of the name - may have side effects (rename process). - - Although name is specified as optional by this schema, it - is in fact mandatory for most object types. The reason for - specifying the name as optional is that the name may be - generated by the system instead of supplied by the clients. - However, all objects stored in the repository must have a name. - """; - // ObjectType.name - // 0 - // true - } - - // Note: the description property is referenced from various contexts (e.g. Object and Assignment). - // To avoid duplication we use global property definition. - // item description; // TODO make this work - - // The same is true for documentation. - // item documentation; // TODO make this work - - item subtype { - type string; - maxOccurs unbounded; - documentation """ - Type of the object. It is used to distinguish what a specific object - represents. Whether it is a different kind of organizational unit, project, - team, or different kind of user, etc. - """; - // ObjectType.subtype - // 15 - } - - item fetchResult { - type OperationResult; - documentation """ - Result of the operation that fetched this instance of the object. - It is mostly used to indicate that the object is not complete or - there is some problem with the object. This is used instead of - exception if the object is part of larger structures (lists as in - list/search operations or composite objects). If not present then - the "SUCCESS" state is assumed. - - This field is TRANSIENT. It must only be used in runtime. It should - never be stored in the repository. - """; - // a:operational - } - - // item extension; // TODO make this work - - item trigger { - type Trigger; - maxOccurs unbounded; - documentation """ - Triggers for this object. They drive invocations of corresponding trigger handlers - at specified time. - """; - // a:operational - } - - item parentOrg { // TODO or should we use 'Ref' suffix i.e. 'parentOrgRef'? - type ObjectReference; - maxOccurs unbounded; - documentation """ - Set of the orgs (organizational units, projects, teams) that the object relates to. - This usually means that the object belongs to them but it may have other meanings as well - (e.g. user manages an organizational unit). - """; - // tns:OrgType - // OrgType.parentOrganization - // 240 - // - } - - item tenant { - type ObjectReference; - documentation """ - Reference to the tenant to which this object belongs. It is a computed value set automatically - by midPoint. It is determined from the organizational structure. Even though this value is - computed it is also stored in the repository due to performance reasons. - """; - // tns:OrgType - // OrgType.tenant - // 250 - // true - } - - item lifecycleState { - type string; - documentation """ - Lifecycle state of the object. This property defines whether the - object represents a draft, proposed definition, whether it is active, - deprecated, and so on. - - There are few pre-defined lifecycle states. But custom lifecycle states - may also be defined. Pre-defined lifecycle states are: - - - draft: Definition of the new object in progress. The object is - NOT active. The definition may change at any moment. It is - not ready yet. - - proposed: Definition of a new object is ready for use, but there - is still a review process to be applied (e.g. approval). - The object is NOT active. However the definition should - not change in this state. - - active: Active and working definition. Ready to be used without - any unusual limitations. - - deprecated: Active definition which is being phased out. The - definition is still fully operational. But it should not - be used for new assignments. E.g. it should not be requested, - it should not be approved, etc. - - archived: Inactive historical definition. It is no longer used. - It is maintained only for historical, auditing and - sentimental reasons. - - failed: Unexpected error has occurred during object lifecycle. Result - of that event is that the object is rendered inactive. - The situation cannot be automatically remedied. Manual action - is needed. - """; - // ObjectType.lifecycleState - // 20 - since "3.5"; - // - } - - item operationExecution { - type OperationExecution; - maxOccurs unbounded; - documentation """ - Description of recent operations executed on this object (or related objects, e.g. shadows - in case of a focal object). The number of operations to be kept here is configurable. - """; - since "3.6"; - // true - } - - item lensContext { - type LensContext; - documentation """ - Model context describing executed operation. - """; - since "4.0"; - // true - } - - item policySituation { - type uri; - maxOccurs unbounded; - documentation """ - The policy situation(s) of this object. The situations are result of - evaluation of the policy rules. This property is recorded for each object - and can be used for reporting, diagnostics, target selection in certification - campaigns, etc. - """; - since "3.5"; - // true - } - - item policyException { - type PolicyException; - maxOccurs unbounded; - documentation """ - Recorded exception from a policy rule. The exceptions that are approved are - recoded here to avoid re-evaluating and re-approving them all the time. - This is EXPERIMENTAL functionality. It is likely to change in the near future. - """; - since "3.5"; - // true - } - - item diagnosticInformation { - type DiagnosticInformation; - maxOccurs unbounded; - documentation """ - Diagnostic information attached to this object. - """; - since "4.0"; - // true - } - - // Note that oid and version are not defined here. These are intrinsic parts of prism objects - // so they do not have to be mentioned in the schema. - // TODO: is this OK? See also related questions in ObjectReference type. - } - - type AssignmentHolder { - extends Object; - itemName assignmentHolder; - documentation """ - Abstract supertype for all object types that can have assignments. - """; - - item assignment { - type Assignment; - maxOccurs unbounded; - documentation """ - Set of object's assignments. - Assignments define the privileges and "features" that this object should have, that - this object is entitled to. Typical assignment will point to a role or define - a construction of an account. - - Assignments represent what the object SHOULD HAVE. The assignments represent a policy, - a desired state of things (cf. linkRef). - """; - // FocusType.assignmentKey - } - - item iteration { - type int; // TODO - documentation """ - Iteration number. Starts with 0. It is used to iteratively find unique identifier - for the object. - """; - // true - } - - item iterationToken { - type string; - documentation """ - Iteration token. String value that is usually a suffix to the identifier based - on iteration number. E.g. ".007". It is used to iteratively find unique identifier - for the object. - """; - // true - } - - item archetype { - type ObjectReference; - maxOccurs unbounded; - documentation """ - References to all applicable archetypes, including "indirect" archetypes such as archetype supertypes. - Contains references to active archetypes only. - - Note: the value of this reference is only updated when object is recomputed. - Therefore if a role definition changes then all the affected objects must be recomputed - for this reference to be consistent. - - This is an operational property. It is set and managed by the system. It is used - for efficient use of archetypes. - """; - // tns:ArchetypeType - // true - // AssignmentHolderType.archetypeRef - since "4.0"; - } - - item roleMembership { - type ObjectReference; - maxOccurs unbounded; - documentation """ - References to abstract roles (roles, orgs, services) that this focus currently belongs to - directly - or indirectly. This reference points to all the roles in the role hierarchy. It only points to - the roles that were evaluated as active during last recompute (conditions were true, validity - constraints not violated). - - Note: the value of this reference is only updated when a focal object is recomputed. - Therefore if a role definition changes then all the affected focal objects must be recomputed - for this reference to be consistent. - - Roles mentioned here are those that are NOT obtained via delegation, i.e. "deputy" relations. - Relations acquired by delegation are listed in delegatedRef item. - - This is an operational property. It is set and managed by the system. It is used - for efficient search of all current role members, e.g. for the purpose of displaying this - information in the GUI. - """; - // tns:AbstractRoleType - // true - // FocusType.roleMembershipRef - } - - item delegated { - type ObjectReference; - maxOccurs unbounded; - documentation """ - References to objects (abstract roles as well as users) obtained via delegation. - If A1 is a deputy of A, its delegatedRef contains a union of A, A.roleMembershipRef and - A.delegatedRef. - - This is an operational property. It is set and managed by the system. It is used - for efficient search of all current role members, e.g. for the purpose of displaying this - information in the GUI. - """; - // tns:FocusType - // true - since "3.5"; - } - - item roleInfluence { - type ObjectReference; - maxOccurs unbounded; - documentation """ - References to abstract roles (roles and orgs) that this focus may directly belong to. - This reference only points to the next role in the hierarchy. However, it is backed by - a "closure" index in the repository subsystem. Therefore it can efficiently support tree-like - queries. This reference points to the roles for whose the condition is not true. - Therefore it does not reliably show - who actually has a role. It shows potential role members - all the object that are possibly - influenced when a role definition changes. - - This is an operational property. It is set and managed by the system. It is used - for efficient search of all possible role members, e.g. for the purpose of recomputing - all role members after the role definition is changed. - - TODO. NOT IMPLEMENTED YET. EXPERIMENTAL. UNSTABLE. - """; - // tns:AbstractRoleType - // true - } - } - - type Focus { - extends AssignmentHolder; - itemName focus; - documentation """ - Abstract supertype for all object types that can be focus of full midPoint computation. - This basically means objects that have projections. But focal objects also have - activation, they may have personas, etc. - """; - item link { - type ObjectReference; - maxOccurs unbounded; - documentation """ - Set of shadows (projections) linked to this focal object. - E.g. a set of accounts linked to a user. This is the set of - shadows that belongs to the focal object in a sense - that these shadows represents the focal object on the resource. - E.g. The set of accounts that represent the same midPoint user (the - same physical person, they are "analogous"). - - Links define what the object HAS. The links reflect real state of things - (cf. assignment). - """; - // tns:ShadowType - } - - item persona { - type ObjectReference; - maxOccurs unbounded; - documentation """ - Set of personas linked to this focal object. - E.g. a set of virtual identities linked to a user. This is the set of - "secondary" focal objects that belongs to this focal object in a sense - that the current focal object is in control over the linked focal objects. - E.g. this reference can be used to link user object which specified a physical - person with his virtual identities (personas) that specify his identity as an - employee, system administrator, customer, etc. - The default meaning is that the personas are "analogous", i.e. the represent - different facets of the same physical person. However, this meaning may be - theoretically overridden by using various relation parameters in this reference. - - This reference define what the object HAS. The links reflect real state of - things (cf. assignment). - """; - // tns:FocusType - since "3.6"; - } - - item activation { - type Activation; - } - - item jpegPhoto { - type binary; - documentation """ - Photo corresponding to the user / org / role / service. - """; - // FocusType.jpegPhoto - } - - item costCenter { - type string; - documentation """ - The name, identifier or code of the cost center to which the object belongs. - - Please note that organization objects (OrgType) also have a costCenter property. - Therefore it is usual that if a user belongs to an organization the costCenter from - the organization is used. Therefore this property is usually used only for users that - do not belong to any organization or for users that have different cost center than - the one defined by the organization. - """; - // FocusType.costCenter - // 420 - } - - item locality { - type PolyString; - documentation """ - Primary locality of the object, the place where - the (e.g.) user usually works, the country, city or - building that he belongs to. The specific meaning - and form of this property is deployment-specific. - """; - // FocusType.locality - // 450 - } - - item preferredLanguage { - type string; - documentation """ - Indicates user's preferred language, usually for the purpose of localizing - user interfaces. The format is IETF language tag defined in BCP 47, where - underscore is used as a subtag separator. This is usually a ISO 639-1 two-letter - language code optionally followed by ISO 3166-1 two letter country code - separated by underscore. The languages that do not have country-specific - variants are usually specified by using a two-letter country code ("sk", - "cs", "tr"). Languages with country-specific variants have country-specific - subtags ("pt_BR", "zn_CN"). - If no value is specified in this property then system default locale is assumed. - - Examples: - - en_US - - sk - - cs - - pt_BR - """; - // FocusType.preferredLanguage - // 200 - // - } - - item locale { - type string; - documentation """ - Defines user's preference in displaying currency, dates and other items - related to location and culture. The format is IETF language tag defined in BCP 47, where - underscore is used as a subtag separator. This is usually a ISO 639-1 two-letter - language code optionally followed by ISO 3166-1 two letter country code - separated by underscore. The languages that do not have country-specific - variants are usually specified by using a two-letter country code ("sk", - "cs", "tr"). Languages with country-specific variants have country-specific - subtags ("pt_BR", "zn_CN"). - If not specified then system default locale is assumed. - - Examples: - - en_US - - sk - - cs - - pt_BR - """; - // FocusType.locale - // 210 - // - } - - item timezone { - type string; - documentation """ - User's preferred timezone. It is specified in the "tz database" (a.k.a "Olson") - format. If not specified then system default timezone is assumed. - - Examples: - - Europe/Bratislava - """; - // FocusType.timezone - // 220 - // - } - - item emailAddress { - type string; - documentation """ - E-Mail address of the user, org. unit, etc. This is the address - supposed to be used for communication with the - user, org. unit, etc. E.g. IDM system may send notifications - to the e-mail address. It is NOT supposed to be - full-featured e-mail address data structure - e.g. for the purpose of complex address-book application. - """; - // FocusType.emailAddress - // 300 - } - - item telephoneNumber { - type string; - documentation """ - Primary telephone number of the user, org. unit, etc. - """; - // FocusType.telephoneNumber - // 310 - } - - item credentials { - type Credentials; - documentation """ - The set of focus's credentials (such as passwords). - """; - // FocusType.credentials - } - } - - type User { - extends Focus; - documentation """ - User object represents a physical user of the system. - It differs from the account, as "account" represents a data structure in a target system while - "user" represents data structure in midPoint. One user typically has many accounts. - Properties of User object typically describe the user as a physical person. - Therefore the user object defines handful of properties that are commonly used to describe users - in the IDM solutions (employees, customers, partners, etc.) Custom extensions are possible by utilizing - the "extension" container. - """; - - item fullName { - type PolyString; - documentation """ - Full name of the user with all the decorations, - middle name initials, honorific title and any - other structure that is usual in the cultural - environment that the system operates in. This - element is intended to be displayed to - a common user of the system. - - Examples: - - cpt. Jack Sparrow - - William "Bootstrap" Turner - - James W. Random, PhD. - - Vladimir Iljic Lenin - - Josip Broz Tito - - Chuck Norris - """; - // UserType.fullName - // 100 - // true - } - - item givenName { - type PolyString; - documentation """ - Given name of the user. It is usually the first - name of the user, but the order of names may - differ in various cultural environments. This - element will always contain the name that was - given to the user at birth or was chosen - by the user. - - Examples: - - Jack - - Chuck - """; - // UserType.givenName - // 110 - // true - } - - item familyName { - type PolyString; - documentation """ - Family name of the user. It is usually the last - name of the user, but the order of names may - differ in various cultural environments. This - element will always contain the name that was - inherited from the family or was assigned - to a user by some other means. - - Examples: - - Sparrow - - Norris - """; - // UserType.familyName - // 120 - // true - } - - item additionalName { - type PolyString; - documentation """ - Middle name, patronymic, matronymic or any other name of a person. It is usually the - middle component of the name, however that may be culture-dependent. - - Examples: - - Walker - - John - - Iljic - """; - // UserType.additionalName - // 130 - } - - item nickName { - type PolyString; - documentation """ - Familiar or otherwise informal way to address a person. - - Examples: - - Bootstrap - - Bobby< - - The meaning of this property is to take part in the formatted full - name of the person, e.g. William "Bootstrap" Turner. It is not intended - to be used as a username or login name. This value is usually changeable - by the user itself and it defines how the user wants other to address him. - Therefore it is not ideal for use as an identifier. - """; - // UserType.nickname - // 140 - } - - item honorificPrefix { - type PolyString; - documentation """ - Honorific titles that go before the name. - Examples: - - cpt. - - Ing. - - Sir - - This property is single-valued. If more - than one title is applicable, they have to be represented in - a single string (concatenated) form in the correct order. - """; - // UserType.honorificPrefix - // 150 - } - - item honorificSuffix { - type PolyString; - documentation """ - Honorific titles that go after the name. - - Examples: - - PhD. - - KBE - - This property is single-valued. If more - than one title is applicable, they have to be represented in - a single string (concatenated) form in the correct order. - """; - // UserType.honorificSuffix - // 160 - } - - item title { - type PolyString; - documentation """ - User's title defining a work position or a primary role in the - organization. - Examples: - - CEO - - Security Officer - - Assistant - """; - // UserType.title - // 170 - } - - item employeeNumber { - type string; - documentation """ - Unique, business-oriented identifier of the employee. - Typically used as correlation identifier and for - auditing purposes. Should be immutable, but the - specific properties and usage are deployment-specific. - """; - // UserType.employeeNumber - // 400 - } - - item employeeType { - type string; - maxOccurs unbounded; - documentation """ - Employee type specification such as internal employee, - external or partner. The specific values are - deployment-specific. However it is generally assumed that this - will be enumeration of several type names or codes that define - "classes" of users. - - Even though this property is named "employeeType" due to the historical - reasons it is used in a more generic way to mean general type of user. - Therefore it can be used to distinguish employees from customers, etc. - - DEPRECATED: Use ObjectType.subtype - """; - // UserType.employeeType - // 410 - // true - // 3.8 - } - item organization { - type PolyString; - maxOccurs unbounded; - documentation """ - Name or (preferably) immutable identifier of organization that the user belongs to. - The format is deployment-specific. This property together with organizationalUnit - may be used to provide easy-to-use data about organizational membership of the user. - - This is multi-valued property to allow membership of a user to several - organizations. Please note that midPoint does not maintain ordering in - multi-value properties therefore this is not usable to model a complex - organization hierarchies. Use OrgType instead. - """; - // UserType.organization - // 430 - } - - item organizationalUnit { - type PolyString; - maxOccurs unbounded; - documentation """ - Name or (preferably) immutable identifier of organizational unit that the user belongs to. - The format is deployment-specific. This property together with organization - may be used to provide easy-to-use data about organizational membership of the user. - - This is multi-valued property to allow membership of a user to several - organizational units. Please note that midPoint does not maintain ordering in - multi-value properties therefore this is not usable to model a complex - organization hierarchies. Use OrgType instead. - """; - // UserType.organizationalUnit - // 440 - } - item adminGuiConfiguration { - type AdminGuiConfiguration; - documentation """ - Specifies the admin GUI configuration that should be used - by this user. - """; - since "3.5"; - // AdminGuiConfigurationType.adminGuiConfiguration - } - } - - type ObjectReference { - objectReference; - documentation """ - Reference to an object. It contains OID of the object that it - refers to. - """; - - // item description; // TODO make this work - - // item documentation; // TODO make this work - - item filter { - type SearchFilter; // TODO namespace of "query-3" - documentation """ - Filter that can be used to dynamically lookup the reference OID e.g. during imports. - It must not be used for normal operations. The filter may be stored in the repository - to avoid data loss. But even if it is stored it will not be used beyond initial - import or unless explicitly requested (e.g. by setting resolutionTime). - - Note: The filter will NOT be used if the OID in the reference is set. The OID always takes - precedence. - """; - } - - item resolutionTime { - type EvaluationTime; - // TODO defaultValue "import"; - documentation """ - Definition of the "time" when the reference will be resolved. Resolving the reference means using - the filter to get object(s) or OID(s). - - Import-time resolution means that the reference will be resolved once when the file is imported. - OID will be recorded in the reference and then only the OID will be used to follow the reference. - This is a very efficient method and it is the default. - - Run-time resolution means that the reference will be resolved every time that the reference is - evaluated. This is less efficient but it provides great flexibility as the filter may contain - expressions and therefore the reference target may dynamically change. - """; - } - - item referentialIntegrity { - type ReferentialIntegrity; - // TODO defaultValue "default"; - documentation """ - Definition of the behavior related to non-existence of object with specified target OID. - (Currently supported only at selected places in midPoint.) - """; - since "4.1"; - } - - item targetName { - type PolyString; - documentation """ - Cached name of the target object. - This is a ephemeral value. It is not stored in the repository. - It may be computed at object retrieval time or it may not be present at all. - This is NOT an authoritative information. Setting it or changing it will - not influence the reference meaning. OID is the only authoritative linking - mechanism. - """; - } - - // TODO what about (attributes) oid, type, and relation? - // Should they be listed here even if they are defined in PrismReferenceValue? - // But if not, why should we list filter, resolution time, referential integrity here, - // as they are also defined in PrismReferenceValue. - } - - item description { - type string; - documentation """ - Free-form textual description of the object. It is supposed to describe - the object or a construct that it is attached to. - - This information may be presented to midPoint users, even to ordinary end users. - For example role description may be presented to users when they are selecting - roles to request. Therefore the description should be written in a language that - the users can understand. - - Description is assumed to be a plan, non-formatted text. - Amount of white space is considered insignificant. E.g. leading and trailing - white space may be skipped, multiple spaces can be collapsed to one and so on. - """; - // ObjectType.description - // 10 - } - - item documentation { - type string; - documentation """ - Technical documentation for a particular object or construct. - - The purpose of this element is to document system configuration and behavior. - The documentation will not be presented to end users. In fact, it will probably - not be presented at all in midPoint user interface. This documentation element - is supposed to be a part of the technical documentation of midPoint deployment. - The tools than generate deployment configuration will look for these elements - and combine them to compiled documentation document. - - AsciiDoc formatting is assumed for this element. Any leading or trailing - whitespace is skipped. Indentation equivalent to he indentation of the first - non-blank line of text is also skipped. - """; - // ObjectType.documentation - // 11 - } - - // Example of short version of container definition. - container { - name Assignment; - itemName assignment; - - // item description; // TODO make this work - // item documentation; // TODO make this work - // item extension; // TODO make this work - - // ... - } - - container { - name Extension; - itemName extension; - documentation """ - Extension container that provides generic extensibility mechanism. - Almost any extension property can be placed in this container. - This mechanism is used to extend objects with new properties. - The extension is treated exactly the same as other object - properties by the code (storage, modifications, etc), except - that the system may not be able to understand their meaning. - """; - // ObjectType.extension - // 1000 - } - - object GenericObject { - extends Focus; - itemName genericObject; - documentation """ - Generic object for storing unknown (unexpected) object types. - - The generic object should be used if there is a need to - store a custom object (e.g KangarooType) at deployment-time. - The properties of such custom objects are to be placed in the - extension part of this object. The schema is not checked or - enforced for this type of objects if technically possible. - """; - item objectType { - type uri; // TODO - // deprecated - } - } - - container Trigger { - itemName trigger; - documentation """ - Defines triggers for an object. Trigger is an action that should take place - at specified time or under some other condition. - """; - item timestamp { - type dateTime; // TODO - documentation """ - The time when a trigger needs to be activated. - """; - } - item handlerUri { - type uri; // TODO - documentation """ - Handler URI indirectly specifies which class is responsible to handle the task. The handler will - to be used to handle trigger activation. - """; - } - item originDescription { - type string; - documentation """ - Short description of trigger origin, e.g. name of the mapping. - Used for diagnostic purposes. - """; - // true - since "4.0"; - } - item extension { // TODO - type Extension; - documentation """ - Extension container used to provide additional situation-specific information to the trigger. - """; - } - } - - container Metadata { - itemName metadata; - documentation """ - Meta-data about data creation, modification, etc. - It may apply to objects but also parts of the object (e.g. assignments). - - Meta-data only apply to successful operations. That is obvious for create, but it also applies - to modify. For obvious reasons there are no metadata about delete. - We keep no metadata about reading. That would be a huge performance hit. - - Meta-data only describe the last operation of its kind. E.g. there is a record of last - modification, last approval, etc. There is no history. The last operation overwrites data - about the previous operation. - - These data are informational only. They should not be used for security purposes (use auditing - subsystem for that). But presence of metadata simplifies system administration and may provide - some basic information "at the glance" which may be later confirmed by the audit logs. - - Meta-data are also supposed to be searchable. Therefore they may be used to quickly find - "candidate" objects for a closer examination. - """; - // true - // - // Metadata - - item requestTimestamp { - type dateTime; - documentation """ - The timestamp of "create" operation request. It is set once and should never be changed. - - In case of "background" processes to create object (e.g. create with approval) - this should be the timestamp when the process started. I.e. the timestamp when - the operation was requested. - """; - // MetadataType.requestTimestamp - // true - since "3.5"; - // - } - - item requestor { - type ObjectReference; - documentation """ - Reference to the user that requested the "create" operation for this object or assignment. - """; - // MetadataType.requestorRef - // true - // tns:UserType - // - } - - item requestorComment { - type string; - documentation """ - Comment of the user that requested the "create" operation for this object or assignment. - """; - // MetadataType.requestorComment - // true - since "3.7"; - } - - item createTimestamp { - type dateTime; - documentation """ - The timestamp of data creation. It is set once and should never be changed. - - In case of "background" processes to create object (e.g. create with approval) - this should be the timestamp when the process ended. I.e. the timestamp when - the operation was executed. - """; - // MetadataType.createTimestamp - // true - // true - since "3.5"; - } - - item creator { - type ObjectReference; - maxOccurs unbounded; - documentation """ - Reference to the user that approved the creation of the data (if there was such a user). - This is multi-value reference therefore multiple approvers may be recorded. However the order and - hierarchy of the approvers is lost. - """; - // MetadataType.createApproverRef - // true - // true - // tns:UserType - } - - item createApproverComment { - type string; - maxOccurs unbounded; - documentation """ - Comments of the approvers during the creation of the data. Note that these comments are in no - particular order, so basically it is not known who entered which comment. - """; - // MetadataType.createApprovalComment - // true - since "3.7"; - } - - item createApprovalTimestamp { - type dateTime; - documentation """ - The timestamp of creation approval. - """; - // MetadataType.createApprovalTimestamp - // true - since "3.5"; - } - - item createChannel { - type uri; - documentation """ - Channel in which the object was created. - """; - // MetadataType.createChannel - // true - // true - } - - item createTask { - type ObjectReference; - documentation """ - Reference to the task that created the object (if it was a persistent one). - """; - // MetadataType.createTaskRef - // true - // tns:TaskType - since "3.7"; - } - - item modifyTimestamp { - type dateTime; - // MetadataType.modifyTimestamp - // true - // true - } - - item modifier { - type ObjectReference; - // MetadataType.modifierRef - // true - // true - // tns:UserType - } - - item modifyApprover { - type ObjectReference; - maxOccurs unbounded; - // MetadataType.modifyApproverRef - // true - // true - // tns:UserType - } - - item modifyApprovalComment { - type string; - maxOccurs unbounded; - // MetadataType.modifyApprovalComment - // true - since "3.7"; - } - - item modifyChannel { - type uri; - // MetadataType.modifyChannel - // true - // true - } - - item modifyTask { - type ObjectReference; - // MetadataType.modifyTaskRef - // true - // tns:TaskType - since "3.7"; - } - - item lastProvisioningTimestamp { - type dateTime; - // MetadataType.lastProvisioningTimestamp - // true - since "3.6.1"; - } - - item certificationFinishedTimestamp { - type dateTime; - // MetadataType.certificationFinishedTimestamp - // true - since "3.7"; - } - - item certificationOutcome { - type string; - // MetadataType.certificationOutcome - // true - since "3.7"; - } - - item certifier { - type ObjectReference; - // MetadataType.certifierRef - // true - // tns:UserType - since "3.7"; - } - - item certifierComment { - type string; - maxOccurs unbounded; - // MetadataType.certifierComment - // true - since "3.7"; - } - - item originMappingName { - type string; - // MetadataType.originMappingName - // true - since "3.7"; - } - } - - // axiom - - // types-3 - type PolyString; - - // query-3 - type SearchFilter; - type EvaluationTime; - type ReferentialIntegrity; - - // ??? - // type Extension; - - // common-3 - type OperationResult; - type OperationExecution; - type LensContext; - type PolicyException; - type DiagnosticInformation; - type Credentials; - type AdminGuiConfiguration; - type Activation; - - // should exist because of "container XXX" - // Already defined - // type Trigger; - // type Assignment; - -} diff --git a/infra/axiom/src/test/resources/prism/common-core.prism b/infra/axiom/src/test/resources/prism/common-core.prism index f8b4f02e6f3..031e94abd26 100644 --- a/infra/axiom/src/test/resources/prism/common-core.prism +++ b/infra/axiom/src/test/resources/prism/common-core.prism @@ -840,43 +840,47 @@ prism:model common-core { // as they are also defined in PrismReferenceValue. } - item description { - type string; - documentation """ - Free-form textual description of the object. It is supposed to describe - the object or a construct that it is attached to. + mixin Description { + item description { + type string; + documentation """ + Free-form textual description of the object. It is supposed to describe + the object or a construct that it is attached to. - This information may be presented to midPoint users, even to ordinary end users. - For example role description may be presented to users when they are selecting - roles to request. Therefore the description should be written in a language that - the users can understand. + This information may be presented to midPoint users, even to ordinary end users. + For example role description may be presented to users when they are selecting + roles to request. Therefore the description should be written in a language that + the users can understand. - Description is assumed to be a plan, non-formatted text. - Amount of white space is considered insignificant. E.g. leading and trailing - white space may be skipped, multiple spaces can be collapsed to one and so on. - """; - // ObjectType.description - // 10 + Description is assumed to be a plan, non-formatted text. + Amount of white space is considered insignificant. E.g. leading and trailing + white space may be skipped, multiple spaces can be collapsed to one and so on. + """; + // ObjectType.description + // 10 + } } - item documentation { - type string; - documentation """ - Technical documentation for a particular object or construct. - - The purpose of this element is to document system configuration and behavior. - The documentation will not be presented to end users. In fact, it will probably - not be presented at all in midPoint user interface. This documentation element - is supposed to be a part of the technical documentation of midPoint deployment. - The tools than generate deployment configuration will look for these elements - and combine them to compiled documentation document. - - AsciiDoc formatting is assumed for this element. Any leading or trailing - whitespace is skipped. Indentation equivalent to he indentation of the first - non-blank line of text is also skipped. - """; - // ObjectType.documentation - // 11 + mixin Documentation { + item documentation { + type string; + documentation """ + Technical documentation for a particular object or construct. + + The purpose of this element is to document system configuration and behavior. + The documentation will not be presented to end users. In fact, it will probably + not be presented at all in midPoint user interface. This documentation element + is supposed to be a part of the technical documentation of midPoint deployment. + The tools than generate deployment configuration will look for these elements + and combine them to compiled documentation document. + + AsciiDoc formatting is assumed for this element. Any leading or trailing + whitespace is skipped. Indentation equivalent to he indentation of the first + non-blank line of text is also skipped. + """; + // ObjectType.documentation + // 11 + } } // Example of short version of container definition. diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom index 9b87afeab98..690fd745a7f 100644 --- a/infra/axiom/src/test/resources/prism/prism.axiom +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -7,38 +7,29 @@ model prism { } root model { - documentation """ - Axiom Model - - Declares a new axiom model. - """; type PrismModel; } - type PrismModel { - extends axiom:AxiomModel; - - - } - - extension PrismDefinition { + extension PrismModelExtension { target axiom:AxiomModel; - // TODO move to prism schema; consider renaming to objectType? + item object { type PrismObjectDefinition; } - // TODO move to prism schema; consider renaming to containerType? item container { type PrismContainerDefinition; } - // TODO move to prism schema; consider renaming to referenceType? item reference { type PrismReferenceDefinition; } } + type PrismModel { + extends axiom:AxiomModel; + } + extension PrismTypeDefinitionAnnotation { target axiom:AxiomTypeDefinition; // TODO move to prism schema From a3aa1c1bee426f93ace985cc81f4bdf1dcb94093 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 09:10:12 +0200 Subject: [PATCH 26/60] Updaded Axiom model & Prism model based on discussion Signed-off-by: Tony Tkacik --- .../evolveum/axiom/api/meta/Inheritance.java | 35 +++++++++++++++++++ .../axiom/lang/test/TestAxiomExtension.java | 4 +-- .../test/resources/prism/common-core.axiom | 14 ++++---- .../test/resources/prism/common-core.prism | 4 +-- .../src/test/resources/prism/prism.axiom | 5 ++- 5 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java new file mode 100644 index 00000000000..ffb44ca0606 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java @@ -0,0 +1,35 @@ +package com.evolveum.axiom.api.meta; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; + +public interface Inheritance { + + Inheritance INHERIT = Inheritance::inheritNamespace; + Inheritance NO_CHANGE = Inheritance::noChange; + Inheritance NO_NAMESPACE = Inheritance::noNamespace; + Inheritance CURRENT = NO_CHANGE; + + + static AxiomIdentifier adapt(AxiomIdentifier parent, AxiomIdentifier child) { + return CURRENT.apply(parent, child); + } + + static AxiomIdentifier adapt(AxiomIdentifier parent, AxiomItemDefinition child) { + return child.inherited() ? adapt(parent, child.name()) : child.name(); + } + + AxiomIdentifier apply(AxiomIdentifier parent, AxiomIdentifier child); + + static AxiomIdentifier inheritNamespace(AxiomIdentifier parent, AxiomIdentifier name) { + return parent.localName(name.localName()); + } + + static AxiomIdentifier noNamespace(AxiomIdentifier parent, AxiomIdentifier name) { + return name.defaultNamespace(); + } + + static AxiomIdentifier noChange(AxiomIdentifier parent, AxiomIdentifier name) { + return name; + } +} diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index 9125c157dc5..b7b828113f0 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -81,11 +81,9 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio AxiomTypeDefinition typeDef = schemaContext.getType(Type.TYPE_DEFINITION.name()).get(); assertNotNull(typeDef.itemDefinition(STORAGE).get()); - ModelReactorContext extendedLanguage = ModelReactorContext.reactor(schemaContext); extendedLanguage.loadModelFromSource(source(LANG_EXT)); extendedLanguage.loadModelFromSource(source(LANG_EXT_USE)); - schemaContext = extendedLanguage.computeSchemaContext(); AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); @@ -95,8 +93,8 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio assertTrue(personDef.isPresent()); AxiomItem extension = personDef.get().item(STORAGE).get(); - assertFalse(extension.values().isEmpty(), "Extension statements should be available."); + assertFalse(extension.values().isEmpty(), "Extension statements should be available."); assertEquals(2, personDef.get().itemDefinitions().entrySet().size()); } diff --git a/infra/axiom/src/test/resources/prism/common-core.axiom b/infra/axiom/src/test/resources/prism/common-core.axiom index 83b95e6c0b4..91e4d698f41 100644 --- a/infra/axiom/src/test/resources/prism/common-core.axiom +++ b/infra/axiom/src/test/resources/prism/common-core.axiom @@ -885,15 +885,15 @@ model common-core { // Example of short version of container definition. prism:container { - name Assignment; - itemName assignment; + name Assignment; + itemName assignment; - // item description; // TODO make this work - // item documentation; // TODO make this work - // item extension; // TODO make this work + // item description; // TODO make this work + // item documentation; // TODO make this work + // item extension; // TODO make this work - // ... - } + // ... + } prism:container { name Extension; diff --git a/infra/axiom/src/test/resources/prism/common-core.prism b/infra/axiom/src/test/resources/prism/common-core.prism index 031e94abd26..1dba7175fab 100644 --- a/infra/axiom/src/test/resources/prism/common-core.prism +++ b/infra/axiom/src/test/resources/prism/common-core.prism @@ -10,7 +10,7 @@ prism:model common-core { namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; version "3.0.0"; - + import prism { namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; } @@ -861,7 +861,7 @@ prism:model common-core { } } - mixin Documentation { + mixin Documentation { item documentation { type string; documentation """ diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom index 690fd745a7f..1de7e6a2088 100644 --- a/infra/axiom/src/test/resources/prism/prism.axiom +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -12,7 +12,7 @@ model prism { extension PrismModelExtension { target axiom:AxiomModel; - + item object { type PrismObjectDefinition; } @@ -28,6 +28,9 @@ model prism { type PrismModel { extends axiom:AxiomModel; + item type { // {}:type + type PrismTypeDefinition; + } } extension PrismTypeDefinitionAnnotation { From 3c7c53ac115a0a48062e96ce19a8d93b6871b77d Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 10:46:31 +0200 Subject: [PATCH 27/60] Axiom: Added data loading functionality Signed-off-by: Tony Tkacik --- .../lang/antlr/AxiomAntlrStatementSource.java | 4 + .../lang/api/AxiomBuilderStreamTarget.java | 104 ++++++++++++ .../axiom/lang/api/AxiomItemBuilder.java | 37 ++++ .../axiom/lang/api/AxiomItemTarget.java | 159 ++++++++++++++++++ .../axiom/lang/api/AxiomItemValueBuilder.java | 9 + .../lang/impl/ItemStreamContextBuilder.java | 104 ++++++++++++ .../lang/spi/AxiomIdentifierResolver.java | 20 ++- .../axiom/lang/test/AbstractReactorTest.java | 7 +- .../axiom/lang/test/TestTypeDerivation.java | 35 +++- .../multimodel/derived/base-person.axiom | 1 + .../multimodel/derived/derived-person.axiom | 4 + .../multimodel/derived/john-doe.axiomd | 4 + 12 files changed, 483 insertions(+), 5 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java create mode 100644 infra/axiom/src/test/resources/multimodel/derived/john-doe.axiomd diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index 35447bd25ac..d75c343fae1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -60,6 +60,10 @@ protected final StatementContext root() { return root; } + public final void stream(AxiomItemStream.TargetWithResolver target) { + stream(target, Optional.empty()); + } + public final void stream(AxiomItemStream.TargetWithResolver target, Optional> emitOnly) { AxiomAntlrVisitor2 visitor = new AxiomAntlrVisitor2<>(sourceName, target, emitOnly.orElse(null)); visitor.visit(root); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java new file mode 100644 index 00000000000..7050161b565 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java @@ -0,0 +1,104 @@ +/* + * 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.Deque; +import java.util.LinkedList; +import java.util.Optional; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; +import com.evolveum.axiom.lang.spi.SourceLocation; +import com.google.common.base.Preconditions; + + +public class AxiomBuilderStreamTarget implements AxiomItemStream.TargetWithResolver { + + private final Deque queue = new LinkedList<>(); + + protected AxiomBuilderStreamTarget() {} + + public AxiomBuilderStreamTarget(ValueBuilder root) { + queue.add(root); + } + + protected V offer(V builder) { + queue.offerFirst(builder); + return builder; + } + + protected Builder current() { + return queue.peek(); + } + + protected Builder poll() { + return queue.poll(); + } + + private ItemBuilder item(Builder node) { + Preconditions.checkState(node instanceof ItemBuilder); + return (ItemBuilder) node; + } + + private ValueBuilder value(Builder node) { + Preconditions.checkState(node instanceof ValueBuilder); + return (ValueBuilder) node; + } + + @Override + public void startValue(Object value, SourceLocation loc) { + queue.offerFirst(item(current()).startValue(value, loc)); + } + + @Override + public void endValue(SourceLocation loc) { + value(poll()).endValue(loc); + } + + @Override + public void startItem(AxiomIdentifier item, SourceLocation loc) { + Optional childDef = value(current()).childDef(item); + AxiomSyntaxException.check(childDef.isPresent(), loc , "Item %s not allowed in %s", item, current().name()); + offer(value(current()).startItem(item, loc)); + } + + @Override + public void endItem(SourceLocation loc) { + item(poll()).endNode(loc); + } + + private interface Builder { + AxiomIdentifier name(); + + AxiomIdentifierResolver itemResolver(); + + AxiomIdentifierResolver valueResolver(); + } + + public interface ItemBuilder extends Builder { + ValueBuilder startValue(Object value, SourceLocation loc); + void endNode(SourceLocation loc); + + } + + public interface ValueBuilder extends Builder { + Optional childDef(AxiomIdentifier statement); + ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc); + void endValue(SourceLocation loc); + } + + @Override + public AxiomIdentifierResolver itemResolver() { + return current().itemResolver(); + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return current().valueResolver(); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java new file mode 100644 index 00000000000..5c4c5f67ab5 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java @@ -0,0 +1,37 @@ +package com.evolveum.axiom.lang.api; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.function.Supplier; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; + +public class AxiomItemBuilder implements Supplier> { + + Collection>> values = new ArrayList<>(); + private AxiomItemDefinition definition; + + public AxiomItemBuilder(AxiomItemDefinition definition) { + this.definition = definition; + } + + public AxiomItemDefinition definition() { + return definition; + } + + public void addValue(Supplier> value) { + values.add(value); + } + + @Override + public AxiomItem get() { + Builder> result = ImmutableList.builder(); + for(Supplier> value : values) { + result.add(value.get()); + } + return AxiomItem.from(definition, result.build()); + } + + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java new file mode 100644 index 00000000000..25a705a4189 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java @@ -0,0 +1,159 @@ +package com.evolveum.axiom.lang.api; + +import java.util.Optional; +import java.util.function.Supplier; + +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.SourceLocation; + +public class AxiomItemTarget extends AxiomBuilderStreamTarget implements Supplier>, AxiomItemStream.TargetWithResolver { + + private final AxiomSchemaContext context; + private final AxiomIdentifierResolver resolver; + private Item result; + + public AxiomItemTarget(AxiomSchemaContext context, AxiomIdentifierResolver resolver) { + offer(new Root()); + this.context = context; + this.resolver = resolver; + } + + @Override + public AxiomItem get() { + return result.get(); + } + + private final class Root implements ValueBuilder { + + @Override + public AxiomIdentifier name() { + return AxiomIdentifier.axiom("AbstractRoot"); + } + + @Override + public AxiomIdentifierResolver itemResolver() { + return resolver; + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return resolver; + } + + @Override + public Optional childDef(AxiomIdentifier statement) { + return context.getRoot(statement); + } + + @Override + public ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc) { + result = new Item<>(childDef(identifier).get()); + return result; + } + + @Override + public void endValue(SourceLocation loc) { + + } + + } + + private final class Item implements ItemBuilder, Supplier> { + + private AxiomItemBuilder builder; + + public Item(AxiomItemDefinition definition) { + this.builder = new AxiomItemBuilder<>(definition); + } + + @Override + public AxiomIdentifier name() { + return builder.definition().name(); + } + + @Override + public AxiomIdentifierResolver itemResolver() { + return resolver; + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return resolver; + } + + @Override + public ValueBuilder startValue(Object value, SourceLocation loc) { + Value newValue = new Value<>((V) value, builder.definition().typeDefinition()); + builder.addValue(newValue); + return newValue; + } + + @Override + public void endNode(SourceLocation loc) { + // Noop for now + } + + @Override + public AxiomItem get() { + return builder.get(); + } + + + } + + private final class Value implements ValueBuilder, Supplier> { + + private final AxiomItemValueBuilder builder; + + public Value(V value, AxiomTypeDefinition type) { + builder = AxiomItemValueBuilder.from(type); + builder.setValue(value); + if(value != null && type.argument().isPresent()) { + AxiomItemDefinition argument = type.argument().get(); + startItem(argument.name(), null).startValue(value, null); + } else { + builder.setValue(value); + } + } + + @Override + public AxiomIdentifier name() { + return builder.type().name(); + } + + @Override + public AxiomIdentifierResolver itemResolver() { + return AxiomIdentifierResolver.defaultNamespaceFromType(builder.type()); + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return resolver; + } + + @Override + public Optional childDef(AxiomIdentifier statement) { + return builder.type().itemDefinition(statement); + } + + @Override + public ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc) { + Object itemImpl = builder.get(identifier, (id) -> { + return new Item(childDef(identifier).get()); + }); + return (Item) (itemImpl); + } + + @Override + public void endValue(SourceLocation loc) { + // Noop for now + } + + @Override + public AxiomItemValue get() { + return builder.get(); + } + + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java index c2e9045f3e1..6b78a6a541b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java @@ -1,6 +1,7 @@ package com.evolveum.axiom.lang.api; import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.impl.ItemValueImpl; import java.util.LinkedHashMap; import java.util.Map; @@ -25,6 +26,10 @@ public AxiomItemValueBuilder(AxiomTypeDefinition type, AxiomItemValueFactory AxiomItemValueBuilder> from(AxiomTypeDefinition type) { + return new AxiomItemValueBuilder(type, ItemValueImpl.factory()); + } + public V getValue() { return value; } @@ -62,4 +67,8 @@ public void setFactory(AxiomItemValueFactory factoryFor) { this.factory = factoryFor; } + public AxiomTypeDefinition type() { + return type; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java new file mode 100644 index 00000000000..205a67198dc --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java @@ -0,0 +1,104 @@ +/* + * 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.impl; + +import java.util.Deque; +import java.util.LinkedList; +import java.util.Optional; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemStream; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; +import com.evolveum.axiom.lang.spi.SourceLocation; +import com.google.common.base.Preconditions; + + +public class ItemStreamContextBuilder implements AxiomItemStream.TargetWithResolver { + + private final Deque queue = new LinkedList<>(); + + public ItemStreamContextBuilder(ValueBuilder root) { + queue.add(root); + } + + protected V offer(V builder) { + queue.offerFirst(builder); + return builder; + } + + protected Builder current() { + return queue.peek(); + } + + protected Builder poll() { + return queue.poll(); + } + + private ItemBuilder item(Builder node) { + Preconditions.checkState(node instanceof ItemBuilder); + return (ItemBuilder) node; + } + + private ValueBuilder value(Builder node) { + Preconditions.checkState(node instanceof ValueBuilder); + return (ValueBuilder) node; + } + + @Override + public void startValue(Object value, SourceLocation loc) { + queue.offerFirst(item(current()).startValue(value, loc)); + } + + @Override + public void endValue(SourceLocation loc) { + value(poll()).endValue(loc); + } + + @Override + public void startItem(AxiomIdentifier item, SourceLocation loc) { + Optional childDef = value(current()).childDef(item); + AxiomSyntaxException.check(childDef.isPresent(), loc , "Item %s not allowed in %s", item, current().name()); + offer(value(current()).startItem(item, loc)); + } + + @Override + public void endItem(SourceLocation loc) { + item(poll()).endNode(loc); + } + + private interface Builder { + AxiomIdentifier name(); + + AxiomIdentifierResolver itemResolver(); + + AxiomIdentifierResolver valueResolver(); + } + + public interface ItemBuilder extends Builder { + ValueBuilder startValue(Object value, SourceLocation loc); + void endNode(SourceLocation loc); + + } + + public interface ValueBuilder extends Builder { + Optional childDef(AxiomIdentifier statement); + ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc); + void endValue(SourceLocation loc); + } + + @Override + public AxiomIdentifierResolver itemResolver() { + return current().itemResolver(); + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return current().valueResolver(); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java index a0cc6ec4651..7e4467f1b76 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java @@ -6,11 +6,16 @@ */ package com.evolveum.axiom.lang.spi; +import java.util.Optional; import java.util.Set; import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.meta.Inheritance; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; import org.jetbrains.annotations.Nullable; @@ -29,7 +34,7 @@ public interface AxiomIdentifierResolver { AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName); static AxiomIdentifierResolver defaultNamespace(String namespace) { - return (prefix, localName) -> prefix == null ? AxiomIdentifier.from(namespace, localName) : null; + return (prefix, localName) -> Strings.isNullOrEmpty(prefix) ? AxiomIdentifier.from(namespace, localName) : null; } default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { @@ -42,4 +47,17 @@ default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { }; } + static AxiomIdentifierResolver defaultNamespaceFromType(AxiomTypeDefinition type) { + return (prefix, localName) -> { + if(Strings.isNullOrEmpty(prefix)) { + AxiomIdentifier localNs = AxiomIdentifier.local(localName); + Optional childDef = type.itemDefinition(localNs); + if(childDef.isPresent()) { + return Inheritance.adapt(type.name(), childDef.get()); + } + } + return null; + }; + } + } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java index 2c392debc06..8b93c34fabd 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java @@ -5,7 +5,7 @@ import java.io.IOException; import java.io.InputStream; -import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; @@ -37,4 +37,9 @@ protected static AxiomModelStatementSource source(String name) throws AxiomSynta InputStream stream = new FileInputStream(COMMON_DIR_PATH + name); return AxiomModelStatementSource.from(name, stream); } + + protected static AxiomAntlrStatementSource dataSource(String name) throws AxiomSyntaxException, IOException { + InputStream stream = new FileInputStream(COMMON_DIR_PATH + name); + return AxiomAntlrStatementSource.from(name, stream); + } } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 0bc1dffe4ad..87c5f998ee7 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -9,6 +9,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map.Entry; import java.util.Optional; @@ -20,25 +21,38 @@ import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.meta.Inheritance; +import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; +import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomItemTarget; +import com.evolveum.axiom.lang.api.AxiomItemValue; import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class TestTypeDerivation extends AbstractReactorTest { private static final AxiomIdentifier DERIVED_PERSON = AxiomIdentifier.from("https://example.org/derived", "Person"); + private static final AxiomIdentifier FIRST_NAME = DERIVED_PERSON.localName("firstName"); + private static final AxiomIdentifier LAST_NAME = DERIVED_PERSON.localName("lastName"); + private static final AxiomIdentifier NAME = AxiomIdentifier.from("https://example.org/base", "name"); private static final String DIR = "multimodel/derived/"; private static final String BASE = DIR + "base-person.axiom"; private static final String DERIVED = DIR + "derived-person.axiom"; + private static final String JOHN_DOE_FILE = DIR + "john-doe.axiomd"; - @Test - public void axiomTestInheritance() throws IOException, AxiomSyntaxException { + + private AxiomSchemaContext loadModel() throws AxiomSyntaxException, IOException { ModelReactorContext context = ModelReactorContext.defaultReactor(); context.loadModelFromSource(source(BASE)); context.loadModelFromSource(source(DERIVED)); - AxiomSchemaContext schemaContext = context.computeSchemaContext(); + return context.computeSchemaContext(); + } + @Test + public void axiomTestInheritance() throws IOException, AxiomSyntaxException { + AxiomSchemaContext schemaContext = loadModel(); AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); assertTrue(!langExtDef.identifierDefinitions().isEmpty()); @@ -49,4 +63,19 @@ public void axiomTestInheritance() throws IOException, AxiomSyntaxException { assertEquals(idDef.getKey(), Inheritance.adapt(DERIVED_PERSON, item), " should have different namespace"); } } + + @Test + public void axiomData() throws AxiomSyntaxException, FileNotFoundException, IOException { + AxiomSchemaContext context = loadModel(); + AxiomAntlrStatementSource stream = dataSource(JOHN_DOE_FILE); + AxiomItemTarget target = new AxiomItemTarget(context, AxiomIdentifierResolver.defaultNamespace(DERIVED_PERSON.namespace())); + stream.stream(target); + AxiomItem root = target.get(); + assertEquals(root.name(), DERIVED_PERSON.localName("person")); + AxiomItemValue person = root.onlyValue(); + assertEquals(person.item(NAME).get().onlyValue().get(), "John Doe"); + assertEquals(person.item(FIRST_NAME).get().onlyValue().get(), "John"); + + + } } diff --git a/infra/axiom/src/test/resources/multimodel/derived/base-person.axiom b/infra/axiom/src/test/resources/multimodel/derived/base-person.axiom index 78eb8f6dfc1..a421db08a3b 100644 --- a/infra/axiom/src/test/resources/multimodel/derived/base-person.axiom +++ b/infra/axiom/src/test/resources/multimodel/derived/base-person.axiom @@ -3,6 +3,7 @@ model base-person { namespace "https://example.org/base"; type Person { + argument name; item name { type string; } diff --git a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom index 6a2a563dc79..485cfe16761 100644 --- a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom +++ b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom @@ -6,6 +6,10 @@ model derived-person { namespace "https://example.org/base"; } + root person { + type Person; + } + type Person { extends base:Person; diff --git a/infra/axiom/src/test/resources/multimodel/derived/john-doe.axiomd b/infra/axiom/src/test/resources/multimodel/derived/john-doe.axiomd new file mode 100644 index 00000000000..532784466de --- /dev/null +++ b/infra/axiom/src/test/resources/multimodel/derived/john-doe.axiomd @@ -0,0 +1,4 @@ +person "John Doe" { + firstName "John"; + lastName "Doe"; +} \ No newline at end of file From e5c92f95f73552f95ad56fba09a88c973d1a3aba Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 10:50:07 +0200 Subject: [PATCH 28/60] Renamed AxiomItemValue to AxiomValue Signed-off-by: Tony Tkacik --- .../lang/api/AxiomIdentifierDefinition.java | 2 +- .../evolveum/axiom/lang/api/AxiomItem.java | 8 +++--- .../axiom/lang/api/AxiomItemBuilder.java | 8 +++--- .../axiom/lang/api/AxiomItemDefinition.java | 2 +- .../axiom/lang/api/AxiomItemFactory.java | 2 +- .../axiom/lang/api/AxiomItemImpl.java | 8 +++--- .../axiom/lang/api/AxiomItemTarget.java | 8 +++--- .../axiom/lang/api/AxiomTypeDefinition.java | 2 +- .../{AxiomItemValue.java => AxiomValue.java} | 6 ++-- ...lueBuilder.java => AxiomValueBuilder.java} | 16 +++++------ ...lueFactory.java => AxiomValueFactory.java} | 2 +- .../axiom/lang/api/CompactAxiomItem.java | 6 ++-- ...{SimpleItemValue.java => SimpleValue.java} | 4 +-- .../lang/impl/AxiomSchemaContextImpl.java | 10 +++---- .../axiom/lang/impl/AxiomStatementRule.java | 8 +++--- .../axiom/lang/impl/AxiomValueContext.java | 4 +-- .../axiom/lang/impl/BasicStatementRule.java | 20 ++++++------- .../lang/impl/IdentifierSpaceHolderImpl.java | 8 +++--- .../evolveum/axiom/lang/impl/ItemContext.java | 4 +-- .../axiom/lang/impl/ItemValueImpl.java | 12 ++++---- .../axiom/lang/impl/ModelReactorContext.java | 14 +++++----- .../axiom/lang/impl/SourceContext.java | 6 ++-- .../axiom/lang/impl/ValueActionImpl.java | 6 ++-- .../axiom/lang/impl/ValueContext.java | 28 +++++++++---------- .../spi/AxiomIdentifierDefinitionImpl.java | 8 +++--- .../lang/spi/AxiomItemDefinitionImpl.java | 4 +-- .../lang/spi/AxiomTypeDefinitionImpl.java | 12 ++++---- .../axiom/lang/test/TestTypeDerivation.java | 4 +-- 28 files changed, 111 insertions(+), 111 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/api/{AxiomItemValue.java => AxiomValue.java} (79%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/api/{AxiomItemValueBuilder.java => AxiomValueBuilder.java} (71%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/api/{AxiomItemValueFactory.java => AxiomValueFactory.java} (73%) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/api/{SimpleItemValue.java => SimpleValue.java} (77%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java index 7db0007aff8..01c65500a5f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java @@ -6,7 +6,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.collect.ImmutableSet; -public interface AxiomIdentifierDefinition extends AxiomItemValue { +public interface AxiomIdentifierDefinition extends AxiomValue { @Override default AxiomIdentifierDefinition get() { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java index 3783bcb4a80..b40e029169d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java @@ -12,9 +12,9 @@ public interface AxiomItem { AxiomIdentifier name(); Optional definition(); - Collection> values(); + Collection> values(); - default AxiomItemValue onlyValue() { + default AxiomValue onlyValue() { return Iterables.getOnlyElement(values()); } @@ -22,11 +22,11 @@ static AxiomItem of(AxiomItemDefinition def, V value) { return CompactAxiomItem.of(def, value); } - static AxiomItem from(AxiomItemDefinition def, Collection> values) { + static AxiomItem from(AxiomItemDefinition def, Collection> values) { return AxiomItemImpl.from(def, values); } - static AxiomItem from(AxiomItemDefinition def, AxiomItemValue value) { + static AxiomItem from(AxiomItemDefinition def, AxiomValue value) { return AxiomItemImpl.from(def, Collections.singleton(value)); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java index 5c4c5f67ab5..ce8d955f509 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java @@ -9,7 +9,7 @@ public class AxiomItemBuilder implements Supplier> { - Collection>> values = new ArrayList<>(); + Collection>> values = new ArrayList<>(); private AxiomItemDefinition definition; public AxiomItemBuilder(AxiomItemDefinition definition) { @@ -20,14 +20,14 @@ public AxiomItemDefinition definition() { return definition; } - public void addValue(Supplier> value) { + public void addValue(Supplier> value) { values.add(value); } @Override public AxiomItem get() { - Builder> result = ImmutableList.builder(); - for(Supplier> value : values) { + Builder> result = ImmutableList.builder(); + for(Supplier> value : values) { result.add(value.get()); } return AxiomItem.from(definition, result.build()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java index e2a8464df11..307bbd2f67c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java @@ -10,7 +10,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; -public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomItemValue { +public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomValue { AxiomIdentifier ROOT_SPACE = AxiomIdentifier.axiom("AxiomRootDefinition"); AxiomIdentifier SPACE = AxiomIdentifier.axiom("AxiomItemDefinition"); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java index 69131b6268a..1d917e19493 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java @@ -4,6 +4,6 @@ public interface AxiomItemFactory { - AxiomItem create(AxiomItemDefinition def, Collection> axiomItem); + AxiomItem create(AxiomItemDefinition def, Collection> axiomItem); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java index 765abc850a6..c891408a33c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java @@ -6,20 +6,20 @@ class AxiomItemImpl extends AbstractAxiomItem { - Collection> values; + Collection> values; - private AxiomItemImpl(AxiomItemDefinition definition, Collection> val) { + private AxiomItemImpl(AxiomItemDefinition definition, Collection> val) { super(definition); this.values = ImmutableList.copyOf(val); } - static AxiomItem from(AxiomItemDefinition definition, Collection> values) { + static AxiomItem from(AxiomItemDefinition definition, Collection> values) { return new AxiomItemImpl<>(definition, values); } @Override - public Collection> values() { + public Collection> values() { return values; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java index 25a705a4189..cba53d1c0ca 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java @@ -102,12 +102,12 @@ public AxiomItem get() { } - private final class Value implements ValueBuilder, Supplier> { + private final class Value implements ValueBuilder, Supplier> { - private final AxiomItemValueBuilder builder; + private final AxiomValueBuilder builder; public Value(V value, AxiomTypeDefinition type) { - builder = AxiomItemValueBuilder.from(type); + builder = AxiomValueBuilder.from(type); builder.setValue(value); if(value != null && type.argument().isPresent()) { AxiomItemDefinition argument = type.argument().get(); @@ -151,7 +151,7 @@ public void endValue(SourceLocation loc) { } @Override - public AxiomItemValue get() { + public AxiomValue get() { return builder.get(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java index 3cde7a1469a..ef93010d234 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java @@ -15,7 +15,7 @@ import com.evolveum.axiom.api.meta.Inheritance; import com.google.common.collect.ImmutableMap; -public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomItemValue { +public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomValue { public final AxiomIdentifier IDENTIFIER_MEMBER = AxiomIdentifier.axiom("name"); public final AxiomIdentifier IDENTIFIER_SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition"); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValue.java similarity index 79% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValue.java index 29b40321e79..d2b95076e8c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValue.java @@ -8,7 +8,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; -public interface AxiomItemValue extends Supplier { +public interface AxiomValue extends Supplier { Optional type(); @@ -29,8 +29,8 @@ default Optional> item(AxiomIdentifier name) { @Override V get(); - static AxiomItemValue from(AxiomTypeDefinition typeDefinition, V value) { - return new SimpleItemValue(typeDefinition, value); + static AxiomValue from(AxiomTypeDefinition typeDefinition, V value) { + return new SimpleValue(typeDefinition, value); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueBuilder.java similarity index 71% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueBuilder.java index 6b78a6a541b..6c59bcee215 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueBuilder.java @@ -13,21 +13,21 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -public class AxiomItemValueBuilder> implements Lazy.Supplier { +public class AxiomValueBuilder> implements Lazy.Supplier { private final AxiomTypeDefinition type; - private AxiomItemValueFactory factory; + private AxiomValueFactory factory; private Map>> children = new LinkedHashMap<>(); private V value; - public AxiomItemValueBuilder(AxiomTypeDefinition type, AxiomItemValueFactory factory) { + public AxiomValueBuilder(AxiomTypeDefinition type, AxiomValueFactory factory) { this.type = type; this.factory = factory; } - public static AxiomItemValueBuilder> from(AxiomTypeDefinition type) { - return new AxiomItemValueBuilder(type, ItemValueImpl.factory()); + public static AxiomValueBuilder> from(AxiomTypeDefinition type) { + return new AxiomValueBuilder(type, ItemValueImpl.factory()); } public V getValue() { @@ -59,11 +59,11 @@ public T get() { return factory.create(type, value, builder.build()); } - public static > AxiomItemValueBuilder create(AxiomTypeDefinition type, AxiomItemValueFactory factory) { - return new AxiomItemValueBuilder<>(type, factory); + public static > AxiomValueBuilder create(AxiomTypeDefinition type, AxiomValueFactory factory) { + return new AxiomValueBuilder<>(type, factory); } - public void setFactory(AxiomItemValueFactory factoryFor) { + public void setFactory(AxiomValueFactory factoryFor) { this.factory = factoryFor; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueFactory.java similarity index 73% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueFactory.java index 93fb5d8baa4..1047485ccc8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemValueFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueFactory.java @@ -4,7 +4,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; -public interface AxiomItemValueFactory> { +public interface AxiomValueFactory> { T create(AxiomTypeDefinition def, V value, Map> items); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java index cd300a09322..1f02cffa5d9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java @@ -5,7 +5,7 @@ import com.google.common.collect.ImmutableSet; -class CompactAxiomItem extends AbstractAxiomItem implements AxiomItemValue { +class CompactAxiomItem extends AbstractAxiomItem implements AxiomValue { private final V value; @@ -29,12 +29,12 @@ public V get() { } @Override - public Collection> values() { + public Collection> values() { return ImmutableSet.of(this); } @Override - public AxiomItemValue onlyValue() { + public AxiomValue onlyValue() { return this; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleItemValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleValue.java similarity index 77% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleItemValue.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleValue.java index 4d07e341a13..8342ad94320 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleItemValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleValue.java @@ -2,14 +2,14 @@ import java.util.Optional; -class SimpleItemValue implements AxiomItemValue { +class SimpleValue implements AxiomValue { private final AxiomTypeDefinition type; private final T value; - SimpleItemValue(AxiomTypeDefinition type, T value) { + SimpleValue(AxiomTypeDefinition type, T value) { super(); this.type = type; this.value = value; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index 547bea72415..b7e714d49cc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -7,7 +7,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -18,9 +18,9 @@ public class AxiomSchemaContextImpl implements AxiomSchemaContext { private Map roots; private Map types; - private Map>> globals; + private Map>> globals; - public AxiomSchemaContextImpl(Map>> globalMap) { + public AxiomSchemaContextImpl(Map>> globalMap) { this.globals = globalMap; this.roots = Maps.transformValues(globalMap.get(AxiomItemDefinition.ROOT_SPACE), AxiomItemDefinition.class::cast); this.types = Maps.transformValues(globalMap.get(AxiomTypeDefinition.IDENTIFIER_SPACE), AxiomTypeDefinition.class::cast); @@ -51,8 +51,8 @@ private static IdentifierSpaceKey nameKey(AxiomIdentifier type) { } public static AxiomSchemaContextImpl boostrapContext() { - Map> root = ImmutableMap.of(nameKey(AxiomBuiltIn.Item.MODEL_DEFINITION.name()), AxiomBuiltIn.Item.MODEL_DEFINITION); - Map>> global + Map> root = ImmutableMap.of(nameKey(AxiomBuiltIn.Item.MODEL_DEFINITION.name()), AxiomBuiltIn.Item.MODEL_DEFINITION); + Map>> global = ImmutableMap.of(AxiomItemDefinition.ROOT_SPACE, root, AxiomTypeDefinition.IDENTIFIER_SPACE, ImmutableMap.of()); return new AxiomSchemaContextImpl(global); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index 6fa978895d4..ea8fe236354 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -3,7 +3,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; @@ -31,9 +31,9 @@ default AxiomTypeDefinition typeDefinition() { Dependency> modify(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); - Dependency.Search> global(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + Dependency.Search> global(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); - Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey itemName); + Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey itemName); Dependency finalValue(); @@ -55,7 +55,7 @@ interface ActionBuilder { ActionBuilder apply(Action action); - Dependency> require(AxiomValueContext ext); + Dependency> require(AxiomValueContext ext); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java index 32fc7d5de64..80f1bdf8473 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java @@ -4,13 +4,13 @@ import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; public interface AxiomValueContext { - void replace(AxiomItemValue axiomItemValue); + void replace(AxiomValue axiomItemValue); default AxiomItemContext childItem(AxiomItemDefinition def) { return childItem(def.name()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index c7e4a3bf8ed..9721d819cf3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -14,7 +14,7 @@ import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomModel; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -65,9 +65,9 @@ public boolean isApplicableTo(AxiomItemDefinition definition) { @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Collection idDefs = context.typeDefinition().identifierDefinitions(); - Map>>> identReq = new HashMap<>(); + Map>>> identReq = new HashMap<>(); for(AxiomIdentifierDefinition idDef : idDefs) { - Map>> components = new HashMap<>(); + Map>> components = new HashMap<>(); for(AxiomItemDefinition cmp : idDef.components()) { components.put(cmp.name(), action.require(context.child(cmp, Object.class)) .unsatisfied(()-> context.error("Item '%s' is required by identifier, but not defined.", cmp.name())) @@ -88,7 +88,7 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { AxiomIdentifier type = context.originalValue(); - Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); + Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); typeDef.notFound(() -> action.error("type '%s' was not found.", type)); typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); action.apply(ctx -> { @@ -106,7 +106,7 @@ public boolean isApplicableTo(AxiomItemDefinition definition) { @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { AxiomIdentifier itemName = context.currentValue(); - Search> itemDef = action.require(context.namespaceValue(AxiomItemDefinition.SPACE, AxiomItemDefinition.identifier(itemName))) + Search> itemDef = action.require(context.namespaceValue(AxiomItemDefinition.SPACE, AxiomItemDefinition.identifier(itemName))) .notFound(() -> action.error("item '%s' was not found", itemName)); action.apply((val) -> { val.replace(itemDef.get()); @@ -120,7 +120,7 @@ public void apply(Lookup context, ActionBuilder> typeName = action.require(context.parentValue().child(Item.NAME, AxiomIdentifier.class)) .unsatisfied(() -> action.error("type does not have name defined")); - Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); + Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); typeDef.notFound(() -> action.error("type '%s' was not found.", type)); typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); @@ -180,7 +180,7 @@ public void apply(Lookup context, ActionBuilder> itemDef = action.require(context.child(Item.ITEM_DEFINITION, AxiomItemDefinition.class)); action.apply(ext -> { - for(AxiomItemValue item : itemDef.get().values()) { + for(AxiomValue item : itemDef.get().values()) { targetRef.get().mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, item.get().notInherited())); } }); @@ -208,9 +208,9 @@ private BasicStatementRule(Set items, Set type this.types = ImmutableSet.copyOf(types); } - static IdentifierSpaceKey keyFrom(Map>> ctx) { + static IdentifierSpaceKey keyFrom(Map>> ctx) { ImmutableMap.Builder components = ImmutableMap.builder(); - for(Entry>> entry : ctx.entrySet()) { + for(Entry>> entry : ctx.entrySet()) { components.put(entry.getKey(), entry.getValue().get().get()); } return IdentifierSpaceKey.from(components.build()); @@ -257,7 +257,7 @@ private static IdentifierSpaceKey namespaceId(String uri) { return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); } - public static void addFromType(AxiomItemValue source, AxiomValueContext target, AxiomIdentifier targetName) { + public static void addFromType(AxiomValue source, AxiomValueContext target, AxiomIdentifier targetName) { AxiomTypeDefinition superType = (AxiomTypeDefinition) source.get(); Preconditions.checkState(!(superType instanceof AxiomBuiltIn.Type)); // FIXME: Add namespace change if necessary diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index e6daa6d57f4..d828e42f95a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -9,7 +9,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -47,11 +47,11 @@ public Map> space(AxiomIdentifier spaceId) { return space.computeIfAbsent(spaceId, k -> new HashMap<>()); } - Map>> build() { - ImmutableMap.Builder>> roots = ImmutableMap + Map>> build() { + ImmutableMap.Builder>> roots = ImmutableMap .builder(); for (Entry>> entry : space.entrySet()) { - ImmutableMap.Builder> space = ImmutableMap.builder(); + ImmutableMap.Builder> space = ImmutableMap.builder(); for (Entry> item : entry.getValue().entrySet()) { space.put(item.getKey(), item.getValue().get()); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 26f22ff1cf0..e21738f1e1f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -9,7 +9,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ItemBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; @@ -21,7 +21,7 @@ public class ItemContext extends AbstractContext> implements AxiomItemContext, Supplier>, Dependency>, ItemBuilder { private final AxiomIdentifier name; - Collection>> values = new ArrayList<>(); + Collection>> values = new ArrayList<>(); private final AxiomItemDefinition definition; public ItemContext(ValueContext sourceContext, AxiomIdentifier name, AxiomItemDefinition definition, SourceLocation loc) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index 4788398bade..60aa11fe22b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -7,14 +7,14 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; -import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomValue; +import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; -public class ItemValueImpl implements AxiomItemValue { +public class ItemValueImpl implements AxiomValue { @SuppressWarnings({ "rawtypes", "unchecked" }) - private static final AxiomItemValueFactory FACTORY = ItemValueImpl::new; + private static final AxiomValueFactory FACTORY = ItemValueImpl::new; private final AxiomTypeDefinition type; private final V value; private final Map> items; @@ -29,7 +29,7 @@ public ItemValueImpl(AxiomTypeDefinition type, V value, Map AxiomItemValueFactory> factory() { + public static AxiomValueFactory> factory() { return FACTORY; } @@ -45,7 +45,7 @@ public V get() { @Override public Optional> item(AxiomItemDefinition def) { - return AxiomItemValue.super.item(def); + return AxiomValue.super.item(def); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 20365b4b975..82a8607c05b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -17,8 +17,8 @@ import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomItemValue; -import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomValue; +import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -102,7 +102,7 @@ private static void defaults(ModelReactorContext reactorContext) { IdentifierSpaceHolderImpl globalSpace = new IdentifierSpaceHolderImpl(Scope.GLOBAL); - Map> typeFactories = new HashMap<>(); + Map> typeFactories = new HashMap<>(); List> roots = new ArrayList<>(); public ModelReactorContext(AxiomSchemaContext boostrapContext) { @@ -165,17 +165,17 @@ public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull Strin return null; } - public void addStatementFactory(AxiomIdentifier statementType, AxiomItemValueFactory factory) { + public void addStatementFactory(AxiomIdentifier statementType, AxiomValueFactory factory) { typeFactories.put(statementType, factory); } - public AxiomItemValueFactory> typeFactory(AxiomTypeDefinition statementType) { + public AxiomValueFactory> typeFactory(AxiomTypeDefinition statementType) { Optional current = Optional.of(statementType); do { @SuppressWarnings("unchecked") - AxiomItemValueFactory maybe = (AxiomItemValueFactory) typeFactories.get(current.get().name()); + AxiomValueFactory maybe = (AxiomValueFactory) typeFactories.get(current.get().name()); if (maybe != null) { - return (AxiomItemValueFactory) maybe; + return (AxiomValueFactory) maybe; } current = current.get().superType(); } while (current.isPresent()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 8f66a30b50a..6f39aecfeca 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -7,8 +7,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; -import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomValue; +import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; @@ -73,7 +73,7 @@ public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { return globalSpace.lookup(space, key); } - public AxiomItemValueFactory> factoryFor(AxiomTypeDefinition type) { + public AxiomValueFactory> factoryFor(AxiomTypeDefinition type) { return context.typeFactory(type); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java index 175a7de0ee3..25c8442a7fd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java @@ -7,7 +7,7 @@ import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.DependantAction; @@ -119,8 +119,8 @@ public Collection> build() { @Override - public Dependency> require(AxiomValueContext ext) { - return require((Dependency>) ext); + public Dependency> require(AxiomValueContext ext) { + return require((Dependency>) ext); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 78943a4e305..1c79b1e8464 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -4,8 +4,8 @@ import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; -import com.evolveum.axiom.lang.api.AxiomItemValueBuilder; +import com.evolveum.axiom.lang.api.AxiomValue; +import com.evolveum.axiom.lang.api.AxiomValueBuilder; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; @@ -26,9 +26,9 @@ import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.SourceLocation; -public class ValueContext extends AbstractContext> implements AxiomValueContext, ValueBuilder, Dependency> { +public class ValueContext extends AbstractContext> implements AxiomValueContext, ValueBuilder, Dependency> { - private Dependency> result; + private Dependency> result; private final LookupImpl lookup = new LookupImpl(); private final V originalValue; private final Collection> dependencies = new HashSet<>(); @@ -80,7 +80,7 @@ public boolean isSatisfied() { } @Override - public AxiomItemValue get() { + public AxiomValue get() { return result.get(); } @@ -106,16 +106,16 @@ protected ItemContext createItem(AxiomIdentifier id, SourceLocation loc) { return new ItemContext<>(this, id ,childDef(id).get(), loc); } - private class Result implements Dependency> { + private class Result implements Dependency> { AxiomTypeDefinition type; - AxiomItemValueBuilder> builder; + AxiomValueBuilder> builder; private V value; public Result(AxiomTypeDefinition type, V value) { this.type = type; this.value = value; - builder = AxiomItemValueBuilder.create(type, null); + builder = AxiomValueBuilder.create(type, null); } ItemContext getOrCreateItem(AxiomIdentifier identifier, SourceLocation loc) { @@ -143,7 +143,7 @@ public boolean isSatisfied() { } @Override - public AxiomItemValue get() { + public AxiomValue get() { builder.setValue(value); builder.setFactory(rootImpl().factoryFor(type)); return builder.get(); @@ -161,8 +161,8 @@ void addDependency(Dependency action) { } @Override - public void replace(AxiomItemValue axiomItemValue) { - this.result = Dependency.immediate((AxiomItemValue) axiomItemValue); + public void replace(AxiomValue axiomItemValue) { + this.result = Dependency.immediate((AxiomValue) axiomItemValue); } @Override @@ -181,7 +181,7 @@ public V currentValue() { @Override public void mergeItem(AxiomItem axiomItem) { ItemContext item = startItem(axiomItem.name(), SourceLocation.runtime()); - for(AxiomItemValue value : axiomItem.values()) { + for(AxiomValue value : axiomItem.values()) { ValueContext valueCtx = item.startValue(value.get(),SourceLocation.runtime()); valueCtx.replace(value); valueCtx.endValue(SourceLocation.runtime()); @@ -278,7 +278,7 @@ public Dependency> modify(AxiomIdentifier space, Identifier } @Override - public Dependency.Search> global(AxiomIdentifier space, + public Dependency.Search> global(AxiomIdentifier space, IdentifierSpaceKey key) { return Dependency.retriableDelegate(() -> { ValueContext maybe = lookup(space, key); @@ -290,7 +290,7 @@ public Dependency.Search> global(AxiomIdentifier space, } @Override - public Dependency.Search> namespaceValue(AxiomIdentifier space, + public Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey key) { return Dependency.retriableDelegate(() -> { ValueContext maybe = lookup(space, key); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index ca51b3ae288..831a8b07158 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -9,13 +9,13 @@ import com.google.common.collect.ImmutableList; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; -import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomValue; +import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { - public static final AxiomItemValueFactory FACTORY = AxiomIdentifierDefinitionImpl::new ; + public static final AxiomValueFactory FACTORY = AxiomIdentifierDefinitionImpl::new ; private final Scope scope; @@ -29,7 +29,7 @@ public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, Ax this.space = this.item(Item.ID_SPACE.name()).get().onlyValue().get(); ImmutableList.Builder components = ImmutableList.builder(); - for (AxiomItemValue val : this.item(Item.ID_MEMBER.name()).get().values()) { + for (AxiomValue val : this.item(Item.ID_MEMBER.name()).get().values()) { components.add(val.get()); } this.components = components.build(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index c3898397373..cc0d7dd4d10 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -7,12 +7,12 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { - public static final AxiomItemValueFactory FACTORY = AxiomItemDefinitionImpl::new ; + public static final AxiomValueFactory FACTORY = AxiomItemDefinitionImpl::new ; private final AxiomTypeDefinition valueType; private final Optional> minOccurs; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index c4236ab3c04..4312cb44f2a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -9,8 +9,8 @@ import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemValue; -import com.evolveum.axiom.lang.api.AxiomItemValueFactory; +import com.evolveum.axiom.lang.api.AxiomValue; +import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.google.common.collect.ImmutableMap; @@ -19,7 +19,7 @@ public class AxiomTypeDefinitionImpl extends AbstractBaseDefinition implements AxiomTypeDefinition { - public static final AxiomItemValueFactory FACTORY =AxiomTypeDefinitionImpl::new; + public static final AxiomValueFactory FACTORY =AxiomTypeDefinitionImpl::new; private final Map itemDefinitions; private final Optional superType; @@ -48,7 +48,7 @@ public AxiomTypeDefinition get() { return this; } - private > Collection upcast(Collection> itemValue) { + private > Collection upcast(Collection> itemValue) { return (Collection) itemValue; } @@ -81,8 +81,8 @@ public Collection identifierDefinitions() { } private void supplyAll(AxiomIdentifier type, Builder builder, - Collection> values) { - for(AxiomItemValue v : values) { + Collection> values) { + for(AxiomValue v : values) { AxiomItemDefinition val = v.get(); AxiomIdentifier name = Inheritance.adapt(type, val.name()); builder.put(name, val); diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 87c5f998ee7..2452657e1d4 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -26,7 +26,7 @@ import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemTarget; -import com.evolveum.axiom.lang.api.AxiomItemValue; +import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; @@ -72,7 +72,7 @@ public void axiomData() throws AxiomSyntaxException, FileNotFoundException, IOEx stream.stream(target); AxiomItem root = target.get(); assertEquals(root.name(), DERIVED_PERSON.localName("person")); - AxiomItemValue person = root.onlyValue(); + AxiomValue person = root.onlyValue(); assertEquals(person.item(NAME).get().onlyValue().get(), "John Doe"); assertEquals(person.item(FIRST_NAME).get().onlyValue().get(), "John"); From 4ab84e8a135ef6dd16c7809e21311847c636b345 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 10:51:51 +0200 Subject: [PATCH 29/60] Moved AxiomValue to axiom.api Signed-off-by: Tony Tkacik --- .../java/com/evolveum/axiom/{lang => }/api/AxiomValue.java | 6 ++++-- .../evolveum/axiom/{lang => }/api/AxiomValueBuilder.java | 5 +++-- .../evolveum/axiom/{lang => }/api/AxiomValueFactory.java | 5 +++-- .../java/com/evolveum/axiom/{lang => }/api/SimpleValue.java | 4 +++- .../evolveum/axiom/lang/api/AxiomIdentifierDefinition.java | 1 + .../main/java/com/evolveum/axiom/lang/api/AxiomItem.java | 1 + .../java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java | 1 + .../com/evolveum/axiom/lang/api/AxiomItemDefinition.java | 1 + .../java/com/evolveum/axiom/lang/api/AxiomItemFactory.java | 2 ++ .../java/com/evolveum/axiom/lang/api/AxiomItemImpl.java | 1 + .../java/com/evolveum/axiom/lang/api/AxiomItemTarget.java | 2 ++ .../com/evolveum/axiom/lang/api/AxiomTypeDefinition.java | 1 + .../java/com/evolveum/axiom/lang/api/CompactAxiomItem.java | 1 + .../evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java | 2 +- .../com/evolveum/axiom/lang/impl/AxiomStatementRule.java | 2 +- .../com/evolveum/axiom/lang/impl/AxiomValueContext.java | 2 +- .../com/evolveum/axiom/lang/impl/BasicStatementRule.java | 2 +- .../evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java | 2 +- .../main/java/com/evolveum/axiom/lang/impl/ItemContext.java | 2 +- .../java/com/evolveum/axiom/lang/impl/ItemValueImpl.java | 4 ++-- .../com/evolveum/axiom/lang/impl/ModelReactorContext.java | 4 ++-- .../java/com/evolveum/axiom/lang/impl/SourceContext.java | 4 ++-- .../java/com/evolveum/axiom/lang/impl/ValueActionImpl.java | 2 +- .../java/com/evolveum/axiom/lang/impl/ValueContext.java | 4 ++-- .../axiom/lang/spi/AxiomIdentifierDefinitionImpl.java | 4 ++-- .../evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java | 2 +- .../evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java | 4 ++-- .../com/evolveum/axiom/lang/test/TestTypeDerivation.java | 2 +- 28 files changed, 45 insertions(+), 28 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomValue.java (82%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomValueBuilder.java (94%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomValueFactory.java (57%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/SimpleValue.java (83%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java similarity index 82% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValue.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index d2b95076e8c..20544a6fb81 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -1,11 +1,13 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Collection; import java.util.Collections; import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public interface AxiomValue extends Supplier { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java similarity index 94% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueBuilder.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index 6c59bcee215..c5faa1951c8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -1,6 +1,8 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import com.evolveum.axiom.concepts.Lazy; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.impl.ItemValueImpl; import java.util.LinkedHashMap; @@ -9,7 +11,6 @@ import java.util.function.Function; import java.util.function.Supplier; -import com.evolveum.axiom.api.AxiomIdentifier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java similarity index 57% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueFactory.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java index 1047485ccc8..0e95339b55c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomValueFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java @@ -1,8 +1,9 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Map; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.lang.api.AxiomItem; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public interface AxiomValueFactory> { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java similarity index 83% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleValue.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java index 8342ad94320..8a4533c6a0d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/SimpleValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java @@ -1,7 +1,9 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Optional; +import com.evolveum.axiom.lang.api.AxiomTypeDefinition; + class SimpleValue implements AxiomValue { private final AxiomTypeDefinition type; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java index 01c65500a5f..745ea0cb2b8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java @@ -4,6 +4,7 @@ import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; public interface AxiomIdentifierDefinition extends AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java index b40e029169d..480d527c338 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java @@ -5,6 +5,7 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.Iterables; public interface AxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java index ce8d955f509..8bdced1ea4a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.function.Supplier; +import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java index 307bbd2f67c..bf9912ed503 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java @@ -7,6 +7,7 @@ package com.evolveum.axiom.lang.api; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java index 1d917e19493..cae1e73987c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java @@ -2,6 +2,8 @@ import java.util.Collection; +import com.evolveum.axiom.api.AxiomValue; + public interface AxiomItemFactory { AxiomItem create(AxiomItemDefinition def, Collection> axiomItem); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java index c891408a33c..3ffe5c5c079 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java @@ -2,6 +2,7 @@ import java.util.Collection; +import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableList; class AxiomItemImpl extends AbstractAxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java index cba53d1c0ca..a571bea3396 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java @@ -4,6 +4,8 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValueBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java index ef93010d234..80d72b30f15 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java @@ -12,6 +12,7 @@ import java.util.stream.Collectors; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java index 1f02cffa5d9..abed3b74661 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java @@ -3,6 +3,7 @@ import java.util.Collection; import java.util.Optional; +import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; class CompactAxiomItem extends AbstractAxiomItem implements AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index b7e714d49cc..74eeba3d75f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -5,9 +5,9 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index ea8fe236354..acc542663ae 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -1,9 +1,9 @@ package com.evolveum.axiom.lang.impl; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java index 80f1bdf8473..56b17362f06 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java @@ -1,10 +1,10 @@ package com.evolveum.axiom.lang.impl; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 9721d819cf3..b5755f47663 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -7,6 +7,7 @@ import java.util.Optional; import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; @@ -14,7 +15,6 @@ import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomModel; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index d828e42f95a..8de98e32214 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -7,9 +7,9 @@ import java.util.Map.Entry; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.google.common.base.Preconditions; import com.google.common.base.Strings; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index e21738f1e1f..33c241c3ceb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -7,9 +7,9 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ItemBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index 60aa11fe22b..86924347258 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -5,10 +5,10 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class ItemValueImpl implements AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 82a8607c05b..4fd4c9bf9a4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -11,14 +11,14 @@ import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 6f39aecfeca..d8c609d65c1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -5,10 +5,10 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java index 25c8442a7fd..94b3a467be9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java @@ -7,7 +7,7 @@ import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.lang.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.DependantAction; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 1c79b1e8464..97205b27ed8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -4,8 +4,6 @@ import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomValueBuilder; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; @@ -21,6 +19,8 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValueBuilder; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index 831a8b07158..9eed3480eaf 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -3,14 +3,14 @@ import java.util.Collection; import java.util.Map; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.impl.ItemValueImpl; import com.google.common.collect.ImmutableList; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index cc0d7dd4d10..06d7b35ce9f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -4,10 +4,10 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 4312cb44f2a..a9424427587 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -5,12 +5,12 @@ import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 2452657e1d4..334ca78288e 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -20,13 +20,13 @@ import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemTarget; -import com.evolveum.axiom.lang.api.AxiomValue; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; From 63c7f4c823d6cf072bc6b16f3468a7791d32d600 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 10:52:14 +0200 Subject: [PATCH 30/60] Moved AxiomItem to axiom.api Signed-off-by: Tony Tkacik --- .../evolveum/axiom/{lang => }/api/AbstractAxiomItem.java | 4 +--- .../java/com/evolveum/axiom/{lang => }/api/AxiomItem.java | 4 +--- .../evolveum/axiom/{lang => }/api/AxiomItemBuilder.java | 3 +-- .../evolveum/axiom/{lang => }/api/AxiomItemDefinition.java | 6 +++--- .../evolveum/axiom/{lang => }/api/AxiomItemFactory.java | 4 +--- .../com/evolveum/axiom/{lang => }/api/AxiomItemImpl.java | 3 +-- .../evolveum/axiom/{lang => }/api/AxiomTypeDefinition.java | 7 ++++--- .../src/main/java/com/evolveum/axiom/api/AxiomValue.java | 4 ---- .../java/com/evolveum/axiom/api/AxiomValueBuilder.java | 2 -- .../java/com/evolveum/axiom/api/AxiomValueFactory.java | 3 --- .../evolveum/axiom/{lang => }/api/CompactAxiomItem.java | 3 +-- .../axiom/{lang => }/api/DelegatedItemDefinition.java | 4 +--- .../src/main/java/com/evolveum/axiom/api/SimpleValue.java | 2 -- .../main/java/com/evolveum/axiom/api/meta/Inheritance.java | 2 +- .../evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java | 1 + .../java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java | 2 ++ .../evolveum/axiom/lang/api/AxiomIdentifierDefinition.java | 1 + .../axiom/lang/api/AxiomIdentifierDefinitionImpl.java | 2 ++ .../java/com/evolveum/axiom/lang/api/AxiomItemTarget.java | 4 ++++ .../com/evolveum/axiom/lang/api/AxiomSchemaContext.java | 2 ++ .../java/com/evolveum/axiom/lang/impl/AbstractContext.java | 2 +- .../evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java | 4 ++-- .../com/evolveum/axiom/lang/impl/AxiomStatementRule.java | 6 +++--- .../com/evolveum/axiom/lang/impl/AxiomValueContext.java | 4 ++-- .../com/evolveum/axiom/lang/impl/BasicStatementRule.java | 6 +++--- .../java/com/evolveum/axiom/lang/impl/ItemContext.java | 6 +++--- .../evolveum/axiom/lang/impl/ItemStreamContextBuilder.java | 2 +- .../java/com/evolveum/axiom/lang/impl/ItemValueImpl.java | 6 +++--- .../com/evolveum/axiom/lang/impl/ModelReactorContext.java | 4 ++-- .../java/com/evolveum/axiom/lang/impl/SourceContext.java | 4 ++-- .../java/com/evolveum/axiom/lang/impl/ValueContext.java | 6 +++--- .../evolveum/axiom/lang/spi/AbstractBaseDefinition.java | 4 ++-- .../axiom/lang/spi/AxiomIdentifierDefinitionImpl.java | 6 +++--- .../evolveum/axiom/lang/spi/AxiomIdentifierResolver.java | 4 ++-- .../evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java | 6 +++--- .../axiom/lang/spi/AxiomItemStreamTreeBuilder.java | 2 +- .../evolveum/axiom/lang/spi/AxiomSemanticException.java | 2 +- .../evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java | 6 +++--- .../com/evolveum/axiom/lang/test/AbstractReactorTest.java | 2 +- .../com/evolveum/axiom/lang/test/TestAxiomExtension.java | 4 ++-- .../com/evolveum/axiom/lang/test/TestAxiomMultimodule.java | 3 +-- .../java/com/evolveum/axiom/lang/test/TestAxiomParser.java | 5 ++--- .../com/evolveum/axiom/lang/test/TestTypeDerivation.java | 6 +++--- 43 files changed, 76 insertions(+), 87 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AbstractAxiomItem.java (84%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomItem.java (86%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomItemBuilder.java (92%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomItemDefinition.java (94%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomItemFactory.java (68%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomItemImpl.java (88%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/AxiomTypeDefinition.java (92%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/CompactAxiomItem.java (91%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang => }/api/DelegatedItemDefinition.java (94%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AbstractAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java similarity index 84% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AbstractAxiomItem.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java index 42a9085ca31..f7ba4266d08 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AbstractAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java @@ -1,9 +1,7 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; - public abstract class AbstractAxiomItem implements AxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java similarity index 86% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java index 480d527c338..57777543e49 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java @@ -1,11 +1,9 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Collection; import java.util.Collections; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.Iterables; public interface AxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java similarity index 92% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java index 8bdced1ea4a..f9c03d3c7f3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java @@ -1,10 +1,9 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.ArrayList; import java.util.Collection; import java.util.function.Supplier; -import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemDefinition.java similarity index 94% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemDefinition.java index bf9912ed503..8de95c83fda 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemDefinition.java @@ -4,10 +4,10 @@ * 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; +package com.evolveum.axiom.api; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.lang.api.AxiomNamedDefinition; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemFactory.java similarity index 68% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemFactory.java index cae1e73987c..478d035d7ae 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemFactory.java @@ -1,9 +1,7 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Collection; -import com.evolveum.axiom.api.AxiomValue; - public interface AxiomItemFactory { AxiomItem create(AxiomItemDefinition def, Collection> axiomItem); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java similarity index 88% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java index 3ffe5c5c079..d91c11ed7f9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java @@ -1,8 +1,7 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Collection; -import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableList; class AxiomItemImpl extends AbstractAxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomTypeDefinition.java similarity index 92% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomTypeDefinition.java index 80d72b30f15..c9de977e4b8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomTypeDefinition.java @@ -4,16 +4,17 @@ * 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; +package com.evolveum.axiom.api; import java.util.Collection; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; +import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; +import com.evolveum.axiom.lang.api.AxiomNamedDefinition; +import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.collect.ImmutableMap; public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 20544a6fb81..85d2391d507 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -5,10 +5,6 @@ import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; - public interface AxiomValue extends Supplier { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index c5faa1951c8..8ba8c8ea1c1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -1,8 +1,6 @@ package com.evolveum.axiom.api; import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.impl.ItemValueImpl; import java.util.LinkedHashMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java index 0e95339b55c..5430e174bfc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java @@ -2,9 +2,6 @@ import java.util.Map; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; - public interface AxiomValueFactory> { T create(AxiomTypeDefinition def, V value, Map> items); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java similarity index 91% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java index abed3b74661..cdc0d8013f1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/CompactAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java @@ -1,9 +1,8 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Collection; import java.util.Optional; -import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; class CompactAxiomItem extends AbstractAxiomItem implements AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/DelegatedItemDefinition.java similarity index 94% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/DelegatedItemDefinition.java index 4fdde7e3931..ec7b294029f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/DelegatedItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/DelegatedItemDefinition.java @@ -1,10 +1,8 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api; import java.util.Collection; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; - abstract class DelegatedItemDefinition implements AxiomItemDefinition { protected abstract AxiomItemDefinition delegate(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java index 8a4533c6a0d..98efaa878ab 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java @@ -2,8 +2,6 @@ import java.util.Optional; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; - class SimpleValue implements AxiomValue { private final AxiomTypeDefinition type; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java index ffb44ca0606..063816fed64 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java @@ -1,7 +1,7 @@ package com.evolveum.axiom.api.meta; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomItemDefinition; public interface Inheritance { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java index 7050161b565..750bc906a80 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java @@ -10,6 +10,7 @@ import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 547fd40c27d..802ec2cb82d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -12,6 +12,8 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.concepts.Lazy; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java index 745ea0cb2b8..23fa579cb84 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java @@ -4,6 +4,7 @@ import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinitionImpl.java index 8e94320f2d7..23cd0888080 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinitionImpl.java @@ -4,6 +4,8 @@ import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.google.common.collect.ImmutableSet; class AxiomIdentifierDefinitionImpl implements AxiomIdentifierDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java index a571bea3396..49129528a3f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java @@ -4,6 +4,10 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemBuilder; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomSchemaContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomSchemaContext.java index 89e8565aa38..a1229277ddc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomSchemaContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomSchemaContext.java @@ -4,6 +4,8 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; public interface AxiomSchemaContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java index faacde90e30..3ea96a9a4c5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java @@ -4,8 +4,8 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index 74eeba3d75f..d6ba3df6c00 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -5,11 +5,11 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index acc542663ae..70651c9ce4d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -1,10 +1,10 @@ package com.evolveum.axiom.lang.impl; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java index 56b17362f06..a24f7e01e74 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java @@ -1,10 +1,10 @@ package com.evolveum.axiom.lang.impl; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index b5755f47663..887b73f54f4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -7,16 +7,16 @@ import java.util.Optional; import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomModel; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 33c241c3ceb..a6c20d1874b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -7,10 +7,10 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ItemBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java index 205a67198dc..bf78dce7196 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemStream; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index 86924347258..b2329e574b9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -5,11 +5,11 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class ItemValueImpl implements AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 4fd4c9bf9a4..799a5fa111b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -11,16 +11,16 @@ import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomSchemaContext; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomIdentifierDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index d8c609d65c1..1f9bd7b7caa 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -5,11 +5,11 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 97205b27ed8..7b375d20dd5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -2,9 +2,6 @@ import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; import com.evolveum.axiom.lang.impl.AxiomStatementRule.Lookup; @@ -19,6 +16,9 @@ import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueBuilder; import com.evolveum.axiom.api.meta.Inheritance; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java index e8012a5265c..432cce06afd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java @@ -3,10 +3,10 @@ import java.util.Map; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomNamedDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.impl.ItemValueImpl; public class AbstractBaseDefinition extends ItemValueImpl implements AxiomNamedDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index 9eed3480eaf..4dd65a969d2 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -3,15 +3,15 @@ import java.util.Collection; import java.util.Map; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.impl.ItemValueImpl; import com.google.common.collect.ImmutableList; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java index 7e4467f1b76..6352004aebb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java @@ -12,9 +12,9 @@ import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.meta.Inheritance; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 06d7b35ce9f..0c8965c3d0a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -4,11 +4,11 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java index c37afa12e30..65d6a6f184d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemStream; import com.google.common.base.Preconditions; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java index 0d1c6ea8c0e..947c31b800b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java @@ -1,6 +1,6 @@ package com.evolveum.axiom.lang.spi; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.google.common.base.Strings; public class AxiomSemanticException extends RuntimeException { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index a9424427587..5a0214a8875 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -5,13 +5,13 @@ import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java index 8b93c34fabd..29a69635820 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java @@ -5,10 +5,10 @@ import java.io.IOException; import java.io.InputStream; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index b7b828113f0..3b2ecfdbcfb 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -18,10 +18,10 @@ import com.evolveum.axiom.lang.api.AxiomSchemaContext; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; -import com.evolveum.axiom.lang.api.AxiomItem; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java index a35a9caf581..532089ba447 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java @@ -10,8 +10,7 @@ import java.io.IOException; import org.testng.annotations.Test; - -import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.impl.ModelReactorContext; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index 7ea5f732e9f..0600299a670 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -15,10 +15,9 @@ import org.testng.annotations.Test; - -import com.evolveum.axiom.lang.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomSchemaContext; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.ModelReactorContext; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 334ca78288e..2a17227e626 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -18,14 +18,14 @@ import com.evolveum.axiom.lang.api.AxiomSchemaContext; -import com.evolveum.axiom.lang.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; -import com.evolveum.axiom.lang.api.AxiomItem; -import com.evolveum.axiom.lang.api.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemTarget; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; From d6c31c46aa125305963c151d29c05b6df167aef4 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 11:02:06 +0200 Subject: [PATCH 31/60] Moved Axiom*Definition to axiom.api.schema Signed-off-by: Tony Tkacik --- .../java/com/evolveum/axiom/api/AbstractAxiomItem.java | 2 ++ .../src/main/java/com/evolveum/axiom/api/AxiomItem.java | 1 + .../java/com/evolveum/axiom/api/AxiomItemBuilder.java | 1 + .../java/com/evolveum/axiom/api/AxiomItemFactory.java | 2 ++ .../main/java/com/evolveum/axiom/api/AxiomItemImpl.java | 1 + .../src/main/java/com/evolveum/axiom/api/AxiomValue.java | 3 +++ .../java/com/evolveum/axiom/api/AxiomValueBuilder.java | 1 + .../java/com/evolveum/axiom/api/AxiomValueFactory.java | 2 ++ .../java/com/evolveum/axiom/api/CompactAxiomItem.java | 2 ++ .../src/main/java/com/evolveum/axiom/api/SimpleValue.java | 2 ++ .../java/com/evolveum/axiom/api/meta/Inheritance.java | 2 +- .../api => api/schema}/AxiomIdentifierDefinition.java | 3 +-- .../api => api/schema}/AxiomIdentifierDefinitionImpl.java | 4 +--- .../axiom/api/{ => schema}/AxiomItemDefinition.java | 5 +++-- .../{lang/api => api/schema}/AxiomNamedDefinition.java | 2 +- .../{lang/api => api/schema}/AxiomSchemaContext.java | 6 +++--- .../axiom/api/{ => schema}/AxiomTypeDefinition.java | 6 +++--- .../axiom/api/{ => schema}/DelegatedItemDefinition.java | 5 ++++- .../evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java | 2 +- .../java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java | 5 +++-- .../java/com/evolveum/axiom/lang/api/AxiomItemTarget.java | 5 +++-- .../com/evolveum/axiom/lang/impl/AbstractContext.java | 4 ++-- .../evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java | 6 +++--- .../com/evolveum/axiom/lang/impl/AxiomStatementRule.java | 4 ++-- .../com/evolveum/axiom/lang/impl/AxiomValueContext.java | 4 ++-- .../com/evolveum/axiom/lang/impl/BasicStatementRule.java | 6 +++--- .../axiom/lang/impl/CompositeIdentifierSpace.java | 2 +- .../evolveum/axiom/lang/impl/IdentifierSpaceHolder.java | 2 +- .../axiom/lang/impl/IdentifierSpaceHolderImpl.java | 2 +- .../java/com/evolveum/axiom/lang/impl/ItemContext.java | 4 ++-- .../axiom/lang/impl/ItemStreamContextBuilder.java | 2 +- .../java/com/evolveum/axiom/lang/impl/ItemValueImpl.java | 4 ++-- .../com/evolveum/axiom/lang/impl/ModelReactorContext.java | 8 ++++---- .../java/com/evolveum/axiom/lang/impl/SourceContext.java | 6 +++--- .../java/com/evolveum/axiom/lang/impl/ValueContext.java | 8 ++++---- .../evolveum/axiom/lang/spi/AbstractBaseDefinition.java | 4 ++-- .../axiom/lang/spi/AxiomIdentifierDefinitionImpl.java | 6 +++--- .../evolveum/axiom/lang/spi/AxiomIdentifierResolver.java | 4 ++-- .../evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java | 4 ++-- .../axiom/lang/spi/AxiomItemStreamTreeBuilder.java | 2 +- .../evolveum/axiom/lang/spi/AxiomSemanticException.java | 2 +- .../evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java | 6 +++--- .../com/evolveum/axiom/lang/test/AbstractReactorTest.java | 4 ++-- .../com/evolveum/axiom/lang/test/TestAxiomExtension.java | 5 ++--- .../evolveum/axiom/lang/test/TestAxiomMultimodule.java | 4 ++-- .../com/evolveum/axiom/lang/test/TestAxiomParser.java | 6 +++--- .../java/com/evolveum/axiom/lang/test/TestAxiomPrism.java | 3 +-- .../com/evolveum/axiom/lang/test/TestTypeDerivation.java | 7 +++---- 48 files changed, 99 insertions(+), 82 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => api/schema}/AxiomIdentifierDefinition.java (95%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => api/schema}/AxiomIdentifierDefinitionImpl.java (87%) rename infra/axiom/src/main/java/com/evolveum/axiom/api/{ => schema}/AxiomItemDefinition.java (95%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => api/schema}/AxiomNamedDefinition.java (89%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => api/schema}/AxiomSchemaContext.java (72%) rename infra/axiom/src/main/java/com/evolveum/axiom/api/{ => schema}/AxiomTypeDefinition.java (94%) rename infra/axiom/src/main/java/com/evolveum/axiom/api/{ => schema}/DelegatedItemDefinition.java (92%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java index f7ba4266d08..c350798deb4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java @@ -2,6 +2,8 @@ import java.util.Optional; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; + public abstract class AbstractAxiomItem implements AxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java index 57777543e49..def79148443 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.Optional; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.google.common.collect.Iterables; public interface AxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java index f9c03d3c7f3..02ebb05d437 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.function.Supplier; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemFactory.java index 478d035d7ae..7947e8c40e1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemFactory.java @@ -2,6 +2,8 @@ import java.util.Collection; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; + public interface AxiomItemFactory { AxiomItem create(AxiomItemDefinition def, Collection> axiomItem); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java index d91c11ed7f9..bf8576c71bc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java @@ -2,6 +2,7 @@ import java.util.Collection; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.google.common.collect.ImmutableList; class AxiomItemImpl extends AbstractAxiomItem { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 85d2391d507..370599a308b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -5,6 +5,9 @@ import java.util.Optional; import java.util.function.Supplier; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; + public interface AxiomValue extends Supplier { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index 8ba8c8ea1c1..0f3b87e1dbd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -1,5 +1,6 @@ package com.evolveum.axiom.api; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.impl.ItemValueImpl; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java index 5430e174bfc..8b51c3bc12f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java @@ -2,6 +2,8 @@ import java.util.Map; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; + public interface AxiomValueFactory> { T create(AxiomTypeDefinition def, V value, Map> items); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java index cdc0d8013f1..cddf61e2959 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java @@ -3,6 +3,8 @@ import java.util.Collection; import java.util.Optional; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.google.common.collect.ImmutableSet; class CompactAxiomItem extends AbstractAxiomItem implements AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java index 98efaa878ab..6ef584c7292 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java @@ -2,6 +2,8 @@ import java.util.Optional; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; + class SimpleValue implements AxiomValue { private final AxiomTypeDefinition type; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java index 063816fed64..7fe174266cc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java @@ -1,7 +1,7 @@ package com.evolveum.axiom.api.meta; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; public interface Inheritance { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java similarity index 95% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java index 23fa579cb84..7837b4e140e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java @@ -1,10 +1,9 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api.schema; import java.util.Collection; import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java similarity index 87% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinitionImpl.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java index 23cd0888080..366b2b66f02 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java @@ -1,11 +1,9 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api.schema; import java.util.Optional; import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.google.common.collect.ImmutableSet; class AxiomIdentifierDefinitionImpl implements AxiomIdentifierDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java similarity index 95% rename from infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java index 8de95c83fda..86ef91612b5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java @@ -4,9 +4,10 @@ * 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.api; +package com.evolveum.axiom.api.schema; -import com.evolveum.axiom.lang.api.AxiomNamedDefinition; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomNamedDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomNamedDefinition.java similarity index 89% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomNamedDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomNamedDefinition.java index 4e6854067a9..c726a8cb70d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomNamedDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomNamedDefinition.java @@ -4,7 +4,7 @@ * 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; +package com.evolveum.axiom.api.schema; import com.evolveum.axiom.api.AxiomIdentifier; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomSchemaContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomSchemaContext.java similarity index 72% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomSchemaContext.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomSchemaContext.java index a1229277ddc..8dcd350c001 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomSchemaContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomSchemaContext.java @@ -1,11 +1,9 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api.schema; import java.util.Collection; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; public interface AxiomSchemaContext { @@ -16,4 +14,6 @@ public interface AxiomSchemaContext { Optional getType(AxiomIdentifier type); Collection types(); + + //AxiomValueFactory factoryFor(AxiomTypeDefinition type); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java similarity index 94% rename from infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomTypeDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java index c9de977e4b8..2a706716d17 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java @@ -4,16 +4,16 @@ * 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.api; +package com.evolveum.axiom.api.schema; import java.util.Collection; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; -import com.evolveum.axiom.lang.api.AxiomNamedDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.collect.ImmutableMap; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java similarity index 92% rename from infra/axiom/src/main/java/com/evolveum/axiom/api/DelegatedItemDefinition.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java index ec7b294029f..e58e07ba380 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/DelegatedItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java @@ -1,8 +1,11 @@ -package com.evolveum.axiom.api; +package com.evolveum.axiom.api.schema; import java.util.Collection; import java.util.Optional; +import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomItem; + abstract class DelegatedItemDefinition implements AxiomItemDefinition { protected abstract AxiomItemDefinition delegate(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java index 750bc906a80..93162113bec 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 802ec2cb82d..5789aa2fa4f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -12,8 +12,9 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; +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; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java index 49129528a3f..c963361ab05 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java @@ -6,10 +6,11 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomItemBuilder; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueBuilder; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java index 3ea96a9a4c5..8981689fd2a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java @@ -4,8 +4,8 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index d6ba3df6c00..669cd29736f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -5,11 +5,11 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index 70651c9ce4d..4b980f8d698 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -2,9 +2,9 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java index a24f7e01e74..3cee854c673 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java @@ -2,9 +2,9 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; import com.evolveum.axiom.api.AxiomValue; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 887b73f54f4..136dd6fc253 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -8,14 +8,14 @@ import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; +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.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.api.AxiomModel; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java index fb5efd77449..24684043309 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java @@ -5,8 +5,8 @@ import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; class CompositeIdentifierSpace implements IdentifierSpaceHolder, NamespaceContext { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java index f70d59c7e19..ee410c06c6d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java @@ -3,8 +3,8 @@ import java.util.Map; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; interface IdentifierSpaceHolder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index 8de98e32214..21f48fc2cce 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -8,8 +8,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.google.common.base.Preconditions; import com.google.common.base.Strings; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index a6c20d1874b..95f1b5e6678 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -8,9 +8,9 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ItemBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java index bf78dce7196..eeb80d95f5c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemStream; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index b2329e574b9..18448f51207 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -6,10 +6,10 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; public class ItemValueImpl implements AxiomValue { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 799a5fa111b..8f57c8d5818 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -11,16 +11,16 @@ import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomIdentifierDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 1f9bd7b7caa..e08e959adbf 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -5,13 +5,13 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ValueBuilder; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 7b375d20dd5..8084751a534 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -1,7 +1,5 @@ package com.evolveum.axiom.lang.impl; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; import com.evolveum.axiom.lang.impl.AxiomStatementRule.Lookup; @@ -17,11 +15,13 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueBuilder; import com.evolveum.axiom.api.meta.Inheritance; +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.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.SourceLocation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java index 432cce06afd..97648959166 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java @@ -4,8 +4,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.AxiomNamedDefinition; +import com.evolveum.axiom.api.schema.AxiomNamedDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.impl.ItemValueImpl; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index 4dd65a969d2..688d0495a8f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -4,12 +4,12 @@ import java.util.Map; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; +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.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; import com.evolveum.axiom.lang.impl.ItemValueImpl; import com.google.common.collect.ImmutableList; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java index 6352004aebb..47e1f9b057f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java @@ -12,9 +12,9 @@ import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.meta.Inheritance; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 0c8965c3d0a..8c25fec3911 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -5,9 +5,9 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValueFactory; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java index 65d6a6f184d..e3d0d7d054a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.lang.api.AxiomItemStream; import com.google.common.base.Preconditions; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java index 947c31b800b..023722b0d6e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java @@ -1,6 +1,6 @@ package com.evolveum.axiom.lang.spi; -import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.google.common.base.Strings; public class AxiomSemanticException extends RuntimeException { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 5a0214a8875..2f849f4ad96 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -6,12 +6,12 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.meta.Inheritance; -import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition; +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.lang.api.AxiomBuiltIn.Item; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java index 29a69635820..a165f0d97a0 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/AbstractReactorTest.java @@ -5,11 +5,11 @@ import java.io.IOException; import java.io.InputStream; -import com.evolveum.axiom.api.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.evolveum.midpoint.tools.testng.AbstractUnitTest; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index 3b2ecfdbcfb..0fe43d216b1 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -16,11 +16,10 @@ import org.testng.annotations.Test; - -import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomTypeDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java index 532089ba447..6421d86036e 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomMultimodule.java @@ -10,8 +10,8 @@ import java.io.IOException; import org.testng.annotations.Test; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java index 0600299a670..6d9f7be2b17 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomParser.java @@ -15,9 +15,9 @@ import org.testng.annotations.Test; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; -import com.evolveum.axiom.lang.api.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.ModelReactorContext; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java index 9e2647c7f14..21f7abee4ea 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java @@ -11,9 +11,8 @@ import java.io.IOException; import org.testng.annotations.Test; - -import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 2a17227e626..6207d5ba526 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -16,14 +16,13 @@ import org.testng.annotations.Test; - -import com.evolveum.axiom.lang.api.AxiomSchemaContext; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomItemDefinition; -import com.evolveum.axiom.api.AxiomTypeDefinition; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.api.AxiomItemTarget; From b46f52b2af17b81bcfd8bec3f12c69716549ad1a Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 11:18:14 +0200 Subject: [PATCH 32/60] Axiom: Moved stream interfaces to api.stream Signed-off-by: Tony Tkacik --- .../stream}/AxiomBuilderStreamTarget.java | 4 +-- .../api => api/stream}/AxiomItemStream.java | 4 +-- .../api => api/stream}/AxiomItemTarget.java | 4 +-- .../spi => concepts}/SourceLocation.java | 2 +- .../lang/antlr/AbstractAxiomAntlrVisitor.java | 4 +-- .../lang/antlr/AxiomAntlrStatementSource.java | 2 +- .../axiom/lang/antlr/AxiomAntlrVisitor.java | 4 +-- .../axiom/lang/antlr/AxiomAntlrVisitor2.java | 4 +-- .../axiom/lang/antlr/AxiomErrorListener.java | 3 +- .../lang/antlr/AxiomModelStatementSource.java | 2 +- .../axiom/lang/impl/AbstractContext.java | 2 +- .../lang/impl/IdentifierSpaceHolderImpl.java | 8 ++--- .../evolveum/axiom/lang/impl/ItemContext.java | 2 +- .../lang/impl/ItemStreamContextBuilder.java | 4 +-- .../axiom/lang/impl/ModelReactorContext.java | 2 +- .../axiom/lang/impl/RuleErrorMessage.java | 2 +- .../axiom/lang/impl/SourceContext.java | 2 +- .../axiom/lang/impl/ValueActionImpl.java | 2 +- .../axiom/lang/impl/ValueContext.java | 4 +-- .../lang/spi/AxiomItemStreamTreeBuilder.java | 3 +- .../lang/spi/AxiomSemanticException.java | 34 +++++++------------ .../axiom/lang/spi/AxiomSyntaxException.java | 6 ++-- .../axiom/lang/test/TestTypeDerivation.java | 2 +- 23 files changed, 47 insertions(+), 59 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => api/stream}/AxiomBuilderStreamTarget.java (96%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => api/stream}/AxiomItemStream.java (85%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/api => api/stream}/AxiomItemTarget.java (98%) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/spi => concepts}/SourceLocation.java (95%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java similarity index 96% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java index 93162113bec..a27c5c8d021 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuilderStreamTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java @@ -4,16 +4,16 @@ * 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; +package com.evolveum.axiom.api.stream; import java.util.Deque; import java.util.LinkedList; import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.base.Preconditions; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java similarity index 85% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java index 712c9a5c3af..a20c7bfc64e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemStream.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java @@ -1,8 +1,8 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api.stream; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.SourceLocation; public interface AxiomItemStream { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java similarity index 98% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java index c963361ab05..9484091ad8c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.api; +package com.evolveum.axiom.api.stream; import java.util.Optional; import java.util.function.Supplier; @@ -11,8 +11,8 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.SourceLocation; public class AxiomItemTarget extends AxiomBuilderStreamTarget implements Supplier>, AxiomItemStream.TargetWithResolver { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/SourceLocation.java similarity index 95% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java rename to infra/axiom/src/main/java/com/evolveum/axiom/concepts/SourceLocation.java index bfaca9d8e89..593e423101a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/SourceLocation.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/SourceLocation.java @@ -1,4 +1,4 @@ -package com.evolveum.axiom.lang.spi; +package com.evolveum.axiom.concepts; public class SourceLocation { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java index d1de47ac96c..443bb53d666 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java @@ -12,12 +12,12 @@ import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.stream.AxiomItemStream; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; -import com.evolveum.axiom.lang.api.AxiomItemStream; -import com.evolveum.axiom.lang.spi.SourceLocation; public abstract class AbstractAxiomAntlrVisitor extends AxiomBaseVisitor { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index d75c343fae1..d1134c3fad3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -16,8 +16,8 @@ import org.antlr.v4.runtime.CommonTokenStream; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; -import com.evolveum.axiom.lang.api.AxiomItemStream; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index a2ce03b78cd..b5c3deb0bfd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -9,8 +9,8 @@ import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemStream; -import com.evolveum.axiom.lang.api.AxiomItemStream.Target; +import com.evolveum.axiom.api.stream.AxiomItemStream; +import com.evolveum.axiom.api.stream.AxiomItemStream.Target; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; public class AxiomAntlrVisitor extends AbstractAxiomAntlrVisitor { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java index 80314bef755..bf9e8f8668e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java @@ -9,8 +9,8 @@ import java.util.Set; import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.lang.api.AxiomItemStream; -import com.evolveum.axiom.lang.api.AxiomItemStream.Target; +import com.evolveum.axiom.api.stream.AxiomItemStream; +import com.evolveum.axiom.api.stream.AxiomItemStream.Target; public class AxiomAntlrVisitor2 extends AbstractAxiomAntlrVisitor { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java index 21f8b5eb47f..450e09de14f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomErrorListener.java @@ -12,8 +12,9 @@ import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Recognizer; + +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.evolveum.axiom.lang.spi.SourceLocation; public class AxiomErrorListener extends BaseErrorListener { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 6cf53605841..969afc62e53 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -19,8 +19,8 @@ import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; -import com.evolveum.axiom.lang.api.AxiomItemStream; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java index 8981689fd2a..cfb30f8d341 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java @@ -6,8 +6,8 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.spi.SourceLocation; abstract class AbstractContext

> implements IdentifierSpaceHolder { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index 21f48fc2cce..92729bb93e7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -12,7 +12,6 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; public class IdentifierSpaceHolderImpl implements IdentifierSpaceHolder { @@ -30,11 +29,8 @@ public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, // Auto-generated // method stub ValueContext previous = space(space).putIfAbsent(key, item); - if (previous != null) { - throw new AxiomSemanticException(item.startLocation() - + Strings.lenientFormat("%s identifier space: Item %s is already defined at %s", space, - item, previous.startLocation())); - } + AxiomSemanticException.check(previous == null, item.startLocation(), + "%s identifier space: Item %s is already defined at %s", space,item, previous); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 95f1b5e6678..1e6ba9976b8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -11,9 +11,9 @@ import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ItemBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java index eeb80d95f5c..15cf81fa812 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java @@ -11,10 +11,10 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.schema.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemStream; +import com.evolveum.axiom.api.stream.AxiomItemStream; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.evolveum.axiom.lang.spi.SourceLocation; import com.google.common.base.Preconditions; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 8f57c8d5818..c7646b0dd04 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -129,7 +129,7 @@ protected void failOutstanding(Collection> outstanding) throw } } } - throw new AxiomSemanticException(messages.toString()); + throw new AxiomSemanticException(null, messages.toString()); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java index d4883c1705d..b064f5d093f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/RuleErrorMessage.java @@ -1,6 +1,6 @@ package com.evolveum.axiom.lang.impl; -import com.evolveum.axiom.lang.spi.SourceLocation; +import com.evolveum.axiom.concepts.SourceLocation; import com.google.common.base.Strings; public class RuleErrorMessage { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index e08e959adbf..bae28177601 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -10,11 +10,11 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ValueBuilder; -import com.evolveum.axiom.lang.spi.SourceLocation; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; import com.google.common.base.Strings; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java index 94b3a467be9..3fb2463a63e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java @@ -127,7 +127,7 @@ public Dependency> require(AxiomValueContext ext) { @Override public AxiomSemanticException error(String message, Object... arguments) { - return new AxiomSemanticException(context.startLocation() + Strings.lenientFormat(message, arguments)); + return AxiomSemanticException.create(context.startLocation(), message, arguments); } public String name() { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 8084751a534..0401c265e9b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -22,9 +22,9 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; -import com.evolveum.axiom.lang.spi.SourceLocation; public class ValueContext extends AbstractContext> implements AxiomValueContext, ValueBuilder, Dependency> { @@ -328,7 +328,7 @@ public Lookup parentValue() { @Override public AxiomSemanticException error(String message, Object... arguments) { - return new AxiomSemanticException(startLocation() + " " + Strings.lenientFormat(message, arguments)); + return AxiomSemanticException.create(startLocation(), message, arguments); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java index e3d0d7d054a..3bc2a072331 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java @@ -11,7 +11,8 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.schema.AxiomItemDefinition; -import com.evolveum.axiom.lang.api.AxiomItemStream; +import com.evolveum.axiom.api.stream.AxiomItemStream; +import com.evolveum.axiom.concepts.SourceLocation; import com.google.common.base.Preconditions; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java index 023722b0d6e..d51281e6809 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSemanticException.java @@ -1,39 +1,29 @@ package com.evolveum.axiom.lang.spi; -import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.concepts.SourceLocation; import com.google.common.base.Strings; public class AxiomSemanticException extends RuntimeException { + private final SourceLocation source; - - public AxiomSemanticException(String message, Throwable cause) { - super(message, cause); - } - - public AxiomSemanticException(String message) { - super(message); - } - - public AxiomSemanticException(Throwable cause) { - super(cause); + public AxiomSemanticException(SourceLocation source, String message, Throwable cause) { + super(source + ":" + message, cause); + this.source = source; } - public AxiomSemanticException(AxiomItemDefinition definition, String message) { - super(definition.toString() + " " + message); - } - - public static V checkNotNull(V value, AxiomItemDefinition definition, String message) throws AxiomSemanticException { - if(value == null) { - throw new AxiomSemanticException(definition, message); - } - return value; + public AxiomSemanticException(SourceLocation source, String message) { + this(source, message, null); } public static void check(boolean check, SourceLocation start, String format, Object... arguments) { if(!check) { - throw new AxiomSemanticException(start + Strings.lenientFormat(format, arguments)); + throw create(start, format, arguments); } } + public static AxiomSemanticException create(SourceLocation start, String format, Object... arguments) { + return new AxiomSemanticException(start, Strings.lenientFormat(format, arguments)); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java index 4e2b845d1c2..fbf8efef811 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomSyntaxException.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.Nullable; +import com.evolveum.axiom.concepts.SourceLocation; import com.google.common.base.Strings; public class AxiomSyntaxException extends RuntimeException { @@ -22,8 +23,8 @@ public AxiomSyntaxException(@Nullable final SourceLocation source, String messag this.source = source; } - public AxiomSyntaxException(SourceLocation source2, String message) { - this(source2, message, null); + public AxiomSyntaxException(SourceLocation source, String message) { + this(source, message, null); } public final Optional getSource() { @@ -35,7 +36,6 @@ public String getFormattedMessage() { if (source != null) { sb.append(source); } - return sb.append(getMessage()).toString(); } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 6207d5ba526..81cd005cacb 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -23,9 +23,9 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; +import com.evolveum.axiom.api.stream.AxiomItemTarget; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; -import com.evolveum.axiom.lang.api.AxiomItemTarget; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; From ebe83b01ed82a185d7a685215292e3ad6db14ba6 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 11:23:20 +0200 Subject: [PATCH 33/60] Axiom: Removed duplicate implementation Signed-off-by: Tony Tkacik --- .../axiom/lang/impl/AbstractContext.java | 1 - .../evolveum/axiom/lang/impl/ItemContext.java | 2 +- .../lang/impl/ItemStreamContextBuilder.java | 104 ------------------ .../axiom/lang/impl/ModelReactorContext.java | 3 +- .../axiom/lang/impl/SourceContext.java | 2 +- .../axiom/lang/impl/ValueContext.java | 2 +- 6 files changed, 5 insertions(+), 109 deletions(-) delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java index cfb30f8d341..d35d1c50888 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java @@ -40,7 +40,6 @@ public SourceLocation startLocation() { return start; } - @Override public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { ValueContext maybe = localSpace.lookup(space, key); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 1e6ba9976b8..f81d0c7f983 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -12,7 +12,7 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.concepts.SourceLocation; -import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ItemBuilder; +import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ItemBuilder; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java deleted file mode 100644 index 15cf81fa812..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemStreamContextBuilder.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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.impl; - -import java.util.Deque; -import java.util.LinkedList; -import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; -import com.evolveum.axiom.api.schema.AxiomItemDefinition; -import com.evolveum.axiom.api.stream.AxiomItemStream; -import com.evolveum.axiom.concepts.SourceLocation; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -import com.google.common.base.Preconditions; - - -public class ItemStreamContextBuilder implements AxiomItemStream.TargetWithResolver { - - private final Deque queue = new LinkedList<>(); - - public ItemStreamContextBuilder(ValueBuilder root) { - queue.add(root); - } - - protected V offer(V builder) { - queue.offerFirst(builder); - return builder; - } - - protected Builder current() { - return queue.peek(); - } - - protected Builder poll() { - return queue.poll(); - } - - private ItemBuilder item(Builder node) { - Preconditions.checkState(node instanceof ItemBuilder); - return (ItemBuilder) node; - } - - private ValueBuilder value(Builder node) { - Preconditions.checkState(node instanceof ValueBuilder); - return (ValueBuilder) node; - } - - @Override - public void startValue(Object value, SourceLocation loc) { - queue.offerFirst(item(current()).startValue(value, loc)); - } - - @Override - public void endValue(SourceLocation loc) { - value(poll()).endValue(loc); - } - - @Override - public void startItem(AxiomIdentifier item, SourceLocation loc) { - Optional childDef = value(current()).childDef(item); - AxiomSyntaxException.check(childDef.isPresent(), loc , "Item %s not allowed in %s", item, current().name()); - offer(value(current()).startItem(item, loc)); - } - - @Override - public void endItem(SourceLocation loc) { - item(poll()).endNode(loc); - } - - private interface Builder { - AxiomIdentifier name(); - - AxiomIdentifierResolver itemResolver(); - - AxiomIdentifierResolver valueResolver(); - } - - public interface ItemBuilder extends Builder { - ValueBuilder startValue(Object value, SourceLocation loc); - void endNode(SourceLocation loc); - - } - - public interface ValueBuilder extends Builder { - Optional childDef(AxiomIdentifier statement); - ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc); - void endValue(SourceLocation loc); - } - - @Override - public AxiomIdentifierResolver itemResolver() { - return current().itemResolver(); - } - - @Override - public AxiomIdentifierResolver valueResolver() { - return current().valueResolver(); - } - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index c7646b0dd04..b2dbf02e3bb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -17,6 +17,7 @@ import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; +import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget; import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; @@ -154,7 +155,7 @@ public void addRules(AxiomStatementRule... rules) { public void loadModelFromSource(AxiomModelStatementSource source) { SourceContext sourceCtx = new SourceContext(this, source, source.imports(), new CompositeIdentifierSpace()); - source.stream(new ItemStreamContextBuilder(sourceCtx), Optional.empty()); + source.stream(new AxiomBuilderStreamTarget(sourceCtx), Optional.empty()); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index bae28177601..03f6d33acfb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -14,7 +14,7 @@ import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; -import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ValueBuilder; +import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; import com.google.common.base.Strings; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 0401c265e9b..e7be20b0fbd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -3,7 +3,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; import com.evolveum.axiom.lang.impl.AxiomStatementRule.Lookup; -import com.evolveum.axiom.lang.impl.ItemStreamContextBuilder.ValueBuilder; +import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; import com.google.common.base.Strings; From 281fa7815be635ba7d02571d4004e0d6303c62ef Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 27 May 2020 16:19:38 +0200 Subject: [PATCH 34/60] Axiom: Allow to use any of supertypes as item Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/api/AxiomValue.java | 11 +++ .../evolveum/axiom/api/AxiomValueBuilder.java | 1 + .../axiom/api/schema/AxiomTypeDefinition.java | 2 +- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 7 +- .../axiom/lang/impl/AxiomItemContext.java | 2 + .../lang/impl/AxiomSchemaContextImpl.java | 4 +- .../axiom/lang/impl/AxiomStatementRule.java | 6 +- .../axiom/lang/impl/AxiomValueReference.java | 5 ++ .../axiom/lang/impl/BasicStatementRule.java | 39 +++++----- .../evolveum/axiom/lang/impl/ItemContext.java | 22 +++++- .../axiom/lang/impl/ItemValueImpl.java | 3 + .../evolveum/axiom/lang/impl/LazyValue.java | 33 ++++++++ .../axiom/lang/impl/ValueActionImpl.java | 3 +- .../axiom/lang/impl/ValueContext.java | 76 ++++++++++++++++++- .../lang/spi/AxiomItemDefinitionImpl.java | 7 +- .../lang/spi/AxiomTypeDefinitionImpl.java | 2 +- .../evolveum/axiom/reactor/Dependency.java | 23 +++--- .../axiom/reactor/FlatMapDependency.java | 25 ++++++ .../evolveum/axiom/reactor/MapDependency.java | 26 +++++++ .../axiom/src/main/resources/axiom-lang.axiom | 14 ++-- 20 files changed, 259 insertions(+), 52 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueReference.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 370599a308b..881a4622978 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -34,4 +34,15 @@ static AxiomValue from(AxiomTypeDefinition typeDefinition, V value) { return new SimpleValue(typeDefinition, value); } + default Optional> onlyValue(Class type, AxiomItemDefinition... components) { + Optional> current = Optional.of(this); + for(AxiomItemDefinition name : components) { + current = current.get().item(name).map(v -> v.onlyValue()); + if(current.isEmpty()) { + return Optional.empty(); + } + } + return (Optional) current; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index 0f3b87e1dbd..65114745be9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -54,6 +54,7 @@ public Supplier> get(AxiomIdentifier name, Function> builder = ImmutableMap.builder(); for(Entry>> entry : children.entrySet()) { + AxiomItem item = entry.getValue().get(); builder.put(entry.getKey(), entry.getValue().get()); } return factory.create(type, value, builder.build()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java index 2a706716d17..0298895be02 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java @@ -20,7 +20,7 @@ public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomValue { public final AxiomIdentifier IDENTIFIER_MEMBER = AxiomIdentifier.axiom("name"); - public final AxiomIdentifier IDENTIFIER_SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition"); + public final AxiomIdentifier SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition"); @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 5789aa2fa4f..62770262611 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -54,6 +54,8 @@ public static class Item implements AxiomItemDefinition { 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); + private final AxiomIdentifier identifier; private final AxiomTypeDefinition type; @@ -128,7 +130,10 @@ 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 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, diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java index ca571fb4294..48eeed9c865 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomItemContext.java @@ -8,4 +8,6 @@ public interface AxiomItemContext { T onlyValue(); + void addOperationalValue(AxiomValueReference value); + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index 669cd29736f..f9baaab7af5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -23,7 +23,7 @@ public class AxiomSchemaContextImpl implements AxiomSchemaContext { public AxiomSchemaContextImpl(Map>> globalMap) { this.globals = globalMap; this.roots = Maps.transformValues(globalMap.get(AxiomItemDefinition.ROOT_SPACE), AxiomItemDefinition.class::cast); - this.types = Maps.transformValues(globalMap.get(AxiomTypeDefinition.IDENTIFIER_SPACE), AxiomTypeDefinition.class::cast); + this.types = Maps.transformValues(globalMap.get(AxiomTypeDefinition.SPACE), AxiomTypeDefinition.class::cast); } @Override @@ -53,7 +53,7 @@ private static IdentifierSpaceKey nameKey(AxiomIdentifier type) { public static AxiomSchemaContextImpl boostrapContext() { Map> root = ImmutableMap.of(nameKey(AxiomBuiltIn.Item.MODEL_DEFINITION.name()), AxiomBuiltIn.Item.MODEL_DEFINITION); Map>> global - = ImmutableMap.of(AxiomItemDefinition.ROOT_SPACE, root, AxiomTypeDefinition.IDENTIFIER_SPACE, ImmutableMap.of()); + = ImmutableMap.of(AxiomItemDefinition.ROOT_SPACE, root, AxiomTypeDefinition.SPACE, ImmutableMap.of()); return new AxiomSchemaContextImpl(global); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index 4b980f8d698..c33b538e4e6 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -27,12 +27,16 @@ default AxiomTypeDefinition typeDefinition() { Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); - Dependency> child(AxiomItemDefinition namespace, Class valueType); + Dependency> child(AxiomItemDefinition item, Class valueType); + + Dependency> onlyItemValue(AxiomItemDefinition item, Class valueType); Dependency> modify(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); Dependency.Search> global(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + Dependency.Search> reference(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey itemName); Dependency finalValue(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueReference.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueReference.java new file mode 100644 index 00000000000..b92bdf4852d --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueReference.java @@ -0,0 +1,5 @@ +package com.evolveum.axiom.lang.impl; + +public interface AxiomValueReference { + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 136dd6fc253..b1eaf4389d3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -84,15 +84,21 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { - AxiomIdentifier type = context.originalValue(); - Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); - typeDef.notFound(() -> action.error("type '%s' was not found.", type)); - typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); + + Dependency> typeDef = action.require(context.child(Item.NAME, AxiomIdentifier.class) + .unsatisfied(() -> action.error("type name is missing.")) + .map(v -> v.onlyValue().get()) + .flatMap(name -> + context.reference(AxiomTypeDefinition.SPACE,AxiomTypeDefinition.identifier(name)) + .notFound(() -> action.error("type '%s' was not found.", name)) + .unsatisfied(() -> action.error("Referenced type %s is not complete.", name)) + ) + ); action.apply(ctx -> { - ctx.replace(typeDef.get()); + ctx.childItem(Item.REF_TARGET).addOperationalValue((AxiomValueReference) typeDef.get()); }); } }, @@ -117,16 +123,13 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { - AxiomIdentifier type = context.originalValue(); - Dependency> typeName = action.require(context.parentValue().child(Item.NAME, AxiomIdentifier.class)) - .unsatisfied(() -> action.error("type does not have name defined")); - Dependency.Search> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type))); - - typeDef.notFound(() -> action.error("type '%s' was not found.", type)); - typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type)); + Dependency typeDef = + action.require( + context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) + .map(v -> v.get())); + typeDef.unsatisfied(() -> action.error("Supertype is not complete.")); action.apply(superTypeValue -> { - superTypeValue.replace(typeDef.get()); - addFromType(typeDef.get(), superTypeValue.parentValue(), typeName.get().onlyValue().get()); + addFromType(typeDef.get(), superTypeValue.parentValue(), typeDef.get().name()); }); } @@ -134,7 +137,6 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { Dependency req = action.require(context.namespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES))); @@ -174,9 +176,10 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { Dependency> targetRef = action.require(context.child(Item.TARGET, AxiomIdentifier.class) + .map(v -> v.onlyValue().item(Item.NAME).get())) .flatMap(item -> - context.modify(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(item.onlyValue().get())) - .unsatisfied(() -> action.error("Target %s not found.",item.onlyValue().get())) + context.modify(AxiomTypeDefinition.SPACE, AxiomTypeDefinition.identifier((AxiomIdentifier) item.onlyValue().get())) + .unsatisfied(() -> action.error("Target %s not found.",item.onlyValue().get()) )); Dependency> itemDef = action.require(context.child(Item.ITEM_DEFINITION, AxiomItemDefinition.class)); action.apply(ext -> { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index f81d0c7f983..56f22b9508f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -58,7 +58,14 @@ protected Optional childDef(AxiomIdentifier id) { @Override public boolean isSatisfied() { - return Dependency.allSatisfied(values); + for (Dependency> value : values) { + if(!(value instanceof ValueContext.ReferenceDependency)) { + if(!value.isSatisfied()) { + return false; + } + } + } + return true; } @Override @@ -83,6 +90,12 @@ public AxiomValueContext addValue(V value) { return ret; } + @Override + public void addOperationalValue(AxiomValueReference value) { + Preconditions.checkState(value instanceof ValueContext.Reference); + values.add(((ValueContext.Reference) value).asDependency()); + } + @Override public V onlyValue() { Preconditions.checkState(values.size() == 1); @@ -99,4 +112,11 @@ public AxiomIdentifierResolver valueResolver() { return rootImpl().valueResolver(); } + public Dependency> onlyValue0() { + if(values.size() == 1) { + return values.iterator().next(); + } + return null; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index 18448f51207..414daead9eb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -20,6 +20,9 @@ public class ItemValueImpl implements AxiomValue { private final Map> items; + protected X require(Optional value) { + return value.get(); + } public ItemValueImpl(AxiomTypeDefinition type, V value, Map> items) { super(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java new file mode 100644 index 00000000000..db347a75621 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java @@ -0,0 +1,33 @@ +package com.evolveum.axiom.lang.impl; + +import java.util.Optional; +import java.util.function.Supplier; + +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; + +class LazyValue implements AxiomValue{ + + private final AxiomTypeDefinition type; + private Object delegate; + + public LazyValue(AxiomTypeDefinition type, Supplier> supplier) { + this.type = type; + this.delegate = supplier; + } + + @Override + public Optional type() { + return Optional.of(type); + } + + @Override + public V get() { + if(delegate instanceof AxiomValue) { + return ((AxiomValue) delegate).get(); + } + delegate = ((Supplier>)delegate).get(); + return get(); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java index 3fb2463a63e..6b0c2aad5f7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueActionImpl.java @@ -11,7 +11,6 @@ import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; import com.evolveum.axiom.reactor.DependantAction; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; public class ValueActionImpl implements AxiomStatementRule.ActionBuilder, DependantAction { @@ -91,7 +90,7 @@ public Collection> requirements() { @Override public void fail(Exception e) throws AxiomSemanticException { - this.error = e; + this.error = new AxiomSemanticException(context.startLocation(), e.getClass().getName() + " " + e.getMessage(), e); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index e7be20b0fbd..f4093abbaa8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -32,6 +32,9 @@ public class ValueContext extends AbstractContext> implements private final LookupImpl lookup = new LookupImpl(); private final V originalValue; private final Collection> dependencies = new HashSet<>(); + private AxiomValue lazyValue; + public ReferenceDependency referenceDependency = new ReferenceDependency(); + public Reference reference = new Reference(); public ValueContext(SourceLocation loc, IdentifierSpaceHolder space) { super(null, loc, space); @@ -43,6 +46,7 @@ public ValueContext(ItemContext itemContext, V value, SourceLocation loc) { super(itemContext, loc, AxiomIdentifierDefinition.Scope.LOCAL); originalValue = value; result = new Result(parent().type(), value); + lazyValue = new LazyValue<>(itemDefinition().typeDefinition(),() -> get()); } @Override @@ -70,7 +74,7 @@ public void endValue(SourceLocation loc) { } protected Result mutable() { - Preconditions.checkState(result instanceof ValueContext.Result); + Preconditions.checkState(result instanceof ValueContext.Result, "Result is not mutable."); return (Result) result; } @@ -81,6 +85,9 @@ public boolean isSatisfied() { @Override public AxiomValue get() { + if(isMutable()) { + result = Dependency.immediate(result.get()); + } return result.get(); } @@ -166,8 +173,8 @@ public void replace(AxiomValue axiomItemValue) { } @Override - public AxiomItemContext childItem(AxiomIdentifier name) { - return (AxiomItemContext) mutable().getOrCreateItem(Inheritance.adapt(parent().name(), name), SourceLocation.runtime()); + public ItemContext childItem(AxiomIdentifier name) { + return (ItemContext) mutable().getOrCreateItem(Inheritance.adapt(parent().name(), name), SourceLocation.runtime()); } @Override @@ -210,7 +217,7 @@ public void dependsOnAction(ValueActionImpl action) { addDependency(action); } - public Dependency> requireChild(AxiomIdentifier item) { + public Dependency.Search> requireChild(AxiomIdentifier item) { return Dependency.retriableDelegate(() -> { if(result instanceof ValueContext.Result) { return ((ValueContext.Result) result).getItem(item); @@ -265,6 +272,24 @@ public Dependency> child(AxiomItemDefinition definition, Class< return requireChild(Inheritance.adapt(parent().name(), definition)); } + @Override + public Dependency> onlyItemValue(AxiomItemDefinition definition, Class valueType) { + return Dependency.retriableDelegate(() -> { + Dependency> item; + if(result instanceof ValueContext.Result) { + item = ((ValueContext.Result) result).getItem(definition.name()); + } else { + item = result.flatMap(v -> Dependency.from(v.item(definition))); + } + if(item instanceof ItemContext) { + return ((ItemContext) item).onlyValue0(); + } else if (item == null) { + return null; + } + return item.map(i -> i.onlyValue()); + }); + } + @Override public Dependency> modify(AxiomIdentifier space, IdentifierSpaceKey key) { return (Dependency.retriableDelegate(() -> { @@ -289,6 +314,18 @@ public Dependency.Search> global(AxiomIdentifier space, }); } + @Override + public Dependency.Search> reference(AxiomIdentifier space, + IdentifierSpaceKey key) { + return Dependency.retriableDelegate(() -> { + ValueContext maybe = lookup(space, key); + if(maybe != null) { + return Dependency.immediate(maybe.reference); + } + return null; + }); + } + @Override public Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey key) { @@ -354,9 +391,40 @@ public AxiomIdentifierResolver itemResolver() { }; } + public AxiomValue lazyValue() { + return lazyValue; + } + @Override public AxiomIdentifierResolver valueResolver() { return rootImpl().valueResolver(); } + final class Reference implements AxiomValueReference { + + public ReferenceDependency asDependency() { + return referenceDependency; + } + + } + + final class ReferenceDependency implements Dependency> { + + @Override + public boolean isSatisfied() { + return ValueContext.this.isSatisfied(); + } + + @Override + public AxiomValue get() { + return lazyValue; + } + + @Override + public Exception errorMessage() { + // TODO Auto-generated method stub + return null; + } + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 8c25fec3911..168416f6dd8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -5,6 +5,7 @@ import com.evolveum.axiom.api.AxiomIdentifier; import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -13,12 +14,12 @@ public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { public static final AxiomValueFactory FACTORY = AxiomItemDefinitionImpl::new ; - private final AxiomTypeDefinition valueType; + private final AxiomValue valueType; private final Optional> minOccurs; public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomItemDefinition value, Map> items) { super(axiomItemDefinition, value, items); - this.valueType = this.item(Item.TYPE_REFERENCE.name()).get().onlyValue().get(); + this.valueType = require(onlyValue(AxiomTypeDefinition.class,Item.TYPE_REFERENCE, Item.REF_TARGET)); minOccurs = this.item(Item.MIN_OCCURS.name()); } @@ -39,7 +40,7 @@ public AxiomItemDefinition get() { @Override public AxiomTypeDefinition typeDefinition() { - return valueType; + return valueType.get(); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 2f849f4ad96..5a7e38226ee 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -37,7 +37,7 @@ public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition valu } itemDefinitions = builder.build(); - superType = this.item(Item.SUPERTYPE_REFERENCE.name()).map(v -> v.onlyValue().get()); + superType = onlyValue(AxiomTypeDefinition.class,Item.SUPERTYPE_REFERENCE, Item.REF_TARGET).map(v -> v.get()); argument = this.item(Item.ARGUMENT.name()).flatMap(v -> itemDefinition(v.onlyValue().get())); identifiers = upcast(this.item(Item.IDENTIFIER_DEFINITION.name()).map(v -> v.values()).orElse(Collections.emptyList())); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java index e37b5fc1593..3cb076ce517 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java @@ -146,6 +146,12 @@ public T get() { Preconditions.checkState(isSatisfied(), "Requirement was not satisfied"); return delegate().get(); } + + @Override + public Exception errorMessage() { + Exception maybe = super.errorMessage(); + return maybe != null ? maybe : delegate().errorMessage(); + } } public final class OptionalDep extends Delegated { @@ -240,21 +246,14 @@ static boolean allSatisfied(Collection> outstanding) { } default Dependency map(Function map) { - return new Suppliable(() -> { - if(isSatisfied()) { - return map.apply(get()); - } - return null; - }); + return new MapDependency<>(this, map); } default Dependency flatMap(Function> map) { - return new RetriableDelegate(() -> { - if(isSatisfied()) { - return map.apply(get()); - } - return null; - }); + return new FlatMapDependency<>(this, map); + } + static Dependency of(T from) { + return Dependency.immediate(from); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java new file mode 100644 index 00000000000..21b2ea41e82 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java @@ -0,0 +1,25 @@ +package com.evolveum.axiom.reactor; + +import java.util.function.Function; + +public class FlatMapDependency extends Dependency.Delegated { + + private Dependency delegate; + private Function> mapping; + + public FlatMapDependency(Dependency delegate, Function> mapping) { + super(); + this.delegate = delegate; + this.mapping = mapping; + } + + @Override + Dependency delegate() { + if(mapping != null && delegate.isSatisfied()) { + delegate = mapping.apply((I) delegate.get()); + mapping = null; + } + return delegate; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java new file mode 100644 index 00000000000..c2194e06681 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java @@ -0,0 +1,26 @@ +package com.evolveum.axiom.reactor; + +import java.util.function.Function; + +public class MapDependency extends Dependency.Delegated { + + private Dependency delegate; + private Function mapping; + + public MapDependency(Dependency delegate, Function mapping) { + super(); + this.delegate = delegate; + this.mapping = mapping; + } + + @Override + Dependency delegate() { + return delegate; + } + + @Override + public O get() { + return mapping.apply(delegate.get()); + } + +} diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 69c407bcca3..aaa2beb70c9 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -190,12 +190,14 @@ model axiom-lang { } type AxiomTypeReference { - //type AxiomIdentifier; - //reference { - // scope global; - // space AxiomTypeDefinition; - // argument name; - //} + argument name; + item name { + type AxiomIdentifier; + } + item target { + type AxiomTypeDefinition; + operational true; + } } type AxiomMixinDefinition { From 22b81ca362513c47f533b1bc8dafc96611358b5e Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 29 May 2020 08:45:23 +0200 Subject: [PATCH 35/60] Changed definition of IDENTIFIER token - removed ./ Signed-off-by: Tony Tkacik --- .../src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 index bee08241596..812743ff872 100644 --- a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 +++ b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 @@ -7,7 +7,7 @@ COLON : ':'; PLUS : '+'; LINE_COMMENT : [ \n\r\t]* ('//' (~[\r\n]*)) [ \n\r\t]* -> skip; SEP: [ \n\r\t]+; -IDENTIFIER : [a-zA-Z_/][a-zA-Z0-9_\-./]*; +IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_\-]*; fragment SQOUTE : '\''; fragment DQOUTE : '"'; From 7c50dfd7d12f5cb60e13df303b5d96779d3ce44e Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 29 May 2020 08:45:41 +0200 Subject: [PATCH 36/60] Axiom: Added support for mixins Signed-off-by: Tony Tkacik --- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 1 + .../axiom/lang/impl/BasicStatementRule.java | 15 +++++++++++-- .../axiom/src/main/resources/axiom-lang.axiom | 22 ++++++++++--------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 62770262611..854f7ca8fc9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -55,6 +55,7 @@ public static class Item implements AxiomItemDefinition { 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 USES = new Item("uses", Type.TYPE_REFERENCE, true); private final AxiomIdentifier identifier; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index b1eaf4389d3..7de2d74e3cf 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -132,10 +132,21 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { + Dependency typeDef = + action.require( + context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) + .map(v -> v.get())); + typeDef.unsatisfied(() -> action.error("Supertype is not complete.")); + action.apply(superTypeValue -> { + addFromType(typeDef.get(), superTypeValue.parentValue(), typeDef.get().name()); + }); + } + }, IMPORT_DEFAULT_TYPES(all(), types(Type.MODEL)) { @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index aaa2beb70c9..a09154c370a 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -4,10 +4,8 @@ model axiom-lang { root model { documentation """ - Axiom Model - Declares a new axiom model. - """; + """; type AxiomModel; } @@ -28,10 +26,8 @@ model axiom-lang { item root { documentation """ - Root Definition - - Root Definition defines allowed root for serialized documents - modeled by Axiom language. + Defines allowed root for serialized documents + modeled by Axiom language. """; type AxiomRootDefinition; } @@ -49,7 +45,7 @@ model axiom-lang { item mixin { type AxiomMixinDefinition; documentation """ - Mixin Declaration, declares a new global mixin, aset of reusable item + Declares a new global mixin, a set of reusable item definitions, which can be used in type definitions. """; } @@ -190,12 +186,20 @@ model axiom-lang { } type AxiomTypeReference { + documentation "Type Reference"; argument name; + item name { + documentation "Name of referenced type"; type AxiomIdentifier; + minOccurs 1; + maxOccurs 1; } item target { + documentation "Definition of referenced type"; type AxiomTypeDefinition; + minOccurs 1; + maxOccurs 1; operational true; } } @@ -213,8 +217,6 @@ model axiom-lang { // "Type library" (temporary) - - type SemanticVersion { extends string; } From aa54e9e67b24fd363e3e4783c045e6e2cdf174b3 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 29 May 2020 09:26:43 +0200 Subject: [PATCH 37/60] Axiom: Added documentation to Axiom language Signed-off-by: Tony Tkacik --- .../axiom/src/main/resources/axiom-lang.axiom | 134 ++++++++++++++---- 1 file changed, 104 insertions(+), 30 deletions(-) diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index a09154c370a..a587e426606 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -4,7 +4,7 @@ model axiom-lang { root model { documentation """ - Declares a new axiom model. + Declaration of Axiom model. """; type AxiomModel; } @@ -14,20 +14,33 @@ model axiom-lang { item namespace { type string; + documentation """ + Namespace of model. + """; } item version { - type string; + type SemanticVersion; + documentation """ + Version of model. + + Model versioning follows Semantic Versioning 2.0. + """; } item import { type AxiomImportDeclaration; + documentation """ + Declaration of model imports. + + Type definitions from imported models are referencable and + visible to all definition contained in this model. + """; } item root { documentation """ - Defines allowed root for serialized documents - modeled by Axiom language. + Defines allowed root type for value serialization / deserialization. """; type AxiomRootDefinition; } @@ -35,23 +48,27 @@ model axiom-lang { item type { type AxiomTypeDefinition; documentation """ - Type Declaration - - type statement declares a new global type, which is available - to model items. + Declaration of a type. This type is visible to models + importing parent model namespace. """; } item mixin { type AxiomMixinDefinition; documentation """ - Declares a new global mixin, a set of reusable item + Declaration of mixin, a set of reusable item definitions, which can be used in type definitions. """; } + // FIXME: should be augmentation item extension { type AxiomExtensionDefinition; + documentation """ + Declaration of augmentation. Augmentation adds new items + to already existing type, which can be defined in other + models (namespaces). + """; } } @@ -89,12 +106,13 @@ model axiom-lang { item since { type SemanticVersion; } - //item status { - // documentation """ - // Status of definition, could be experimental, stable, deprecated. - // """; - // type string; - //} + + item status { + type string; + documentation """ + Status of definition, could be experimental, stable, deprecated. + """; + } } type AxiomIdentifierDefinition { @@ -115,6 +133,11 @@ model axiom-lang { type AxiomTypeDefinition { extends AxiomBaseDefinition; + documentation """ + Definition of value type. + + Defines type name, type supertype and set of value items. + """; identifier name { scope global; @@ -123,18 +146,38 @@ model axiom-lang { item argument { type AxiomIdentifier; + documentation """ + Name of item, which is target of short-form value declaration. + """; + minOccurs 0; + maxOccurs 1; } + // FIXME: should be inherit item extends { type AxiomTypeReference; + documentation """ + Reference to super type definition, which is subtyped by this type. + """; + minOccurs 0; + maxOccurs 1; } + // FIXME: should be use item uses { type AxiomTypeReference; + documentation """ + Reference to mixin, from which this type definition reuses item definitions. + """; + minOccurs 0; } item identifier { type AxiomIdentifierDefinition; + documentation """ + Definition of identifiers of this type. + """; + minOccurs 0; } // TODO reconsider this - strictly speaking this is part of "global type+item definition combo" @@ -144,15 +187,24 @@ model axiom-lang { item item { type AxiomItemDefinition; + documentation """ + Definition of child items + """; + minOccurs 0; } } + // FIXME: Should be AxiomName type AxiomIdentifier { + documentation """ + Qualified name. Consists of namespace and local name. + """; } type AxiomItemDefinition { extends AxiomBaseDefinition; + // FIXME: Move this to AxionTypeDefinition -> item(item) identifier name { space AxiomItemDefinition; scope parent; @@ -160,45 +212,69 @@ model axiom-lang { item type { type AxiomTypeReference; + documentation """ + Value type. + + All values must be instances or referenced type or it's subtypes. + """; + minOccurs 1; + maxOccurs 1; } + item minOccurs { type string; + documentation """ + Declares minimum count of values required for this item. + """; } + item maxOccurs { type string; + documentation """ + Declares maximum possible count of values for this item. + """; } - + item operational { type boolean; - operational true; + documentation """ + Marks if data are operational (provided by system). + """; } - + item inherited { type boolean; operational true; } } - type AxiomReference { - item targetType { - type AxiomTypeReference; - } - } - type AxiomTypeReference { - documentation "Type Reference"; + documentation """ + Reference to type definition. + + Referenced type definition is referenced by it's fully qualified + (namespace and local name). + """; argument name; item name { - documentation "Name of referenced type"; type AxiomIdentifier; + documentation """ + Name of referenced type definition. + The value must be name of existing type definition, which is + available (visible) to model using this type reference. + """; minOccurs 1; maxOccurs 1; } item target { - documentation "Definition of referenced type"; type AxiomTypeDefinition; - minOccurs 1; + documentation """ + Referenced Type Definition. + + The value is resolved operational definition of referenced type. + """; + minOccurs 0; maxOccurs 1; operational true; } @@ -215,8 +291,6 @@ model axiom-lang { } } - // "Type library" (temporary) - type SemanticVersion { extends string; } From a0d66c0563a32219007f34ecdcf240d7c7cc2fef Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 29 May 2020 09:33:41 +0200 Subject: [PATCH 38/60] Axoim: Renamed AxiomIdentifier to AxiomName Signed-off-by: Tony Tkacik --- .../evolveum/axiom/api/AbstractAxiomItem.java | 2 +- .../com/evolveum/axiom/api/AxiomItem.java | 2 +- .../{AxiomIdentifier.java => AxiomName.java} | 32 +++++----- .../com/evolveum/axiom/api/AxiomValue.java | 2 +- .../evolveum/axiom/api/AxiomValueBuilder.java | 12 ++-- .../evolveum/axiom/api/AxiomValueFactory.java | 2 +- .../evolveum/axiom/api/meta/Inheritance.java | 14 ++-- .../api/schema/AxiomIdentifierDefinition.java | 12 ++-- .../schema/AxiomIdentifierDefinitionImpl.java | 8 +-- .../axiom/api/schema/AxiomItemDefinition.java | 16 ++--- .../api/schema/AxiomNamedDefinition.java | 4 +- .../axiom/api/schema/AxiomSchemaContext.java | 6 +- .../axiom/api/schema/AxiomTypeDefinition.java | 16 ++--- .../api/schema/DelegatedItemDefinition.java | 6 +- .../api/stream/AxiomBuilderStreamTarget.java | 10 +-- .../axiom/api/stream/AxiomItemStream.java | 4 +- .../axiom/api/stream/AxiomItemTarget.java | 18 +++--- .../lang/antlr/AbstractAxiomAntlrVisitor.java | 20 +++--- .../lang/antlr/AxiomAntlrStatementSource.java | 6 +- .../axiom/lang/antlr/AxiomAntlrVisitor.java | 8 +-- .../axiom/lang/antlr/AxiomAntlrVisitor2.java | 8 +-- .../lang/antlr/AxiomModelStatementSource.java | 8 +-- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 34 +++++----- .../evolveum/axiom/lang/api/AxiomModel.java | 6 +- .../axiom/lang/api/IdentifierSpaceKey.java | 14 ++-- .../axiom/lang/impl/AbstractContext.java | 10 +-- .../lang/impl/AxiomSchemaContextImpl.java | 14 ++-- .../axiom/lang/impl/AxiomStatementRule.java | 12 ++-- .../axiom/lang/impl/AxiomValueContext.java | 6 +- .../axiom/lang/impl/BasicStatementRule.java | 64 +++++++++---------- .../lang/impl/CompositeIdentifierSpace.java | 8 +-- .../lang/impl/IdentifierSpaceHolder.java | 8 +-- .../lang/impl/IdentifierSpaceHolderImpl.java | 16 ++--- .../evolveum/axiom/lang/impl/ItemContext.java | 10 +-- .../axiom/lang/impl/ItemValueImpl.java | 8 +-- .../axiom/lang/impl/ModelReactorContext.java | 18 +++--- .../axiom/lang/impl/SourceContext.java | 24 +++---- .../axiom/lang/impl/ValueContext.java | 34 +++++----- .../lang/spi/AbstractBaseDefinition.java | 10 +-- .../spi/AxiomIdentifierDefinitionImpl.java | 12 ++-- .../lang/spi/AxiomIdentifierResolver.java | 14 ++-- .../lang/spi/AxiomItemDefinitionImpl.java | 4 +- .../lang/spi/AxiomItemStreamTreeBuilder.java | 10 +-- .../lang/spi/AxiomTypeDefinitionImpl.java | 18 +++--- .../axiom/src/main/resources/axiom-lang.axiom | 17 +++-- .../axiom/lang/test/TestAxiomExtension.java | 10 +-- .../axiom/lang/test/TestAxiomPrism.java | 8 +-- .../axiom/lang/test/TestTypeDerivation.java | 12 ++-- 48 files changed, 308 insertions(+), 309 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/api/{AxiomIdentifier.java => AxiomName.java} (68%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java index c350798deb4..1110b3b07fe 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomItem.java @@ -19,7 +19,7 @@ public Optional definition() { } @Override - public AxiomIdentifier name() { + public AxiomName name() { return definition.name(); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java index def79148443..9f42bab3648 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java @@ -9,7 +9,7 @@ public interface AxiomItem { - AxiomIdentifier name(); + AxiomName name(); Optional definition(); Collection> values(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java similarity index 68% rename from infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java index a3c03867c70..46d14346409 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java @@ -11,13 +11,13 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; -public class AxiomIdentifier { +public class AxiomName { public static final String AXIOM_NAMESPACE = "https://ns.evolveum.com/axiom/language"; private final String namespace; private final String localName; - public AxiomIdentifier(String namespace, String localName) { + public AxiomName(String namespace, String localName) { this.namespace = Preconditions.checkNotNull(namespace, "namespace"); this.localName = Preconditions.checkNotNull(localName, "localName"); } @@ -43,9 +43,9 @@ public int hashCode() { public boolean equals(Object obj) { if (this == obj) return true; - if (!(obj instanceof AxiomIdentifier)) + if (!(obj instanceof AxiomName)) return false; - AxiomIdentifier other = (AxiomIdentifier) obj; + AxiomName other = (AxiomName) obj; if (localName == null) { if (other.localName != null) return false; @@ -67,31 +67,31 @@ public String toString() { return "(" + namespace + ")" +localName; } - public static AxiomIdentifier axiom(String identifier) { - return new AxiomIdentifier(AXIOM_NAMESPACE, identifier); + public static AxiomName axiom(String identifier) { + return new AxiomName(AXIOM_NAMESPACE, identifier); } - public static AxiomIdentifier from(String namespace, String localName) { - return new AxiomIdentifier(namespace, localName); + public static AxiomName from(String namespace, String localName) { + return new AxiomName(namespace, localName); } - public boolean sameNamespace(AxiomIdentifier other) { + public boolean sameNamespace(AxiomName other) { return this.namespace().equals(other.namespace()); } - public AxiomIdentifier localName(String name) { - return AxiomIdentifier.from(namespace, name); + public AxiomName localName(String name) { + return AxiomName.from(namespace, name); } - public AxiomIdentifier namespace(String targetNamespace) { - return AxiomIdentifier.from(targetNamespace, localName); + public AxiomName namespace(String targetNamespace) { + return AxiomName.from(targetNamespace, localName); } - public AxiomIdentifier defaultNamespace() { - return AxiomIdentifier.from("", localName); + public AxiomName defaultNamespace() { + return AxiomName.from("", localName); } - public static AxiomIdentifier local(@NotNull String localName) { + public static AxiomName local(@NotNull String localName) { return from("", localName); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 881a4622978..77f7df5b312 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -23,7 +23,7 @@ default Optional> item(AxiomItemDefinition def) { } @SuppressWarnings("unchecked") - default Optional> item(AxiomIdentifier name) { + default Optional> item(AxiomName name) { return items().stream().filter(value -> name.equals(value.name())).findFirst().map(v -> (AxiomItem) v); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index 65114745be9..052d846c035 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -18,7 +18,7 @@ public class AxiomValueBuilder> implements Lazy.Suppli private final AxiomTypeDefinition type; private AxiomValueFactory factory; - private Map>> children = new LinkedHashMap<>(); + private Map>> children = new LinkedHashMap<>(); private V value; public AxiomValueBuilder(AxiomTypeDefinition type, AxiomValueFactory factory) { @@ -38,22 +38,22 @@ public void setValue(V value) { this.value = value; } - public void add(AxiomIdentifier name, Supplier> child) { + public void add(AxiomName name, Supplier> child) { children.put(name, child); } - public Supplier> get(AxiomIdentifier name) { + public Supplier> get(AxiomName name) { return children.get(name); } - public Supplier> get(AxiomIdentifier name, Function>> child) { + public Supplier> get(AxiomName name, Function>> child) { return children.computeIfAbsent(name, child); } @Override public T get() { - Builder> builder = ImmutableMap.builder(); - for(Entry>> entry : children.entrySet()) { + Builder> builder = ImmutableMap.builder(); + for(Entry>> entry : children.entrySet()) { AxiomItem item = entry.getValue().get(); builder.put(entry.getKey(), entry.getValue().get()); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java index 8b51c3bc12f..201845715f8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java @@ -6,6 +6,6 @@ public interface AxiomValueFactory> { - T create(AxiomTypeDefinition def, V value, Map> items); + T create(AxiomTypeDefinition def, V value, Map> items); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java index 7fe174266cc..8d203a02896 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/meta/Inheritance.java @@ -1,6 +1,6 @@ package com.evolveum.axiom.api.meta; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomItemDefinition; public interface Inheritance { @@ -11,25 +11,25 @@ public interface Inheritance { Inheritance CURRENT = NO_CHANGE; - static AxiomIdentifier adapt(AxiomIdentifier parent, AxiomIdentifier child) { + static AxiomName adapt(AxiomName parent, AxiomName child) { return CURRENT.apply(parent, child); } - static AxiomIdentifier adapt(AxiomIdentifier parent, AxiomItemDefinition child) { + static AxiomName adapt(AxiomName parent, AxiomItemDefinition child) { return child.inherited() ? adapt(parent, child.name()) : child.name(); } - AxiomIdentifier apply(AxiomIdentifier parent, AxiomIdentifier child); + AxiomName apply(AxiomName parent, AxiomName child); - static AxiomIdentifier inheritNamespace(AxiomIdentifier parent, AxiomIdentifier name) { + static AxiomName inheritNamespace(AxiomName parent, AxiomName name) { return parent.localName(name.localName()); } - static AxiomIdentifier noNamespace(AxiomIdentifier parent, AxiomIdentifier name) { + static AxiomName noNamespace(AxiomName parent, AxiomName name) { return name.defaultNamespace(); } - static AxiomIdentifier noChange(AxiomIdentifier parent, AxiomIdentifier name) { + static AxiomName noChange(AxiomName parent, AxiomName name) { return name; } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java index 7837b4e140e..1fad4a318cd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java @@ -3,7 +3,7 @@ import java.util.Collection; import java.util.Set; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; @@ -18,7 +18,7 @@ default AxiomIdentifierDefinition get() { Scope scope(); - AxiomIdentifier space(); + AxiomName space(); enum Scope { GLOBAL, @@ -26,11 +26,11 @@ enum Scope { LOCAL } - static AxiomIdentifierDefinition global(AxiomIdentifier name, AxiomItemDefinition... components) { + static AxiomIdentifierDefinition global(AxiomName name, AxiomItemDefinition... components) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.GLOBAL); } - static AxiomIdentifierDefinition local(AxiomIdentifier name, AxiomItemDefinition... components) { + static AxiomIdentifierDefinition local(AxiomName name, AxiomItemDefinition... components) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.LOCAL); } @@ -47,11 +47,11 @@ static Scope scope(String scope) { throw new IllegalArgumentException("Unknown scope " + scope); } - static AxiomIdentifierDefinition from(AxiomIdentifier space, Scope scope, Set members) { + static AxiomIdentifierDefinition from(AxiomName space, Scope scope, Set members) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(members), space, scope); } - static AxiomIdentifierDefinition parent(AxiomIdentifier name, AxiomItemDefinition... components) { + static AxiomIdentifierDefinition parent(AxiomName name, AxiomItemDefinition... components) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.PARENT); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java index 366b2b66f02..53e485bbf1f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java @@ -3,18 +3,18 @@ import java.util.Optional; import java.util.Set; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.google.common.collect.ImmutableSet; class AxiomIdentifierDefinitionImpl implements AxiomIdentifierDefinition { private Set components; - private AxiomIdentifier space; + private AxiomName space; private Scope scope; - public AxiomIdentifierDefinitionImpl(Set components, AxiomIdentifier space, Scope scope) { + public AxiomIdentifierDefinitionImpl(Set components, AxiomName space, Scope scope) { super(); this.components = ImmutableSet.copyOf(components); this.space = space; @@ -32,7 +32,7 @@ public Scope scope() { } @Override - public AxiomIdentifier space() { + public AxiomName space() { return space; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java index 86ef91612b5..a925a4b0807 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java @@ -6,7 +6,7 @@ */ package com.evolveum.axiom.api.schema; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.base.MoreObjects; @@ -14,9 +14,9 @@ public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomValue { - AxiomIdentifier ROOT_SPACE = AxiomIdentifier.axiom("AxiomRootDefinition"); - AxiomIdentifier SPACE = AxiomIdentifier.axiom("AxiomItemDefinition"); - AxiomIdentifier NAME = AxiomIdentifier.axiom("name"); + AxiomName ROOT_SPACE = AxiomName.axiom("AxiomRootDefinition"); + AxiomName SPACE = AxiomName.axiom("AxiomItemDefinition"); + AxiomName NAME = AxiomName.axiom("name"); @Override default AxiomItemDefinition get() { @@ -47,7 +47,7 @@ static String toString(AxiomItemDefinition def) { .toString(); } - static AxiomItemDefinition derived(AxiomIdentifier name , AxiomItemDefinition source) { + static AxiomItemDefinition derived(AxiomName name , AxiomItemDefinition source) { return new DelegatedItemDefinition() { @Override @@ -56,13 +56,13 @@ protected AxiomItemDefinition delegate() { } @Override - public AxiomIdentifier name() { + public AxiomName name() { return name; } }; } - static IdentifierSpaceKey identifier(AxiomIdentifier name) { + static IdentifierSpaceKey identifier(AxiomName name) { return IdentifierSpaceKey.from(ImmutableMap.of(NAME, name)); } @@ -78,7 +78,7 @@ interface Extended extends AxiomItemDefinition { } - default AxiomItemDefinition derived(AxiomIdentifier name) { + default AxiomItemDefinition derived(AxiomName name) { return derived(name, this); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomNamedDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomNamedDefinition.java index c726a8cb70d..23e07296f81 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomNamedDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomNamedDefinition.java @@ -6,10 +6,10 @@ */ package com.evolveum.axiom.api.schema; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; public interface AxiomNamedDefinition { - AxiomIdentifier name(); + AxiomName name(); String documentation(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomSchemaContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomSchemaContext.java index 8dcd350c001..6a0605bfd8f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomSchemaContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomSchemaContext.java @@ -3,15 +3,15 @@ import java.util.Collection; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; public interface AxiomSchemaContext { Collection roots(); - Optional getRoot(AxiomIdentifier type); + Optional getRoot(AxiomName type); - Optional getType(AxiomIdentifier type); + Optional getType(AxiomName type); Collection types(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java index 0298895be02..023dc562e07 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java @@ -11,7 +11,7 @@ import java.util.Optional; import java.util.stream.Collectors; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -19,8 +19,8 @@ public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomValue { - public final AxiomIdentifier IDENTIFIER_MEMBER = AxiomIdentifier.axiom("name"); - public final AxiomIdentifier SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition"); + public final AxiomName IDENTIFIER_MEMBER = AxiomName.axiom("name"); + public final AxiomName SPACE = AxiomName.axiom("AxiomTypeDefinition"); @Override @@ -37,11 +37,11 @@ default Optional type() { Optional superType(); - Map itemDefinitions(); + Map itemDefinitions(); Collection identifierDefinitions(); - default Optional itemDefinition(AxiomIdentifier child) { + default Optional itemDefinition(AxiomName child) { AxiomItemDefinition maybe = itemDefinitions().get(child); if(maybe == null) { maybe = itemDefinitions().get(Inheritance.adapt(name(), child)); @@ -52,7 +52,7 @@ default Optional itemDefinition(AxiomIdentifier child) { return Optional.ofNullable(maybe).or(() -> superType().flatMap(s -> s.itemDefinition(child))); } - static IdentifierSpaceKey identifier(AxiomIdentifier name) { + static IdentifierSpaceKey identifier(AxiomName name) { return IdentifierSpaceKey.from(ImmutableMap.of(IDENTIFIER_MEMBER, name)); } @@ -60,7 +60,7 @@ default Collection requiredItems() { return itemDefinitions().values().stream().filter(AxiomItemDefinition::required).collect(Collectors.toList()); } - default Optional itemDefinition(AxiomIdentifier parentItem, AxiomIdentifier name) { + default Optional itemDefinition(AxiomName parentItem, AxiomName name) { return itemDefinition(Inheritance.adapt(parentItem, name)); } @@ -72,7 +72,7 @@ default boolean isSupertypeOf(AxiomTypeDefinition other) { return other.isSubtypeOf(this); } - default boolean isSubtypeOf(AxiomIdentifier other) { + default boolean isSubtypeOf(AxiomName other) { Optional current = Optional.of(this); while(current.isPresent()) { if(current.get().name().equals(other)) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java index e58e07ba380..7d12075c28f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java @@ -3,7 +3,7 @@ import java.util.Collection; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; abstract class DelegatedItemDefinition implements AxiomItemDefinition { @@ -26,7 +26,7 @@ public Collection> items() { } @Override - public AxiomIdentifier name() { + public AxiomName name() { return delegate().name(); } @@ -41,7 +41,7 @@ public Optional> item(AxiomItemDefinition def) { } @Override - public Optional> item(AxiomIdentifier name) { + public Optional> item(AxiomName name) { return delegate().item(name); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java index a27c5c8d021..6d723b9e8e7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java @@ -9,7 +9,7 @@ import java.util.Deque; import java.util.LinkedList; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; @@ -61,7 +61,7 @@ public void endValue(SourceLocation loc) { } @Override - public void startItem(AxiomIdentifier item, SourceLocation loc) { + public void startItem(AxiomName item, SourceLocation loc) { Optional childDef = value(current()).childDef(item); AxiomSyntaxException.check(childDef.isPresent(), loc , "Item %s not allowed in %s", item, current().name()); offer(value(current()).startItem(item, loc)); @@ -73,7 +73,7 @@ public void endItem(SourceLocation loc) { } private interface Builder { - AxiomIdentifier name(); + AxiomName name(); AxiomIdentifierResolver itemResolver(); @@ -87,8 +87,8 @@ public interface ItemBuilder extends Builder { } public interface ValueBuilder extends Builder { - Optional childDef(AxiomIdentifier statement); - ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc); + Optional childDef(AxiomName statement); + ItemBuilder startItem(AxiomName identifier, SourceLocation loc); void endValue(SourceLocation loc); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java index a20c7bfc64e..aaa06e4ad6d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java @@ -1,13 +1,13 @@ package com.evolveum.axiom.api.stream; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; public interface AxiomItemStream { interface Target { - void startItem(AxiomIdentifier item, SourceLocation loc); + void startItem(AxiomName item, SourceLocation loc); void startValue(Object value, SourceLocation loc); void endValue(SourceLocation loc); void endItem(SourceLocation loc); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java index 9484091ad8c..6084f7afe18 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java @@ -3,7 +3,7 @@ import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomItemBuilder; import com.evolveum.axiom.api.AxiomValue; @@ -34,8 +34,8 @@ public AxiomItem get() { private final class Root implements ValueBuilder { @Override - public AxiomIdentifier name() { - return AxiomIdentifier.axiom("AbstractRoot"); + public AxiomName name() { + return AxiomName.axiom("AbstractRoot"); } @Override @@ -49,12 +49,12 @@ public AxiomIdentifierResolver valueResolver() { } @Override - public Optional childDef(AxiomIdentifier statement) { + public Optional childDef(AxiomName statement) { return context.getRoot(statement); } @Override - public ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc) { + public ItemBuilder startItem(AxiomName identifier, SourceLocation loc) { result = new Item<>(childDef(identifier).get()); return result; } @@ -75,7 +75,7 @@ public Item(AxiomItemDefinition definition) { } @Override - public AxiomIdentifier name() { + public AxiomName name() { return builder.definition().name(); } @@ -125,7 +125,7 @@ public Value(V value, AxiomTypeDefinition type) { } @Override - public AxiomIdentifier name() { + public AxiomName name() { return builder.type().name(); } @@ -140,12 +140,12 @@ public AxiomIdentifierResolver valueResolver() { } @Override - public Optional childDef(AxiomIdentifier statement) { + public Optional childDef(AxiomName statement) { return builder.type().itemDefinition(statement); } @Override - public ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc) { + public ItemBuilder startItem(AxiomName identifier, SourceLocation loc) { Object itemImpl = builder.get(identifier, (id) -> { return new Item(childDef(identifier).get()); }); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java index 443bb53d666..093a7037eff 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java @@ -11,7 +11,7 @@ import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; @@ -21,15 +21,15 @@ public abstract class AbstractAxiomAntlrVisitor extends AxiomBaseVisitor { - private final Optional> limit; + private final Optional> limit; private final String sourceName; - public AbstractAxiomAntlrVisitor(String name, Set limit) { + public AbstractAxiomAntlrVisitor(String name, Set limit) { this.sourceName = name; this.limit = Optional.ofNullable(limit); } - private AxiomIdentifier statementIdentifier(IdentifierContext identifier) { + private AxiomName statementIdentifier(IdentifierContext identifier) { String prefix = nullableText(identifier.prefix()); String localName = identifier.localIdentifier().getText(); return resolveItemName(prefix, localName); @@ -37,8 +37,8 @@ private AxiomIdentifier statementIdentifier(IdentifierContext identifier) { protected abstract AxiomItemStream.Target delegate(); - protected abstract AxiomIdentifier resolveItemName(String prefix, String localName); - protected abstract AxiomIdentifier resolveArgument(String prefix, String localName); + protected abstract AxiomName resolveItemName(String prefix, String localName); + protected abstract AxiomName resolveArgument(String prefix, String localName); private String nullableText(ParserRuleContext prefix) { return prefix != null ? prefix.getText() : ""; @@ -46,7 +46,7 @@ private String nullableText(ParserRuleContext prefix) { @Override public final T visitStatement(StatementContext ctx) { - AxiomIdentifier identifier = statementIdentifier(ctx.identifier()); + AxiomName identifier = statementIdentifier(ctx.identifier()); if(canEmit(identifier)) { SourceLocation start = sourceLocation(ctx.identifier().start); delegate().startItem(identifier, start); @@ -78,7 +78,7 @@ private Object convert(ArgumentContext ctx) { } } - private boolean canEmit(AxiomIdentifier identifier) { + private boolean canEmit(AxiomName identifier) { if (limit.isPresent()) { return limit.get().contains(identifier); } @@ -91,11 +91,11 @@ public final T visitArgument(ArgumentContext ctx) { return defaultResult(); } - private AxiomIdentifier convert(IdentifierContext argument) { + private AxiomName convert(IdentifierContext argument) { return argumentIdentifier(argument); } - private AxiomIdentifier argumentIdentifier(IdentifierContext identifier) { + private AxiomName argumentIdentifier(IdentifierContext identifier) { String prefix = nullableText(identifier.prefix()); String localName = identifier.localIdentifier().getText(); return resolveArgument(prefix, localName); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index d1134c3fad3..d8ada5079f3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -15,7 +15,7 @@ import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; @@ -64,13 +64,13 @@ public final void stream(AxiomItemStream.TargetWithResolver target) { stream(target, Optional.empty()); } - public final void stream(AxiomItemStream.TargetWithResolver target, Optional> emitOnly) { + public final void stream(AxiomItemStream.TargetWithResolver target, Optional> emitOnly) { AxiomAntlrVisitor2 visitor = new AxiomAntlrVisitor2<>(sourceName, target, emitOnly.orElse(null)); visitor.visit(root); } public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Target listener, - Optional> emitOnly) { + Optional> emitOnly) { AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, statements, arguments, listener, emitOnly.orElse(null)); visitor.visit(root); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index b5c3deb0bfd..b667656d16b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -8,7 +8,7 @@ import java.util.Set; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.api.stream.AxiomItemStream.Target; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; @@ -20,7 +20,7 @@ public class AxiomAntlrVisitor extends AbstractAxiomAntlrVisitor { private final AxiomItemStream.Target delegate; public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Target delegate, - Set limit) { + Set limit) { super(name, limit); this.statements = statements; this.arguments = arguments; @@ -28,12 +28,12 @@ public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomI } @Override - protected AxiomIdentifier resolveArgument(String prefix, String localName) { + protected AxiomName resolveArgument(String prefix, String localName) { return arguments.resolveIdentifier(prefix, localName); } @Override - protected AxiomIdentifier resolveItemName(String prefix, String localName) { + protected AxiomName resolveItemName(String prefix, String localName) { return statements.resolveIdentifier(prefix, localName); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java index bf9e8f8668e..b0304229c5c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java @@ -8,7 +8,7 @@ import java.util.Set; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.api.stream.AxiomItemStream.Target; @@ -17,18 +17,18 @@ public class AxiomAntlrVisitor2 extends AbstractAxiomAntlrVisitor { private final AxiomItemStream.TargetWithResolver delegate; public AxiomAntlrVisitor2(String name, AxiomItemStream.TargetWithResolver delegate, - Set limit) { + Set limit) { super(name, limit); this.delegate = delegate; } @Override - protected AxiomIdentifier resolveArgument(String prefix, String localName) { + protected AxiomName resolveArgument(String prefix, String localName) { return delegate.valueResolver().resolveIdentifier(prefix, localName); } @Override - protected AxiomIdentifier resolveItemName(String prefix, String localName) { + protected AxiomName resolveItemName(String prefix, String localName) { return delegate.itemResolver().resolveIdentifier(prefix, localName); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 969afc62e53..f34a115b3d0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; @@ -65,7 +65,7 @@ public String namespace() { public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Target listener, - Optional> emitOnly) { + Optional> emitOnly) { stream(resolver.or(this), BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); } @@ -91,13 +91,13 @@ private static String namespace(StatementContext c) { } @Override - public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName) { + public AxiomName resolveIdentifier(@Nullable String prefix, @NotNull String localName) { if(prefix == null) { prefix = ""; } String maybeNs = imports.get(prefix); if(maybeNs != null) { - return AxiomIdentifier.from(maybeNs, localName); + return AxiomName.from(maybeNs, localName); } return null; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 854f7ca8fc9..d3f57bbed81 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -11,7 +11,7 @@ import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +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; @@ -22,7 +22,7 @@ public class AxiomBuiltIn { - public static final Lazy> EMPTY = Lazy.instant(ImmutableMap.of()); + public static final Lazy> EMPTY = Lazy.instant(ImmutableMap.of()); public static final Lazy NO_ARGUMENT = Lazy.nullValue(); @@ -58,13 +58,13 @@ public static class Item implements AxiomItemDefinition { public static final AxiomItemDefinition USES = new Item("uses", Type.TYPE_REFERENCE, true); - private final AxiomIdentifier identifier; + private final AxiomName identifier; private final AxiomTypeDefinition type; private boolean required; private Item(String identifier, AxiomTypeDefinition type, boolean required) { - this.identifier = AxiomIdentifier.axiom(identifier); + this.identifier = AxiomName.axiom(identifier); this.type = type; this.required = required; } @@ -75,7 +75,7 @@ public Optional type() { } @Override - public AxiomIdentifier name() { + public AxiomName name() { return identifier; } @@ -130,7 +130,7 @@ public AxiomTypeDefinition definingType() { 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 IDENTIFIER = new Type("AxiomName"); public static final Type TYPE_REFERENCE = new Type("AxiomTypeReference", null, () -> Item.NAME, () -> itemDefs( Item.NAME, Item.REF_TARGET @@ -206,40 +206,40 @@ public Collection identifierDefinitions() { public static final Type IMPORT_DEFINITION = new Type("AxiomImportDeclaration"); public static final Type EXTENSION_DEFINITION = new Type("AxiomExtensionDefinition"); - private final AxiomIdentifier identifier; + private final AxiomName identifier; private final AxiomTypeDefinition superType; private final Lazy argument; - private final Lazy> items; + private final Lazy> items; private Type(String identifier) { this(identifier, null, Lazy.nullValue(), EMPTY); } - private Type(String identifier, Lazy.Supplier> items) { + private Type(String identifier, Lazy.Supplier> items) { this(identifier, null, Lazy.nullValue(), Lazy.from(items)); } - private Type(String identifier, AxiomTypeDefinition superType, Lazy.Supplier> items) { + private Type(String identifier, AxiomTypeDefinition superType, Lazy.Supplier> items) { this(identifier, superType, NO_ARGUMENT, Lazy.from(items)); } private Type(String identifier, AxiomTypeDefinition superType, Lazy.Supplier argument, - Lazy.Supplier> items) { + Lazy.Supplier> items) { this(identifier, superType, Lazy.from(argument), Lazy.from(items)); } private Type(String identifier, AxiomTypeDefinition superType, Lazy argument, - Lazy> items) { - this.identifier = AxiomIdentifier.axiom(identifier); + Lazy> items) { + this.identifier = AxiomName.axiom(identifier); this.argument = argument; this.superType = superType; this.items = items; } @Override - public AxiomIdentifier name() { + public AxiomName name() { return identifier; } @@ -254,12 +254,12 @@ public Optional superType() { } @Override - public Map itemDefinitions() { + public Map itemDefinitions() { return items.get(); } - private static Map itemDefs(AxiomItemDefinition... items) { - Builder builder = ImmutableMap.builder(); + private static Map itemDefs(AxiomItemDefinition... items) { + Builder builder = ImmutableMap.builder(); for (AxiomItemDefinition item : items) { builder.put(item.name(), item); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java index 441eeb9593a..c759c1c6c86 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java @@ -1,11 +1,11 @@ package com.evolveum.axiom.lang.api; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; public interface AxiomModel { - AxiomIdentifier NAMESPACE = AxiomIdentifier.axiom("namespace"); - AxiomIdentifier IMPORTED_NAMESPACE = AxiomIdentifier.axiom("ImportedNamespace"); + AxiomName NAMESPACE = AxiomName.axiom("namespace"); + AxiomName IMPORTED_NAMESPACE = AxiomName.axiom("ImportedNamespace"); String BUILTIN_TYPES = "https://ns.evolveum.com/axiom/language"; String name(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java index 6d8826c6a52..ca8318ec2e3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/IdentifierSpaceKey.java @@ -3,18 +3,18 @@ import java.util.Map; import java.util.Map.Entry; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.google.common.collect.ImmutableMap; public class IdentifierSpaceKey { - private final Map components; + private final Map components; - public IdentifierSpaceKey(Map components) { + public IdentifierSpaceKey(Map components) { this.components = ImmutableMap.copyOf(components); } - public Map components() { + public Map components() { return components; } @@ -34,7 +34,7 @@ public boolean equals(Object obj) { return false; } - public static IdentifierSpaceKey from(Map build) { + public static IdentifierSpaceKey from(Map build) { return new IdentifierSpaceKey(build); } @@ -43,7 +43,7 @@ public String toString() { StringBuilder b = new StringBuilder(); b.append("["); boolean first = true; - for(Entry val : components().entrySet()) { + for(Entry val : components().entrySet()) { if(!first) { b.append(","); } @@ -53,7 +53,7 @@ public String toString() { return b.toString(); } - public static IdentifierSpaceKey of(AxiomIdentifier key, Object value) { + public static IdentifierSpaceKey of(AxiomName key, Object value) { return from(ImmutableMap.of(key, value)); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java index d35d1c50888..7f8361da59f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java @@ -3,7 +3,7 @@ import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.concepts.SourceLocation; @@ -29,7 +29,7 @@ public AbstractContext(P context, SourceLocation loc, IdentifierSpaceHolder spac public P parent() { return parent; } - protected abstract Optional childDef(AxiomIdentifier id); + protected abstract Optional childDef(AxiomName id); protected SourceContext rootImpl() { @@ -41,7 +41,7 @@ public SourceLocation startLocation() { } @Override - public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + public ValueContext lookup(AxiomName space, IdentifierSpaceKey key) { ValueContext maybe = localSpace.lookup(space, key); if(maybe != null) { return maybe; @@ -50,7 +50,7 @@ public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { } @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + public void register(AxiomName space, Scope scope, IdentifierSpaceKey key, ValueContext context) { switch (scope) { case GLOBAL: rootImpl().register(space, scope, key, context); @@ -67,7 +67,7 @@ public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, } @Override - public Map> space(AxiomIdentifier space) { + public Map> space(AxiomName space) { return localSpace.space(space); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java index f9baaab7af5..d8a24de4c90 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomSchemaContextImpl.java @@ -4,7 +4,7 @@ import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomSchemaContext; @@ -18,9 +18,9 @@ public class AxiomSchemaContextImpl implements AxiomSchemaContext { private Map roots; private Map types; - private Map>> globals; + private Map>> globals; - public AxiomSchemaContextImpl(Map>> globalMap) { + public AxiomSchemaContextImpl(Map>> globalMap) { this.globals = globalMap; this.roots = Maps.transformValues(globalMap.get(AxiomItemDefinition.ROOT_SPACE), AxiomItemDefinition.class::cast); this.types = Maps.transformValues(globalMap.get(AxiomTypeDefinition.SPACE), AxiomTypeDefinition.class::cast); @@ -32,7 +32,7 @@ public Collection roots() { } @Override - public Optional getType(AxiomIdentifier type) { + public Optional getType(AxiomName type) { return Optional.ofNullable(types.get(nameKey(type))); } @@ -42,17 +42,17 @@ public Collection types() { } @Override - public Optional getRoot(AxiomIdentifier type) { + public Optional getRoot(AxiomName type) { return Optional.ofNullable(roots.get(nameKey(type))); } - private static IdentifierSpaceKey nameKey(AxiomIdentifier type) { + private static IdentifierSpaceKey nameKey(AxiomName type) { return IdentifierSpaceKey.of(AxiomTypeDefinition.IDENTIFIER_MEMBER, type); } public static AxiomSchemaContextImpl boostrapContext() { Map> root = ImmutableMap.of(nameKey(AxiomBuiltIn.Item.MODEL_DEFINITION.name()), AxiomBuiltIn.Item.MODEL_DEFINITION); - Map>> global + Map>> global = ImmutableMap.of(AxiomItemDefinition.ROOT_SPACE, root, AxiomTypeDefinition.SPACE, ImmutableMap.of()); return new AxiomSchemaContextImpl(global); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index c33b538e4e6..1963a7305fc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -1,6 +1,6 @@ package com.evolveum.axiom.lang.impl; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; @@ -25,19 +25,19 @@ default AxiomTypeDefinition typeDefinition() { AxiomItemDefinition itemDefinition(); - Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId); + Dependency namespace(AxiomName name, IdentifierSpaceKey namespaceId); Dependency> child(AxiomItemDefinition item, Class valueType); Dependency> onlyItemValue(AxiomItemDefinition item, Class valueType); - Dependency> modify(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + Dependency> modify(AxiomName identifierSpace, IdentifierSpaceKey identifier); - Dependency.Search> global(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + Dependency.Search> global(AxiomName identifierSpace, IdentifierSpaceKey identifier); - Dependency.Search> reference(AxiomIdentifier identifierSpace, IdentifierSpaceKey identifier); + Dependency.Search> reference(AxiomName identifierSpace, IdentifierSpaceKey identifier); - Dependency.Search> namespaceValue(AxiomIdentifier space, IdentifierSpaceKey itemName); + Dependency.Search> namespaceValue(AxiomName space, IdentifierSpaceKey itemName); Dependency finalValue(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java index 3cee854c673..ab6c32fe43e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomValueContext.java @@ -1,6 +1,6 @@ package com.evolveum.axiom.lang.impl; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; @@ -16,7 +16,7 @@ default AxiomItemContext childItem(AxiomItemDefinition def) { return childItem(def.name()); } - AxiomItemContext childItem(AxiomIdentifier name); + AxiomItemContext childItem(AxiomName name); V currentValue(); @@ -24,7 +24,7 @@ default AxiomItemContext childItem(AxiomItemDefinition def) { void mergeItem(AxiomItem axiomItem); - void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key); + void register(AxiomName space, Scope scope, IdentifierSpaceKey key); AxiomRootContext root(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 7de2d74e3cf..cb945e20068 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -6,7 +6,7 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.Set; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; @@ -27,7 +27,7 @@ import com.google.common.collect.ImmutableSet; -public enum BasicStatementRule implements AxiomStatementRule { +public enum BasicStatementRule implements AxiomStatementRule { /* REQUIRE_REQUIRED_ITEMS(all(),all()) { @Override @@ -42,7 +42,7 @@ public void apply(Context rule) throws AxiomSemanticException { MOVE_ARGUMENT_VALUE(all(),all()) { @Override - public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { if(context.isMutable()) { Optional argument = context.typeDefinition().argument(); if(argument.isPresent() && context.originalValue() != null) { @@ -63,11 +63,11 @@ public boolean isApplicableTo(AxiomItemDefinition definition) { } @Override - public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Collection idDefs = context.typeDefinition().identifierDefinitions(); - Map>>> identReq = new HashMap<>(); + Map>>> identReq = new HashMap<>(); for(AxiomIdentifierDefinition idDef : idDefs) { - Map>> components = new HashMap<>(); + Map>> components = new HashMap<>(); for(AxiomItemDefinition cmp : idDef.components()) { components.put(cmp.name(), action.require(context.child(cmp, Object.class)) .unsatisfied(()-> context.error("Item '%s' is required by identifier, but not defined.", cmp.name())) @@ -86,9 +86,9 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - Dependency> typeDef = action.require(context.child(Item.NAME, AxiomIdentifier.class) + Dependency> typeDef = action.require(context.child(Item.NAME, AxiomName.class) .unsatisfied(() -> action.error("type name is missing.")) .map(v -> v.onlyValue().get()) .flatMap(name -> @@ -110,8 +110,8 @@ public boolean isApplicableTo(AxiomItemDefinition definition) { } @Override - public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - AxiomIdentifier itemName = context.currentValue(); + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + AxiomName itemName = context.currentValue(); Search> itemDef = action.require(context.namespaceValue(AxiomItemDefinition.SPACE, AxiomItemDefinition.identifier(itemName))) .notFound(() -> action.error("item '%s' was not found", itemName)); action.apply((val) -> { @@ -122,7 +122,7 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency typeDef = action.require( context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) @@ -136,7 +136,7 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency typeDef = action.require( context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) @@ -149,7 +149,7 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency req = action.require(context.namespace(Item.NAMESPACE.name(), namespaceId(AxiomModel.BUILTIN_TYPES))); req.unsatisfied(() -> action.error("Default types not found.")); action.apply((ctx) -> { @@ -160,7 +160,7 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency namespace = action.require(context.child(Item.NAMESPACE, String.class).map(v -> v.onlyValue().get())); action.apply(ctx -> { ctx.root().exportIdentifierSpace(namespaceId(namespace.get())); @@ -170,7 +170,7 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency namespace = action.require(context.child(Item.NAMESPACE, String.class) .map(item -> item.onlyValue()) .flatMap(uri -> context.namespace(Item.NAMESPACE.name(), namespaceId(uri.get())) @@ -185,11 +185,11 @@ public void apply(Lookup context, ActionBuilder context, ActionBuilder action) throws AxiomSemanticException { - Dependency> targetRef = action.require(context.child(Item.TARGET, AxiomIdentifier.class) + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Dependency> targetRef = action.require(context.child(Item.TARGET, AxiomName.class) .map(v -> v.onlyValue().item(Item.NAME).get())) .flatMap(item -> - context.modify(AxiomTypeDefinition.SPACE, AxiomTypeDefinition.identifier((AxiomIdentifier) item.onlyValue().get())) + context.modify(AxiomTypeDefinition.SPACE, AxiomTypeDefinition.identifier((AxiomName) item.onlyValue().get())) .unsatisfied(() -> action.error("Target %s not found.",item.onlyValue().get()) )); Dependency> itemDef = action.require(context.child(Item.ITEM_DEFINITION, AxiomItemDefinition.class)); @@ -213,18 +213,18 @@ public void apply(Context rule) throws AxiomSemanticException { */ ; - private final Set items; - private final Set types; + private final Set items; + private final Set types; - private BasicStatementRule(Set items, Set types) { + private BasicStatementRule(Set items, Set types) { this.items = ImmutableSet.copyOf(items); this.types = ImmutableSet.copyOf(types); } - static IdentifierSpaceKey keyFrom(Map>> ctx) { - ImmutableMap.Builder components = ImmutableMap.builder(); - for(Entry>> entry : ctx.entrySet()) { + static IdentifierSpaceKey keyFrom(Map>> ctx) { + ImmutableMap.Builder components = ImmutableMap.builder(); + for(Entry>> entry : ctx.entrySet()) { components.put(entry.getKey(), entry.getValue().get().get()); } return IdentifierSpaceKey.from(components.build()); @@ -236,7 +236,7 @@ public boolean isApplicableTo(AxiomItemDefinition definition) { if(types.isEmpty()) { return true; } - for(AxiomIdentifier type : types) { + for(AxiomName type : types) { if(definition.typeDefinition().isSubtypeOf(type)) { return true; } @@ -246,8 +246,8 @@ public boolean isApplicableTo(AxiomItemDefinition definition) { return false; } - private static ImmutableSet types(AxiomTypeDefinition... types) { - ImmutableSet.Builder builder = ImmutableSet.builder(); + private static ImmutableSet types(AxiomTypeDefinition... types) { + ImmutableSet.Builder builder = ImmutableSet.builder(); for (AxiomTypeDefinition item : types) { builder.add(item.name()); } @@ -255,15 +255,15 @@ private static ImmutableSet types(AxiomTypeDefinition... types) } - private static ImmutableSet items(AxiomItemDefinition... items) { - ImmutableSet.Builder builder = ImmutableSet.builder(); + private static ImmutableSet items(AxiomItemDefinition... items) { + ImmutableSet.Builder builder = ImmutableSet.builder(); for (AxiomItemDefinition item : items) { builder.add(item.name()); } return builder.build(); } - private static ImmutableSet all() { + private static ImmutableSet all() { return ImmutableSet.of(); } @@ -271,7 +271,7 @@ private static IdentifierSpaceKey namespaceId(String uri) { return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); } - public static void addFromType(AxiomValue source, AxiomValueContext target, AxiomIdentifier targetName) { + public static void addFromType(AxiomValue source, AxiomValueContext target, AxiomName targetName) { AxiomTypeDefinition superType = (AxiomTypeDefinition) source.get(); Preconditions.checkState(!(superType instanceof AxiomBuiltIn.Type)); // FIXME: Add namespace change if necessary @@ -283,7 +283,7 @@ public static void addFromType(AxiomValue source, AxiomValueContext target Collection itemDefs = ImmutableList.copyOf(superType.itemDefinitions().values()); for (AxiomItemDefinition item : superType.itemDefinitions().values()) { if(item.inherited()) { - final AxiomIdentifier derivedName = Inheritance.adapt(targetName, item); + final AxiomName derivedName = Inheritance.adapt(targetName, item); item = item.derived(derivedName); } target.mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, item)); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java index 24684043309..60472c2e11d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/CompositeIdentifierSpace.java @@ -4,7 +4,7 @@ import java.util.Map; import java.util.Set; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -24,7 +24,7 @@ public CompositeIdentifierSpace() { } @Override - public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + public ValueContext lookup(AxiomName space, IdentifierSpaceKey key) { for (IdentifierSpaceHolder delegate : delegates) { ValueContext maybe = delegate.lookup(space, key); if(maybe != null) { @@ -35,12 +35,12 @@ public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { } @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + public void register(AxiomName space, Scope scope, IdentifierSpaceKey key, ValueContext context) { export.register(space, scope, key, context); } @Override - public Map> space(AxiomIdentifier space) { + public Map> space(AxiomName space) { throw new UnsupportedOperationException(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java index ee410c06c6d..4769db1e084 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolder.java @@ -2,16 +2,16 @@ import java.util.Map; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; interface IdentifierSpaceHolder { - void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context); + void register(AxiomName space, Scope scope, IdentifierSpaceKey key, ValueContext context); - public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key); + public ValueContext lookup(AxiomName space, IdentifierSpaceKey key); - Map> space(AxiomIdentifier space); + Map> space(AxiomName space); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index 92729bb93e7..63429613292 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -6,7 +6,7 @@ import java.util.Set; import java.util.Map.Entry; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -17,14 +17,14 @@ public class IdentifierSpaceHolderImpl implements IdentifierSpaceHolder { Set allowedScopes; - Map>> space = new HashMap<>(); + Map>> space = new HashMap<>(); public IdentifierSpaceHolderImpl(Scope first, Scope... rest) { allowedScopes = EnumSet.of(first, rest); } @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext item) { + public void register(AxiomName space, Scope scope, IdentifierSpaceKey key, ValueContext item) { Preconditions.checkArgument(allowedScopes.contains(scope), "Scope " + scope + " is not allowed");// TODO // Auto-generated // method stub @@ -34,19 +34,19 @@ public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, } @Override - public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + public ValueContext lookup(AxiomName space, IdentifierSpaceKey key) { return space(space).get(key); } @Override - public Map> space(AxiomIdentifier spaceId) { + public Map> space(AxiomName spaceId) { return space.computeIfAbsent(spaceId, k -> new HashMap<>()); } - Map>> build() { - ImmutableMap.Builder>> roots = ImmutableMap + Map>> build() { + ImmutableMap.Builder>> roots = ImmutableMap .builder(); - for (Entry>> entry : space.entrySet()) { + for (Entry>> entry : space.entrySet()) { ImmutableMap.Builder> space = ImmutableMap.builder(); for (Entry> item : entry.getValue().entrySet()) { space.put(item.getKey(), item.getValue().get()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 56f22b9508f..1d8d37830d0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -6,7 +6,7 @@ import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; @@ -20,18 +20,18 @@ public class ItemContext extends AbstractContext> implements AxiomItemContext, Supplier>, Dependency>, ItemBuilder { - private final AxiomIdentifier name; + private final AxiomName name; Collection>> values = new ArrayList<>(); private final AxiomItemDefinition definition; - public ItemContext(ValueContext sourceContext, AxiomIdentifier name, AxiomItemDefinition definition, SourceLocation loc) { + public ItemContext(ValueContext sourceContext, AxiomName name, AxiomItemDefinition definition, SourceLocation loc) { super(sourceContext, loc, sourceContext); this.name = name; this.definition = definition; } @Override - public AxiomIdentifier name() { + public AxiomName name() { return name; } @@ -52,7 +52,7 @@ public AxiomTypeDefinition type() { } @Override - protected Optional childDef(AxiomIdentifier id) { + protected Optional childDef(AxiomName id) { return type().itemDefinition(id); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index 414daead9eb..278f5427a0e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -4,7 +4,7 @@ import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; @@ -17,14 +17,14 @@ public class ItemValueImpl implements AxiomValue { private static final AxiomValueFactory FACTORY = ItemValueImpl::new; private final AxiomTypeDefinition type; private final V value; - private final Map> items; + private final Map> items; protected X require(Optional value) { return value.get(); } - public ItemValueImpl(AxiomTypeDefinition type, V value, Map> items) { + public ItemValueImpl(AxiomTypeDefinition type, V value, Map> items) { super(); this.type = type; this.value = value; @@ -52,7 +52,7 @@ public Optional> item(AxiomItemDefinition def) { } @Override - public Optional> item(AxiomIdentifier name) { + public Optional> item(AxiomName name) { return Optional.ofNullable((AxiomItem) items.get(name)); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index b2dbf02e3bb..bc869dc0143 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.schema.AxiomItemDefinition; @@ -38,7 +38,7 @@ public class ModelReactorContext extends RuleReactorContext, ValueActionImpl, RuleContextImpl> implements AxiomIdentifierResolver { - private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); + private static final AxiomName ROOT = AxiomName.from("root", "root"); private static final String AXIOM_LANG_RESOURCE = "/axiom-lang.axiom"; private static final String AXIOM_BUILTIN_RESOURCE = "/axiom-base-types.axiom"; @@ -103,7 +103,7 @@ private static void defaults(ModelReactorContext reactorContext) { IdentifierSpaceHolderImpl globalSpace = new IdentifierSpaceHolderImpl(Scope.GLOBAL); - Map> typeFactories = new HashMap<>(); + Map> typeFactories = new HashMap<>(); List> roots = new ArrayList<>(); public ModelReactorContext(AxiomSchemaContext boostrapContext) { @@ -159,14 +159,14 @@ public void loadModelFromSource(AxiomModelStatementSource source) { } @Override - public AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName) { + public AxiomName resolveIdentifier(@Nullable String prefix, @NotNull String localName) { if (Strings.isNullOrEmpty(prefix)) { - return AxiomIdentifier.axiom(localName); + return AxiomName.axiom(localName); } return null; } - public void addStatementFactory(AxiomIdentifier statementType, AxiomValueFactory factory) { + public void addStatementFactory(AxiomName statementType, AxiomValueFactory factory) { typeFactories.put(statementType, factory); } @@ -192,7 +192,7 @@ private CompositeIdentifierSpace exported(IdentifierSpaceKey namespace) { return exported.computeIfAbsent(namespace, k -> new CompositeIdentifierSpace()); } - public Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + public Dependency namespace(AxiomName name, IdentifierSpaceKey namespaceId) { return Dependency.orNull(exported.get(namespaceId)); } @@ -207,7 +207,7 @@ protected Collection rulesFor(ValueContext context) { return rules; } - public Optional rootDefinition(AxiomIdentifier statement) { + public Optional rootDefinition(AxiomName statement) { return boostrapContext.getRoot(statement); } @@ -215,7 +215,7 @@ public void applyRuleDefinitions(ValueContext valueContext) { addActionsFor(valueContext); } - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + public void register(AxiomName space, Scope scope, IdentifierSpaceKey key, ValueContext context) { globalSpace.register(space, scope, key, context); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 03f6d33acfb..95d84496f44 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -4,7 +4,7 @@ import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.schema.AxiomItemDefinition; @@ -21,11 +21,11 @@ class SourceContext extends ValueContext implements AxiomRootContext, ValueBuilder { - private static final AxiomIdentifier ROOT = AxiomIdentifier.from("root", "root"); + private static final AxiomName ROOT = AxiomName.from("root", "root"); private final ModelReactorContext context; private final AxiomModelStatementSource source; - private final Map items = new HashMap(); + private final Map items = new HashMap(); private final CompositeIdentifierSpace globalSpace; private Map imports; @@ -38,17 +38,17 @@ public SourceContext(ModelReactorContext context, AxiomModelStatementSource sour } @Override - public AxiomIdentifier name() { + public AxiomName name() { return ROOT; } @Override - public ItemContext startItem(AxiomIdentifier identifier, SourceLocation loc) { + public ItemContext startItem(AxiomName identifier, SourceLocation loc) { return items.computeIfAbsent(identifier, id -> createItem(id, loc)); } @Override - public Optional childDef(AxiomIdentifier statement) { + public Optional childDef(AxiomName statement) { return context.rootDefinition(statement); } @@ -63,13 +63,13 @@ public void endValue(SourceLocation loc) { } @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key, ValueContext context) { + public void register(AxiomName space, Scope scope, IdentifierSpaceKey key, ValueContext context) { globalSpace.register(space, scope, key, context); this.context.register(space, scope, key, context); } @Override - public ValueContext lookup(AxiomIdentifier space, IdentifierSpaceKey key) { + public ValueContext lookup(AxiomName space, IdentifierSpaceKey key) { return globalSpace.lookup(space, key); } @@ -81,7 +81,7 @@ public void applyRuleDefinitions(ValueContext valueContext) { context.applyRuleDefinitions(valueContext); } - public Dependency requireNamespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + public Dependency requireNamespace(AxiomName name, IdentifierSpaceKey namespaceId) { return Dependency.retriableDelegate(() -> { return context.namespace(name, namespaceId); }); @@ -102,13 +102,13 @@ public void exportIdentifierSpace(IdentifierSpaceKey namespaceId) { public AxiomIdentifierResolver itemResolver() { return (prefix, localName) -> { if(Strings.isNullOrEmpty(prefix)) { - AxiomIdentifier axiomNs = AxiomIdentifier.axiom(localName); + AxiomName axiomNs = AxiomName.axiom(localName); if(childDef(axiomNs).isPresent()) { return axiomNs; } } String namespace = imports.get(prefix); - return AxiomIdentifier.from(namespace, localName); + return AxiomName.from(namespace, localName); }; } @@ -116,7 +116,7 @@ public AxiomIdentifierResolver itemResolver() { public AxiomIdentifierResolver valueResolver() { return AxiomIdentifierResolver.BUILTIN_TYPES.or((prefix, localName) -> { String namespace = imports.get(prefix); - return AxiomIdentifier.from(namespace, localName); + return AxiomName.from(namespace, localName); }); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index f4093abbaa8..065124c0918 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -13,7 +13,7 @@ import java.util.Optional; import java.util.function.Supplier; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueBuilder; @@ -50,7 +50,7 @@ public ValueContext(ItemContext itemContext, V value, SourceLocation loc) { } @Override - public AxiomIdentifier name() { + public AxiomName name() { return parent().name(); } @@ -59,12 +59,12 @@ public LookupImpl getLookup() { } @Override - public Optional childDef(AxiomIdentifier statement) { + public Optional childDef(AxiomName statement) { return parent().type().itemDefinition(statement); } @Override - public ItemContext startItem(AxiomIdentifier identifier, SourceLocation loc) { + public ItemContext startItem(AxiomName identifier, SourceLocation loc) { return mutable().getOrCreateItem(Inheritance.adapt(parent().name(), identifier), loc); } @@ -109,7 +109,7 @@ public ValueActionImpl addAction(String name) { return new ValueActionImpl<>(this, name); } - protected ItemContext createItem(AxiomIdentifier id, SourceLocation loc) { + protected ItemContext createItem(AxiomName id, SourceLocation loc) { return new ItemContext<>(this, id ,childDef(id).get(), loc); } @@ -125,7 +125,7 @@ public Result(AxiomTypeDefinition type, V value) { builder = AxiomValueBuilder.create(type, null); } - ItemContext getOrCreateItem(AxiomIdentifier identifier, SourceLocation loc) { + ItemContext getOrCreateItem(AxiomName identifier, SourceLocation loc) { return mutableItem(builder.get(identifier, id -> { ItemContext item = createItem(id, loc); addDependency(item); @@ -133,7 +133,7 @@ ItemContext getOrCreateItem(AxiomIdentifier identifier, SourceLocation loc) { })); } - Dependency> getItem(AxiomIdentifier item) { + Dependency> getItem(AxiomName item) { Supplier> maybeItem = builder.get(item); if(maybeItem == null) { return null; @@ -173,7 +173,7 @@ public void replace(AxiomValue axiomItemValue) { } @Override - public ItemContext childItem(AxiomIdentifier name) { + public ItemContext childItem(AxiomName name) { return (ItemContext) mutable().getOrCreateItem(Inheritance.adapt(parent().name(), name), SourceLocation.runtime()); } @@ -197,7 +197,7 @@ public void mergeItem(AxiomItem axiomItem) { } @Override - public void register(AxiomIdentifier space, Scope scope, IdentifierSpaceKey key) { + public void register(AxiomName space, Scope scope, IdentifierSpaceKey key) { register(space, scope, key, this); } @@ -217,7 +217,7 @@ public void dependsOnAction(ValueActionImpl action) { addDependency(action); } - public Dependency.Search> requireChild(AxiomIdentifier item) { + public Dependency.Search> requireChild(AxiomName item) { return Dependency.retriableDelegate(() -> { if(result instanceof ValueContext.Result) { return ((ValueContext.Result) result).getItem(item); @@ -252,7 +252,7 @@ public AxiomItemDefinition itemDefinition() { } @Override - public Dependency namespace(AxiomIdentifier name, IdentifierSpaceKey namespaceId) { + public Dependency namespace(AxiomName name, IdentifierSpaceKey namespaceId) { return rootImpl().requireNamespace(name, namespaceId); } @@ -291,7 +291,7 @@ public Dependency> onlyItemValue(AxiomItemDefinition definitio } @Override - public Dependency> modify(AxiomIdentifier space, IdentifierSpaceKey key) { + public Dependency> modify(AxiomName space, IdentifierSpaceKey key) { return (Dependency.retriableDelegate(() -> { ValueContext maybe = lookup(space, key); if(maybe != null) { @@ -303,7 +303,7 @@ public Dependency> modify(AxiomIdentifier space, Identifier } @Override - public Dependency.Search> global(AxiomIdentifier space, + public Dependency.Search> global(AxiomName space, IdentifierSpaceKey key) { return Dependency.retriableDelegate(() -> { ValueContext maybe = lookup(space, key); @@ -315,7 +315,7 @@ public Dependency.Search> global(AxiomIdentifier space, } @Override - public Dependency.Search> reference(AxiomIdentifier space, + public Dependency.Search> reference(AxiomName space, IdentifierSpaceKey key) { return Dependency.retriableDelegate(() -> { ValueContext maybe = lookup(space, key); @@ -327,7 +327,7 @@ public Dependency.Search> reference(AxiomIdentifier space } @Override - public Dependency.Search> namespaceValue(AxiomIdentifier space, + public Dependency.Search> namespaceValue(AxiomName space, IdentifierSpaceKey key) { return Dependency.retriableDelegate(() -> { ValueContext maybe = lookup(space, key); @@ -373,14 +373,14 @@ public AxiomSemanticException error(String message, Object... arguments) { public AxiomIdentifierResolver itemResolver() { return (prefix, localName) -> { if(Strings.isNullOrEmpty(prefix)) { - AxiomIdentifier localNs = AxiomIdentifier.local(localName); + AxiomName localNs = AxiomName.local(localName); Optional childDef = childDef(localNs); if(childDef.isPresent()) { return Inheritance.adapt(parent().name(), childDef.get()); } ItemContext parent = parent(); while(parent != null) { - AxiomIdentifier parentNs = AxiomIdentifier.from(parent.name().namespace(), localName); + AxiomName parentNs = AxiomName.from(parent.name().namespace(), localName); if(childDef(parentNs).isPresent()) { return parentNs; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java index 97648959166..b3c1b80d7ee 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java @@ -2,7 +2,7 @@ import java.util.Map; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.schema.AxiomNamedDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -11,17 +11,17 @@ public class AbstractBaseDefinition extends ItemValueImpl implements AxiomNamedDefinition { - private final AxiomIdentifier name; + private final AxiomName name; private final String documentation; - public AbstractBaseDefinition(AxiomTypeDefinition type, V value, Map> items) { + public AbstractBaseDefinition(AxiomTypeDefinition type, V value, Map> items) { super(type, value, items); - name = (AxiomIdentifier) item(Item.NAME).get().onlyValue().get(); + name = (AxiomName) item(Item.NAME).get().onlyValue().get(); documentation = item(Item.DOCUMENTATION).map(i -> i.onlyValue().get().toString()).orElse(null); // } @Override - public AxiomIdentifier name() { + public AxiomName name() { return name; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index 688d0495a8f..db4dddd6f8f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -2,7 +2,7 @@ import java.util.Collection; import java.util.Map; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; @@ -21,12 +21,12 @@ public class AxiomIdentifierDefinitionImpl extends ItemValueImpl components; - private final AxiomIdentifier space; + private final AxiomName space; - public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomIdentifierDefinition value, Map> items) { + public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomIdentifierDefinition value, Map> items) { super(axiomItemDefinition, value, items); - this.scope = AxiomIdentifierDefinition.scope(this.item(Item.ID_SCOPE.name()).get().onlyValue().get().localName()); - this.space = this.item(Item.ID_SPACE.name()).get().onlyValue().get(); + this.scope = AxiomIdentifierDefinition.scope(this.item(Item.ID_SCOPE.name()).get().onlyValue().get().localName()); + this.space = this.item(Item.ID_SPACE.name()).get().onlyValue().get(); ImmutableList.Builder components = ImmutableList.builder(); for (AxiomValue val : this.item(Item.ID_MEMBER.name()).get().values()) { @@ -51,7 +51,7 @@ public Scope scope() { } @Override - public AxiomIdentifier space() { + public AxiomName space() { return space; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java index 47e1f9b057f..4e00a67981c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java @@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -22,24 +22,24 @@ public interface AxiomIdentifierResolver { - final AxiomIdentifierResolver AXIOM_DEFAULT_NAMESPACE = defaultNamespace(AxiomIdentifier.AXIOM_NAMESPACE); + final AxiomIdentifierResolver AXIOM_DEFAULT_NAMESPACE = defaultNamespace(AxiomName.AXIOM_NAMESPACE); final Set BUILTINS = ImmutableSet.of("string","boolean","uri", "int", "binary", "dateTime"); final AxiomIdentifierResolver BUILTIN_TYPES = (prefix, localName) -> { if((prefix == null || prefix.isEmpty()) && BUILTINS.contains(localName)) { - return AxiomIdentifier.axiom(localName); + return AxiomName.axiom(localName); } return null; }; - AxiomIdentifier resolveIdentifier(@Nullable String prefix, @NotNull String localName); + AxiomName resolveIdentifier(@Nullable String prefix, @NotNull String localName); static AxiomIdentifierResolver defaultNamespace(String namespace) { - return (prefix, localName) -> Strings.isNullOrEmpty(prefix) ? AxiomIdentifier.from(namespace, localName) : null; + return (prefix, localName) -> Strings.isNullOrEmpty(prefix) ? AxiomName.from(namespace, localName) : null; } default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { return (prefix, localName) -> { - AxiomIdentifier maybe = this.resolveIdentifier(prefix, localName); + AxiomName maybe = this.resolveIdentifier(prefix, localName); if (maybe != null) { return maybe; } @@ -50,7 +50,7 @@ default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { static AxiomIdentifierResolver defaultNamespaceFromType(AxiomTypeDefinition type) { return (prefix, localName) -> { if(Strings.isNullOrEmpty(prefix)) { - AxiomIdentifier localNs = AxiomIdentifier.local(localName); + AxiomName localNs = AxiomName.local(localName); Optional childDef = type.itemDefinition(localNs); if(childDef.isPresent()) { return Inheritance.adapt(type.name(), childDef.get()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 168416f6dd8..a95b1a420ed 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -3,7 +3,7 @@ import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; @@ -17,7 +17,7 @@ public class AxiomItemDefinitionImpl extends AbstractBaseDefinition valueType; private final Optional> minOccurs; - public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomItemDefinition value, Map> items) { + public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomItemDefinition value, Map> items) { super(axiomItemDefinition, value, items); this.valueType = require(onlyValue(AxiomTypeDefinition.class,Item.TYPE_REFERENCE, Item.REF_TARGET)); minOccurs = this.item(Item.MIN_OCCURS.name()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java index 3bc2a072331..46a1b5baabd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemStreamTreeBuilder.java @@ -9,7 +9,7 @@ import java.util.Deque; import java.util.LinkedList; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.concepts.SourceLocation; @@ -58,7 +58,7 @@ public void endValue(SourceLocation loc) { } @Override - public void startItem(AxiomIdentifier item, SourceLocation loc) { + public void startItem(AxiomName item, SourceLocation loc) { Optional childDef = value(current()).childDef(item); AxiomSyntaxException.check(childDef.isPresent(), loc , "Item %s not allowed in %s", item, current().name()); offer(value(current()).startItem(item, loc)); @@ -70,7 +70,7 @@ public void endItem(SourceLocation loc) { } private interface Builder { - AxiomIdentifier name(); + AxiomName name(); } public interface ItemBuilder extends Builder { @@ -80,8 +80,8 @@ public interface ItemBuilder extends Builder { } public interface ValueBuilder extends Builder { - Optional childDef(AxiomIdentifier statement); - ItemBuilder startItem(AxiomIdentifier identifier, SourceLocation loc); + Optional childDef(AxiomName statement); + ItemBuilder startItem(AxiomName identifier, SourceLocation loc); void endValue(SourceLocation loc); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 5a7e38226ee..874a168ab89 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -4,7 +4,7 @@ import java.util.Collections; import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; @@ -21,16 +21,16 @@ public class AxiomTypeDefinitionImpl extends AbstractBaseDefinition FACTORY =AxiomTypeDefinitionImpl::new; - private final Map itemDefinitions; + private final Map itemDefinitions; private final Optional superType; private final Optional argument; private final Collection identifiers; - public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition value, Map> keywordMap) { + public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition value, Map> keywordMap) { super(def, null, keywordMap); //super(keyword, value, children, keywordMap); - ImmutableMap.Builder builder = ImmutableMap.builder(); + ImmutableMap.Builder builder = ImmutableMap.builder(); Optional> itemDef = item(Item.ITEM_DEFINITION.name()); if(itemDef.isPresent()) { supplyAll(name(),builder, itemDef.get().values()); @@ -39,7 +39,7 @@ public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition valu superType = onlyValue(AxiomTypeDefinition.class,Item.SUPERTYPE_REFERENCE, Item.REF_TARGET).map(v -> v.get()); - argument = this.item(Item.ARGUMENT.name()).flatMap(v -> itemDefinition(v.onlyValue().get())); + argument = this.item(Item.ARGUMENT.name()).flatMap(v -> itemDefinition(v.onlyValue().get())); identifiers = upcast(this.item(Item.IDENTIFIER_DEFINITION.name()).map(v -> v.values()).orElse(Collections.emptyList())); } @@ -53,7 +53,7 @@ private > Collection upcast(Collection> } @Override - public Optional> item(AxiomIdentifier name) { + public Optional> item(AxiomName name) { return super.item(name); } @@ -71,7 +71,7 @@ public Optional superType() { } @Override - public Map itemDefinitions() { + public Map itemDefinitions() { return itemDefinitions; } @@ -80,11 +80,11 @@ public Collection identifierDefinitions() { return identifiers; } - private void supplyAll(AxiomIdentifier type, Builder builder, + private void supplyAll(AxiomName type, Builder builder, Collection> values) { for(AxiomValue v : values) { AxiomItemDefinition val = v.get(); - AxiomIdentifier name = Inheritance.adapt(type, val.name()); + AxiomName name = Inheritance.adapt(type, val.name()); builder.put(name, val); } } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index a587e426606..733f004bdfe 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -76,7 +76,7 @@ model axiom-lang { argument prefix; item prefix { - type AxiomIdentifier; + type AxiomName; } item namespace { @@ -96,7 +96,7 @@ model axiom-lang { argument name; item name { - type AxiomIdentifier; + type AxiomName; } item documentation { @@ -118,7 +118,7 @@ model axiom-lang { type AxiomIdentifierDefinition { argument key; item key { - type AxiomIdentifier; + type AxiomName; minOccurs "1"; } item scope { @@ -126,7 +126,7 @@ model axiom-lang { minOccurs "1"; } item space { - type AxiomIdentifier; + type AxiomName; minOccurs "1"; } } @@ -145,7 +145,7 @@ model axiom-lang { } item argument { - type AxiomIdentifier; + type AxiomName; documentation """ Name of item, which is target of short-form value declaration. """; @@ -182,7 +182,7 @@ model axiom-lang { // TODO reconsider this - strictly speaking this is part of "global type+item definition combo" item itemName { - type AxiomIdentifier; + type AxiomName; } item item { @@ -194,8 +194,7 @@ model axiom-lang { } } - // FIXME: Should be AxiomName - type AxiomIdentifier { + type AxiomName { documentation """ Qualified name. Consists of namespace and local name. """; @@ -258,7 +257,7 @@ model axiom-lang { argument name; item name { - type AxiomIdentifier; + type AxiomName; documentation """ Name of referenced type definition. The value must be name of existing type definition, which is diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index 0fe43d216b1..557d1d8670c 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -16,7 +16,7 @@ import org.testng.annotations.Test; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -26,10 +26,10 @@ public class TestAxiomExtension extends AbstractReactorTest { - private static final AxiomIdentifier PERSON = AxiomIdentifier.from("https://example.org", "Person"); - private static final AxiomIdentifier STORAGE = AxiomIdentifier.from("https://example.org/extension", "type"); + private static final AxiomName PERSON = AxiomName.from("https://example.org", "Person"); + private static final AxiomName STORAGE = AxiomName.from("https://example.org/extension", "type"); - private static final AxiomIdentifier PERSON_EXTENSION = AxiomIdentifier.from("https://schema.org", "SchemaOrgPerson"); + private static final AxiomName PERSON_EXTENSION = AxiomName.from("https://schema.org", "SchemaOrgPerson"); private static final String DIR = "multimodel/extension/"; private static final String SCHEMA_ORG = DIR + "person-extension.axiom"; private static final String BASE = DIR + "test-person.axiom"; @@ -52,7 +52,7 @@ public void axiomTestExtension() throws IOException, AxiomSyntaxException { Optional extPersonDef = schemaContext.getType(PERSON_EXTENSION); assertTrue(extPersonDef.isPresent()); - for(AxiomIdentifier item : extPersonDef.get().itemDefinitions().keySet()) { + for(AxiomName item : extPersonDef.get().itemDefinitions().keySet()) { assertTrue(personDef.get().itemDefinition(item).isPresent()); } } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java index 21f7abee4ea..a60a32c94d9 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomPrism.java @@ -11,17 +11,17 @@ import java.io.IOException; import org.testng.annotations.Test; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class TestAxiomPrism extends AbstractReactorTest { - private static final AxiomIdentifier PERSON = AxiomIdentifier.from("https://example.org", "Person"); - private static final AxiomIdentifier STORAGE = AxiomIdentifier.from("https://example.org/extension", "type"); + private static final AxiomName PERSON = AxiomName.from("https://example.org", "Person"); + private static final AxiomName STORAGE = AxiomName.from("https://example.org/extension", "type"); - private static final AxiomIdentifier PERSON_EXTENSION = AxiomIdentifier.from("https://schema.org", "SchemaOrgPerson"); + private static final AxiomName PERSON_EXTENSION = AxiomName.from("https://schema.org", "SchemaOrgPerson"); private static final String DIR = "prism/"; private static final String PRISM = DIR + "prism.axiom"; private static final String COMMON_CORE = DIR + "common-core.axiom"; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 81cd005cacb..a50bff4c9eb 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -16,7 +16,7 @@ import org.testng.annotations.Test; -import com.evolveum.axiom.api.AxiomIdentifier; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; @@ -32,10 +32,10 @@ public class TestTypeDerivation extends AbstractReactorTest { - private static final AxiomIdentifier DERIVED_PERSON = AxiomIdentifier.from("https://example.org/derived", "Person"); - private static final AxiomIdentifier FIRST_NAME = DERIVED_PERSON.localName("firstName"); - private static final AxiomIdentifier LAST_NAME = DERIVED_PERSON.localName("lastName"); - private static final AxiomIdentifier NAME = AxiomIdentifier.from("https://example.org/base", "name"); + private static final AxiomName DERIVED_PERSON = AxiomName.from("https://example.org/derived", "Person"); + private static final AxiomName FIRST_NAME = DERIVED_PERSON.localName("firstName"); + private static final AxiomName LAST_NAME = DERIVED_PERSON.localName("lastName"); + private static final AxiomName NAME = AxiomName.from("https://example.org/base", "name"); private static final String DIR = "multimodel/derived/"; private static final String BASE = DIR + "base-person.axiom"; private static final String DERIVED = DIR + "derived-person.axiom"; @@ -57,7 +57,7 @@ public void axiomTestInheritance() throws IOException, AxiomSyntaxException { Optional personDef = schemaContext.getType(DERIVED_PERSON); assertTrue(personDef.isPresent()); - for (Entry idDef : personDef.get().itemDefinitions().entrySet()) { + for (Entry idDef : personDef.get().itemDefinitions().entrySet()) { AxiomItemDefinition item = idDef.getValue(); assertEquals(idDef.getKey(), Inheritance.adapt(DERIVED_PERSON, item), " should have different namespace"); } From 6ed88745076b48b43cef750548586892dca012c1 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 29 May 2020 09:40:40 +0200 Subject: [PATCH 39/60] Axiom: Renamed Extension to Augmentation Signed-off-by: Tony Tkacik --- .../main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java | 2 +- .../com/evolveum/axiom/lang/impl/BasicStatementRule.java | 2 +- infra/axiom/src/main/resources/axiom-lang.axiom | 6 +++--- .../com/evolveum/axiom/lang/test/TestAxiomExtension.java | 6 +++--- .../com/evolveum/axiom/lang/test/TestTypeDerivation.java | 2 +- .../resources/multimodel/extension/declaration-order.axiom | 2 +- .../resources/multimodel/extension/language-extension.axiom | 2 +- .../resources/multimodel/extension/person-extension.axiom | 2 +- infra/axiom/src/test/resources/prism/prism.axiom | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index d3f57bbed81..ecb6a7b8541 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -204,7 +204,7 @@ public Collection identifierDefinitions() { Item.ID_SPACE )); public static final Type IMPORT_DEFINITION = new Type("AxiomImportDeclaration"); - public static final Type EXTENSION_DEFINITION = new Type("AxiomExtensionDefinition"); + public static final Type AUGMENTATION_DEFINITION = new Type("AxiomAugmentationDefinition"); private final AxiomName identifier; private final AxiomTypeDefinition superType; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index cb945e20068..fa012f32bf0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -182,7 +182,7 @@ public void apply(Lookup context, ActionBuilder action) th } }, - APPLY_EXTENSION(all(), types(Type.EXTENSION_DEFINITION)) { + APPLY_AUGMENTATION(all(), types(Type.AUGMENTATION_DEFINITION)) { @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 733f004bdfe..3fb8ea29919 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -62,8 +62,8 @@ model axiom-lang { } // FIXME: should be augmentation - item extension { - type AxiomExtensionDefinition; + item augmentation { + type AxiomAugmentationDefinition; documentation """ Declaration of augmentation. Augmentation adds new items to already existing type, which can be defined in other @@ -283,7 +283,7 @@ model axiom-lang { extends AxiomTypeDefinition; } - type AxiomExtensionDefinition { + type AxiomAugmentationDefinition { extends AxiomMixinDefinition; item target { type AxiomTypeReference; diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index 557d1d8670c..4f32daae587 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -44,7 +44,7 @@ public void axiomTestExtension() throws IOException, AxiomSyntaxException { context.loadModelFromSource(source(BASE)); AxiomSchemaContext schemaContext = context.computeSchemaContext(); - AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(PERSON); @@ -63,7 +63,7 @@ public void axiomTestOrder() throws IOException, AxiomSyntaxException { context.loadModelFromSource(source(ORDER)); AxiomSchemaContext schemaContext = context.computeSchemaContext(); - AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(PERSON); @@ -85,7 +85,7 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio extendedLanguage.loadModelFromSource(source(LANG_EXT_USE)); schemaContext = extendedLanguage.computeSchemaContext(); - AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(PERSON); diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index a50bff4c9eb..ae8eda4b618 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -52,7 +52,7 @@ private AxiomSchemaContext loadModel() throws AxiomSyntaxException, IOException @Test public void axiomTestInheritance() throws IOException, AxiomSyntaxException { AxiomSchemaContext schemaContext = loadModel(); - AxiomTypeDefinition langExtDef = schemaContext.getType(Type.EXTENSION_DEFINITION.name()).get(); + AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(DERIVED_PERSON); diff --git a/infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom b/infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom index fd1d7c581ab..048c8211a7f 100644 --- a/infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom +++ b/infra/axiom/src/test/resources/multimodel/extension/declaration-order.axiom @@ -8,7 +8,7 @@ model test-person { } } - extension PersonExtension { + augmentation PersonExtension { target Person; item fullName { type string; diff --git a/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom b/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom index d1f7cd96107..436e147e001 100644 --- a/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom +++ b/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom @@ -6,7 +6,7 @@ model language-extension { namespace "https://ns.evolveum.com/axiom/language"; } - extension Storage { + augmentation Storage { target axiom:AxiomTypeDefinition; item type { diff --git a/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom b/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom index 5523388e417..7930c4c2430 100644 --- a/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom +++ b/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom @@ -6,7 +6,7 @@ model schema-org-person { namespace "https://example.org"; } - extension SchemaOrgPerson { + augmentation SchemaOrgPerson { target base:Person; item honorificPrefix { diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom index 1de7e6a2088..321579f7698 100644 --- a/infra/axiom/src/test/resources/prism/prism.axiom +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -10,7 +10,7 @@ model prism { type PrismModel; } - extension PrismModelExtension { + augmentation PrismModelExtension { target axiom:AxiomModel; item object { @@ -33,7 +33,7 @@ model prism { } } - extension PrismTypeDefinitionAnnotation { + augmentation PrismTypeDefinitionAnnotation { target axiom:AxiomTypeDefinition; // TODO move to prism schema item object { From cd7ed64670c569c854fc6d67b3e986027be85bf7 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 29 May 2020 11:08:12 +0200 Subject: [PATCH 40/60] Axiom: moved identifier declaration to AxiomItemDefinition Signed-off-by: Tony Tkacik --- .../api/schema/AxiomIdentifierDefinition.java | 14 ++- .../schema/AxiomIdentifierDefinitionImpl.java | 22 +---- .../axiom/api/schema/AxiomItemDefinition.java | 5 ++ .../api/schema/DelegatedItemDefinition.java | 5 ++ .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 63 ++++++------- .../axiom/lang/impl/AxiomStatementRule.java | 2 + .../axiom/lang/impl/BasicStatementRule.java | 90 +++++++++---------- .../lang/impl/IdentifierSpaceHolderImpl.java | 5 +- .../axiom/lang/impl/ValueContext.java | 5 ++ .../spi/AxiomIdentifierDefinitionImpl.java | 24 +---- .../lang/spi/AxiomItemDefinitionImpl.java | 8 ++ .../axiom/src/main/resources/axiom-lang.axiom | 41 +++------ .../axiom/lang/test/TestAxiomExtension.java | 12 +-- .../axiom/lang/test/TestTypeDerivation.java | 3 - 14 files changed, 126 insertions(+), 173 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java index 1fad4a318cd..d7abd419f48 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java @@ -14,11 +14,7 @@ default AxiomIdentifierDefinition get() { return this; } - Collection components(); - - Scope scope(); - - AxiomName space(); + Collection components(); enum Scope { GLOBAL, @@ -26,11 +22,11 @@ enum Scope { LOCAL } - static AxiomIdentifierDefinition global(AxiomName name, AxiomItemDefinition... components) { + static AxiomIdentifierDefinition global(AxiomName name, AxiomName... components) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.GLOBAL); } - static AxiomIdentifierDefinition local(AxiomName name, AxiomItemDefinition... components) { + static AxiomIdentifierDefinition local(AxiomName name, AxiomName... components) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.LOCAL); } @@ -47,11 +43,11 @@ static Scope scope(String scope) { throw new IllegalArgumentException("Unknown scope " + scope); } - static AxiomIdentifierDefinition from(AxiomName space, Scope scope, Set members) { + static AxiomIdentifierDefinition from(AxiomName space, Scope scope, Set members) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(members), space, scope); } - static AxiomIdentifierDefinition parent(AxiomName name, AxiomItemDefinition... components) { + static AxiomIdentifierDefinition parent(AxiomName name, AxiomName... components) { return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.PARENT); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java index 53e485bbf1f..58588d0339e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java @@ -8,34 +8,18 @@ class AxiomIdentifierDefinitionImpl implements AxiomIdentifierDefinition { - private Set components; + private Set components; - private AxiomName space; - private Scope scope; - - public AxiomIdentifierDefinitionImpl(Set components, AxiomName space, Scope scope) { + public AxiomIdentifierDefinitionImpl(Set components, AxiomName space, Scope scope) { super(); this.components = ImmutableSet.copyOf(components); - this.space = space; - this.scope = scope; } @Override - public Set components() { + public Set components() { return components; } - - @Override - public Scope scope() { - return scope; - } - - @Override - public AxiomName space() { - return space; - } - @Override public Optional type() { // TODO Auto-generated method stub diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java index a925a4b0807..59a58891a26 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java @@ -6,6 +6,8 @@ */ package com.evolveum.axiom.api.schema; +import java.util.Optional; + import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; @@ -17,6 +19,7 @@ public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomValue identifierDefinition(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java index 7d12075c28f..05b588b1784 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java @@ -79,4 +79,9 @@ public String toString() { public AxiomTypeDefinition definingType() { return delegate().definingType(); } + + @Override + public Optional identifierDefinition() { + return delegate().identifierDefinition(); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index ecb6a7b8541..79953b7eb75 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -18,7 +18,6 @@ import com.evolveum.axiom.concepts.Lazy; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import com.google.common.collect.ImmutableSet; public class AxiomBuiltIn { @@ -30,6 +29,8 @@ 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); @@ -38,9 +39,16 @@ public static class Item implements AxiomItemDefinition { 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 Item ROOT_DEFINITION = new Item("root", Type.ROOT_DEFINITION, false); - public static final AxiomItemDefinition ITEM_DEFINITION = new Item("item", Type.ITEM_DEFINITION, false); + public static final AxiomItemDefinition ITEM_DEFINITION = new Item("item", Type.ITEM_DEFINITION, false) { + + @Override + public Optional 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); @@ -58,6 +66,9 @@ public static class Item implements AxiomItemDefinition { public static final AxiomItemDefinition USES = new Item("uses", Type.TYPE_REFERENCE, true); + protected static final Lazy NAME_IDENTIFIER = Lazy.from( + ()-> (AxiomIdentifierDefinition.parent(ITEM_DEFINITION.name(), Item.NAME.name()))); + private final AxiomName identifier; private final AxiomTypeDefinition type; private boolean required; @@ -122,9 +133,13 @@ public AxiomItemDefinition get() { @Override public AxiomTypeDefinition definingType() { - // TODO Auto-generated method stub return null; } + + @Override + public Optional identifierDefinition() { + return Optional.empty(); + } } public static class Type implements AxiomTypeDefinition { @@ -153,49 +168,21 @@ public static class Type implements AxiomTypeDefinition { public static final Type TYPE_DEFINITION = new Type("AxiomTypeDefinition", BASE_DEFINITION, () -> itemDefs( Item.ARGUMENT, - Item.IDENTIFIER_DEFINITION, Item.SUPERTYPE_REFERENCE, Item.ITEM_DEFINITION - )) { - @Override - public Collection identifierDefinitions() { - return TYPE_IDENTIFIER_DEFINITION.get(); - } - }; - - protected static final Lazy> TYPE_IDENTIFIER_DEFINITION = Lazy.from(()-> - ImmutableSet.of(AxiomIdentifierDefinition.global(TYPE_DEFINITION.name(), Item.NAME))); + )); public static final Type ITEM_DEFINITION = new Type("AxiomItemDefinition", BASE_DEFINITION, () -> itemDefs( Item.TYPE_REFERENCE, + Item.IDENTIFIER_DEFINITION, Item.MIN_OCCURS, Item.MAX_OCCURS, Item.OPERATIONAL - )) { - - @Override - public Collection identifierDefinitions() { - return ITEM_IDENTIFIER_DEFINITION.get(); - } - }; - - public static final Type ROOT_DEFINITION = - new Type("AxiomRootDefinition", ITEM_DEFINITION, () -> itemDefs()) { - - @Override - public Collection identifierDefinitions() { - return ROOT_IDENTIFIER_DEFINITION.get(); - } - }; - - protected static final Lazy> ITEM_IDENTIFIER_DEFINITION = Lazy.from(()-> - ImmutableSet.of(AxiomIdentifierDefinition.parent(ITEM_DEFINITION.name(), Item.NAME))); - - protected static final Lazy> ROOT_IDENTIFIER_DEFINITION = Lazy.from(()-> - ImmutableSet.of(AxiomIdentifierDefinition.global(AxiomItemDefinition.ROOT_SPACE, Item.NAME))); + )); + 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( @@ -204,7 +191,7 @@ public Collection identifierDefinitions() { Item.ID_SPACE )); public static final Type IMPORT_DEFINITION = new Type("AxiomImportDeclaration"); - public static final Type AUGMENTATION_DEFINITION = new Type("AxiomAugmentationDefinition"); + public static final Type AUGMENTATION_DEFINITION = new Type("AxiomAugmentationDefinition",TYPE_DEFINITION); private final AxiomName identifier; private final AxiomTypeDefinition superType; @@ -220,6 +207,10 @@ private Type(String identifier, Lazy.Supplier> items) { this(identifier, superType, NO_ARGUMENT, Lazy.from(items)); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java index 1963a7305fc..b3e5a6f0fd9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomStatementRule.java @@ -29,6 +29,8 @@ default AxiomTypeDefinition typeDefinition() { Dependency> child(AxiomItemDefinition item, Class valueType); + Dependency> child(AxiomName item, Class valueType); + Dependency> onlyItemValue(AxiomItemDefinition item, Class valueType); Dependency> modify(AxiomName identifierSpace, IdentifierSpaceKey identifier); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index fa012f32bf0..ace043b6e52 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -11,6 +11,7 @@ import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition; +import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn; @@ -20,7 +21,6 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.reactor.Dependency; -import com.evolveum.axiom.reactor.Dependency.Search; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -54,32 +54,52 @@ public void apply(Lookup context, ActionBuilder action) th } } }, + REGISTER_TYPE(all(), types(Type.TYPE_DEFINITION)) { - REGISTER_TO_IDENTIFIER_SPACE(all(),all()){ + @Override + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Dependency typeName = action.require(context.child(Item.NAME, AxiomName.class) + .map(v -> v.onlyValue().get())) + .unsatisfied(() -> action.error("Type does not have name defined.")); + action.apply(ctx -> { + ctx.register(AxiomTypeDefinition.SPACE, AxiomIdentifierDefinition.Scope.GLOBAL, AxiomTypeDefinition.identifier(typeName.get())); + }); + } + }, + REGISTER_ROOT(all(), types(Type.ROOT_DEFINITION)) { + + @Override + public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { + Dependency typeName = action.require(context.child(Item.NAME, AxiomName.class) + .map(v -> v.onlyValue().get())) + .unsatisfied(() -> action.error("Type does not have name defined.")); + action.apply(ctx -> { + ctx.register(AxiomItemDefinition.ROOT_SPACE, AxiomIdentifierDefinition.Scope.GLOBAL, AxiomItemDefinition.identifier(typeName.get())); + }); + } + }, + ITEM_VALUE_IDENTIFIER(all(),all()){ @Override public boolean isApplicableTo(AxiomItemDefinition definition) { - return !definition.typeDefinition().identifierDefinitions().isEmpty(); + if(definition.identifierDefinition().isPresent()) { + return true; + } + return false; } @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - Collection idDefs = context.typeDefinition().identifierDefinitions(); - Map>>> identReq = new HashMap<>(); - for(AxiomIdentifierDefinition idDef : idDefs) { - Map>> components = new HashMap<>(); - for(AxiomItemDefinition cmp : idDef.components()) { - components.put(cmp.name(), action.require(context.child(cmp, Object.class)) - .unsatisfied(()-> context.error("Item '%s' is required by identifier, but not defined.", cmp.name())) - .map(v -> v.onlyValue())); - } - identReq.put(idDef, components); + AxiomIdentifierDefinition idDef = context.itemDefinition().identifierDefinition().get(); + Map>> components = new HashMap<>(); + for(AxiomName key : idDef.components()) { + components.put(key, action.require(context.child(key, Object.class)) + .unsatisfied(()-> context.error("Item '%s' is required by identifier, but not defined.", key)) + .map(v -> v.onlyValue())); } action.apply(ctx -> { - for (AxiomIdentifierDefinition idDef : idDefs) { - IdentifierSpaceKey key = keyFrom(identReq.get(idDef)); - ctx.register(idDef.space(), idDef.scope(), key); - } + IdentifierSpaceKey key = keyFrom(components); + ctx.register(AxiomItemDefinition.VALUE_SPACE, Scope.PARENT, key); }); } @@ -102,23 +122,6 @@ public void apply(Lookup context, ActionBuilder action) th }); } }, - EXPAND_IDENTIFIER_ITEM(items(Item.ID_MEMBER), all()) { - - @Override - public boolean isApplicableTo(AxiomItemDefinition definition) { - return Item.ID_MEMBER.name().equals(definition.name()); - } - - @Override - public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - AxiomName itemName = context.currentValue(); - Search> itemDef = action.require(context.namespaceValue(AxiomItemDefinition.SPACE, AxiomItemDefinition.identifier(itemName))) - .notFound(() -> action.error("item '%s' was not found", itemName)); - action.apply((val) -> { - val.replace(itemDef.get()); - }); - } - }, ITEMS_FROM_SUPERTYPE(items(Item.SUPERTYPE_REFERENCE),types(Type.TYPE_REFERENCE)) { @Override @@ -184,6 +187,11 @@ public void apply(Lookup context, ActionBuilder action) th APPLY_AUGMENTATION(all(), types(Type.AUGMENTATION_DEFINITION)) { + @Override + public boolean isApplicableTo(AxiomItemDefinition definition) { + return super.isApplicableTo(definition); + } + @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency> targetRef = action.require(context.child(Item.TARGET, AxiomName.class) @@ -199,19 +207,7 @@ public void apply(Lookup context, ActionBuilder action) th } }); } - }, - /* - * Not needed - registration is handled by identifier statement - REGISTER_TYPE(items(Item.TYPE_DEFINITION), types(Type.TYPE_DEFINITION)) { - - @Override - public void apply(Context rule) throws AxiomSemanticException { - AxiomIdentifier typeName = action.requireValue(); - action.apply(ctx -> ctx.registerAsGlobalItem(typeName)); - } - }, - */ - ; + }; private final Set items; private final Set types; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java index 63429613292..083faa003f2 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/IdentifierSpaceHolderImpl.java @@ -29,8 +29,9 @@ public void register(AxiomName space, Scope scope, IdentifierSpaceKey key, Value // Auto-generated // method stub ValueContext previous = space(space).putIfAbsent(key, item); - AxiomSemanticException.check(previous == null, item.startLocation(), - "%s identifier space: Item %s is already defined at %s", space,item, previous); + if(previous != null) { + throw AxiomSemanticException.create(item.startLocation(), "%s: %s is already defined at %s", space.localName(),item, previous.startLocation()); + } } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 065124c0918..f5b93b51aa3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -272,6 +272,11 @@ public Dependency> child(AxiomItemDefinition definition, Class< return requireChild(Inheritance.adapt(parent().name(), definition)); } + @Override + public Dependency> child(AxiomName definition, Class valueType) { + return requireChild(Inheritance.adapt(parent().name(), definition)); + } + @Override public Dependency> onlyItemValue(AxiomItemDefinition definition, Class valueType) { return Dependency.retriableDelegate(() -> { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index db4dddd6f8f..cddfd530fbe 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -7,7 +7,6 @@ import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; 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.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.impl.ItemValueImpl; @@ -17,19 +16,14 @@ public class AxiomIdentifierDefinitionImpl extends ItemValueImpl FACTORY = AxiomIdentifierDefinitionImpl::new ; + private final Collection components; - private final Scope scope; - private final Collection components; - - private final AxiomName space; public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomIdentifierDefinition value, Map> items) { super(axiomItemDefinition, value, items); - this.scope = AxiomIdentifierDefinition.scope(this.item(Item.ID_SCOPE.name()).get().onlyValue().get().localName()); - this.space = this.item(Item.ID_SPACE.name()).get().onlyValue().get(); - ImmutableList.Builder components = ImmutableList.builder(); - for (AxiomValue val : this.item(Item.ID_MEMBER.name()).get().values()) { + ImmutableList.Builder components = ImmutableList.builder(); + for (AxiomValue val : this.item(Item.ID_MEMBER.name()).get().values()) { components.add(val.get()); } this.components = components.build(); @@ -41,18 +35,8 @@ public AxiomIdentifierDefinition get() { } @Override - public Collection components() { + public Collection components() { return components; } - @Override - public Scope scope() { - return scope; - } - - @Override - public AxiomName space() { - return space; - } - } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index a95b1a420ed..70b8d1d700f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -7,6 +7,7 @@ import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; +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.lang.api.AxiomBuiltIn.Item; @@ -16,10 +17,12 @@ public class AxiomItemDefinitionImpl extends AbstractBaseDefinition FACTORY = AxiomItemDefinitionImpl::new ; private final AxiomValue valueType; private final Optional> minOccurs; + private Optional identifierDef; public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomItemDefinition value, Map> items) { super(axiomItemDefinition, value, items); this.valueType = require(onlyValue(AxiomTypeDefinition.class,Item.TYPE_REFERENCE, Item.REF_TARGET)); + this.identifierDef = onlyValue(AxiomIdentifierDefinition.class, Item.IDENTIFIER_DEFINITION).map(v -> v.get()); minOccurs = this.item(Item.MIN_OCCURS.name()); } @@ -64,4 +67,9 @@ public String toString() { return AxiomItemDefinition.toString(this); } + @Override + public Optional identifierDefinition() { + return identifierDef; + } + } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 3fb8ea29919..0a1d069fb2a 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -86,10 +86,11 @@ model axiom-lang { type AxiomRootDefinition { extends AxiomItemDefinition; - identifier name { - scope global; - space AxiomRootDefinition; - } + documentation """ + Root item definition. + + Root item is item which can be root of the serialized / deserialized document. + """; } type AxiomBaseDefinition { @@ -121,14 +122,6 @@ model axiom-lang { type AxiomName; minOccurs "1"; } - item scope { - type string; - minOccurs "1"; - } - item space { - type AxiomName; - minOccurs "1"; - } } type AxiomTypeDefinition { @@ -139,11 +132,6 @@ model axiom-lang { Defines type name, type supertype and set of value items. """; - identifier name { - scope global; - space AxiomTypeDefinition; - } - item argument { type AxiomName; documentation """ @@ -172,14 +160,6 @@ model axiom-lang { minOccurs 0; } - item identifier { - type AxiomIdentifierDefinition; - documentation """ - Definition of identifiers of this type. - """; - minOccurs 0; - } - // TODO reconsider this - strictly speaking this is part of "global type+item definition combo" item itemName { type AxiomName; @@ -187,6 +167,7 @@ model axiom-lang { item item { type AxiomItemDefinition; + identifier name; documentation """ Definition of child items """; @@ -203,10 +184,12 @@ model axiom-lang { type AxiomItemDefinition { extends AxiomBaseDefinition; - // FIXME: Move this to AxionTypeDefinition -> item(item) - identifier name { - space AxiomItemDefinition; - scope parent; + item identifier { + type AxiomIdentifierDefinition; + documentation """ + Definition of value identifiers for this item. + """; + minOccurs 0; } item type { diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index 4f32daae587..07add5871d9 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -24,6 +24,7 @@ import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; + public class TestAxiomExtension extends AbstractReactorTest { private static final AxiomName PERSON = AxiomName.from("https://example.org", "Person"); @@ -43,10 +44,6 @@ public void axiomTestExtension() throws IOException, AxiomSyntaxException { context.loadModelFromSource(source(SCHEMA_ORG)); context.loadModelFromSource(source(BASE)); AxiomSchemaContext schemaContext = context.computeSchemaContext(); - - AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); - assertTrue(!langExtDef.identifierDefinitions().isEmpty()); - Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); Optional extPersonDef = schemaContext.getType(PERSON_EXTENSION); @@ -64,7 +61,6 @@ public void axiomTestOrder() throws IOException, AxiomSyntaxException { AxiomSchemaContext schemaContext = context.computeSchemaContext(); AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); - assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); @@ -73,6 +69,9 @@ public void axiomTestOrder() throws IOException, AxiomSyntaxException { @Test public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxException { + + assertTrue(Type.AUGMENTATION_DEFINITION.isSubtypeOf(Type.TYPE_DEFINITION.get())); + ModelReactorContext context = ModelReactorContext.defaultReactor(); context.loadModelFromSource(source(LANG_EXT)); AxiomSchemaContext schemaContext = context.computeSchemaContext(); @@ -85,9 +84,6 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio extendedLanguage.loadModelFromSource(source(LANG_EXT_USE)); schemaContext = extendedLanguage.computeSchemaContext(); - AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); - assertTrue(!langExtDef.identifierDefinitions().isEmpty()); - Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index ae8eda4b618..ff558931ff6 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -25,7 +25,6 @@ import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.api.stream.AxiomItemTarget; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; -import com.evolveum.axiom.lang.api.AxiomBuiltIn.Type; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; @@ -52,8 +51,6 @@ private AxiomSchemaContext loadModel() throws AxiomSyntaxException, IOException @Test public void axiomTestInheritance() throws IOException, AxiomSyntaxException { AxiomSchemaContext schemaContext = loadModel(); - AxiomTypeDefinition langExtDef = schemaContext.getType(Type.AUGMENTATION_DEFINITION.name()).get(); - assertTrue(!langExtDef.identifierDefinitions().isEmpty()); Optional personDef = schemaContext.getType(DERIVED_PERSON); assertTrue(personDef.isPresent()); From 9be1c425de711b22180b3daef2a6f11b1ca5f280 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 29 May 2020 11:16:41 +0200 Subject: [PATCH 41/60] Axiom: Moved itemName to Prism Signed-off-by: Tony Tkacik --- infra/axiom/src/main/resources/axiom-lang.axiom | 5 ----- .../src/test/resources/prism/common-core.axiom | 16 ++++++++-------- infra/axiom/src/test/resources/prism/prism.axiom | 3 +++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 0a1d069fb2a..20de9718940 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -160,11 +160,6 @@ model axiom-lang { minOccurs 0; } - // TODO reconsider this - strictly speaking this is part of "global type+item definition combo" - item itemName { - type AxiomName; - } - item item { type AxiomItemDefinition; identifier name; diff --git a/infra/axiom/src/test/resources/prism/common-core.axiom b/infra/axiom/src/test/resources/prism/common-core.axiom index 91e4d698f41..b0145ce6fa3 100644 --- a/infra/axiom/src/test/resources/prism/common-core.axiom +++ b/infra/axiom/src/test/resources/prism/common-core.axiom @@ -17,7 +17,7 @@ model common-core { type Object { prism:object; - itemName object; + prism:itemName object; documentation """ Common supertype for all identity objects. Defines basic properties that each object must have to live in our system (identifier, name). @@ -235,7 +235,7 @@ model common-core { type AssignmentHolder { extends Object; - itemName assignmentHolder; + prism:itemName assignmentHolder; documentation """ Abstract supertype for all object types that can have assignments. """; @@ -361,7 +361,7 @@ model common-core { type Focus { extends AssignmentHolder; - itemName focus; + prism:itemName focus; documentation """ Abstract supertype for all object types that can be focus of full midPoint computation. This basically means objects that have projections. But focal objects also have @@ -886,7 +886,7 @@ model common-core { // Example of short version of container definition. prism:container { name Assignment; - itemName assignment; + prism:itemName assignment; // item description; // TODO make this work // item documentation; // TODO make this work @@ -897,7 +897,7 @@ model common-core { prism:container { name Extension; - itemName extension; + prism:itemName extension; documentation """ Extension container that provides generic extensibility mechanism. Almost any extension property can be placed in this container. @@ -912,7 +912,7 @@ model common-core { prism:object GenericObject { extends Focus; - itemName genericObject; + prism:itemName genericObject; documentation """ Generic object for storing unknown (unexpected) object types. @@ -929,7 +929,7 @@ model common-core { } prism:container Trigger { - itemName trigger; + prism:itemName trigger; documentation """ Defines triggers for an object. Trigger is an action that should take place at specified time or under some other condition. @@ -965,7 +965,7 @@ model common-core { } prism:container Metadata { - itemName metadata; + prism:itemName metadata; documentation """ Meta-data about data creation, modification, etc. It may apply to objects but also parts of the object (e.g. assignments). diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom index 321579f7698..39571c15023 100644 --- a/infra/axiom/src/test/resources/prism/prism.axiom +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -48,6 +48,9 @@ model prism { item objectReference { type boolean; } + item itemName { + type axiom:AxiomName; + } } type PrismTypeDefinition { From dbeeb8b038a9dc604c10a9d0755a38c39b5bd9f3 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 2 Jun 2020 11:27:17 +0200 Subject: [PATCH 42/60] Axiom: Moved Dependency.* to separate classes Signed-off-by: Tony Tkacik --- .../axiom/reactor/AbstractDependency.java | 24 ++++ .../com/evolveum/axiom/reactor/Deffered.java | 2 +- .../axiom/reactor/DelegatedDependency.java | 30 +++++ .../evolveum/axiom/reactor/Dependency.java | 106 +----------------- .../axiom/reactor/FlatMapDependency.java | 2 +- .../evolveum/axiom/reactor/MapDependency.java | 2 +- .../axiom/reactor/RetriableDependency.java | 48 ++++++++ .../axiom/src/main/resources/axiom-lang.axiom | 17 ++- 8 files changed, 123 insertions(+), 108 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/AbstractDependency.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/DelegatedDependency.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/reactor/RetriableDependency.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/AbstractDependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/AbstractDependency.java new file mode 100644 index 00000000000..07639641950 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/AbstractDependency.java @@ -0,0 +1,24 @@ +package com.evolveum.axiom.reactor; + +import java.util.function.Supplier; + +public abstract class AbstractDependency implements Dependency { + + + private Supplier errorMessage; + + @Override + public Dependency unsatisfied(Supplier unsatisfiedMessage) { + errorMessage = unsatisfiedMessage; + return this; + } + + + @Override + public Exception errorMessage() { + if(errorMessage != null) { + return errorMessage.get(); + } + return null; + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java index bb6dbb2904f..4a2c0fe9376 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Deffered.java @@ -4,7 +4,7 @@ import com.google.common.base.Preconditions; -class Deffered extends Dependency.Delegated { +class Deffered extends DelegatedDependency { private Object ret; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DelegatedDependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DelegatedDependency.java new file mode 100644 index 00000000000..da124cfbdad --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/DelegatedDependency.java @@ -0,0 +1,30 @@ +package com.evolveum.axiom.reactor; + +import com.google.common.base.Preconditions; + +public abstract class DelegatedDependency extends AbstractDependency { + + abstract Dependency delegate(); + + @Override + public boolean isSatisfied() { + return delegate().isSatisfied(); + } + + @Override + public boolean isRequired() { + return delegate().isRequired(); + } + + @Override + public T get() { + Preconditions.checkState(isSatisfied(), "Requirement was not satisfied"); + return delegate().get(); + } + + @Override + public Exception errorMessage() { + Exception maybe = super.errorMessage(); + return maybe != null ? maybe : delegate().errorMessage(); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java index 3cb076ce517..838bdd63ef5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/Dependency.java @@ -5,8 +5,6 @@ import java.util.function.Function; import java.util.function.Supplier; -import com.google.common.base.Preconditions; - public interface Dependency { @@ -50,29 +48,7 @@ default Dependency.Search notFound(Supplier unsatisfiedM } - public static abstract class Abstract implements Dependency { - - - private Supplier errorMessage; - - @Override - public Dependency unsatisfied(Supplier unsatisfiedMessage) { - errorMessage = unsatisfiedMessage; - return this; - } - - - @Override - public Exception errorMessage() { - if(errorMessage != null) { - return errorMessage.get(); - } - return null; - } - } - - - public static final class Immediate extends Abstract { + public static final class Immediate extends AbstractDependency { private final V value; @@ -93,7 +69,7 @@ public V get() { } - public static final class Suppliable extends Abstract { + public static final class Suppliable extends AbstractDependency { private final Supplier value; @@ -114,7 +90,7 @@ public V get() { } - public static final class Unsatified extends Abstract { + public static final class Unsatified extends AbstractDependency { @Override public boolean isSatisfied() { @@ -127,34 +103,7 @@ public V get() { } } - public abstract class Delegated extends Abstract { - - abstract Dependency delegate(); - - @Override - public boolean isSatisfied() { - return delegate().isSatisfied(); - } - - @Override - public boolean isRequired() { - return delegate().isRequired(); - } - - @Override - public T get() { - Preconditions.checkState(isSatisfied(), "Requirement was not satisfied"); - return delegate().get(); - } - - @Override - public Exception errorMessage() { - Exception maybe = super.errorMessage(); - return maybe != null ? maybe : delegate().errorMessage(); - } - } - - public final class OptionalDep extends Delegated { + public final class OptionalDep extends DelegatedDependency { private final Dependency delegate; @@ -175,53 +124,8 @@ Dependency delegate() { } - public final class RetriableDelegate extends Delegated implements Search { - - private Object maybeDelegate; - private Supplier notFound; - - public RetriableDelegate(Supplier> lookup) { - maybeDelegate = lookup; - } - - @Override - Dependency delegate() { - if(maybeDelegate instanceof Dependency) { - return (Dependency) maybeDelegate; - } - if(maybeDelegate instanceof Supplier) { - Dependency result = ((Supplier>) maybeDelegate).get(); - if(result != null) { - maybeDelegate = result; - return (Dependency) result; - } - - } - return Dependency.unsatisfied(); - } - - @Override - public Search notFound(Supplier unsatisfiedMessage) { - notFound = unsatisfiedMessage; - return this; - } - - @Override - public Exception errorMessage() { - if(maybeDelegate instanceof Supplier && notFound != null) { - return notFound.get(); - } - Exception maybeFound = super.errorMessage(); - if(maybeFound == null && maybeDelegate instanceof Dependency) { - maybeFound = ((Dependency)maybeDelegate).errorMessage(); - } - return maybeFound; - } - - } - static Search retriableDelegate(Supplier> lookup) { - return new RetriableDelegate(lookup); + return new RetriableDependency(lookup); } static Dependency from(Optional maybe) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java index 21b2ea41e82..f32430b0d4c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/FlatMapDependency.java @@ -2,7 +2,7 @@ import java.util.function.Function; -public class FlatMapDependency extends Dependency.Delegated { +public class FlatMapDependency extends DelegatedDependency { private Dependency delegate; private Function> mapping; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java index c2194e06681..4e5e01b52a8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/MapDependency.java @@ -2,7 +2,7 @@ import java.util.function.Function; -public class MapDependency extends Dependency.Delegated { +public class MapDependency extends DelegatedDependency { private Dependency delegate; private Function mapping; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/RetriableDependency.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/RetriableDependency.java new file mode 100644 index 00000000000..e70b096c575 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/RetriableDependency.java @@ -0,0 +1,48 @@ +package com.evolveum.axiom.reactor; + +import java.util.function.Supplier; + +import com.evolveum.axiom.reactor.Dependency.Search; + +public final class RetriableDependency extends DelegatedDependency implements Search { + + private Object maybeDelegate; + private Supplier notFound; + + public RetriableDependency(Supplier> lookup) { + maybeDelegate = lookup; + } + + @Override + Dependency delegate() { + if(maybeDelegate instanceof Dependency) { + return (Dependency) maybeDelegate; + } + if(maybeDelegate instanceof Supplier) { + Dependency result = ((Supplier>) maybeDelegate).get(); + if(result != null) { + maybeDelegate = result; + return (Dependency) result; + } + } + return Dependency.unsatisfied(); + } + + @Override + public Search notFound(Supplier unsatisfiedMessage) { + notFound = unsatisfiedMessage; + return this; + } + + @Override + public Exception errorMessage() { + if(maybeDelegate instanceof Supplier && notFound != null) { + return notFound.get(); + } + Exception maybeFound = super.errorMessage(); + if(maybeFound == null && maybeDelegate instanceof Dependency) { + maybeFound = ((Dependency)maybeDelegate).errorMessage(); + } + return maybeFound; + } +} diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 20de9718940..aaeeb884244 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -32,8 +32,8 @@ model axiom-lang { type AxiomImportDeclaration; documentation """ Declaration of model imports. - - Type definitions from imported models are referencable and + + Type definitions from imported models are referencable and visible to all definition contained in this model. """; } @@ -160,6 +160,11 @@ model axiom-lang { minOccurs 0; } + // TODO reconsider this - strictly speaking this is part of "global type+item definition combo" + item itemName { + type AxiomName; + } + item item { type AxiomItemDefinition; identifier name; @@ -168,6 +173,10 @@ model axiom-lang { """; minOccurs 0; } + + item itemName { + type AxiomItemDefinition; + } } type AxiomName { @@ -191,7 +200,7 @@ model axiom-lang { type AxiomTypeReference; documentation """ Value type. - + All values must be instances or referenced type or it's subtypes. """; minOccurs 1; @@ -238,7 +247,7 @@ model axiom-lang { type AxiomName; documentation """ Name of referenced type definition. - The value must be name of existing type definition, which is + The value must be name of existing type definition, which is available (visible) to model using this type reference. """; minOccurs 1; From be04d33ea3608b005a324109a9990dad177fe3d4 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 2 Jun 2020 11:34:07 +0200 Subject: [PATCH 43/60] Axiom: Removed comments from grammar Signed-off-by: Tony Tkacik --- .../antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 | 13 ------------- infra/axiom/src/main/resources/axiom-lang.axiom | 3 --- 2 files changed, 16 deletions(-) diff --git a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 index 812743ff872..1be95e8c61c 100644 --- a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 +++ b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 @@ -12,18 +12,10 @@ IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_\-]*; fragment SQOUTE : '\''; fragment DQOUTE : '"'; - -//fragment SUB_STRING : ('"' (ESC | ~["])*? '"') | ('\'' (ESC | ~['])* '\''); -//fragment ESC : '\\' (["\\/bfnrt] | UNICODE); -//fragment UNICODE : 'u' HEX HEX HEX HEX; -//fragment HEX : [0-9a-fA-F] ; -//STRING: ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | '}' | '/' | '+')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '}' )* ) | SUB_STRING ); - fragment ESC : '\\'; STRING_SINGLEQUOTE: SQOUTE ((ESC SQOUTE) | ~[\n'])* SQOUTE; STRING_DOUBLEQUOTE: DQOUTE ((ESC DQOUTE) | ~[\n"])* DQOUTE; -//STRING_MULTILINE: '"""' (ESC | ~('"""'))* '"""'; statement : SEP* identifier SEP* (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (statement)* SEP* RIGHT_BRACE SEP*) SEP*; @@ -31,15 +23,10 @@ identifier : (prefix COLON)? localIdentifier; prefix : IDENTIFIER; localIdentifier : IDENTIFIER; - -// argument : STRING (SEP* PLUS SEP* STRING)* | IDENTIFIER; argument : identifier | string; string : singleQuoteString | doubleQuoteString | multilineString; - singleQuoteString : STRING_SINGLEQUOTE; doubleQuoteString : STRING_DOUBLEQUOTE; multilineString: '"""\n' (~('"""'))*'"""'; - - diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index aaeeb884244..66f3d7617d9 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -174,9 +174,6 @@ model axiom-lang { minOccurs 0; } - item itemName { - type AxiomItemDefinition; - } } type AxiomName { From 7a67dd47a749547354521f2f3b9e3919c8253b97 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 2 Jun 2020 13:38:51 +0200 Subject: [PATCH 44/60] Axiom: added draft of axiom-data with axioms Signed-off-by: Tony Tkacik --- .../axiom/src/test/resources/axiom-data.axiom | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 infra/axiom/src/test/resources/axiom-data.axiom diff --git a/infra/axiom/src/test/resources/axiom-data.axiom b/infra/axiom/src/test/resources/axiom-data.axiom new file mode 100644 index 00000000000..d60cd0edbbd --- /dev/null +++ b/infra/axiom/src/test/resources/axiom-data.axiom @@ -0,0 +1,51 @@ +model axiom-data { + + import axiom; + + type AxiomValue { + metadata type { + type axiom:AxiomTypeReference; + } + item metadata; + } + + type AxiomSimpleValue { + supertype AxiomValue; + argument value; + item value; + } + + type AxiomComplexValue { + supertype AxiomValue; + item item { + type AxiomItem; + } + } + + type AxiomItem { + metadata definition { + type AxiomItemDefinition; + operational true; + } + item value { + type AxiomValue; + } + } + + axiom ComplexValueHasDefinedItems { + // We have language Axioms + // Complex Value contains only items defined in its type. + target AxiomComplexValue; + all item/@definition { + subsetOf @type/item; + } + } + + axiom ItemAllowsOnlyValuesOfSType { + // Item values must be of type. + target AxiomItem; + each value/@type/definition { + subsetOf @definition/type; // + } + } +} \ No newline at end of file From 0d3a1ffaa4979e6101600ddb15c9a031d6fc30a1 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 3 Jun 2020 10:11:19 +0200 Subject: [PATCH 45/60] Axiom: fixed Java 8 Optional compilation issues Signed-off-by: Tony Tkacik --- .../src/main/java/com/evolveum/axiom/api/AxiomValue.java | 2 +- .../com/evolveum/axiom/api/schema/AxiomTypeDefinition.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 77f7df5b312..78f7aab65f0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -38,7 +38,7 @@ default Optional> onlyValue(Class type, AxiomItemDefinition Optional> current = Optional.of(this); for(AxiomItemDefinition name : components) { current = current.get().item(name).map(v -> v.onlyValue()); - if(current.isEmpty()) { + if(!current.isPresent()) { return Optional.empty(); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java index 023dc562e07..08919c32c8c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java @@ -49,7 +49,10 @@ default Optional itemDefinition(AxiomName child) { if(maybe == null && child.namespace().isEmpty()) { maybe = itemDefinitions().get(name().localName(child.localName())); } - return Optional.ofNullable(maybe).or(() -> superType().flatMap(s -> s.itemDefinition(child))); + if(maybe != null) { + return Optional.of(maybe); + } + return superType().flatMap(s -> s.itemDefinition(child)); } static IdentifierSpaceKey identifier(AxiomName name) { From 2d0371dab6ccf54f1873bb642c62888f16d2683e Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 3 Jun 2020 14:07:09 +0200 Subject: [PATCH 46/60] Axiom: Added Simple and Complex type Signed-off-by: Tony Tkacik --- .../evolveum/axiom/api/AxiomComplexValue.java | 45 +++++++++++++++ .../evolveum/axiom/api/AxiomSimpleValue.java | 9 +++ .../com/evolveum/axiom/api/AxiomValue.java | 34 +++-------- .../evolveum/axiom/api/AxiomValueBuilder.java | 18 ++++-- .../evolveum/axiom/api/CompactAxiomItem.java | 2 +- .../com/evolveum/axiom/api/SimpleValue.java | 18 ++++-- .../api/schema/AxiomIdentifierDefinition.java | 8 +-- .../schema/AxiomIdentifierDefinitionImpl.java | 9 ++- .../axiom/api/schema/AxiomItemDefinition.java | 9 +-- .../axiom/api/schema/AxiomTypeDefinition.java | 11 ++-- .../api/schema/DelegatedItemDefinition.java | 15 ++--- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 24 ++++++-- .../axiom/lang/impl/BasicStatementRule.java | 57 +++++++++---------- .../evolveum/axiom/lang/impl/ItemContext.java | 2 +- .../axiom/lang/impl/ItemValueImpl.java | 27 ++++----- .../evolveum/axiom/lang/impl/LazyValue.java | 18 +++++- .../axiom/lang/impl/ModelReactorContext.java | 4 +- .../axiom/lang/impl/ValueContext.java | 10 ++-- .../lang/spi/AbstractBaseDefinition.java | 7 ++- .../spi/AxiomIdentifierDefinitionImpl.java | 19 ++++--- .../lang/spi/AxiomItemDefinitionImpl.java | 25 ++++---- .../lang/spi/AxiomTypeDefinitionImpl.java | 26 +++++---- .../axiom/lang/test/TestAxiomExtension.java | 4 +- .../axiom/lang/test/TestTypeDerivation.java | 7 ++- 24 files changed, 241 insertions(+), 167 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomSimpleValue.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java new file mode 100644 index 00000000000..2e08d53456a --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java @@ -0,0 +1,45 @@ +package com.evolveum.axiom.api; + +import java.util.Collection; +import java.util.Map; +import java.util.Optional; + +import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; + +public interface AxiomComplexValue extends AxiomValue>> { + + + @Override + default Collection> value() { + return itemMap().values(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + default Optional> item(AxiomItemDefinition def) { + return (Optional) item(def.name()); + } + + @SuppressWarnings("unchecked") + default Optional> item(AxiomName name) { + return Optional.ofNullable((AxiomItem) itemMap().get(name)); + } + + static AxiomValue from(AxiomTypeDefinition typeDefinition, V value) { + return new SimpleValue(typeDefinition, value); + } + + default Optional> onlyValue(Class type, AxiomItemDefinition... components) { + Optional> current = Optional.of(this); + for(AxiomItemDefinition name : components) { + current = current.get().asComplex().flatMap(c -> c.item(name)).map(i -> i.onlyValue()); // map(v -> v.onlyValue().asComplex()); + if(!current.isPresent()) { + return Optional.empty(); + } + } + return (Optional) current; + } + + Map> itemMap(); + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomSimpleValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomSimpleValue.java new file mode 100644 index 00000000000..662b4090542 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomSimpleValue.java @@ -0,0 +1,9 @@ +package com.evolveum.axiom.api; + +import java.util.Optional; + +public interface AxiomSimpleValue extends AxiomValue { + + + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 78f7aab65f0..76e4b0fcd5a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -3,46 +3,26 @@ import java.util.Collection; import java.util.Collections; import java.util.Optional; -import java.util.function.Supplier; -import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -public interface AxiomValue extends Supplier { +public interface AxiomValue { Optional type(); - default Collection> items() { + default Collection> metadata() { return Collections.emptyList(); } - @SuppressWarnings({ "rawtypes", "unchecked" }) - default Optional> item(AxiomItemDefinition def) { - return (Optional) item(def.name()); - } - - @SuppressWarnings("unchecked") - default Optional> item(AxiomName name) { - return items().stream().filter(value -> name.equals(value.name())).findFirst().map(v -> (AxiomItem) v); - } - @Override - V get(); - - static AxiomValue from(AxiomTypeDefinition typeDefinition, V value) { - return new SimpleValue(typeDefinition, value); - } + V value(); - default Optional> onlyValue(Class type, AxiomItemDefinition... components) { - Optional> current = Optional.of(this); - for(AxiomItemDefinition name : components) { - current = current.get().item(name).map(v -> v.onlyValue()); - if(!current.isPresent()) { - return Optional.empty(); - } + default Optional> asComplex() { + if(this instanceof AxiomComplexValue) { + return Optional.of((AxiomComplexValue) this); } - return (Optional) current; + return Optional.empty(); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index 052d846c035..b9b1ca4e4d2 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -4,12 +4,14 @@ import com.evolveum.axiom.concepts.Lazy; import com.evolveum.axiom.lang.impl.ItemValueImpl; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.function.Function; import java.util.function.Supplier; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; @@ -27,7 +29,7 @@ public AxiomValueBuilder(AxiomTypeDefinition type, AxiomValueFactory factor } public static AxiomValueBuilder> from(AxiomTypeDefinition type) { - return new AxiomValueBuilder(type, ItemValueImpl.factory()); + return new AxiomValueBuilder(type, type.isComplex() ? ItemValueImpl.factory() : SimpleValue.factory()); } public V getValue() { @@ -52,12 +54,16 @@ public Supplier> get(AxiomName name, Function> builder = ImmutableMap.builder(); - for(Entry>> entry : children.entrySet()) { - AxiomItem item = entry.getValue().get(); - builder.put(entry.getKey(), entry.getValue().get()); + if(type.isComplex()) { + Builder> builder = ImmutableMap.builder(); + for(Entry>> entry : children.entrySet()) { + AxiomItem item = entry.getValue().get(); + builder.put(entry.getKey(), entry.getValue().get()); + } + return factory.create(type, null, builder.build()); } - return factory.create(type, value, builder.build()); + Preconditions.checkState(children.isEmpty(), "%s does not have items. Items found %s", type.name(), children.keySet()); + return factory.create(type, value, Collections.emptyMap()); } public static > AxiomValueBuilder create(AxiomTypeDefinition type, AxiomValueFactory factory) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java index cddf61e2959..f7912294d38 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java @@ -26,7 +26,7 @@ public static AxiomItem of(AxiomItemDefinition def, V value) { } @Override - public V get() { + public V value() { return value; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java index 6ef584c7292..69f57bb4877 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java @@ -1,30 +1,40 @@ package com.evolveum.axiom.api; +import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -class SimpleValue implements AxiomValue { +public class SimpleValue implements AxiomSimpleValue { + private static final AxiomValueFactory FACTORY = SimpleValue::create; private final AxiomTypeDefinition type; private final T value; - - SimpleValue(AxiomTypeDefinition type, T value) { super(); this.type = type; this.value = value; } + public static final AxiomSimpleValue create(AxiomTypeDefinition def, V value, Map> items) { + return new SimpleValue(def, value); + } + @Override public Optional type() { return Optional.ofNullable(type); } @Override - public T get() { + public T value() { return value; } + public static AxiomValueFactory> factory() { + return FACTORY; + } + + + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java index d7abd419f48..fca96338678 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java @@ -3,16 +3,12 @@ import java.util.Collection; import java.util.Set; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; -public interface AxiomIdentifierDefinition extends AxiomValue { - - @Override - default AxiomIdentifierDefinition get() { - return this; - } +public interface AxiomIdentifierDefinition extends AxiomComplexValue { Collection components(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java index 58588d0339e..95a26facf32 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java @@ -1,8 +1,11 @@ package com.evolveum.axiom.api.schema; +import java.util.Collections; +import java.util.Map; import java.util.Optional; import java.util.Set; +import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomName; import com.google.common.collect.ImmutableSet; @@ -22,8 +25,12 @@ public Set components() { } @Override public Optional type() { - // TODO Auto-generated method stub return null; } + @Override + public Map> itemMap() { + return Collections.emptyMap(); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java index 59a58891a26..66916f35222 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java @@ -8,24 +8,19 @@ import java.util.Optional; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomName; -import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; -public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomValue { +public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomComplexValue { AxiomName ROOT_SPACE = AxiomName.axiom("AxiomRootDefinition"); AxiomName SPACE = AxiomName.axiom("AxiomItemDefinition"); AxiomName NAME = AxiomName.axiom("name"); AxiomName VALUE_SPACE = AxiomName.axiom("value"); - @Override - default AxiomItemDefinition get() { - return this; - } - AxiomTypeDefinition typeDefinition(); boolean operational(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java index 08919c32c8c..8c3d3c6dd3f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java @@ -11,22 +11,19 @@ import java.util.Optional; import java.util.stream.Collectors; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.collect.ImmutableMap; -public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomValue { +public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomComplexValue { public final AxiomName IDENTIFIER_MEMBER = AxiomName.axiom("name"); public final AxiomName SPACE = AxiomName.axiom("AxiomTypeDefinition"); - @Override - default AxiomTypeDefinition get() { - return this; - } @Override default Optional type() { @@ -86,4 +83,8 @@ default boolean isSubtypeOf(AxiomName other) { return false; } + default boolean isComplex() { + return !itemDefinitions().isEmpty(); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java index 05b588b1784..6bee8f06660 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java @@ -1,9 +1,11 @@ package com.evolveum.axiom.api.schema; import java.util.Collection; +import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomItem; abstract class DelegatedItemDefinition implements AxiomItemDefinition { @@ -21,8 +23,8 @@ public Optional type() { } @Override - public Collection> items() { - return delegate().items(); + public Map> itemMap() { + return delegate().itemMap(); } @Override @@ -37,17 +39,12 @@ public String documentation() { @Override public Optional> item(AxiomItemDefinition def) { - return delegate().item(def); + return delegate().asComplex().get().item(def); } @Override public Optional> item(AxiomName name) { - return delegate().item(name); - } - - @Override - public AxiomItemDefinition get() { - return this; + return delegate().asComplex().get().item(name); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 79953b7eb75..1b2295ce608 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -11,6 +11,7 @@ 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; @@ -126,11 +127,6 @@ public String toString() { return AxiomItemDefinition.toString(this); } - @Override - public AxiomItemDefinition get() { - return this; - } - @Override public AxiomTypeDefinition definingType() { return null; @@ -140,12 +136,18 @@ public AxiomTypeDefinition definingType() { public Optional identifierDefinition() { return Optional.empty(); } + + @Override + public Map> itemMap() { + 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 @@ -280,6 +282,18 @@ public String toString() { return "typedef " + name(); } + @Override + public Map> itemMap() { + return null; + } + + @Override + public boolean isComplex() { + if(superType != null && superType.isComplex()) { + return true; + } + return !itemDefinitions().isEmpty(); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index ace043b6e52..01e7e03e30b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -7,6 +7,7 @@ import java.util.Optional; import java.util.Set; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; @@ -59,7 +60,7 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency typeName = action.require(context.child(Item.NAME, AxiomName.class) - .map(v -> v.onlyValue().get())) + .map(v -> v.onlyValue().value())) .unsatisfied(() -> action.error("Type does not have name defined.")); action.apply(ctx -> { ctx.register(AxiomTypeDefinition.SPACE, AxiomIdentifierDefinition.Scope.GLOBAL, AxiomTypeDefinition.identifier(typeName.get())); @@ -71,7 +72,7 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency typeName = action.require(context.child(Item.NAME, AxiomName.class) - .map(v -> v.onlyValue().get())) + .map(v -> v.onlyValue().value())) .unsatisfied(() -> action.error("Type does not have name defined.")); action.apply(ctx -> { ctx.register(AxiomItemDefinition.ROOT_SPACE, AxiomIdentifierDefinition.Scope.GLOBAL, AxiomItemDefinition.identifier(typeName.get())); @@ -110,7 +111,7 @@ public void apply(Lookup context, ActionBuilder action) th Dependency> typeDef = action.require(context.child(Item.NAME, AxiomName.class) .unsatisfied(() -> action.error("type name is missing.")) - .map(v -> v.onlyValue().get()) + .map(v -> v.onlyValue().value()) .flatMap(name -> context.reference(AxiomTypeDefinition.SPACE,AxiomTypeDefinition.identifier(name)) .notFound(() -> action.error("type '%s' was not found.", name)) @@ -126,13 +127,13 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - Dependency typeDef = + Dependency> typeDef = action.require( context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) - .map(v -> v.get())); + .map(v -> v.asComplex().get())); typeDef.unsatisfied(() -> action.error("Supertype is not complete.")); action.apply(superTypeValue -> { - addFromType(typeDef.get(), superTypeValue.parentValue(), typeDef.get().name()); + addFromType(typeDef.get(), superTypeValue.parentValue()); }); } }, @@ -140,13 +141,13 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - Dependency typeDef = + Dependency> typeDef = action.require( context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) - .map(v -> v.get())); + .map(v -> v.asComplex().get())); typeDef.unsatisfied(() -> action.error("Supertype is not complete.")); action.apply(superTypeValue -> { - addFromType(typeDef.get(), superTypeValue.parentValue(), typeDef.get().name()); + addFromType(typeDef.get(), superTypeValue.parentValue()); }); } }, @@ -164,7 +165,7 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - Dependency namespace = action.require(context.child(Item.NAMESPACE, String.class).map(v -> v.onlyValue().get())); + Dependency namespace = action.require(context.child(Item.NAMESPACE, String.class).map(v -> v.onlyValue().value())); action.apply(ctx -> { ctx.root().exportIdentifierSpace(namespaceId(namespace.get())); }); @@ -175,9 +176,9 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency namespace = action.require(context.child(Item.NAMESPACE, String.class) - .map(item -> item.onlyValue()) - .flatMap(uri -> context.namespace(Item.NAMESPACE.name(), namespaceId(uri.get())) - .unsatisfied(() -> action.error("Namespace %s not found.", uri.get())) + .map(item -> item.onlyValue().value()) + .flatMap(uri -> context.namespace(Item.NAMESPACE.name(), namespaceId(uri)) + .unsatisfied(() -> action.error("Namespace %s not found.", uri)) )); action.apply((ctx) -> { ctx.root().importIdentifierSpace(namespace.get()); @@ -195,15 +196,16 @@ public boolean isApplicableTo(AxiomItemDefinition definition) { @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { Dependency> targetRef = action.require(context.child(Item.TARGET, AxiomName.class) - .map(v -> v.onlyValue().item(Item.NAME).get())) + .map(v -> v.onlyValue().asComplex().get().item(Item.NAME).get().onlyValue())) .flatMap(item -> - context.modify(AxiomTypeDefinition.SPACE, AxiomTypeDefinition.identifier((AxiomName) item.onlyValue().get())) - .unsatisfied(() -> action.error("Target %s not found.",item.onlyValue().get()) + context.modify(AxiomTypeDefinition.SPACE, AxiomTypeDefinition.identifier((AxiomName) item.value())) + .unsatisfied(() -> action.error("Target %s not found.",item.value()) )); Dependency> itemDef = action.require(context.child(Item.ITEM_DEFINITION, AxiomItemDefinition.class)); action.apply(ext -> { for(AxiomValue item : itemDef.get().values()) { - targetRef.get().mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, item.get().notInherited())); + // FIXME: Add inheritance metadata + targetRef.get().mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, item)); } }); } @@ -221,7 +223,7 @@ private BasicStatementRule(Set items, Set types) { static IdentifierSpaceKey keyFrom(Map>> ctx) { ImmutableMap.Builder components = ImmutableMap.builder(); for(Entry>> entry : ctx.entrySet()) { - components.put(entry.getKey(), entry.getValue().get().get()); + components.put(entry.getKey(), entry.getValue().get().value()); } return IdentifierSpaceKey.from(components.build()); } @@ -267,22 +269,15 @@ private static IdentifierSpaceKey namespaceId(String uri) { return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); } - public static void addFromType(AxiomValue source, AxiomValueContext target, AxiomName targetName) { - AxiomTypeDefinition superType = (AxiomTypeDefinition) source.get(); - Preconditions.checkState(!(superType instanceof AxiomBuiltIn.Type)); - // FIXME: Add namespace change if necessary - // Copy Identifiers - Optional> identifiers = superType.item(Item.IDENTIFIER_DEFINITION); + public static void addFromType(AxiomComplexValue source, AxiomValueContext target) { + Optional> identifiers = source.item(Item.IDENTIFIER_DEFINITION); if(identifiers.isPresent()) { target.mergeItem(identifiers.get()); }// Copy Items - Collection itemDefs = ImmutableList.copyOf(superType.itemDefinitions().values()); - for (AxiomItemDefinition item : superType.itemDefinitions().values()) { - if(item.inherited()) { - final AxiomName derivedName = Inheritance.adapt(targetName, item); - item = item.derived(derivedName); - } - target.mergeItem(AxiomItem.from(Item.ITEM_DEFINITION, item)); + + Optional> itemDefs = source.item(Item.ITEM_DEFINITION); + if(itemDefs.isPresent()) { + target.mergeItem(itemDefs.get()); } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 1d8d37830d0..8091746bccc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -99,7 +99,7 @@ public void addOperationalValue(AxiomValueReference value) { @Override public V onlyValue() { Preconditions.checkState(values.size() == 1); - return values.iterator().next().get().get(); + return values.iterator().next().get().value(); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index 278f5427a0e..924fe526558 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -5,18 +5,17 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -public class ItemValueImpl implements AxiomValue { +public class ItemValueImpl implements AxiomComplexValue { - @SuppressWarnings({ "rawtypes", "unchecked" }) - private static final AxiomValueFactory FACTORY = ItemValueImpl::new; + private static final AxiomValueFactory>, AxiomComplexValue> FACTORY = ItemValueImpl::new; private final AxiomTypeDefinition type; - private final V value; private final Map> items; @@ -24,16 +23,15 @@ protected X require(Optional value) { return value.get(); } - public ItemValueImpl(AxiomTypeDefinition type, V value, Map> items) { + public ItemValueImpl(AxiomTypeDefinition type, Collection> value, Map> items) { super(); this.type = type; - this.value = value; this.items = items; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) public static AxiomValueFactory> factory() { - return FACTORY; + return (AxiomValueFactory) FACTORY; } @Override @@ -41,14 +39,9 @@ public Optional type() { return Optional.ofNullable(type); } - @Override - public V get() { - return value; - } - @Override public Optional> item(AxiomItemDefinition def) { - return AxiomValue.super.item(def); + return AxiomComplexValue.super.item(def); } @Override @@ -56,8 +49,12 @@ public Optional> item(AxiomName name) { return Optional.ofNullable((AxiomItem) items.get(name)); } - @Override public Collection> items() { return items.values(); } + + @Override + public Map> itemMap() { + return items; + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java index db347a75621..11b810019ab 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java @@ -3,6 +3,7 @@ import java.util.Optional; import java.util.function.Supplier; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -22,12 +23,23 @@ public Optional type() { } @Override - public V get() { + public V value() { + return delegate().value(); + } + + @Override + public Optional> asComplex() { + return delegate().asComplex(); + } + + private AxiomValue delegate() { if(delegate instanceof AxiomValue) { - return ((AxiomValue) delegate).get(); + return ((AxiomValue) delegate); } delegate = ((Supplier>)delegate).get(); - return get(); + return delegate(); } + + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index bc869dc0143..b0f58f4c636 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -13,6 +13,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; +import com.evolveum.axiom.api.SimpleValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -180,8 +181,7 @@ public AxiomValueFactory> typeFactory(AxiomTypeDefinition s } current = current.get().superType(); } while (current.isPresent()); - - return ItemValueImpl.factory(); + return statementType.isComplex() ? ItemValueImpl.factory() : SimpleValue.factory(); } public void exportIdentifierSpace(IdentifierSpaceKey namespace, IdentifierSpaceHolder localSpace) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index f5b93b51aa3..f0fc5c68242 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -182,14 +182,14 @@ public V currentValue() { if(result instanceof ValueContext.Result) { return ((ValueContext.Result) result).value; } - return get().get(); + return get().value(); } @Override public void mergeItem(AxiomItem axiomItem) { ItemContext item = startItem(axiomItem.name(), SourceLocation.runtime()); for(AxiomValue value : axiomItem.values()) { - ValueContext valueCtx = item.startValue(value.get(),SourceLocation.runtime()); + ValueContext valueCtx = item.startValue(value.value(),SourceLocation.runtime()); valueCtx.replace(value); valueCtx.endValue(SourceLocation.runtime()); } @@ -222,7 +222,7 @@ public Dependency.Search> requireChild(AxiomName item) { if(result instanceof ValueContext.Result) { return ((ValueContext.Result) result).getItem(item); } - return Dependency.from(result.get().item(item)); + return Dependency.from(result.get().asComplex().get().item(item)); }); } @@ -284,7 +284,7 @@ public Dependency> onlyItemValue(AxiomItemDefinition definitio if(result instanceof ValueContext.Result) { item = ((ValueContext.Result) result).getItem(definition.name()); } else { - item = result.flatMap(v -> Dependency.from(v.item(definition))); + item = result.flatMap(v -> Dependency.from(v.asComplex().get().item(definition))); } if(item instanceof ItemContext) { return ((ItemContext) item).onlyValue0(); @@ -345,7 +345,7 @@ public Dependency.Search> namespaceValue(AxiomName space, @Override public Dependency finalValue() { - return map(v -> v.get()); + return map(v -> v.value()); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java index b3c1b80d7ee..63c82b82a7f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java @@ -1,5 +1,6 @@ package com.evolveum.axiom.lang.spi; +import java.util.Collection; import java.util.Map; import com.evolveum.axiom.api.AxiomName; @@ -14,10 +15,10 @@ public class AbstractBaseDefinition extends ItemValueImpl implements Axiom private final AxiomName name; private final String documentation; - public AbstractBaseDefinition(AxiomTypeDefinition type, V value, Map> items) { + public AbstractBaseDefinition(AxiomTypeDefinition type, Collection> value, Map> items) { super(type, value, items); - name = (AxiomName) item(Item.NAME).get().onlyValue().get(); - documentation = item(Item.DOCUMENTATION).map(i -> i.onlyValue().get().toString()).orElse(null); // + name = (AxiomName) item(Item.NAME).get().onlyValue().value(); + documentation = item(Item.DOCUMENTATION).map(i -> i.onlyValue().value().toString()).orElse(null); // } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index cddfd530fbe..93359fcc777 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -3,6 +3,7 @@ import java.util.Collection; import java.util.Map; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; @@ -14,29 +15,31 @@ public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { - public static final AxiomValueFactory FACTORY = AxiomIdentifierDefinitionImpl::new ; + public static final AxiomValueFactory>,AxiomComplexValue> FACTORY = AxiomIdentifierDefinitionImpl::new ; private final Collection components; - public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomIdentifierDefinition value, Map> items) { + public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, Collection> value, Map> items) { super(axiomItemDefinition, value, items); ImmutableList.Builder components = ImmutableList.builder(); for (AxiomValue val : this.item(Item.ID_MEMBER.name()).get().values()) { - components.add(val.get()); + components.add(val.value()); } this.components = components.build(); } - @Override - public AxiomIdentifierDefinition get() { - return this; - } - @Override public Collection components() { return components; } + public static AxiomIdentifierDefinition from(AxiomValue value) { + if (value instanceof AxiomIdentifierDefinition) { + return (AxiomIdentifierDefinition) value; + } + return new AxiomIdentifierDefinitionImpl(value.type().get(), null, value.asComplex().get().itemMap()); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 70b8d1d700f..5f59082061e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -1,5 +1,6 @@ package com.evolveum.axiom.lang.spi; +import java.util.Collection; import java.util.Map; import java.util.Optional; @@ -14,15 +15,15 @@ public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { - public static final AxiomValueFactory FACTORY = AxiomItemDefinitionImpl::new ; + public static final AxiomValueFactory>,AxiomItemDefinition> FACTORY = AxiomItemDefinitionImpl::new ; private final AxiomValue valueType; private final Optional> minOccurs; private Optional identifierDef; - public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, AxiomItemDefinition value, Map> items) { + public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, Collection> value, Map> items) { super(axiomItemDefinition, value, items); - this.valueType = require(onlyValue(AxiomTypeDefinition.class,Item.TYPE_REFERENCE, Item.REF_TARGET)); - this.identifierDef = onlyValue(AxiomIdentifierDefinition.class, Item.IDENTIFIER_DEFINITION).map(v -> v.get()); + this.valueType = require(asComplex().get().onlyValue(AxiomTypeDefinition.class,Item.TYPE_REFERENCE, Item.REF_TARGET)); + this.identifierDef = asComplex().get().onlyValue(AxiomIdentifierDefinition.class, Item.IDENTIFIER_DEFINITION).map(v -> AxiomIdentifierDefinitionImpl.from(v)); minOccurs = this.item(Item.MIN_OCCURS.name()); } @@ -36,14 +37,9 @@ public boolean operational() { return false; } - @Override - public AxiomItemDefinition get() { - return this; - } - @Override public AxiomTypeDefinition typeDefinition() { - return valueType.get(); + return AxiomTypeDefinitionImpl.from(valueType.asComplex().get()); } @Override @@ -53,7 +49,7 @@ public boolean required() { @Override public int minOccurs() { - return minOccurs.map(i -> Integer.parseInt(i.onlyValue().get())).orElse(0); + return minOccurs.map(i -> Integer.parseInt(i.onlyValue().value())).orElse(0); } @Override @@ -72,4 +68,11 @@ public Optional identifierDefinition() { return identifierDef; } + public static AxiomItemDefinition from(AxiomValue value) { + if(value instanceof AxiomItemDefinition) { + return (AxiomItemDefinition) value; + } + return new AxiomItemDefinitionImpl(value.type().get(), null, value.asComplex().get().itemMap()); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 874a168ab89..7550330e581 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; @@ -13,20 +14,21 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; +import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; public class AxiomTypeDefinitionImpl extends AbstractBaseDefinition implements AxiomTypeDefinition { - public static final AxiomValueFactory FACTORY =AxiomTypeDefinitionImpl::new; + public static final AxiomValueFactory>, AxiomTypeDefinition> FACTORY =AxiomTypeDefinitionImpl::new; private final Map itemDefinitions; private final Optional superType; private final Optional argument; private final Collection identifiers; - public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition value, Map> keywordMap) { + public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, Collection> value, Map> keywordMap) { super(def, null, keywordMap); //super(keyword, value, children, keywordMap); @@ -37,19 +39,19 @@ public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, AxiomTypeDefinition valu } itemDefinitions = builder.build(); - superType = onlyValue(AxiomTypeDefinition.class,Item.SUPERTYPE_REFERENCE, Item.REF_TARGET).map(v -> v.get()); + superType = onlyValue(AxiomTypeDefinition.class,Item.SUPERTYPE_REFERENCE, Item.REF_TARGET).map(v -> from(v.asComplex().get())); - argument = this.item(Item.ARGUMENT.name()).flatMap(v -> itemDefinition(v.onlyValue().get())); - identifiers = upcast(this.item(Item.IDENTIFIER_DEFINITION.name()).map(v -> v.values()).orElse(Collections.emptyList())); - } - @Override - public AxiomTypeDefinition get() { - return this; + argument = this.item(Item.ARGUMENT.name()).flatMap(v -> itemDefinition(v.onlyValue().value())); + identifiers = Collections2.transform((this.item(Item.IDENTIFIER_DEFINITION).map(v -> v.values()).orElse(Collections.emptyList())), + AxiomIdentifierDefinitionImpl::from); } - private > Collection upcast(Collection> itemValue) { - return (Collection) itemValue; + public static AxiomTypeDefinition from(AxiomComplexValue value) { + if(value instanceof AxiomTypeDefinition) { + return (AxiomTypeDefinition) value; + } + return new AxiomTypeDefinitionImpl(value.type().get(), null, value.asComplex().get().itemMap()); } @Override @@ -83,7 +85,7 @@ public Collection identifierDefinitions() { private void supplyAll(AxiomName type, Builder builder, Collection> values) { for(AxiomValue v : values) { - AxiomItemDefinition val = v.get(); + AxiomItemDefinition val = AxiomItemDefinitionImpl.from(v); AxiomName name = Inheritance.adapt(type, val.name()); builder.put(name, val); } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java index 07add5871d9..f9a8290512f 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomExtension.java @@ -70,7 +70,7 @@ public void axiomTestOrder() throws IOException, AxiomSyntaxException { @Test public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxException { - assertTrue(Type.AUGMENTATION_DEFINITION.isSubtypeOf(Type.TYPE_DEFINITION.get())); + assertTrue(Type.AUGMENTATION_DEFINITION.isSubtypeOf(Type.TYPE_DEFINITION)); ModelReactorContext context = ModelReactorContext.defaultReactor(); context.loadModelFromSource(source(LANG_EXT)); @@ -87,7 +87,7 @@ public void axiomTestLanguageExtension() throws IOException, AxiomSyntaxExceptio Optional personDef = schemaContext.getType(PERSON); assertTrue(personDef.isPresent()); - AxiomItem extension = personDef.get().item(STORAGE).get(); + AxiomItem extension = personDef.get().asComplex().get().item(STORAGE).get(); assertFalse(extension.values().isEmpty(), "Extension statements should be available."); assertEquals(2, personDef.get().itemDefinitions().entrySet().size()); diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index ff558931ff6..7b7d76468f4 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -17,6 +17,7 @@ import org.testng.annotations.Test; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; @@ -68,9 +69,9 @@ public void axiomData() throws AxiomSyntaxException, FileNotFoundException, IOEx stream.stream(target); AxiomItem root = target.get(); assertEquals(root.name(), DERIVED_PERSON.localName("person")); - AxiomValue person = root.onlyValue(); - assertEquals(person.item(NAME).get().onlyValue().get(), "John Doe"); - assertEquals(person.item(FIRST_NAME).get().onlyValue().get(), "John"); + AxiomComplexValue person = root.onlyValue().asComplex().get(); + assertEquals(person.item(NAME).get().onlyValue().value(), "John Doe"); + assertEquals(person.item(FIRST_NAME).get().onlyValue().value(), "John"); } From 9889f0d8550492b3e30b0e333bbe901de8c95307 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 3 Jun 2020 14:12:50 +0200 Subject: [PATCH 47/60] Removed generic argument from AxiomComplexValue Signed-off-by: Tony Tkacik --- .../main/java/com/evolveum/axiom/api/AxiomComplexValue.java | 2 +- .../src/main/java/com/evolveum/axiom/api/AxiomValue.java | 4 ++-- .../axiom/api/schema/AxiomIdentifierDefinition.java | 2 +- .../com/evolveum/axiom/api/schema/AxiomItemDefinition.java | 2 +- .../com/evolveum/axiom/api/schema/AxiomTypeDefinition.java | 2 +- .../com/evolveum/axiom/lang/impl/BasicStatementRule.java | 6 +++--- .../java/com/evolveum/axiom/lang/impl/ItemValueImpl.java | 4 ++-- .../main/java/com/evolveum/axiom/lang/impl/LazyValue.java | 4 ++-- .../com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java | 2 +- .../axiom/lang/spi/AxiomIdentifierDefinitionImpl.java | 4 ++-- .../evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java | 2 +- .../evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java | 4 ++-- .../com/evolveum/axiom/lang/test/TestTypeDerivation.java | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java index 2e08d53456a..e18b252ef99 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java @@ -7,7 +7,7 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -public interface AxiomComplexValue extends AxiomValue>> { +public interface AxiomComplexValue extends AxiomValue>> { @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 76e4b0fcd5a..664a4087072 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -18,9 +18,9 @@ default Collection> metadata() { V value(); - default Optional> asComplex() { + default Optional asComplex() { if(this instanceof AxiomComplexValue) { - return Optional.of((AxiomComplexValue) this); + return Optional.of((AxiomComplexValue) this); } return Optional.empty(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java index fca96338678..36430bd56c1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinition.java @@ -8,7 +8,7 @@ import com.evolveum.axiom.api.AxiomValue; import com.google.common.collect.ImmutableSet; -public interface AxiomIdentifierDefinition extends AxiomComplexValue { +public interface AxiomIdentifierDefinition extends AxiomComplexValue { Collection components(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java index 66916f35222..20b5eff2277 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomItemDefinition.java @@ -14,7 +14,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; -public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomComplexValue { +public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomComplexValue { AxiomName ROOT_SPACE = AxiomName.axiom("AxiomRootDefinition"); AxiomName SPACE = AxiomName.axiom("AxiomItemDefinition"); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java index 8c3d3c6dd3f..fc4e0fa5c10 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java @@ -18,7 +18,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.collect.ImmutableMap; -public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomComplexValue { +public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomComplexValue { public final AxiomName IDENTIFIER_MEMBER = AxiomName.axiom("name"); public final AxiomName SPACE = AxiomName.axiom("AxiomTypeDefinition"); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java index 01e7e03e30b..e80a2771859 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/BasicStatementRule.java @@ -127,7 +127,7 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - Dependency> typeDef = + Dependency typeDef = action.require( context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) .map(v -> v.asComplex().get())); @@ -141,7 +141,7 @@ public void apply(Lookup context, ActionBuilder action) th @Override public void apply(Lookup context, ActionBuilder action) throws AxiomSemanticException { - Dependency> typeDef = + Dependency typeDef = action.require( context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class) .map(v -> v.asComplex().get())); @@ -269,7 +269,7 @@ private static IdentifierSpaceKey namespaceId(String uri) { return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri); } - public static void addFromType(AxiomComplexValue source, AxiomValueContext target) { + public static void addFromType(AxiomComplexValue source, AxiomValueContext target) { Optional> identifiers = source.item(Item.IDENTIFIER_DEFINITION); if(identifiers.isPresent()) { target.mergeItem(identifiers.get()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java index 924fe526558..d5911434433 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java @@ -12,9 +12,9 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -public class ItemValueImpl implements AxiomComplexValue { +public class ItemValueImpl implements AxiomComplexValue { - private static final AxiomValueFactory>, AxiomComplexValue> FACTORY = ItemValueImpl::new; + private static final AxiomValueFactory>, AxiomComplexValue> FACTORY = ItemValueImpl::new; private final AxiomTypeDefinition type; private final Map> items; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java index 11b810019ab..5e866a72417 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java @@ -7,7 +7,7 @@ import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -class LazyValue implements AxiomValue{ +class LazyValue implements AxiomValue { private final AxiomTypeDefinition type; private Object delegate; @@ -28,7 +28,7 @@ public V value() { } @Override - public Optional> asComplex() { + public Optional asComplex() { return delegate().asComplex(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java index 63c82b82a7f..38bd4c93838 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java @@ -10,7 +10,7 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.impl.ItemValueImpl; -public class AbstractBaseDefinition extends ItemValueImpl implements AxiomNamedDefinition { +public class AbstractBaseDefinition extends ItemValueImpl implements AxiomNamedDefinition { private final AxiomName name; private final String documentation; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index 93359fcc777..1c4d7ff034e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -13,9 +13,9 @@ import com.evolveum.axiom.lang.impl.ItemValueImpl; import com.google.common.collect.ImmutableList; -public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { +public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { - public static final AxiomValueFactory>,AxiomComplexValue> FACTORY = AxiomIdentifierDefinitionImpl::new ; + public static final AxiomValueFactory>,AxiomComplexValue> FACTORY = AxiomIdentifierDefinitionImpl::new ; private final Collection components; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index 5f59082061e..e967a320bcd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -13,7 +13,7 @@ import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { +public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { public static final AxiomValueFactory>,AxiomItemDefinition> FACTORY = AxiomItemDefinitionImpl::new ; private final AxiomValue valueType; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 7550330e581..f63ca5485ac 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -19,7 +19,7 @@ import com.google.common.collect.ImmutableMap.Builder; -public class AxiomTypeDefinitionImpl extends AbstractBaseDefinition implements AxiomTypeDefinition { +public class AxiomTypeDefinitionImpl extends AbstractBaseDefinition implements AxiomTypeDefinition { public static final AxiomValueFactory>, AxiomTypeDefinition> FACTORY =AxiomTypeDefinitionImpl::new; @@ -47,7 +47,7 @@ public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, Collection> AxiomIdentifierDefinitionImpl::from); } - public static AxiomTypeDefinition from(AxiomComplexValue value) { + public static AxiomTypeDefinition from(AxiomComplexValue value) { if(value instanceof AxiomTypeDefinition) { return (AxiomTypeDefinition) value; } diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 7b7d76468f4..13a61a45f02 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -69,7 +69,7 @@ public void axiomData() throws AxiomSyntaxException, FileNotFoundException, IOEx stream.stream(target); AxiomItem root = target.get(); assertEquals(root.name(), DERIVED_PERSON.localName("person")); - AxiomComplexValue person = root.onlyValue().asComplex().get(); + AxiomComplexValue person = root.onlyValue().asComplex().get(); assertEquals(person.item(NAME).get().onlyValue().value(), "John Doe"); assertEquals(person.item(FIRST_NAME).get().onlyValue().value(), "John"); From fcb4b1478a0c2d8f9f61d2c9f28393995e81096f Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 3 Jun 2020 14:27:22 +0200 Subject: [PATCH 48/60] Axiom: Removed statement from grammar, replaced with item / value Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/lang/antlr/Axiom.g4 | 8 ++++++- .../evolveum/axiom/api/AxiomComplexValue.java | 2 +- .../lang/antlr/AbstractAxiomAntlrVisitor.java | 10 ++++---- .../lang/antlr/AxiomAntlrStatementSource.java | 14 +++++------ .../lang/antlr/AxiomModelStatementSource.java | 24 +++++++++---------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 index 1be95e8c61c..8c2b67724fe 100644 --- a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 +++ b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 @@ -17,7 +17,13 @@ fragment ESC : '\\'; STRING_SINGLEQUOTE: SQOUTE ((ESC SQOUTE) | ~[\n'])* SQOUTE; STRING_DOUBLEQUOTE: DQOUTE ((ESC DQOUTE) | ~[\n"])* DQOUTE; -statement : SEP* identifier SEP* (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (statement)* SEP* RIGHT_BRACE SEP*) SEP*; + + +//statement : SEP* identifier SEP* (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (statement)* SEP* RIGHT_BRACE SEP*) SEP*; + + +item : SEP* identifier SEP* value; +value: (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (item)* SEP* RIGHT_BRACE SEP*) SEP*; identifier : (prefix COLON)? localIdentifier; prefix : IDENTIFIER; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java index e18b252ef99..ddc2d76a2c8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java @@ -32,7 +32,7 @@ static AxiomValue from(AxiomTypeDefinition typeDefinition, V value) { default Optional> onlyValue(Class type, AxiomItemDefinition... components) { Optional> current = Optional.of(this); for(AxiomItemDefinition name : components) { - current = current.get().asComplex().flatMap(c -> c.item(name)).map(i -> i.onlyValue()); // map(v -> v.onlyValue().asComplex()); + current = current.get().asComplex().flatMap(c -> c.item(name)).map(i -> i.onlyValue()); if(!current.isPresent()) { return Optional.empty(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java index 093a7037eff..411ce3447fd 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java @@ -16,7 +16,7 @@ import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; -import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; public abstract class AbstractAxiomAntlrVisitor extends AxiomBaseVisitor { @@ -44,14 +44,14 @@ private String nullableText(ParserRuleContext prefix) { return prefix != null ? prefix.getText() : ""; } + @Override - public final T visitStatement(StatementContext ctx) { + public T visitItem(ItemContext ctx) { AxiomName identifier = statementIdentifier(ctx.identifier()); if(canEmit(identifier)) { SourceLocation start = sourceLocation(ctx.identifier().start); delegate().startItem(identifier, start); - - ArgumentContext argument = ctx.argument(); + ArgumentContext argument = ctx.value().argument(); final Object value; final SourceLocation valueStart; if(argument != null) { @@ -62,7 +62,7 @@ public final T visitStatement(StatementContext ctx) { valueStart = start; } delegate().startValue(value, valueStart); - T ret = super.visitStatement(ctx); + T ret = super.visitItem(ctx); delegate().endValue(sourceLocation(ctx.stop)); delegate().endItem(sourceLocation(ctx.stop)); return ret; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index d8ada5079f3..67f7f269a68 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -17,37 +17,37 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; -import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class AxiomAntlrStatementSource { - private final StatementContext root; + private final ItemContext root; private final String sourceName; public static AxiomAntlrStatementSource from(String sourceName, InputStream stream) throws IOException, AxiomSyntaxException { return from(sourceName, CharStreams.fromStream(stream)); } - public static StatementContext contextFrom(String sourceName, CharStream stream) { + public static ItemContext contextFrom(String sourceName, CharStream stream) { AxiomLexer lexer = new AxiomLexer(stream); AxiomParser parser = new AxiomParser(new CommonTokenStream(lexer)); lexer.removeErrorListeners(); parser.removeErrorListeners(); AxiomErrorListener errorListener = new AxiomErrorListener(sourceName); parser.addErrorListener(errorListener); - StatementContext statement = parser.statement(); + ItemContext statement = parser.item(); errorListener.validate(); return statement; } public static AxiomAntlrStatementSource from(String sourceName, CharStream stream) throws AxiomSyntaxException { - StatementContext statement = contextFrom(sourceName, stream); + ItemContext statement = contextFrom(sourceName, stream); return new AxiomAntlrStatementSource(sourceName, statement); } - protected AxiomAntlrStatementSource(String sourceName, StatementContext statement) { + protected AxiomAntlrStatementSource(String sourceName, ItemContext statement) { this.sourceName = sourceName; this.root = statement; } @@ -56,7 +56,7 @@ public String sourceName() { return sourceName; } - protected final StatementContext root() { + protected final ItemContext root() { return root; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index f34a115b3d0..49c16fd0378 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -20,7 +20,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; -import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; @@ -42,12 +42,12 @@ public static AxiomModelStatementSource from(String sourceName, InputStream stre } public static AxiomModelStatementSource from(String sourceName, CharStream stream) throws AxiomSyntaxException { - StatementContext statement = AxiomAntlrStatementSource.contextFrom(sourceName, stream); - String name = statement.argument().identifier().localIdentifier().getText(); - return new AxiomModelStatementSource(sourceName, statement, name, namespace(statement), imports(statement)); + ItemContext root = AxiomAntlrStatementSource.contextFrom(sourceName, stream); + String name = root.value().argument().identifier().localIdentifier().getText(); + return new AxiomModelStatementSource(sourceName, root, name, namespace(root.value()), imports(root.value())); } - private AxiomModelStatementSource(String sourceName, StatementContext statement, String namespace, String name, Map imports) { + private AxiomModelStatementSource(String sourceName, ItemContext statement, String namespace, String name, Map imports) { super(sourceName, statement); this.name = name; this.imports = imports; @@ -73,21 +73,21 @@ public Map imports() { return imports; } - public static Map imports(AxiomParser.StatementContext root) { + public static Map imports(AxiomParser.ValueContext root) { Map prefixMap = new HashMap<>(); - root.statement().stream().filter(s -> IMPORT.equals(s.identifier().getText())).forEach(c -> { - String prefix = c.argument().identifier().localIdentifier().getText(); - String namespace = namespace(c); + root.item().stream().filter(s -> IMPORT.equals(s.identifier().getText())).forEach(c -> { + String prefix = c.value().argument().identifier().localIdentifier().getText(); + String namespace = namespace(c.value()); prefixMap.put(prefix, namespace); }); prefixMap.put("",namespace(root)); return prefixMap; } - private static String namespace(StatementContext c) { - return AxiomAntlrVisitor.convert(c.statement() + private static String namespace(AxiomParser.ValueContext c) { + return AxiomAntlrVisitor.convert(c.item() .stream().filter(s -> NAMESPACE.equals(s.identifier().getText())) - .findFirst().get().argument().string()); + .findFirst().get().value().argument().string()); } @Override From 30904b54aad06eb40bb58495e5b79aabf4ee2686 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 3 Jun 2020 14:56:50 +0200 Subject: [PATCH 49/60] Axiom: Added preparation for metadata introduction Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/lang/antlr/Axiom.g4 | 8 ++-- .../axiom/api/stream/AxiomItemStream.java | 7 +++- .../lang/antlr/AbstractAxiomAntlrVisitor.java | 37 ++++++++++++++++--- .../axiom/lang/antlr/AxiomAntlrVisitor.java | 1 + .../lang/antlr/AxiomModelStatementSource.java | 14 +++---- 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 index 8c2b67724fe..b9a17557ece 100644 --- a/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 +++ b/infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4 @@ -17,13 +17,13 @@ fragment ESC : '\\'; STRING_SINGLEQUOTE: SQOUTE ((ESC SQOUTE) | ~[\n'])* SQOUTE; STRING_DOUBLEQUOTE: DQOUTE ((ESC DQOUTE) | ~[\n"])* DQOUTE; - - //statement : SEP* identifier SEP* (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (statement)* SEP* RIGHT_BRACE SEP*) SEP*; -item : SEP* identifier SEP* value; -value: (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (item)* SEP* RIGHT_BRACE SEP*) SEP*; +itemBody: identifier SEP* value; +item : SEP* itemBody; +value: (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (item | metadata)* SEP* RIGHT_BRACE SEP*) SEP*; +metadata : SEP* '@' itemBody; identifier : (prefix COLON)? localIdentifier; prefix : IDENTIFIER; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java index aaa06e4ad6d..db61dcd7f85 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java @@ -8,9 +8,14 @@ public interface AxiomItemStream { interface Target { void startItem(AxiomName item, SourceLocation loc); + void endItem(SourceLocation loc); + void startValue(Object value, SourceLocation loc); void endValue(SourceLocation loc); - void endItem(SourceLocation loc); + + default void startMetadata(AxiomName item, SourceLocation loc) {}; + default void endMetadata(SourceLocation loc) {}; + } interface TargetWithResolver extends Target { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java index 411ce3447fd..6ad255ac02a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java @@ -16,7 +16,9 @@ import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.ItemBodyContext; import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; +import com.evolveum.axiom.lang.antlr.AxiomParser.MetadataContext; import com.evolveum.axiom.lang.antlr.AxiomParser.StringContext; public abstract class AbstractAxiomAntlrVisitor extends AxiomBaseVisitor { @@ -24,6 +26,14 @@ public abstract class AbstractAxiomAntlrVisitor extends AxiomBaseVisitor { private final Optional> limit; private final String sourceName; + private interface StartDelegate { + void start(AxiomName identifier, SourceLocation location); + } + private interface EndDelegate { + void end(SourceLocation location); + } + + public AbstractAxiomAntlrVisitor(String name, Set limit) { this.sourceName = name; this.limit = Optional.ofNullable(limit); @@ -47,29 +57,44 @@ private String nullableText(ParserRuleContext prefix) { @Override public T visitItem(ItemContext ctx) { - AxiomName identifier = statementIdentifier(ctx.identifier()); + AxiomName identifier = statementIdentifier(ctx.itemBody().identifier()); + return processItemBody(identifier, ctx.itemBody(), delegate()::startItem, delegate()::endItem); + } + + public T processItemBody(AxiomName identifier, ItemBodyContext ctx, StartDelegate start, EndDelegate end) { if(canEmit(identifier)) { - SourceLocation start = sourceLocation(ctx.identifier().start); - delegate().startItem(identifier, start); + + SourceLocation startLoc = sourceLocation(ctx.identifier().start); + start.start(identifier, startLoc); + ArgumentContext argument = ctx.value().argument(); final Object value; final SourceLocation valueStart; + if(argument != null) { value = convert(argument); valueStart = sourceLocation(argument.start); } else { value = null; - valueStart = start; + valueStart = startLoc; } + delegate().startValue(value, valueStart); - T ret = super.visitItem(ctx); + T ret = visitItemBody(ctx); delegate().endValue(sourceLocation(ctx.stop)); - delegate().endItem(sourceLocation(ctx.stop)); + end.end(sourceLocation(ctx.stop)); return ret; } return defaultResult(); } + + @Override + public T visitMetadata(MetadataContext ctx) { + AxiomName identifier = statementIdentifier(ctx.itemBody().identifier()); + return processItemBody(identifier, ctx.itemBody(), delegate()::startMetadata, delegate()::endMetadata); + } + private Object convert(ArgumentContext ctx) { if (ctx.identifier() != null) { return (convert(ctx.identifier())); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index b667656d16b..fe39ebcde80 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -13,6 +13,7 @@ import com.evolveum.axiom.api.stream.AxiomItemStream.Target; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +@Deprecated public class AxiomAntlrVisitor extends AbstractAxiomAntlrVisitor { private final AxiomIdentifierResolver statements; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 49c16fd0378..0754f03d975 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -43,8 +43,8 @@ public static AxiomModelStatementSource from(String sourceName, InputStream stre public static AxiomModelStatementSource from(String sourceName, CharStream stream) throws AxiomSyntaxException { ItemContext root = AxiomAntlrStatementSource.contextFrom(sourceName, stream); - String name = root.value().argument().identifier().localIdentifier().getText(); - return new AxiomModelStatementSource(sourceName, root, name, namespace(root.value()), imports(root.value())); + String name = root.itemBody().value().argument().identifier().localIdentifier().getText(); + return new AxiomModelStatementSource(sourceName, root, name, namespace(root.itemBody().value()), imports(root.itemBody().value())); } private AxiomModelStatementSource(String sourceName, ItemContext statement, String namespace, String name, Map imports) { @@ -75,9 +75,9 @@ public Map imports() { public static Map imports(AxiomParser.ValueContext root) { Map prefixMap = new HashMap<>(); - root.item().stream().filter(s -> IMPORT.equals(s.identifier().getText())).forEach(c -> { - String prefix = c.value().argument().identifier().localIdentifier().getText(); - String namespace = namespace(c.value()); + root.item().stream().filter(s -> IMPORT.equals(s.itemBody().identifier().getText())).forEach(c -> { + String prefix = c.itemBody().value().argument().identifier().localIdentifier().getText(); + String namespace = namespace(c.itemBody().value()); prefixMap.put(prefix, namespace); }); prefixMap.put("",namespace(root)); @@ -86,8 +86,8 @@ public static Map imports(AxiomParser.ValueContext root) { private static String namespace(AxiomParser.ValueContext c) { return AxiomAntlrVisitor.convert(c.item() - .stream().filter(s -> NAMESPACE.equals(s.identifier().getText())) - .findFirst().get().value().argument().string()); + .stream().filter(s -> NAMESPACE.equals(s.itemBody().identifier().getText())) + .findFirst().get().itemBody().value().argument().string()); } @Override From 60de1ff300011982831cd45d7be679676a091675 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 8 Jun 2020 12:54:29 +0200 Subject: [PATCH 50/60] Axiom: Added support for infraItem @value Signed-off-by: Tony Tkacik --- .../axiom/api/AbstractAxiomValue.java | 28 ++++++ .../evolveum/axiom/api/AxiomComplexValue.java | 11 ++- .../evolveum/axiom/api/AxiomInfraValue.java | 17 ++++ .../com/evolveum/axiom/api/AxiomItem.java | 6 +- .../com/evolveum/axiom/api/AxiomItemImpl.java | 3 +- .../com/evolveum/axiom/api/AxiomValue.java | 26 +++-- .../evolveum/axiom/api/AxiomValueBuilder.java | 5 + .../evolveum/axiom/api/CompactAxiomItem.java | 44 --------- .../com/evolveum/axiom/api/SimpleValue.java | 19 +--- .../api/stream/AxiomBuilderStreamTarget.java | 18 +++- .../axiom/api/stream/AxiomItemStream.java | 4 +- .../axiom/api/stream/AxiomItemTarget.java | 99 ++++++++++++++++--- .../evolveum/axiom/concepts/AbstractLazy.java | 24 +++++ .../com/evolveum/axiom/concepts/Lazy.java | 12 +-- .../evolveum/axiom/concepts/LazyDelegate.java | 12 +++ .../lang/antlr/AbstractAxiomAntlrVisitor.java | 2 +- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 6 ++ .../axiom/lang/impl/AbstractContext.java | 2 +- .../evolveum/axiom/lang/impl/ItemContext.java | 2 +- .../evolveum/axiom/lang/impl/LazyValue.java | 20 ++-- .../axiom/lang/impl/SourceContext.java | 4 +- .../axiom/lang/impl/ValueContext.java | 23 +++-- .../lang/spi/AxiomTypeDefinitionImpl.java | 2 +- .../axiom/lang/test/TestAxiomInfra.java | 57 +++++++++++ 24 files changed, 321 insertions(+), 125 deletions(-) create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomValue.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomInfraValue.java delete mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/concepts/AbstractLazy.java create mode 100644 infra/axiom/src/main/java/com/evolveum/axiom/concepts/LazyDelegate.java create mode 100644 infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomValue.java new file mode 100644 index 00000000000..4135f04f928 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AbstractAxiomValue.java @@ -0,0 +1,28 @@ +package com.evolveum.axiom.api; + +import java.util.Map; +import java.util.Optional; + +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; + +public abstract class AbstractAxiomValue implements AxiomValue { + + private final AxiomTypeDefinition type; + private final Map> infraItems; + + public AbstractAxiomValue(AxiomTypeDefinition type, Map> infraItems) { + this.type = type; + this.infraItems = infraItems; + } + + @Override + public Map> infraItems() { + return infraItems; + } + + @Override + public Optional type() { + return Optional.of(type); + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java index ddc2d76a2c8..a87154d3b76 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java @@ -5,7 +5,6 @@ import java.util.Optional; import com.evolveum.axiom.api.schema.AxiomItemDefinition; -import com.evolveum.axiom.api.schema.AxiomTypeDefinition; public interface AxiomComplexValue extends AxiomValue>> { @@ -25,10 +24,6 @@ default Optional> item(AxiomName name) { return Optional.ofNullable((AxiomItem) itemMap().get(name)); } - static AxiomValue from(AxiomTypeDefinition typeDefinition, V value) { - return new SimpleValue(typeDefinition, value); - } - default Optional> onlyValue(Class type, AxiomItemDefinition... components) { Optional> current = Optional.of(this); for(AxiomItemDefinition name : components) { @@ -42,4 +37,10 @@ default Optional> onlyValue(Class type, AxiomItemDefinition Map> itemMap(); + // FIXME: Remove this + @Override + default Map> infraItems() { + return null; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomInfraValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomInfraValue.java new file mode 100644 index 00000000000..c8601c377dd --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomInfraValue.java @@ -0,0 +1,17 @@ +package com.evolveum.axiom.api; + +import java.util.Map; +import java.util.Optional; + +public interface AxiomInfraValue { + + Map> infraItems(); + + default Optional> infraItem(AxiomName name) { + return Optional.ofNullable(infraItems().get(name)); + } + + interface Factory { + V create(Map> infraItems); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java index 9f42bab3648..b7a72318d7a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItem.java @@ -12,16 +12,12 @@ public interface AxiomItem { AxiomName name(); Optional definition(); - Collection> values(); + Collection> values(); default AxiomValue onlyValue() { return Iterables.getOnlyElement(values()); } - static AxiomItem of(AxiomItemDefinition def, V value) { - return CompactAxiomItem.of(def, value); - } - static AxiomItem from(AxiomItemDefinition def, Collection> values) { return AxiomItemImpl.from(def, values); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java index bf8576c71bc..eceb2f34e4e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemImpl.java @@ -7,8 +7,7 @@ class AxiomItemImpl extends AbstractAxiomItem { - Collection> values; - + private final Collection> values; private AxiomItemImpl(AxiomItemDefinition definition, Collection> val) { super(definition); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java index 664a4087072..31a29a3aded 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java @@ -1,20 +1,17 @@ package com.evolveum.axiom.api; -import java.util.Collection; -import java.util.Collections; +import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -public interface AxiomValue { +public interface AxiomValue extends AxiomInfraValue { - Optional type(); - - default Collection> metadata() { - return Collections.emptyList(); - } + AxiomName TYPE = AxiomName.axiom("type"); + AxiomName VALUE = AxiomName.axiom("value"); + Optional type(); V value(); @@ -25,4 +22,17 @@ default Optional asComplex() { return Optional.empty(); } + interface Factory> extends AxiomInfraValue.Factory { + + @Override + default T create(Map> infraItems) { + AxiomTypeDefinition type = (AxiomTypeDefinition) infraItems.get(TYPE).onlyValue().value(); + V value = (V) infraItems.get(VALUE).onlyValue().value(); + return create(type, value, infraItems); + } + + T create(AxiomTypeDefinition type, V value, Map> infraItems); + + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index b9b1ca4e4d2..c383af24ec7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -21,6 +21,7 @@ public class AxiomValueBuilder> implements Lazy.Suppli private AxiomValueFactory factory; private Map>> children = new LinkedHashMap<>(); + private Map>> infra = new LinkedHashMap<>(); private V value; public AxiomValueBuilder(AxiomTypeDefinition type, AxiomValueFactory factory) { @@ -52,6 +53,10 @@ public Supplier> get(AxiomName name, Function> getInfra(AxiomName name, Function>> child) { + return infra.computeIfAbsent(name, child); + } + @Override public T get() { if(type.isComplex()) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java deleted file mode 100644 index f7912294d38..00000000000 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.evolveum.axiom.api; - -import java.util.Collection; -import java.util.Optional; - -import com.evolveum.axiom.api.schema.AxiomItemDefinition; -import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -import com.google.common.collect.ImmutableSet; - -class CompactAxiomItem extends AbstractAxiomItem implements AxiomValue { - - private final V value; - - @Override - public Optional type() { - return definition().map(AxiomItemDefinition::typeDefinition); - } - - private CompactAxiomItem(AxiomItemDefinition definition, V value) { - super(definition); - this.value = value; - } - - public static AxiomItem of(AxiomItemDefinition def, V value) { - return new CompactAxiomItem(def, value); - } - - @Override - public V value() { - return value; - } - - @Override - public Collection> values() { - return ImmutableSet.of(this); - } - - @Override - public AxiomValue onlyValue() { - return this; - } - - -} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java index 69f57bb4877..d172152e8c0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java @@ -1,29 +1,20 @@ package com.evolveum.axiom.api; import java.util.Map; -import java.util.Optional; - import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -public class SimpleValue implements AxiomSimpleValue { +public class SimpleValue extends AbstractAxiomValue implements AxiomSimpleValue { private static final AxiomValueFactory FACTORY = SimpleValue::create; - private final AxiomTypeDefinition type; private final T value; - SimpleValue(AxiomTypeDefinition type, T value) { - super(); - this.type = type; + SimpleValue(AxiomTypeDefinition type, T value, Map> infraItems) { + super(type, infraItems); this.value = value; } - public static final AxiomSimpleValue create(AxiomTypeDefinition def, V value, Map> items) { - return new SimpleValue(def, value); - } - - @Override - public Optional type() { - return Optional.ofNullable(type); + public static final AxiomSimpleValue create(AxiomTypeDefinition def, V value, Map> infraItems) { + return new SimpleValue(def, value, infraItems); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java index 6d723b9e8e7..0554053dd92 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java @@ -62,11 +62,23 @@ public void endValue(SourceLocation loc) { @Override public void startItem(AxiomName item, SourceLocation loc) { - Optional childDef = value(current()).childDef(item); + Optional childDef = value(current()).childItemDef(item); AxiomSyntaxException.check(childDef.isPresent(), loc , "Item %s not allowed in %s", item, current().name()); offer(value(current()).startItem(item, loc)); } + @Override + public void startInfra(AxiomName item, SourceLocation loc) { + Optional childDef = value(current()).infraItemDef(item); + AxiomSyntaxException.check(childDef.isPresent(), loc , "Infra Item %s not allowed in %s", item, current().name()); + offer(value(current()).startInfra(item, loc)); + } + + @Override + public void endInfra(SourceLocation loc) { + item(poll()).endNode(loc); + } + @Override public void endItem(SourceLocation loc) { item(poll()).endNode(loc); @@ -87,8 +99,10 @@ public interface ItemBuilder extends Builder { } public interface ValueBuilder extends Builder { - Optional childDef(AxiomName statement); + Optional childItemDef(AxiomName statement); + Optional infraItemDef(AxiomName item); ItemBuilder startItem(AxiomName identifier, SourceLocation loc); + ItemBuilder startInfra(AxiomName identifier, SourceLocation loc); void endValue(SourceLocation loc); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java index db61dcd7f85..37c6ee7122b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java @@ -13,8 +13,8 @@ interface Target { void startValue(Object value, SourceLocation loc); void endValue(SourceLocation loc); - default void startMetadata(AxiomName item, SourceLocation loc) {}; - default void endMetadata(SourceLocation loc) {}; + default void startInfra(AxiomName item, SourceLocation loc) {}; + default void endInfra(SourceLocation loc) {}; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java index 6084f7afe18..9cea3d179c8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java @@ -12,12 +12,14 @@ import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.concepts.SourceLocation; +import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; public class AxiomItemTarget extends AxiomBuilderStreamTarget implements Supplier>, AxiomItemStream.TargetWithResolver { private final AxiomSchemaContext context; private final AxiomIdentifierResolver resolver; + private AxiomTypeDefinition infraType = AxiomBuiltIn.Type.AXIOM_VALUE; private Item result; public AxiomItemTarget(AxiomSchemaContext context, AxiomIdentifierResolver resolver) { @@ -49,13 +51,18 @@ public AxiomIdentifierResolver valueResolver() { } @Override - public Optional childDef(AxiomName statement) { + public Optional childItemDef(AxiomName statement) { return context.getRoot(statement); } @Override - public ItemBuilder startItem(AxiomName identifier, SourceLocation loc) { - result = new Item<>(childDef(identifier).get()); + public Optional infraItemDef(AxiomName item) { + return infraType.itemDefinition(item); + } + + @Override + public ItemBuilder startItem(AxiomName name, SourceLocation loc) { + result = new Item<>(childItemDef(name).get()); return result; } @@ -64,6 +71,12 @@ public void endValue(SourceLocation loc) { } + @Override + public ItemBuilder startInfra(AxiomName name, SourceLocation loc) { + // TODO Auto-generated method stub + return null; + } + } private final class Item implements ItemBuilder, Supplier> { @@ -106,22 +119,70 @@ public AxiomItem get() { return builder.get(); } + } + + private final class ValueItem implements ItemBuilder, Supplier> { + + private Value value; + + public ValueItem(Value value) { + this.value = value; + } + + @Override + public AxiomName name() { + return AxiomValue.VALUE; + } + + @Override + public AxiomIdentifierResolver itemResolver() { + return resolver; + } + + @Override + public AxiomIdentifierResolver valueResolver() { + return resolver; + } + + @Override + public ValueBuilder startValue(Object value, SourceLocation loc) { + this.value.setValue((V) value); + return this.value; + } + + @Override + public void endNode(SourceLocation loc) { + // Noop for now + } + + @Override + public AxiomItem get() { + throw new UnsupportedOperationException("Should not be called"); + } } private final class Value implements ValueBuilder, Supplier> { private final AxiomValueBuilder builder; + private AxiomTypeDefinition type; public Value(V value, AxiomTypeDefinition type) { + this.type = type; builder = AxiomValueBuilder.from(type); - builder.setValue(value); - if(value != null && type.argument().isPresent()) { - AxiomItemDefinition argument = type.argument().get(); - startItem(argument.name(), null).startValue(value, null); + if(value != null) { + setValue(value); + } + + } + + void setValue(V value) { + if(type.argument().isPresent()) { + startItem(type.argument().get().name(), null).startValue(value, null); } else { builder.setValue(value); } + } @Override @@ -140,14 +201,19 @@ public AxiomIdentifierResolver valueResolver() { } @Override - public Optional childDef(AxiomName statement) { + public Optional childItemDef(AxiomName statement) { return builder.type().itemDefinition(statement); } @Override - public ItemBuilder startItem(AxiomName identifier, SourceLocation loc) { - Object itemImpl = builder.get(identifier, (id) -> { - return new Item(childDef(identifier).get()); + public Optional infraItemDef(AxiomName item) { + return infraType.itemDefinition(item); + } + + @Override + public ItemBuilder startItem(AxiomName name, SourceLocation loc) { + Object itemImpl = builder.get(name, (id) -> { + return new Item(childItemDef(name).get()); }); return (Item) (itemImpl); } @@ -162,5 +228,16 @@ public AxiomValue get() { return builder.get(); } + @Override + public ItemBuilder startInfra(AxiomName name, SourceLocation loc) { + if(AxiomValue.VALUE.equals(name)) { + return new ValueItem(this); + } + Supplier> itemImpl = builder.getInfra(name, (id) -> { + return new Item<>(infraItemDef(name).get()); + }); + return (Item) itemImpl; + } + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/concepts/AbstractLazy.java b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/AbstractLazy.java new file mode 100644 index 00000000000..92296f5b2aa --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/AbstractLazy.java @@ -0,0 +1,24 @@ +/* + * 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.concepts; + +public abstract class AbstractLazy { + + private Object value; + + AbstractLazy(Object supplier) { + value = supplier; + } + + T unwrap() { + if(value instanceof Lazy.Supplier) { + value = ((Lazy.Supplier) value).get(); + return unwrap(); + } + return (T) value; + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/concepts/Lazy.java b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/Lazy.java index 4f97b099b4a..5b65bc33ff5 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/concepts/Lazy.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/Lazy.java @@ -6,20 +6,18 @@ */ package com.evolveum.axiom.concepts; -public class Lazy implements java.util.function.Supplier { +public class Lazy extends AbstractLazy implements java.util.function.Supplier { private static final Lazy NULL = Lazy.instant(null); - private Object value; private Lazy(Object supplier) { - value = supplier; + super(supplier); } public static final Lazy from(Supplier supplier) { return new Lazy<>(supplier); } - public static Lazy instant(T value) { return new Lazy(value); } @@ -29,13 +27,9 @@ public static Lazy nullValue() { return NULL; } - @SuppressWarnings("unchecked") @Override public T get() { - if(value instanceof Supplier) { - value = ((Supplier) value).get(); - } - return (T) value; + return unwrap(); } public interface Supplier extends java.util.function.Supplier { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/concepts/LazyDelegate.java b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/LazyDelegate.java new file mode 100644 index 00000000000..f8838762377 --- /dev/null +++ b/infra/axiom/src/main/java/com/evolveum/axiom/concepts/LazyDelegate.java @@ -0,0 +1,12 @@ +package com.evolveum.axiom.concepts; + +public abstract class LazyDelegate extends AbstractLazy { + + public LazyDelegate(Lazy.Supplier supplier) { + super(supplier); + } + + protected T delegate() { + return unwrap(); + } +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java index 6ad255ac02a..f90fee656b2 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AbstractAxiomAntlrVisitor.java @@ -92,7 +92,7 @@ public T processItemBody(AxiomName identifier, ItemBodyContext ctx, StartDelegat @Override public T visitMetadata(MetadataContext ctx) { AxiomName identifier = statementIdentifier(ctx.itemBody().identifier()); - return processItemBody(identifier, ctx.itemBody(), delegate()::startMetadata, delegate()::endMetadata); + return processItemBody(identifier, ctx.itemBody(), delegate()::startInfra, delegate()::endInfra); } private Object convert(ArgumentContext ctx) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 1b2295ce608..714da3f11dc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -66,6 +66,7 @@ public Optional identifierDefinition() { public static final AxiomItemDefinition REF_TARGET = new Item("target", Type.TYPE_DEFINITION, true); public static final AxiomItemDefinition USES = new Item("uses", Type.TYPE_REFERENCE, true); + public static final AxiomItemDefinition VALUE = new Item("value", null, true); protected static final Lazy NAME_IDENTIFIER = Lazy.from( ()-> (AxiomIdentifierDefinition.parent(ITEM_DEFINITION.name(), Item.NAME.name()))); @@ -195,6 +196,11 @@ public static class Type implements AxiomTypeDefinition { 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 argument; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java index 7f8361da59f..f3a31ff9195 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AbstractContext.java @@ -29,7 +29,7 @@ public AbstractContext(P context, SourceLocation loc, IdentifierSpaceHolder spac public P parent() { return parent; } - protected abstract Optional childDef(AxiomName id); + protected abstract Optional childItemDef(AxiomName id); protected SourceContext rootImpl() { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 8091746bccc..2b9493be2dc 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -52,7 +52,7 @@ public AxiomTypeDefinition type() { } @Override - protected Optional childDef(AxiomName id) { + protected Optional childItemDef(AxiomName id) { return type().itemDefinition(id); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java index 5e866a72417..265c08496ba 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/LazyValue.java @@ -1,20 +1,23 @@ package com.evolveum.axiom.lang.impl; +import java.util.Map; import java.util.Optional; import java.util.function.Supplier; import com.evolveum.axiom.api.AxiomComplexValue; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; +import com.evolveum.axiom.concepts.LazyDelegate; -class LazyValue implements AxiomValue { +class LazyValue extends LazyDelegate> implements AxiomValue { private final AxiomTypeDefinition type; - private Object delegate; public LazyValue(AxiomTypeDefinition type, Supplier> supplier) { + super(supplier::get); this.type = type; - this.delegate = supplier; } @Override @@ -32,14 +35,9 @@ public Optional asComplex() { return delegate().asComplex(); } - private AxiomValue delegate() { - if(delegate instanceof AxiomValue) { - return ((AxiomValue) delegate); - } - delegate = ((Supplier>)delegate).get(); - return delegate(); + @Override + public Map> infraItems() { + return delegate().infraItems(); } - - } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 95d84496f44..bc438828650 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -48,7 +48,7 @@ public ItemContext startItem(AxiomName identifier, SourceLocation loc) { } @Override - public Optional childDef(AxiomName statement) { + public Optional childItemDef(AxiomName statement) { return context.rootDefinition(statement); } @@ -103,7 +103,7 @@ public AxiomIdentifierResolver itemResolver() { return (prefix, localName) -> { if(Strings.isNullOrEmpty(prefix)) { AxiomName axiomNs = AxiomName.axiom(localName); - if(childDef(axiomNs).isPresent()) { + if(childItemDef(axiomNs).isPresent()) { return axiomNs; } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index f0fc5c68242..d870ea0621c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -3,6 +3,7 @@ import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.impl.AxiomStatementRule.ActionBuilder; import com.evolveum.axiom.lang.impl.AxiomStatementRule.Lookup; +import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ItemBuilder; import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; @@ -59,7 +60,7 @@ public LookupImpl getLookup() { } @Override - public Optional childDef(AxiomName statement) { + public Optional childItemDef(AxiomName statement) { return parent().type().itemDefinition(statement); } @@ -110,7 +111,7 @@ public ValueActionImpl addAction(String name) { } protected ItemContext createItem(AxiomName id, SourceLocation loc) { - return new ItemContext<>(this, id ,childDef(id).get(), loc); + return new ItemContext<>(this, id ,childItemDef(id).get(), loc); } private class Result implements Dependency> { @@ -257,9 +258,9 @@ public Dependency namespace(AxiomName name, IdentifierSpaceKey } Optional resolveChildDef(AxiomItemDefinition name) { - Optional exactDef = childDef(name.name()); + Optional exactDef = childItemDef(name.name()); if(exactDef.isPresent()) { - Optional localDef = childDef(parent().name().localName(name.name().localName())); + Optional localDef = childItemDef(parent().name().localName(name.name().localName())); if(localDef.isPresent() && localDef.get() instanceof AxiomItemDefinition.Inherited) { return localDef; } @@ -379,14 +380,14 @@ public AxiomIdentifierResolver itemResolver() { return (prefix, localName) -> { if(Strings.isNullOrEmpty(prefix)) { AxiomName localNs = AxiomName.local(localName); - Optional childDef = childDef(localNs); + Optional childDef = childItemDef(localNs); if(childDef.isPresent()) { return Inheritance.adapt(parent().name(), childDef.get()); } ItemContext parent = parent(); while(parent != null) { AxiomName parentNs = AxiomName.from(parent.name().namespace(), localName); - if(childDef(parentNs).isPresent()) { + if(childItemDef(parentNs).isPresent()) { return parentNs; } parent = parent.parent().parent(); @@ -432,4 +433,14 @@ public Exception errorMessage() { } } + @Override + public Optional infraItemDef(AxiomName item) { + throw new UnsupportedOperationException("Infra Items not yet supported for schema"); + } + + @Override + public ItemBuilder startInfra(AxiomName identifier, SourceLocation loc) { + throw new UnsupportedOperationException("Infra Items not yet supported for schema"); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index f63ca5485ac..5b8784697e4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -83,7 +83,7 @@ public Collection identifierDefinitions() { } private void supplyAll(AxiomName type, Builder builder, - Collection> values) { + Collection> values) { for(AxiomValue v : values) { AxiomItemDefinition val = AxiomItemDefinitionImpl.from(v); AxiomName name = Inheritance.adapt(type, val.name()); diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java new file mode 100644 index 00000000000..53d64a1d105 --- /dev/null +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java @@ -0,0 +1,57 @@ +package com.evolveum.axiom.lang.test; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.evolveum.axiom.api.AxiomComplexValue; +import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomValue; +import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.stream.AxiomItemTarget; +import com.evolveum.axiom.concepts.SourceLocation; +import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; +import com.evolveum.axiom.lang.impl.ModelReactorContext; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; + +public class TestAxiomInfra { + + private static final SourceLocation TEST = SourceLocation.from("test", -1, -1); + + private AxiomIdentifierResolver resolver; + + @Test + void testDataStreamApi() { + AxiomSchemaContext context = ModelReactorContext.defaultReactor().computeSchemaContext(); + AxiomItemTarget simpleItem = new AxiomItemTarget(context, resolver); + simpleItem.startItem(Item.MODEL_DEFINITION.name(), TEST); + simpleItem.startValue("test", TEST); + simpleItem.endValue(TEST); + simpleItem.endItem(TEST); + + AxiomItem result = simpleItem.get(); + assertModel(result,"test"); + } + + @Test + void testInfraStreamApi() { + AxiomSchemaContext context = ModelReactorContext.defaultReactor().computeSchemaContext(); + AxiomItemTarget simpleItem = new AxiomItemTarget(context, resolver); + simpleItem.startItem(Item.MODEL_DEFINITION.name(), TEST); + simpleItem.startValue(null, TEST); + simpleItem.startInfra(AxiomValue.VALUE, TEST); + simpleItem.startValue("test", TEST); + simpleItem.endValue(TEST); + simpleItem.endInfra(TEST); + simpleItem.endValue(TEST); + simpleItem.endItem(TEST); + + AxiomItem result = simpleItem.get(); + assertModel(result,"test"); + } + + private void assertModel(AxiomItem result, String name) { + AxiomComplexValue model = result.onlyValue().asComplex().get(); + assertEquals(model.item(Item.NAME).get().onlyValue().value(), name); + } +} From 250c5a4574626a4ed20d14011e0b9d40da8f4aca Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 8 Jun 2020 15:24:55 +0200 Subject: [PATCH 51/60] Axiom: Added support for infra items to AxiomValue and AxiomComplexValue Signed-off-by: Tony Tkacik --- .../evolveum/axiom/api/AxiomComplexValue.java | 14 ++++-- .../evolveum/axiom/api/AxiomItemBuilder.java | 5 +++ .../evolveum/axiom/api/AxiomValueBuilder.java | 39 +++++++++------- .../evolveum/axiom/api/AxiomValueFactory.java | 28 ++++++++++-- .../ComplexValueImpl.java} | 28 ++++++------ .../com/evolveum/axiom/api/SimpleValue.java | 7 --- .../schema/AxiomIdentifierDefinitionImpl.java | 4 ++ .../axiom/api/schema/AxiomTypeDefinition.java | 2 +- .../api/schema/DelegatedItemDefinition.java | 7 ++- .../axiom/api/stream/AxiomItemTarget.java | 44 +++++++++++++++++-- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 10 +++++ .../axiom/lang/impl/ModelReactorContext.java | 16 ++++--- .../axiom/lang/impl/SourceContext.java | 2 +- .../axiom/lang/impl/ValueContext.java | 2 +- .../lang/spi/AbstractBaseDefinition.java | 9 ++-- .../spi/AxiomIdentifierDefinitionImpl.java | 13 +++--- .../lang/spi/AxiomItemDefinitionImpl.java | 9 ++-- .../lang/spi/AxiomTypeDefinitionImpl.java | 9 ++-- .../axiom/lang/test/TestAxiomInfra.java | 36 ++++++++++++++- 19 files changed, 198 insertions(+), 86 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/{lang/impl/ItemValueImpl.java => api/ComplexValueImpl.java} (57%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java index a87154d3b76..af88a4e017e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomComplexValue.java @@ -5,6 +5,7 @@ import java.util.Optional; import com.evolveum.axiom.api.schema.AxiomItemDefinition; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; public interface AxiomComplexValue extends AxiomValue>> { @@ -37,10 +38,15 @@ default Optional> onlyValue(Class type, AxiomItemDefinition Map> itemMap(); - // FIXME: Remove this - @Override - default Map> infraItems() { - return null; + + interface Factory extends AxiomValueFactory>> { + + @Override + default AxiomValue>> createSimple(AxiomTypeDefinition def, + Collection> value, Map> infraItems) { + throw new IllegalStateException("Factory is only for complex types"); + } + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java index 02ebb05d437..794585791a4 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemBuilder.java @@ -6,6 +6,7 @@ import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import com.google.common.collect.ImmutableList.Builder; public class AxiomItemBuilder implements Supplier> { @@ -34,5 +35,9 @@ public AxiomItem get() { return AxiomItem.from(definition, result.build()); } + public Supplier> onlyValue() { + return Iterables.getOnlyElement(values); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java index c383af24ec7..6406cbda8d8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueBuilder.java @@ -2,7 +2,6 @@ import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.concepts.Lazy; -import com.evolveum.axiom.lang.impl.ItemValueImpl; import java.util.Collections; import java.util.LinkedHashMap; @@ -15,22 +14,22 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -public class AxiomValueBuilder> implements Lazy.Supplier { +public class AxiomValueBuilder implements Lazy.Supplier> { - private final AxiomTypeDefinition type; + private AxiomTypeDefinition type; - private AxiomValueFactory factory; + private AxiomValueFactory factory; private Map>> children = new LinkedHashMap<>(); private Map>> infra = new LinkedHashMap<>(); private V value; - public AxiomValueBuilder(AxiomTypeDefinition type, AxiomValueFactory factory) { + public AxiomValueBuilder(AxiomTypeDefinition type, AxiomValueFactory factory) { this.type = type; this.factory = factory; } - public static AxiomValueBuilder> from(AxiomTypeDefinition type) { - return new AxiomValueBuilder(type, type.isComplex() ? ItemValueImpl.factory() : SimpleValue.factory()); + public static AxiomValueBuilder from(AxiomTypeDefinition type) { + return new AxiomValueBuilder<>(type, AxiomValueFactory.defaultFactory()); } public V getValue() { @@ -58,24 +57,28 @@ public Supplier> getInfra(AxiomName name, Function get() { if(type.isComplex()) { Builder> builder = ImmutableMap.builder(); - for(Entry>> entry : children.entrySet()) { - AxiomItem item = entry.getValue().get(); - builder.put(entry.getKey(), entry.getValue().get()); - } - return factory.create(type, null, builder.build()); + return (AxiomValue) factory.createComplex(type, build(children), build(infra)); } Preconditions.checkState(children.isEmpty(), "%s does not have items. Items found %s", type.name(), children.keySet()); - return factory.create(type, value, Collections.emptyMap()); + return factory.createSimple(type, value, Collections.emptyMap()); } - public static > AxiomValueBuilder create(AxiomTypeDefinition type, AxiomValueFactory factory) { + private static Map> build(Map>> children) { + Builder> builder = ImmutableMap.builder(); + for(Entry>> entry : children.entrySet()) { + builder.put(entry.getKey(), entry.getValue().get()); + } + return builder.build(); + } + + public static AxiomValueBuilder create(AxiomTypeDefinition type, AxiomValueFactory factory) { return new AxiomValueBuilder<>(type, factory); } - public void setFactory(AxiomValueFactory factoryFor) { + public void setFactory(AxiomValueFactory factoryFor) { this.factory = factoryFor; } @@ -83,4 +86,8 @@ public AxiomTypeDefinition type() { return type; } + public void setType(AxiomTypeDefinition type) { + this.type = type; + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java index 201845715f8..aa22dde8957 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueFactory.java @@ -4,8 +4,30 @@ import com.evolveum.axiom.api.schema.AxiomTypeDefinition; -public interface AxiomValueFactory> { +public interface AxiomValueFactory { - T create(AxiomTypeDefinition def, V value, Map> items); -} + AxiomValueFactory DEFAULT_FACTORY = new AxiomValueFactory<>() { + + @Override + public AxiomComplexValue createComplex(AxiomTypeDefinition def, Map> items, + Map> infraItems) { + return new ComplexValueImpl(def, items, infraItems); + } + + @Override + public AxiomValue createSimple(AxiomTypeDefinition def, Object value, + Map> infraItems) { + return new SimpleValue(def, value, infraItems); + } + }; + + AxiomValue createSimple(AxiomTypeDefinition def, V value, Map> infraItems); + AxiomComplexValue createComplex(AxiomTypeDefinition def, Map> items ,Map> infraItems); + + @SuppressWarnings("unchecked") + static AxiomValueFactory defaultFactory() { + return (AxiomValueFactory) DEFAULT_FACTORY; + } + +} diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/ComplexValueImpl.java similarity index 57% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java rename to infra/axiom/src/main/java/com/evolveum/axiom/api/ComplexValueImpl.java index d5911434433..5f1a9400cc8 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemValueImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/ComplexValueImpl.java @@ -1,37 +1,30 @@ -package com.evolveum.axiom.lang.impl; +package com.evolveum.axiom.api; import java.util.Collection; import java.util.Map; import java.util.Optional; -import com.evolveum.axiom.api.AxiomName; -import com.evolveum.axiom.api.AxiomComplexValue; -import com.evolveum.axiom.api.AxiomItem; -import com.evolveum.axiom.api.AxiomValue; -import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; +import com.google.common.collect.ImmutableMap; -public class ItemValueImpl implements AxiomComplexValue { +public class ComplexValueImpl implements AxiomComplexValue { - private static final AxiomValueFactory>, AxiomComplexValue> FACTORY = ItemValueImpl::new; private final AxiomTypeDefinition type; private final Map> items; + private final Map> infraItems; + protected X require(Optional value) { return value.get(); } - public ItemValueImpl(AxiomTypeDefinition type, Collection> value, Map> items) { + public ComplexValueImpl(AxiomTypeDefinition type, Map> items, Map> infraItems) { super(); this.type = type; - this.items = items; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public static AxiomValueFactory> factory() { - return (AxiomValueFactory) FACTORY; + this.items = ImmutableMap.copyOf(items); + this.infraItems = ImmutableMap.copyOf(infraItems); } @Override @@ -57,4 +50,9 @@ public Collection> items() { public Map> itemMap() { return items; } + + @Override + public Map> infraItems() { + return infraItems; + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java index d172152e8c0..9bb79121cf9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/SimpleValue.java @@ -5,7 +5,6 @@ public class SimpleValue extends AbstractAxiomValue implements AxiomSimpleValue { - private static final AxiomValueFactory FACTORY = SimpleValue::create; private final T value; SimpleValue(AxiomTypeDefinition type, T value, Map> infraItems) { @@ -22,10 +21,4 @@ public T value() { return value; } - public static AxiomValueFactory> factory() { - return FACTORY; - } - - - } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java index 95a26facf32..d341ca09ff0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomIdentifierDefinitionImpl.java @@ -33,4 +33,8 @@ public Map> itemMap() { return Collections.emptyMap(); } + @Override + public Map> infraItems() { + return null; + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java index fc4e0fa5c10..8a4c9b4957f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/AxiomTypeDefinition.java @@ -13,7 +13,6 @@ import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomName; -import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.google.common.collect.ImmutableMap; @@ -22,6 +21,7 @@ public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomComplexV public final AxiomName IDENTIFIER_MEMBER = AxiomName.axiom("name"); public final AxiomName SPACE = AxiomName.axiom("AxiomTypeDefinition"); + public final AxiomName NAME = AxiomName.axiom("name"); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java index 6bee8f06660..f0e101a75a3 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/schema/DelegatedItemDefinition.java @@ -1,11 +1,9 @@ package com.evolveum.axiom.api.schema; -import java.util.Collection; import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.AxiomName; -import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomItem; abstract class DelegatedItemDefinition implements AxiomItemDefinition { @@ -81,4 +79,9 @@ public AxiomTypeDefinition definingType() { public Optional identifierDefinition() { return delegate().identifierDefinition(); } + + @Override + public Map> infraItems() { + return delegate().infraItems(); + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java index 9cea3d179c8..c6f65b79b1f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java @@ -14,6 +14,7 @@ import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; public class AxiomItemTarget extends AxiomBuilderStreamTarget implements Supplier>, AxiomItemStream.TargetWithResolver { @@ -79,9 +80,9 @@ public ItemBuilder startInfra(AxiomName name, SourceLocation loc) { } - private final class Item implements ItemBuilder, Supplier> { + private class Item implements ItemBuilder, Supplier> { - private AxiomItemBuilder builder; + protected final AxiomItemBuilder builder; public Item(AxiomItemDefinition definition) { this.builder = new AxiomItemBuilder<>(definition); @@ -102,6 +103,11 @@ public AxiomIdentifierResolver valueResolver() { return resolver; } + + protected Value onlyValue() { + return (Value) builder.onlyValue(); + } + @Override public ValueBuilder startValue(Object value, SourceLocation loc) { Value newValue = new Value<>((V) value, builder.definition().typeDefinition()); @@ -150,6 +156,7 @@ public ValueBuilder startValue(Object value, SourceLocation loc) { return this.value; } + @Override public void endNode(SourceLocation loc) { // Noop for now @@ -159,12 +166,35 @@ public void endNode(SourceLocation loc) { public AxiomItem get() { throw new UnsupportedOperationException("Should not be called"); } + } + + private final class TypeItem extends Item { + + private Value value; + + public TypeItem(AxiomItemDefinition definition) { + super(definition); + } + public TypeItem(Value value, AxiomItemDefinition definition) { + super(definition); + this.value = value; + } + + @Override + public void endNode(SourceLocation loc) { + AxiomName typeName = (AxiomName) onlyValue().get().asComplex().get().item(AxiomTypeDefinition.NAME).get().onlyValue().value(); + Optional typeDef = context.getType(typeName); + AxiomSemanticException.check(typeDef.isPresent(), loc, "% type is not defined.", typeName); + this.value.setType(typeDef.get(),loc); + super.endNode(loc); + } } + private final class Value implements ValueBuilder, Supplier> { - private final AxiomValueBuilder builder; + private final AxiomValueBuilder builder; private AxiomTypeDefinition type; public Value(V value, AxiomTypeDefinition type) { @@ -176,6 +206,12 @@ public Value(V value, AxiomTypeDefinition type) { } + public void setType(AxiomTypeDefinition type, SourceLocation start) { + AxiomSemanticException.check(type.isSubtypeOf(this.type), start, "%s is not subtype of %s", type.name(), this.type.name()); + this.type = type; + builder.setType(type); + } + void setValue(V value) { if(type.argument().isPresent()) { startItem(type.argument().get().name(), null).startValue(value, null); @@ -232,6 +268,8 @@ public AxiomValue get() { public ItemBuilder startInfra(AxiomName name, SourceLocation loc) { if(AxiomValue.VALUE.equals(name)) { return new ValueItem(this); + } else if (AxiomValue.TYPE.equals(name)) { + return new TypeItem(this, infraItemDef(name).get()); } Supplier> itemImpl = builder.getInfra(name, (id) -> { return new Item<>(infraItemDef(name).get()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 714da3f11dc..9a4f7bceafe 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -142,6 +142,11 @@ public Optional identifierDefinition() { public Map> itemMap() { return null; } + + @Override + public Map> infraItems() { + return null; + } } public static class Type implements AxiomTypeDefinition { @@ -300,6 +305,11 @@ public boolean isComplex() { } return !itemDefinitions().isEmpty(); } + + @Override + public Map> infraItems() { + return null; + } } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index b0f58f4c636..656c0aa629d 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -13,6 +13,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; +import com.evolveum.axiom.api.ComplexValueImpl; import com.evolveum.axiom.api.SimpleValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomSchemaContext; @@ -104,7 +105,7 @@ private static void defaults(ModelReactorContext reactorContext) { IdentifierSpaceHolderImpl globalSpace = new IdentifierSpaceHolderImpl(Scope.GLOBAL); - Map> typeFactories = new HashMap<>(); + Map> typeFactories = new HashMap<>(); List> roots = new ArrayList<>(); public ModelReactorContext(AxiomSchemaContext boostrapContext) { @@ -154,9 +155,10 @@ public void addRules(AxiomStatementRule... rules) { } } - public void loadModelFromSource(AxiomModelStatementSource source) { + public ModelReactorContext loadModelFromSource(AxiomModelStatementSource source) { SourceContext sourceCtx = new SourceContext(this, source, source.imports(), new CompositeIdentifierSpace()); source.stream(new AxiomBuilderStreamTarget(sourceCtx), Optional.empty()); + return this; } @Override @@ -167,21 +169,21 @@ public AxiomName resolveIdentifier(@Nullable String prefix, @NotNull String loca return null; } - public void addStatementFactory(AxiomName statementType, AxiomValueFactory factory) { + public void addStatementFactory(AxiomName statementType, AxiomValueFactory factory) { typeFactories.put(statementType, factory); } - public AxiomValueFactory> typeFactory(AxiomTypeDefinition statementType) { + public AxiomValueFactory typeFactory(AxiomTypeDefinition statementType) { Optional current = Optional.of(statementType); do { @SuppressWarnings("unchecked") - AxiomValueFactory maybe = (AxiomValueFactory) typeFactories.get(current.get().name()); + AxiomValueFactory maybe = (AxiomValueFactory) typeFactories.get(current.get().name()); if (maybe != null) { - return (AxiomValueFactory) maybe; + return maybe; } current = current.get().superType(); } while (current.isPresent()); - return statementType.isComplex() ? ItemValueImpl.factory() : SimpleValue.factory(); + return AxiomValueFactory.defaultFactory(); } public void exportIdentifierSpace(IdentifierSpaceKey namespace, IdentifierSpaceHolder localSpace) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index bc438828650..a44beef9c8c 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -73,7 +73,7 @@ public ValueContext lookup(AxiomName space, IdentifierSpaceKey key) { return globalSpace.lookup(space, key); } - public AxiomValueFactory> factoryFor(AxiomTypeDefinition type) { + public AxiomValueFactory factoryFor(AxiomTypeDefinition type) { return context.typeFactory(type); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index d870ea0621c..4ad072c7ee9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -117,7 +117,7 @@ protected ItemContext createItem(AxiomName id, SourceLocation loc) { private class Result implements Dependency> { AxiomTypeDefinition type; - AxiomValueBuilder> builder; + AxiomValueBuilder builder; private V value; public Result(AxiomTypeDefinition type, V value) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java index 38bd4c93838..2a2501f3f2f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AbstractBaseDefinition.java @@ -1,22 +1,21 @@ package com.evolveum.axiom.lang.spi; -import java.util.Collection; import java.util.Map; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.ComplexValueImpl; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.schema.AxiomNamedDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.impl.ItemValueImpl; -public class AbstractBaseDefinition extends ItemValueImpl implements AxiomNamedDefinition { +public class AbstractBaseDefinition extends ComplexValueImpl implements AxiomNamedDefinition { private final AxiomName name; private final String documentation; - public AbstractBaseDefinition(AxiomTypeDefinition type, Collection> value, Map> items) { - super(type, value, items); + public AbstractBaseDefinition(AxiomTypeDefinition type, Map> items, Map> infraItems) { + super(type, items, infraItems); name = (AxiomName) item(Item.NAME).get().onlyValue().value(); documentation = item(Item.DOCUMENTATION).map(i -> i.onlyValue().value().toString()).orElse(null); // } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java index 1c4d7ff034e..cf54528c88a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierDefinitionImpl.java @@ -6,22 +6,19 @@ import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; -import com.evolveum.axiom.api.AxiomValueFactory; +import com.evolveum.axiom.api.ComplexValueImpl; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; -import com.evolveum.axiom.lang.impl.ItemValueImpl; import com.google.common.collect.ImmutableList; -public class AxiomIdentifierDefinitionImpl extends ItemValueImpl implements AxiomIdentifierDefinition { - - public static final AxiomValueFactory>,AxiomComplexValue> FACTORY = AxiomIdentifierDefinitionImpl::new ; +public class AxiomIdentifierDefinitionImpl extends ComplexValueImpl implements AxiomIdentifierDefinition { + public static final AxiomComplexValue.Factory FACTORY = AxiomIdentifierDefinitionImpl::new; private final Collection components; - - public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, Collection> value, Map> items) { - super(axiomItemDefinition, value, items); + public AxiomIdentifierDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, Map> items, Map> infraItems) { + super(axiomItemDefinition, items, infraItems); ImmutableList.Builder components = ImmutableList.builder(); for (AxiomValue val : this.item(Item.ID_MEMBER.name()).get().values()) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java index e967a320bcd..59e3612ac1e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomItemDefinitionImpl.java @@ -1,13 +1,12 @@ package com.evolveum.axiom.lang.spi; -import java.util.Collection; import java.util.Map; import java.util.Optional; import com.evolveum.axiom.api.AxiomName; +import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; -import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -15,13 +14,13 @@ public class AxiomItemDefinitionImpl extends AbstractBaseDefinition implements AxiomItemDefinition { - public static final AxiomValueFactory>,AxiomItemDefinition> FACTORY = AxiomItemDefinitionImpl::new ; + public static final AxiomComplexValue.Factory FACTORY = AxiomItemDefinitionImpl::new; private final AxiomValue valueType; private final Optional> minOccurs; private Optional identifierDef; - public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, Collection> value, Map> items) { - super(axiomItemDefinition, value, items); + public AxiomItemDefinitionImpl(AxiomTypeDefinition axiomItemDefinition, Map> items, Map> infraItems) { + super(axiomItemDefinition, items, infraItems); this.valueType = require(asComplex().get().onlyValue(AxiomTypeDefinition.class,Item.TYPE_REFERENCE, Item.REF_TARGET)); this.identifierDef = asComplex().get().onlyValue(AxiomIdentifierDefinition.class, Item.IDENTIFIER_DEFINITION).map(v -> AxiomIdentifierDefinitionImpl.from(v)); minOccurs = this.item(Item.MIN_OCCURS.name()); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java index 5b8784697e4..0b12de00f83 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomTypeDefinitionImpl.java @@ -8,7 +8,6 @@ import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; import com.evolveum.axiom.api.AxiomValue; -import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.meta.Inheritance; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition; import com.evolveum.axiom.api.schema.AxiomItemDefinition; @@ -21,17 +20,15 @@ public class AxiomTypeDefinitionImpl extends AbstractBaseDefinition implements AxiomTypeDefinition { - public static final AxiomValueFactory>, AxiomTypeDefinition> FACTORY =AxiomTypeDefinitionImpl::new; - + public static final AxiomComplexValue.Factory FACTORY = AxiomTypeDefinitionImpl::new; private final Map itemDefinitions; private final Optional superType; private final Optional argument; private final Collection identifiers; - public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, Collection> value, Map> keywordMap) { - super(def, null, keywordMap); + public AxiomTypeDefinitionImpl(AxiomTypeDefinition def, Map> keywordMap, Map> infraItems) { + super(def, keywordMap, infraItems); - //super(keyword, value, children, keywordMap); ImmutableMap.Builder builder = ImmutableMap.builder(); Optional> itemDef = item(Item.ITEM_DEFINITION.name()); if(itemDef.isPresent()) { diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java index 53d64a1d105..eadde240bfe 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java @@ -2,22 +2,32 @@ import static org.testng.Assert.assertEquals; +import java.io.FileNotFoundException; +import java.io.IOException; + import org.testng.annotations.Test; import com.evolveum.axiom.api.AxiomComplexValue; import com.evolveum.axiom.api.AxiomItem; +import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.schema.AxiomSchemaContext; +import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.api.stream.AxiomItemTarget; import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.impl.ModelReactorContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -public class TestAxiomInfra { +public class TestAxiomInfra extends AbstractReactorTest { private static final SourceLocation TEST = SourceLocation.from("test", -1, -1); + private static final String DIR = "prism/prism.axiom"; + private static final AxiomName PRISM_MODEL = AxiomName.from("http://midpoint.evolveum.com/xml/ns/public/common/prism", "PrismModel"); + private AxiomIdentifierResolver resolver; @Test @@ -34,7 +44,7 @@ void testDataStreamApi() { } @Test - void testInfraStreamApi() { + void testInfraValueApi() { AxiomSchemaContext context = ModelReactorContext.defaultReactor().computeSchemaContext(); AxiomItemTarget simpleItem = new AxiomItemTarget(context, resolver); simpleItem.startItem(Item.MODEL_DEFINITION.name(), TEST); @@ -50,6 +60,28 @@ void testInfraStreamApi() { assertModel(result,"test"); } + @Test + void testInfraTypeApi() throws AxiomSemanticException, AxiomSyntaxException, FileNotFoundException, IOException { + AxiomSchemaContext context = ModelReactorContext.defaultReactor() + .loadModelFromSource(source(DIR)) + .computeSchemaContext(); + AxiomItemTarget simpleItem = new AxiomItemTarget(context, resolver); + simpleItem.startItem(Item.MODEL_DEFINITION.name(), TEST); // model + simpleItem.startValue("test", TEST); // test { + simpleItem.startInfra(AxiomValue.TYPE, TEST); // @type + simpleItem.startValue(PRISM_MODEL, TEST); // prism:model + simpleItem.endValue(TEST); // ; + simpleItem.endInfra(TEST); // + simpleItem.endValue(TEST); + simpleItem.endItem(TEST); + + AxiomItem result = simpleItem.get(); + AxiomTypeDefinition typeDef = simpleItem.get().onlyValue().type().get(); + assertEquals(typeDef.name(), PRISM_MODEL); + assertModel(result,"test"); + } + + private void assertModel(AxiomItem result, String name) { AxiomComplexValue model = result.onlyValue().asComplex().get(); assertEquals(model.item(Item.NAME).get().onlyValue().value(), name); From 4f3042bded18edf909c9c45560ee3a3a46260cc6 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 9 Jun 2020 12:54:47 +0200 Subject: [PATCH 52/60] Axiom: Added exmaple with infra type in Axiom language Signed-off-by: Tony Tkacik --- .../api/stream/AxiomBuilderStreamTarget.java | 17 +++++- .../axiom/api/stream/AxiomItemTarget.java | 11 +++- .../lang/antlr/AxiomAntlrStatementSource.java | 10 +++- .../axiom/lang/antlr/AxiomAntlrVisitor2.java | 9 ++- .../lang/antlr/AxiomModelStatementSource.java | 9 ++- .../axiom/lang/impl/SourceContext.java | 12 +--- .../lang/spi/AxiomIdentifierResolver.java | 6 ++ .../axiom/lang/test/TestAxiomInfra.java | 56 ++++++++++++------- .../test/resources/prism/prism-infra.axiom | 10 ++++ 9 files changed, 96 insertions(+), 44 deletions(-) create mode 100644 infra/axiom/src/test/resources/prism/prism-infra.axiom diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java index 0554053dd92..63452bc8013 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java @@ -15,6 +15,7 @@ import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; public class AxiomBuilderStreamTarget implements AxiomItemStream.TargetWithResolver { @@ -41,12 +42,12 @@ protected Builder poll() { } private ItemBuilder item(Builder node) { - Preconditions.checkState(node instanceof ItemBuilder); + Preconditions.checkState(node instanceof ItemBuilder, "Incorrect nesting: expected item, got value"); return (ItemBuilder) node; } private ValueBuilder value(Builder node) { - Preconditions.checkState(node instanceof ValueBuilder); + Preconditions.checkState(node instanceof ValueBuilder, "Incorrect nesting: expected value, got item"); return (ValueBuilder) node; } @@ -104,6 +105,18 @@ public interface ValueBuilder extends Builder { ItemBuilder startItem(AxiomName identifier, SourceLocation loc); ItemBuilder startInfra(AxiomName identifier, SourceLocation loc); void endValue(SourceLocation loc); + + default AxiomIdentifierResolver axiomAsConditionalDefault() { + return (prefix, name) -> { + if(Strings.isNullOrEmpty(prefix)) { + AxiomName axiomNs = AxiomName.axiom(name); + if(childItemDef(axiomNs).isPresent()) { + return axiomNs; + } + } + return null; + }; + } } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java index c6f65b79b1f..5c98eff5d59 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java @@ -15,6 +15,7 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; +import com.google.common.base.Preconditions; public class AxiomItemTarget extends AxiomBuilderStreamTarget implements Supplier>, AxiomItemStream.TargetWithResolver { @@ -23,10 +24,14 @@ public class AxiomItemTarget extends AxiomBuilderStreamTarget implements Supplie private AxiomTypeDefinition infraType = AxiomBuiltIn.Type.AXIOM_VALUE; private Item result; - public AxiomItemTarget(AxiomSchemaContext context, AxiomIdentifierResolver resolver) { + public AxiomItemTarget(AxiomSchemaContext context) { + this(context, AxiomIdentifierResolver.nullResolver()); + } + + public AxiomItemTarget(AxiomSchemaContext context, AxiomIdentifierResolver rootResolver) { offer(new Root()); this.context = context; - this.resolver = resolver; + this.resolver = Preconditions.checkNotNull(rootResolver, "rootResolver"); } @Override @@ -43,7 +48,7 @@ public AxiomName name() { @Override public AxiomIdentifierResolver itemResolver() { - return resolver; + return axiomAsConditionalDefault().or(resolver); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index 67f7f269a68..441616e905e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -17,6 +17,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; +import com.evolveum.axiom.api.stream.AxiomItemStream.TargetWithResolver; import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; @@ -64,8 +65,13 @@ public final void stream(AxiomItemStream.TargetWithResolver target) { stream(target, Optional.empty()); } - public final void stream(AxiomItemStream.TargetWithResolver target, Optional> emitOnly) { - AxiomAntlrVisitor2 visitor = new AxiomAntlrVisitor2<>(sourceName, target, emitOnly.orElse(null)); + public void stream(AxiomItemStream.TargetWithResolver target, Optional> emitOnly) { + stream(target, emitOnly, AxiomIdentifierResolver.nullResolver()); + } + + public final void stream(TargetWithResolver target, Optional> emitOnly, + AxiomIdentifierResolver resolver) { + AxiomAntlrVisitor2 visitor = new AxiomAntlrVisitor2<>(sourceName, target, emitOnly.orElse(null), resolver); visitor.visit(root); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java index b0304229c5c..9cb928e7d56 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java @@ -11,25 +11,28 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.api.stream.AxiomItemStream.Target; +import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; public class AxiomAntlrVisitor2 extends AbstractAxiomAntlrVisitor { private final AxiomItemStream.TargetWithResolver delegate; + private final AxiomIdentifierResolver sourceLocal; public AxiomAntlrVisitor2(String name, AxiomItemStream.TargetWithResolver delegate, - Set limit) { + Set limit, AxiomIdentifierResolver resolver) { super(name, limit); this.delegate = delegate; + this.sourceLocal = resolver; } @Override protected AxiomName resolveArgument(String prefix, String localName) { - return delegate.valueResolver().resolveIdentifier(prefix, localName); + return delegate.valueResolver().or(sourceLocal).resolveIdentifier(prefix, localName); } @Override protected AxiomName resolveItemName(String prefix, String localName) { - return delegate.itemResolver().resolveIdentifier(prefix, localName); + return delegate.itemResolver().or(sourceLocal).resolveIdentifier(prefix, localName); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 0754f03d975..201277f1aab 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable; import com.evolveum.axiom.api.AxiomName; -import com.evolveum.axiom.api.stream.AxiomItemStream; +import com.evolveum.axiom.api.stream.AxiomItemStream.TargetWithResolver; import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; @@ -63,10 +63,9 @@ public String namespace() { return namespace; } - - public void stream(AxiomIdentifierResolver resolver, AxiomItemStream.Target listener, - Optional> emitOnly) { - stream(resolver.or(this), BUILTIN_TYPES.or(this).or(resolver), listener, emitOnly); + @Override + public void stream(TargetWithResolver target, Optional> emitOnly) { + stream(target, emitOnly, this); } public Map imports() { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index a44beef9c8c..62e26a2629a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -5,7 +5,6 @@ import java.util.Optional; import com.evolveum.axiom.api.AxiomName; -import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -17,7 +16,6 @@ import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; class SourceContext extends ValueContext implements AxiomRootContext, ValueBuilder { @@ -100,16 +98,10 @@ public void exportIdentifierSpace(IdentifierSpaceKey namespaceId) { @Override public AxiomIdentifierResolver itemResolver() { - return (prefix, localName) -> { - if(Strings.isNullOrEmpty(prefix)) { - AxiomName axiomNs = AxiomName.axiom(localName); - if(childItemDef(axiomNs).isPresent()) { - return axiomNs; - } - } + return axiomAsConditionalDefault().or((prefix, localName) -> { String namespace = imports.get(prefix); return AxiomName.from(namespace, localName); - }; + }); } @Override diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java index 4e00a67981c..f308f827067 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java @@ -31,12 +31,18 @@ public interface AxiomIdentifierResolver { return null; }; + final AxiomIdentifierResolver NULL_RESOLVER = (p, n) -> null; + AxiomName resolveIdentifier(@Nullable String prefix, @NotNull String localName); static AxiomIdentifierResolver defaultNamespace(String namespace) { return (prefix, localName) -> Strings.isNullOrEmpty(prefix) ? AxiomName.from(namespace, localName) : null; } + static AxiomIdentifierResolver nullResolver() { + return NULL_RESOLVER; + } + default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { return (prefix, localName) -> { AxiomName maybe = this.resolveIdentifier(prefix, localName); diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java index eadde240bfe..8f7f8cad7cf 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestAxiomInfra.java @@ -17,7 +17,6 @@ import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item; import com.evolveum.axiom.lang.impl.ModelReactorContext; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; @@ -25,15 +24,16 @@ public class TestAxiomInfra extends AbstractReactorTest { private static final SourceLocation TEST = SourceLocation.from("test", -1, -1); - private static final String DIR = "prism/prism.axiom"; + private static final String PRISM = "prism/prism.axiom"; + private static final String PRISM_TEST = "prism/prism-infra.axiom"; + private static final AxiomName PRISM_MODEL = AxiomName.from("http://midpoint.evolveum.com/xml/ns/public/common/prism", "PrismModel"); - private AxiomIdentifierResolver resolver; @Test void testDataStreamApi() { AxiomSchemaContext context = ModelReactorContext.defaultReactor().computeSchemaContext(); - AxiomItemTarget simpleItem = new AxiomItemTarget(context, resolver); + AxiomItemTarget simpleItem = new AxiomItemTarget(context); simpleItem.startItem(Item.MODEL_DEFINITION.name(), TEST); simpleItem.startValue("test", TEST); simpleItem.endValue(TEST); @@ -46,7 +46,7 @@ void testDataStreamApi() { @Test void testInfraValueApi() { AxiomSchemaContext context = ModelReactorContext.defaultReactor().computeSchemaContext(); - AxiomItemTarget simpleItem = new AxiomItemTarget(context, resolver); + AxiomItemTarget simpleItem = new AxiomItemTarget(context); simpleItem.startItem(Item.MODEL_DEFINITION.name(), TEST); simpleItem.startValue(null, TEST); simpleItem.startInfra(AxiomValue.VALUE, TEST); @@ -63,26 +63,44 @@ void testInfraValueApi() { @Test void testInfraTypeApi() throws AxiomSemanticException, AxiomSyntaxException, FileNotFoundException, IOException { AxiomSchemaContext context = ModelReactorContext.defaultReactor() - .loadModelFromSource(source(DIR)) + .loadModelFromSource(source(PRISM)) .computeSchemaContext(); - AxiomItemTarget simpleItem = new AxiomItemTarget(context, resolver); - simpleItem.startItem(Item.MODEL_DEFINITION.name(), TEST); // model - simpleItem.startValue("test", TEST); // test { - simpleItem.startInfra(AxiomValue.TYPE, TEST); // @type - simpleItem.startValue(PRISM_MODEL, TEST); // prism:model - simpleItem.endValue(TEST); // ; - simpleItem.endInfra(TEST); // - simpleItem.endValue(TEST); - simpleItem.endItem(TEST); - - AxiomItem result = simpleItem.get(); - AxiomTypeDefinition typeDef = simpleItem.get().onlyValue().type().get(); + AxiomItemTarget t = new AxiomItemTarget(context); + t.startItem(Item.MODEL_DEFINITION.name(), TEST); // model + t.startValue("test", TEST); // test { + t.startInfra(AxiomValue.TYPE, TEST); // @type + t.startValue(PRISM_MODEL, TEST); // prism:model + t.endValue(TEST); // ; + t.endInfra(TEST); // + t.startItem(PRISM_MODEL.localName("container"), TEST); + t.startValue("test", TEST); + t.endValue(TEST); + t.endItem(TEST); + t.endValue(TEST); + t.endItem(TEST); + + AxiomItem result = t.get(); + AxiomTypeDefinition typeDef = t.get().onlyValue().type().get(); assertEquals(typeDef.name(), PRISM_MODEL); assertModel(result,"test"); } + @Test + void testInfraSerialized() throws AxiomSemanticException, AxiomSyntaxException, FileNotFoundException, IOException { + AxiomSchemaContext context = ModelReactorContext.defaultReactor() + .loadModelFromSource(source(PRISM)) + .computeSchemaContext(); + AxiomItemTarget t = new AxiomItemTarget(context); + source(PRISM_TEST).stream(t); + + AxiomItem result = t.get(); + AxiomTypeDefinition typeDef = t.get().onlyValue().type().get(); + assertEquals(typeDef.name(), PRISM_MODEL); + assertModel(result,AxiomName.from("http://example.org", "test")); + } + - private void assertModel(AxiomItem result, String name) { + private void assertModel(AxiomItem result, Object name) { AxiomComplexValue model = result.onlyValue().asComplex().get(); assertEquals(model.item(Item.NAME).get().onlyValue().value(), name); } diff --git a/infra/axiom/src/test/resources/prism/prism-infra.axiom b/infra/axiom/src/test/resources/prism/prism-infra.axiom new file mode 100644 index 00000000000..6a5b40b1907 --- /dev/null +++ b/infra/axiom/src/test/resources/prism/prism-infra.axiom @@ -0,0 +1,10 @@ +model test { + @type prism:PrismModel; + namespace "http://example.org"; + import prism { + namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; + } + container test { + + } +} \ No newline at end of file From f3a0fff47e2703154b081c4b0c135f1a3c236fcd Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 9 Jun 2020 13:05:05 +0200 Subject: [PATCH 53/60] Renamed AxiomIdentifierResolver to AxiomNameResolver Signed-off-by: Tony Tkacik --- .../api/stream/AxiomBuilderStreamTarget.java | 12 ++++----- .../axiom/api/stream/AxiomItemStream.java | 6 ++--- .../axiom/api/stream/AxiomItemTarget.java | 26 +++++++++---------- .../lang/antlr/AxiomAntlrStatementSource.java | 8 +++--- .../axiom/lang/antlr/AxiomAntlrVisitor.java | 8 +++--- .../axiom/lang/antlr/AxiomAntlrVisitor2.java | 6 ++--- .../lang/antlr/AxiomModelStatementSource.java | 4 +-- .../evolveum/axiom/lang/impl/ItemContext.java | 6 ++--- .../axiom/lang/impl/ModelReactorContext.java | 4 +-- .../axiom/lang/impl/SourceContext.java | 8 +++--- .../axiom/lang/impl/ValueContext.java | 6 ++--- ...erResolver.java => AxiomNameResolver.java} | 16 ++++++------ .../axiom/lang/test/TestTypeDerivation.java | 4 +-- 13 files changed, 57 insertions(+), 57 deletions(-) rename infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/{AxiomIdentifierResolver.java => AxiomNameResolver.java} (76%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java index 63452bc8013..a89f3e425c7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomBuilderStreamTarget.java @@ -12,7 +12,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.concepts.SourceLocation; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -88,9 +88,9 @@ public void endItem(SourceLocation loc) { private interface Builder { AxiomName name(); - AxiomIdentifierResolver itemResolver(); + AxiomNameResolver itemResolver(); - AxiomIdentifierResolver valueResolver(); + AxiomNameResolver valueResolver(); } public interface ItemBuilder extends Builder { @@ -106,7 +106,7 @@ public interface ValueBuilder extends Builder { ItemBuilder startInfra(AxiomName identifier, SourceLocation loc); void endValue(SourceLocation loc); - default AxiomIdentifierResolver axiomAsConditionalDefault() { + default AxiomNameResolver axiomAsConditionalDefault() { return (prefix, name) -> { if(Strings.isNullOrEmpty(prefix)) { AxiomName axiomNs = AxiomName.axiom(name); @@ -120,12 +120,12 @@ default AxiomIdentifierResolver axiomAsConditionalDefault() { } @Override - public AxiomIdentifierResolver itemResolver() { + public AxiomNameResolver itemResolver() { return current().itemResolver(); } @Override - public AxiomIdentifierResolver valueResolver() { + public AxiomNameResolver valueResolver() { return current().valueResolver(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java index 37c6ee7122b..2da9fcb9ed0 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemStream.java @@ -2,7 +2,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.concepts.SourceLocation; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; public interface AxiomItemStream { @@ -20,8 +20,8 @@ interface Target { interface TargetWithResolver extends Target { - AxiomIdentifierResolver itemResolver(); - AxiomIdentifierResolver valueResolver(); + AxiomNameResolver itemResolver(); + AxiomNameResolver valueResolver(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java index 5c98eff5d59..1dabfbf66a9 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/stream/AxiomItemTarget.java @@ -13,22 +13,22 @@ import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.api.AxiomBuiltIn; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.google.common.base.Preconditions; public class AxiomItemTarget extends AxiomBuilderStreamTarget implements Supplier>, AxiomItemStream.TargetWithResolver { private final AxiomSchemaContext context; - private final AxiomIdentifierResolver resolver; + private final AxiomNameResolver resolver; private AxiomTypeDefinition infraType = AxiomBuiltIn.Type.AXIOM_VALUE; private Item result; public AxiomItemTarget(AxiomSchemaContext context) { - this(context, AxiomIdentifierResolver.nullResolver()); + this(context, AxiomNameResolver.nullResolver()); } - public AxiomItemTarget(AxiomSchemaContext context, AxiomIdentifierResolver rootResolver) { + public AxiomItemTarget(AxiomSchemaContext context, AxiomNameResolver rootResolver) { offer(new Root()); this.context = context; this.resolver = Preconditions.checkNotNull(rootResolver, "rootResolver"); @@ -47,12 +47,12 @@ public AxiomName name() { } @Override - public AxiomIdentifierResolver itemResolver() { + public AxiomNameResolver itemResolver() { return axiomAsConditionalDefault().or(resolver); } @Override - public AxiomIdentifierResolver valueResolver() { + public AxiomNameResolver valueResolver() { return resolver; } @@ -99,12 +99,12 @@ public AxiomName name() { } @Override - public AxiomIdentifierResolver itemResolver() { + public AxiomNameResolver itemResolver() { return resolver; } @Override - public AxiomIdentifierResolver valueResolver() { + public AxiomNameResolver valueResolver() { return resolver; } @@ -146,12 +146,12 @@ public AxiomName name() { } @Override - public AxiomIdentifierResolver itemResolver() { + public AxiomNameResolver itemResolver() { return resolver; } @Override - public AxiomIdentifierResolver valueResolver() { + public AxiomNameResolver valueResolver() { return resolver; } @@ -232,12 +232,12 @@ public AxiomName name() { } @Override - public AxiomIdentifierResolver itemResolver() { - return AxiomIdentifierResolver.defaultNamespaceFromType(builder.type()); + public AxiomNameResolver itemResolver() { + return AxiomNameResolver.defaultNamespaceFromType(builder.type()); } @Override - public AxiomIdentifierResolver valueResolver() { + public AxiomNameResolver valueResolver() { return resolver; } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java index 441616e905e..8109f24cc51 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrStatementSource.java @@ -19,7 +19,7 @@ import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.api.stream.AxiomItemStream.TargetWithResolver; import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class AxiomAntlrStatementSource { @@ -66,16 +66,16 @@ public final void stream(AxiomItemStream.TargetWithResolver target) { } public void stream(AxiomItemStream.TargetWithResolver target, Optional> emitOnly) { - stream(target, emitOnly, AxiomIdentifierResolver.nullResolver()); + stream(target, emitOnly, AxiomNameResolver.nullResolver()); } public final void stream(TargetWithResolver target, Optional> emitOnly, - AxiomIdentifierResolver resolver) { + AxiomNameResolver resolver) { AxiomAntlrVisitor2 visitor = new AxiomAntlrVisitor2<>(sourceName, target, emitOnly.orElse(null), resolver); visitor.visit(root); } - public final void stream(AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Target listener, + public final void stream(AxiomNameResolver statements, AxiomNameResolver arguments, AxiomItemStream.Target listener, Optional> emitOnly) { AxiomAntlrVisitor visitor = new AxiomAntlrVisitor<>(sourceName, statements, arguments, listener, emitOnly.orElse(null)); visitor.visit(root); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index fe39ebcde80..e3c34c2e10a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -11,16 +11,16 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.api.stream.AxiomItemStream.Target; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; @Deprecated public class AxiomAntlrVisitor extends AbstractAxiomAntlrVisitor { - private final AxiomIdentifierResolver statements; - private final AxiomIdentifierResolver arguments; + private final AxiomNameResolver statements; + private final AxiomNameResolver arguments; private final AxiomItemStream.Target delegate; - public AxiomAntlrVisitor(String name, AxiomIdentifierResolver statements, AxiomIdentifierResolver arguments, AxiomItemStream.Target delegate, + public AxiomAntlrVisitor(String name, AxiomNameResolver statements, AxiomNameResolver arguments, AxiomItemStream.Target delegate, Set limit) { super(name, limit); this.statements = statements; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java index 9cb928e7d56..5d47b45e9f1 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor2.java @@ -11,15 +11,15 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.api.stream.AxiomItemStream.Target; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; public class AxiomAntlrVisitor2 extends AbstractAxiomAntlrVisitor { private final AxiomItemStream.TargetWithResolver delegate; - private final AxiomIdentifierResolver sourceLocal; + private final AxiomNameResolver sourceLocal; public AxiomAntlrVisitor2(String name, AxiomItemStream.TargetWithResolver delegate, - Set limit, AxiomIdentifierResolver resolver) { + Set limit, AxiomNameResolver resolver) { super(name, limit); this.delegate = delegate; this.sourceLocal = resolver; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index 201277f1aab..c36ee6d6fc2 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -21,10 +21,10 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream.TargetWithResolver; import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; -public class AxiomModelStatementSource extends AxiomAntlrStatementSource implements AxiomIdentifierResolver { +public class AxiomModelStatementSource extends AxiomAntlrStatementSource implements AxiomNameResolver { private static final String IMPORT = "import"; private static final String NAMESPACE = "namespace"; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java index 2b9493be2dc..a10e43f8913 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ItemContext.java @@ -13,7 +13,7 @@ import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ItemBuilder; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; @@ -103,12 +103,12 @@ public V onlyValue() { } @Override - public AxiomIdentifierResolver itemResolver() { + public AxiomNameResolver itemResolver() { return rootImpl().itemResolver(); } @Override - public AxiomIdentifierResolver valueResolver() { + public AxiomNameResolver valueResolver() { return rootImpl().valueResolver(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 656c0aa629d..59c5b15e7d7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -26,7 +26,7 @@ import com.evolveum.axiom.lang.api.AxiomBuiltIn; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; import com.evolveum.axiom.lang.spi.AxiomIdentifierDefinitionImpl; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomItemDefinitionImpl; import com.evolveum.axiom.lang.spi.AxiomSemanticException; import com.evolveum.axiom.lang.spi.AxiomTypeDefinitionImpl; @@ -38,7 +38,7 @@ public class ModelReactorContext extends RuleReactorContext, ValueActionImpl, RuleContextImpl> - implements AxiomIdentifierResolver { + implements AxiomNameResolver { private static final AxiomName ROOT = AxiomName.from("root", "root"); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 62e26a2629a..91db53aee1e 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -12,7 +12,7 @@ import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.antlr.AxiomModelStatementSource; import com.evolveum.axiom.lang.api.IdentifierSpaceKey; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.api.stream.AxiomBuilderStreamTarget.ValueBuilder; import com.evolveum.axiom.reactor.Dependency; import com.google.common.base.Preconditions; @@ -97,7 +97,7 @@ public void exportIdentifierSpace(IdentifierSpaceKey namespaceId) { } @Override - public AxiomIdentifierResolver itemResolver() { + public AxiomNameResolver itemResolver() { return axiomAsConditionalDefault().or((prefix, localName) -> { String namespace = imports.get(prefix); return AxiomName.from(namespace, localName); @@ -105,8 +105,8 @@ public AxiomIdentifierResolver itemResolver() { } @Override - public AxiomIdentifierResolver valueResolver() { - return AxiomIdentifierResolver.BUILTIN_TYPES.or((prefix, localName) -> { + public AxiomNameResolver valueResolver() { + return AxiomNameResolver.BUILTIN_TYPES.or((prefix, localName) -> { String namespace = imports.get(prefix); return AxiomName.from(namespace, localName); }); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java index 4ad072c7ee9..38434baf16a 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ValueContext.java @@ -24,7 +24,7 @@ import com.evolveum.axiom.api.schema.AxiomTypeDefinition; import com.evolveum.axiom.api.schema.AxiomIdentifierDefinition.Scope; import com.evolveum.axiom.concepts.SourceLocation; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomSemanticException; public class ValueContext extends AbstractContext> implements AxiomValueContext, ValueBuilder, Dependency> { @@ -376,7 +376,7 @@ public AxiomSemanticException error(String message, Object... arguments) { } @Override - public AxiomIdentifierResolver itemResolver() { + public AxiomNameResolver itemResolver() { return (prefix, localName) -> { if(Strings.isNullOrEmpty(prefix)) { AxiomName localNs = AxiomName.local(localName); @@ -402,7 +402,7 @@ public AxiomValue lazyValue() { } @Override - public AxiomIdentifierResolver valueResolver() { + public AxiomNameResolver valueResolver() { return rootImpl().valueResolver(); } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomNameResolver.java similarity index 76% rename from infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java rename to infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomNameResolver.java index f308f827067..43405befbc7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomIdentifierResolver.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/spi/AxiomNameResolver.java @@ -20,30 +20,30 @@ import org.jetbrains.annotations.Nullable; -public interface AxiomIdentifierResolver { +public interface AxiomNameResolver { - final AxiomIdentifierResolver AXIOM_DEFAULT_NAMESPACE = defaultNamespace(AxiomName.AXIOM_NAMESPACE); + final AxiomNameResolver AXIOM_DEFAULT_NAMESPACE = defaultNamespace(AxiomName.AXIOM_NAMESPACE); final Set BUILTINS = ImmutableSet.of("string","boolean","uri", "int", "binary", "dateTime"); - final AxiomIdentifierResolver BUILTIN_TYPES = (prefix, localName) -> { + final AxiomNameResolver BUILTIN_TYPES = (prefix, localName) -> { if((prefix == null || prefix.isEmpty()) && BUILTINS.contains(localName)) { return AxiomName.axiom(localName); } return null; }; - final AxiomIdentifierResolver NULL_RESOLVER = (p, n) -> null; + final AxiomNameResolver NULL_RESOLVER = (p, n) -> null; AxiomName resolveIdentifier(@Nullable String prefix, @NotNull String localName); - static AxiomIdentifierResolver defaultNamespace(String namespace) { + static AxiomNameResolver defaultNamespace(String namespace) { return (prefix, localName) -> Strings.isNullOrEmpty(prefix) ? AxiomName.from(namespace, localName) : null; } - static AxiomIdentifierResolver nullResolver() { + static AxiomNameResolver nullResolver() { return NULL_RESOLVER; } - default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { + default AxiomNameResolver or(AxiomNameResolver next) { return (prefix, localName) -> { AxiomName maybe = this.resolveIdentifier(prefix, localName); if (maybe != null) { @@ -53,7 +53,7 @@ default AxiomIdentifierResolver or(AxiomIdentifierResolver next) { }; } - static AxiomIdentifierResolver defaultNamespaceFromType(AxiomTypeDefinition type) { + static AxiomNameResolver defaultNamespaceFromType(AxiomTypeDefinition type) { return (prefix, localName) -> { if(Strings.isNullOrEmpty(prefix)) { AxiomName localNs = AxiomName.local(localName); diff --git a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java index 13a61a45f02..3f6661196c5 100644 --- a/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java +++ b/infra/axiom/src/test/java/com/evolveum/axiom/lang/test/TestTypeDerivation.java @@ -27,7 +27,7 @@ import com.evolveum.axiom.api.stream.AxiomItemTarget; import com.evolveum.axiom.lang.antlr.AxiomAntlrStatementSource; import com.evolveum.axiom.lang.impl.ModelReactorContext; -import com.evolveum.axiom.lang.spi.AxiomIdentifierResolver; +import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; public class TestTypeDerivation extends AbstractReactorTest { @@ -65,7 +65,7 @@ public void axiomTestInheritance() throws IOException, AxiomSyntaxException { public void axiomData() throws AxiomSyntaxException, FileNotFoundException, IOException { AxiomSchemaContext context = loadModel(); AxiomAntlrStatementSource stream = dataSource(JOHN_DOE_FILE); - AxiomItemTarget target = new AxiomItemTarget(context, AxiomIdentifierResolver.defaultNamespace(DERIVED_PERSON.namespace())); + AxiomItemTarget target = new AxiomItemTarget(context, AxiomNameResolver.defaultNamespace(DERIVED_PERSON.namespace())); stream.stream(target); AxiomItem root = target.get(); assertEquals(root.name(), DERIVED_PERSON.localName("person")); From cb709a0f7482349948abb49dc43e03bc13333ea8 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 9 Jun 2020 15:12:58 +0200 Subject: [PATCH 54/60] Axiom: Renamed extends to superType Signed-off-by: Tony Tkacik --- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 2 +- .../axiom/lang/impl/SourceContext.java | 10 +++- .../src/main/resources/axiom-base-types.axiom | 1 + .../axiom/src/main/resources/axiom-lang.axiom | 47 +++++++++++++++---- .../multimodel/derived/derived-person.axiom | 2 +- .../test/resources/prism/common-core.axiom | 8 ++-- .../test/resources/prism/common-core.prism | 8 ++-- .../src/test/resources/prism/prism.axiom | 12 ++--- .../axiom/src/test/resources/scripting.axiom | 6 +-- 9 files changed, 67 insertions(+), 29 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index 9a4f7bceafe..fc25646a349 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -41,7 +41,7 @@ public static class Item implements AxiomItemDefinition { 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 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) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java index 91db53aee1e..b0d90df893b 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/SourceContext.java @@ -100,7 +100,10 @@ public void exportIdentifierSpace(IdentifierSpaceKey namespaceId) { public AxiomNameResolver itemResolver() { return axiomAsConditionalDefault().or((prefix, localName) -> { String namespace = imports.get(prefix); - return AxiomName.from(namespace, localName); + if(namespace != null) { + return AxiomName.from(namespace, localName); + } + return null; }); } @@ -108,7 +111,10 @@ public AxiomNameResolver itemResolver() { public AxiomNameResolver valueResolver() { return AxiomNameResolver.BUILTIN_TYPES.or((prefix, localName) -> { String namespace = imports.get(prefix); - return AxiomName.from(namespace, localName); + if(namespace != null) { + return AxiomName.from(namespace, localName); + } + return null; }); } } diff --git a/infra/axiom/src/main/resources/axiom-base-types.axiom b/infra/axiom/src/main/resources/axiom-base-types.axiom index 05a74eaf591..d66d9f83660 100644 --- a/infra/axiom/src/main/resources/axiom-base-types.axiom +++ b/infra/axiom/src/main/resources/axiom-base-types.axiom @@ -18,4 +18,5 @@ model axiom-base-types { type binary; type dateTime; + type anyType; } diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index 66f3d7617d9..b886ae9a3fe 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -8,9 +8,40 @@ model axiom-lang { """; type AxiomModel; } + + type AxiomValue { + item type { + type AxiomTypeReference; + } + } + + type AxiomSimpleValue { + superType AxiomValue; + argument value; + item value { + type anyType; + } + } + + type AxiomComplexValue { + superType AxiomValue; + item item { + type AxiomItem; + } + } + + type AxiomItem { + item definition { + type AxiomItemDefinition; + operational true; + } + item value { + type AxiomValue; + } + } type AxiomModel { - extends AxiomBaseDefinition; + superType AxiomBaseDefinition; item namespace { type string; @@ -85,7 +116,7 @@ model axiom-lang { } type AxiomRootDefinition { - extends AxiomItemDefinition; + superType AxiomItemDefinition; documentation """ Root item definition. @@ -125,7 +156,7 @@ model axiom-lang { } type AxiomTypeDefinition { - extends AxiomBaseDefinition; + superType AxiomBaseDefinition; documentation """ Definition of value type. @@ -142,7 +173,7 @@ model axiom-lang { } // FIXME: should be inherit - item extends { + item superType { type AxiomTypeReference; documentation """ Reference to super type definition, which is subtyped by this type. @@ -183,7 +214,7 @@ model axiom-lang { } type AxiomItemDefinition { - extends AxiomBaseDefinition; + superType AxiomBaseDefinition; item identifier { type AxiomIdentifierDefinition; @@ -264,18 +295,18 @@ model axiom-lang { } type AxiomMixinDefinition { - extends AxiomTypeDefinition; + superType AxiomTypeDefinition; } type AxiomAugmentationDefinition { - extends AxiomMixinDefinition; + superType AxiomMixinDefinition; item target { type AxiomTypeReference; } } type SemanticVersion { - extends string; + superType string; } } diff --git a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom index 485cfe16761..7883978a0a2 100644 --- a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom +++ b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom @@ -11,7 +11,7 @@ model derived-person { } type Person { - extends base:Person; + superType base:Person; item firstName { type string; diff --git a/infra/axiom/src/test/resources/prism/common-core.axiom b/infra/axiom/src/test/resources/prism/common-core.axiom index b0145ce6fa3..9eed9efaad9 100644 --- a/infra/axiom/src/test/resources/prism/common-core.axiom +++ b/infra/axiom/src/test/resources/prism/common-core.axiom @@ -234,7 +234,7 @@ model common-core { } type AssignmentHolder { - extends Object; + superType Object; prism:itemName assignmentHolder; documentation """ Abstract supertype for all object types that can have assignments. @@ -360,7 +360,7 @@ model common-core { } type Focus { - extends AssignmentHolder; + superType AssignmentHolder; prism:itemName focus; documentation """ Abstract supertype for all object types that can be focus of full midPoint computation. @@ -540,7 +540,7 @@ model common-core { } type User { - extends Focus; + superType Focus; documentation """ User object represents a physical user of the system. It differs from the account, as "account" represents a data structure in a target system while @@ -911,7 +911,7 @@ model common-core { } prism:object GenericObject { - extends Focus; + superType Focus; prism:itemName genericObject; documentation """ Generic object for storing unknown (unexpected) object types. diff --git a/infra/axiom/src/test/resources/prism/common-core.prism b/infra/axiom/src/test/resources/prism/common-core.prism index 1dba7175fab..05f320877a8 100644 --- a/infra/axiom/src/test/resources/prism/common-core.prism +++ b/infra/axiom/src/test/resources/prism/common-core.prism @@ -234,7 +234,7 @@ prism:model common-core { } type AssignmentHolder { - extends Object; + superType Object; itemName assignmentHolder; documentation """ Abstract supertype for all object types that can have assignments. @@ -360,7 +360,7 @@ prism:model common-core { } type Focus { - extends AssignmentHolder; + superType AssignmentHolder; itemName focus; documentation """ Abstract supertype for all object types that can be focus of full midPoint computation. @@ -540,7 +540,7 @@ prism:model common-core { } type User { - extends Focus; + superType Focus; documentation """ User object represents a physical user of the system. It differs from the account, as "account" represents a data structure in a target system while @@ -911,7 +911,7 @@ prism:model common-core { } object GenericObject { - extends Focus; + superType Focus; itemName genericObject; documentation """ Generic object for storing unknown (unexpected) object types. diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom index 39571c15023..ef158d1b46d 100644 --- a/infra/axiom/src/test/resources/prism/prism.axiom +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -27,7 +27,7 @@ model prism { } type PrismModel { - extends axiom:AxiomModel; + superType axiom:AxiomModel; item type { // {}:type type PrismTypeDefinition; } @@ -54,23 +54,23 @@ model prism { } type PrismTypeDefinition { - extends axiom:AxiomTypeDefinition; + superType axiom:AxiomTypeDefinition; } type PrismObjectDefinition { - extends PrismTypeDefinition; + superType PrismTypeDefinition; } type PrismContainerDefinition { - extends PrismTypeDefinition; + superType PrismTypeDefinition; } type PrismReferenceDefinition { - extends PrismTypeDefinition; + superType PrismTypeDefinition; } type PrismItemDefinition { - extends PrismTypeDefinition; + superType PrismTypeDefinition; } } diff --git a/infra/axiom/src/test/resources/scripting.axiom b/infra/axiom/src/test/resources/scripting.axiom index c484847ddc1..97f3d5b7582 100644 --- a/infra/axiom/src/test/resources/scripting.axiom +++ b/infra/axiom/src/test/resources/scripting.axiom @@ -65,7 +65,7 @@ model scripting { } type ExpressionPipeline { - extends ScriptingExpression; + superType ScriptingExpression; documentation """ Pipeline of expressions - they are executed one after another, input sent to the pipeline as a whole is sent to the first expression. @@ -85,7 +85,7 @@ model scripting { } type ExpressionSequence { - extends ScriptingExpression; + superType ScriptingExpression; documentation """ Sequence of expressions - they are executed one after another, input sent to the sequence as a whole is then sent individually @@ -104,7 +104,7 @@ model scripting { } type SearchExpression { - extends ScriptingExpression; + superType ScriptingExpression; documentation """ Queries the model for objects of a given type, optionally fulfilling given condition. """; From 6e6a1f406c5b8bcc311ca1f17396024aed2f1c19 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 11 Jun 2020 11:54:33 +0200 Subject: [PATCH 55/60] Axiom: Switched import declaration argument to namespace Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/api/AxiomName.java | 2 +- .../axiom/lang/antlr/AxiomAntlrVisitor.java | 8 ++++++++ .../lang/antlr/AxiomModelStatementSource.java | 20 +++++++++++++++++-- .../evolveum/axiom/lang/api/AxiomModel.java | 2 +- .../axiom/reactor/BaseReactorContext.java | 18 ++++++++--------- .../src/main/resources/axiom-base-types.axiom | 2 +- .../axiom/src/main/resources/axiom-lang.axiom | 4 ++-- .../multimodel/derived/derived-person.axiom | 4 ++-- .../extension/language-extension-use.axiom | 4 ++-- .../extension/language-extension.axiom | 4 ++-- .../extension/person-extension.axiom | 4 ++-- .../multimodel/ref/test-person.axiom | 8 ++++---- .../test/resources/prism/common-core.axiom | 4 ++-- .../test/resources/prism/common-core.prism | 4 ++-- .../src/test/resources/prism/prism.axiom | 4 ++-- 15 files changed, 58 insertions(+), 34 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java index 46d14346409..7f4b56d5b41 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java @@ -13,7 +13,7 @@ public class AxiomName { - public static final String AXIOM_NAMESPACE = "https://ns.evolveum.com/axiom/language"; + public static final String AXIOM_NAMESPACE = "https://schema.evolveum.com/ns/axiom/model"; private final String namespace; private final String localName; diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java index e3c34c2e10a..28222843d2f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrVisitor.java @@ -11,6 +11,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream; import com.evolveum.axiom.api.stream.AxiomItemStream.Target; +import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; import com.evolveum.axiom.lang.spi.AxiomNameResolver; @Deprecated @@ -43,4 +44,11 @@ protected Target delegate() { return delegate; } + public static String convertToString(ArgumentContext argument) { + if((argument.string() != null)) { + return convert(argument.string()); + } + return argument.getText(); + } + } diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java index c36ee6d6fc2..d26178d27bb 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomModelStatementSource.java @@ -20,6 +20,7 @@ import com.evolveum.axiom.api.AxiomName; import com.evolveum.axiom.api.stream.AxiomItemStream.TargetWithResolver; +import com.evolveum.axiom.concepts.SourceLocation; import com.evolveum.axiom.lang.antlr.AxiomParser.ItemContext; import com.evolveum.axiom.lang.spi.AxiomNameResolver; import com.evolveum.axiom.lang.spi.AxiomSyntaxException; @@ -28,6 +29,7 @@ public class AxiomModelStatementSource extends AxiomAntlrStatementSource impleme private static final String IMPORT = "import"; private static final String NAMESPACE = "namespace"; + private static final String PREFIX = "prefix"; private String name; private Map imports; @@ -42,9 +44,15 @@ public static AxiomModelStatementSource from(String sourceName, InputStream stre } public static AxiomModelStatementSource from(String sourceName, CharStream stream) throws AxiomSyntaxException { + try { ItemContext root = AxiomAntlrStatementSource.contextFrom(sourceName, stream); String name = root.itemBody().value().argument().identifier().localIdentifier().getText(); return new AxiomModelStatementSource(sourceName, root, name, namespace(root.itemBody().value()), imports(root.itemBody().value())); + } catch (AxiomSyntaxException e) { + throw e; + } catch (Exception e) { + throw new AxiomSyntaxException(SourceLocation.from(sourceName, 0, 0), "Unexpected error", e); + } } private AxiomModelStatementSource(String sourceName, ItemContext statement, String namespace, String name, Map imports) { @@ -72,23 +80,31 @@ public Map imports() { return imports; } + // FIXME: Use schema & AxiomItemTarget to get base model data? public static Map imports(AxiomParser.ValueContext root) { Map prefixMap = new HashMap<>(); root.item().stream().filter(s -> IMPORT.equals(s.itemBody().identifier().getText())).forEach(c -> { - String prefix = c.itemBody().value().argument().identifier().localIdentifier().getText(); - String namespace = namespace(c.itemBody().value()); + String namespace = AxiomAntlrVisitor.convert(c.itemBody().value().argument().string()); + String prefix = prefix(c.itemBody().value()); prefixMap.put(prefix, namespace); }); prefixMap.put("",namespace(root)); return prefixMap; } + private static String namespace(AxiomParser.ValueContext c) { return AxiomAntlrVisitor.convert(c.item() .stream().filter(s -> NAMESPACE.equals(s.itemBody().identifier().getText())) .findFirst().get().itemBody().value().argument().string()); } + private static String prefix(AxiomParser.ValueContext c) { + return AxiomAntlrVisitor.convertToString(c.item() + .stream().filter(s -> PREFIX.equals(s.itemBody().identifier().getText())) + .findFirst().get().itemBody().value().argument()); + } + @Override public AxiomName resolveIdentifier(@Nullable String prefix, @NotNull String localName) { if(prefix == null) { diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java index c759c1c6c86..398feda6121 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomModel.java @@ -6,7 +6,7 @@ public interface AxiomModel { AxiomName NAMESPACE = AxiomName.axiom("namespace"); AxiomName IMPORTED_NAMESPACE = AxiomName.axiom("ImportedNamespace"); - String BUILTIN_TYPES = "https://ns.evolveum.com/axiom/language"; + String BUILTIN_TYPES = "https://schema.evolveum.com/ns/axiom/model"; String name(); String namespace(); diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java index 024d0178a29..ff1f6d9a13f 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/reactor/BaseReactorContext.java @@ -18,16 +18,16 @@ public void compute() throws E { Iterator iterator = toCheck.iterator(); while (iterator.hasNext()) { A action = iterator.next(); - if (action.canApply()) { - try { - action.apply(); - } catch (Exception e) { - fail(action, e); - } - if(action.successful()) { - iterator.remove(); - anyActionCompleted = true; + try { + if (action.canApply()) { + action.apply(); } + } catch (Exception e) { + action.fail(e); + } + if(action.successful()) { + iterator.remove(); + anyActionCompleted = true; } } // We add not finished items back to outstanding diff --git a/infra/axiom/src/main/resources/axiom-base-types.axiom b/infra/axiom/src/main/resources/axiom-base-types.axiom index d66d9f83660..f431b80c95c 100644 --- a/infra/axiom/src/main/resources/axiom-base-types.axiom +++ b/infra/axiom/src/main/resources/axiom-base-types.axiom @@ -8,7 +8,7 @@ model axiom-base-types { - namespace "https://ns.evolveum.com/axiom/language"; + namespace "https://schema.evolveum.com/ns/axiom/model"; version "0.1.0"; type string; diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-lang.axiom index b886ae9a3fe..2abed0d8b64 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-lang.axiom @@ -1,6 +1,6 @@ model axiom-lang { - namespace "https://ns.evolveum.com/axiom/language"; + namespace "https://schema.evolveum.com/ns/axiom/model"; root model { documentation """ @@ -104,7 +104,7 @@ model axiom-lang { } type AxiomImportDeclaration { - argument prefix; + argument namespace; item prefix { type AxiomName; diff --git a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom index 7883978a0a2..d04b6968a4e 100644 --- a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom +++ b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom @@ -2,8 +2,8 @@ model derived-person { namespace "https://example.org/derived"; - import base { - namespace "https://example.org/base"; + import "https://example.org/base" { + prefix base; } root person { diff --git a/infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom b/infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom index 82c20a7f609..9f40e921369 100644 --- a/infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom +++ b/infra/axiom/src/test/resources/multimodel/extension/language-extension-use.axiom @@ -2,8 +2,8 @@ model language-extension-use { namespace "https://example.org"; - import storage { - namespace "https://example.org/extension"; + import "https://example.org/extension" { + prefix storage; } type Address { diff --git a/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom b/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom index 436e147e001..d18c15d1ea2 100644 --- a/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom +++ b/infra/axiom/src/test/resources/multimodel/extension/language-extension.axiom @@ -2,8 +2,8 @@ model language-extension { namespace "https://example.org/extension"; - import axiom { - namespace "https://ns.evolveum.com/axiom/language"; + import "https://schema.evolveum.com/ns/axiom/model" { + prefix axiom; } augmentation Storage { diff --git a/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom b/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom index 7930c4c2430..c0881c6de47 100644 --- a/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom +++ b/infra/axiom/src/test/resources/multimodel/extension/person-extension.axiom @@ -2,8 +2,8 @@ model schema-org-person { namespace "https://schema.org"; - import base { - namespace "https://example.org"; + import "https://example.org" { + prefix base; } augmentation SchemaOrgPerson { diff --git a/infra/axiom/src/test/resources/multimodel/ref/test-person.axiom b/infra/axiom/src/test/resources/multimodel/ref/test-person.axiom index 6f2700eef3f..b0bbeef0b53 100644 --- a/infra/axiom/src/test/resources/multimodel/ref/test-person.axiom +++ b/infra/axiom/src/test/resources/multimodel/ref/test-person.axiom @@ -2,11 +2,11 @@ model schema-org-person { namespace "https://example.org"; - import foaf { - namespace "http://xmlns.com/foaf/0.1/"; + import "http://xmlns.com/foaf/0.1/" { + prefix foaf; } - import schemaOrg { - namespace "https://schema.org"; + import "https://schema.org" { + prefix schemaOrg; } type Person { diff --git a/infra/axiom/src/test/resources/prism/common-core.axiom b/infra/axiom/src/test/resources/prism/common-core.axiom index 9eed9efaad9..c2bbc2bc380 100644 --- a/infra/axiom/src/test/resources/prism/common-core.axiom +++ b/infra/axiom/src/test/resources/prism/common-core.axiom @@ -11,8 +11,8 @@ model common-core { namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; version "3.0.0"; - import prism { - namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; + import "http://midpoint.evolveum.com/xml/ns/public/common/prism" { + prefix prism; } type Object { diff --git a/infra/axiom/src/test/resources/prism/common-core.prism b/infra/axiom/src/test/resources/prism/common-core.prism index 05f320877a8..668a0d0ab5a 100644 --- a/infra/axiom/src/test/resources/prism/common-core.prism +++ b/infra/axiom/src/test/resources/prism/common-core.prism @@ -11,8 +11,8 @@ prism:model common-core { namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; version "3.0.0"; - import prism { - namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; + import "http://midpoint.evolveum.com/xml/ns/public/common/prism" { + prefix prism; } type Object { diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom index ef158d1b46d..dc7e0ea813f 100644 --- a/infra/axiom/src/test/resources/prism/prism.axiom +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -2,8 +2,8 @@ model prism { namespace "http://midpoint.evolveum.com/xml/ns/public/common/prism"; - import axiom { - namespace "https://ns.evolveum.com/axiom/language"; + import "https://schema.evolveum.com/ns/axiom/model" { + prefix axiom; } root model { From 912611e723836a280f4a75575cf54f286f7fc5fd Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 11 Jun 2020 11:57:17 +0200 Subject: [PATCH 56/60] Axiom: Renamed axiom-lang to axiom-model Signed-off-by: Tony Tkacik --- .../com/evolveum/axiom/lang/impl/ModelReactorContext.java | 5 +---- .../main/resources/{axiom-lang.axiom => axiom-model.axiom} | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) rename infra/axiom/src/main/resources/{axiom-lang.axiom => axiom-model.axiom} (99%) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java index 59c5b15e7d7..4cf24594ad7 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/ModelReactorContext.java @@ -11,10 +11,7 @@ import org.jetbrains.annotations.NotNull; import com.evolveum.axiom.api.AxiomName; -import com.evolveum.axiom.api.AxiomValue; import com.evolveum.axiom.api.AxiomValueFactory; -import com.evolveum.axiom.api.ComplexValueImpl; -import com.evolveum.axiom.api.SimpleValue; import com.evolveum.axiom.api.schema.AxiomItemDefinition; import com.evolveum.axiom.api.schema.AxiomSchemaContext; import com.evolveum.axiom.api.schema.AxiomTypeDefinition; @@ -42,7 +39,7 @@ public class ModelReactorContext extends private static final AxiomName ROOT = AxiomName.from("root", "root"); - private static final String AXIOM_LANG_RESOURCE = "/axiom-lang.axiom"; + private static final String AXIOM_LANG_RESOURCE = "/axiom-model.axiom"; private static final String AXIOM_BUILTIN_RESOURCE = "/axiom-base-types.axiom"; private static final Lazy BASE_LANGUAGE_SOURCE = Lazy.from(() -> { diff --git a/infra/axiom/src/main/resources/axiom-lang.axiom b/infra/axiom/src/main/resources/axiom-model.axiom similarity index 99% rename from infra/axiom/src/main/resources/axiom-lang.axiom rename to infra/axiom/src/main/resources/axiom-model.axiom index 2abed0d8b64..78f697a9ad0 100644 --- a/infra/axiom/src/main/resources/axiom-lang.axiom +++ b/infra/axiom/src/main/resources/axiom-model.axiom @@ -1,4 +1,4 @@ -model axiom-lang { +model axiom-model { namespace "https://schema.evolveum.com/ns/axiom/model"; From 2a09360279cbe58be362774ded7903207155fc68 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 11 Jun 2020 12:07:35 +0200 Subject: [PATCH 57/60] Renamed superType to supertype Signed-off-by: Tony Tkacik --- .../evolveum/axiom/lang/api/AxiomBuiltIn.java | 2 +- .../src/main/resources/axiom-model.axiom | 47 +++++++++++-------- .../multimodel/derived/derived-person.axiom | 2 +- .../test/resources/prism/common-core.axiom | 8 ++-- .../test/resources/prism/common-core.prism | 8 ++-- .../src/test/resources/prism/prism.axiom | 12 ++--- .../axiom/src/test/resources/scripting.axiom | 6 +-- 7 files changed, 47 insertions(+), 38 deletions(-) diff --git a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java index fc25646a349..7b3dd106e14 100644 --- a/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java +++ b/infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltIn.java @@ -41,7 +41,7 @@ public static class Item implements AxiomItemDefinition { 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 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) { diff --git a/infra/axiom/src/main/resources/axiom-model.axiom b/infra/axiom/src/main/resources/axiom-model.axiom index 78f697a9ad0..ddd4818739c 100644 --- a/infra/axiom/src/main/resources/axiom-model.axiom +++ b/infra/axiom/src/main/resources/axiom-model.axiom @@ -8,15 +8,33 @@ model axiom-model { """; type AxiomModel; } - + + // Axiom Baseline Types + + type AxiomName { + documentation """ + Qualified name. Consists of namespace and local name. + """; + } + + type SemanticVersion { + supertype string; + } + + + // Axiom Infra Model + type AxiomValue { item type { type AxiomTypeReference; } + item metadata { + type AxiomItem; + } } type AxiomSimpleValue { - superType AxiomValue; + supertype AxiomValue; argument value; item value { type anyType; @@ -24,7 +42,7 @@ model axiom-model { } type AxiomComplexValue { - superType AxiomValue; + supertype AxiomValue; item item { type AxiomItem; } @@ -41,7 +59,7 @@ model axiom-model { } type AxiomModel { - superType AxiomBaseDefinition; + supertype AxiomBaseDefinition; item namespace { type string; @@ -116,7 +134,7 @@ model axiom-model { } type AxiomRootDefinition { - superType AxiomItemDefinition; + supertype AxiomItemDefinition; documentation """ Root item definition. @@ -156,7 +174,7 @@ model axiom-model { } type AxiomTypeDefinition { - superType AxiomBaseDefinition; + supertype AxiomBaseDefinition; documentation """ Definition of value type. @@ -173,7 +191,7 @@ model axiom-model { } // FIXME: should be inherit - item superType { + item supertype { type AxiomTypeReference; documentation """ Reference to super type definition, which is subtyped by this type. @@ -207,14 +225,8 @@ model axiom-model { } - type AxiomName { - documentation """ - Qualified name. Consists of namespace and local name. - """; - } - type AxiomItemDefinition { - superType AxiomBaseDefinition; + supertype AxiomBaseDefinition; item identifier { type AxiomIdentifierDefinition; @@ -295,18 +307,15 @@ model axiom-model { } type AxiomMixinDefinition { - superType AxiomTypeDefinition; + supertype AxiomTypeDefinition; } type AxiomAugmentationDefinition { - superType AxiomMixinDefinition; + supertype AxiomMixinDefinition; item target { type AxiomTypeReference; } } - type SemanticVersion { - superType string; - } } diff --git a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom index d04b6968a4e..c20b688ec54 100644 --- a/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom +++ b/infra/axiom/src/test/resources/multimodel/derived/derived-person.axiom @@ -11,7 +11,7 @@ model derived-person { } type Person { - superType base:Person; + supertype base:Person; item firstName { type string; diff --git a/infra/axiom/src/test/resources/prism/common-core.axiom b/infra/axiom/src/test/resources/prism/common-core.axiom index c2bbc2bc380..33b029b785f 100644 --- a/infra/axiom/src/test/resources/prism/common-core.axiom +++ b/infra/axiom/src/test/resources/prism/common-core.axiom @@ -234,7 +234,7 @@ model common-core { } type AssignmentHolder { - superType Object; + supertype Object; prism:itemName assignmentHolder; documentation """ Abstract supertype for all object types that can have assignments. @@ -360,7 +360,7 @@ model common-core { } type Focus { - superType AssignmentHolder; + supertype AssignmentHolder; prism:itemName focus; documentation """ Abstract supertype for all object types that can be focus of full midPoint computation. @@ -540,7 +540,7 @@ model common-core { } type User { - superType Focus; + supertype Focus; documentation """ User object represents a physical user of the system. It differs from the account, as "account" represents a data structure in a target system while @@ -911,7 +911,7 @@ model common-core { } prism:object GenericObject { - superType Focus; + supertype Focus; prism:itemName genericObject; documentation """ Generic object for storing unknown (unexpected) object types. diff --git a/infra/axiom/src/test/resources/prism/common-core.prism b/infra/axiom/src/test/resources/prism/common-core.prism index 668a0d0ab5a..45a3c9a15d6 100644 --- a/infra/axiom/src/test/resources/prism/common-core.prism +++ b/infra/axiom/src/test/resources/prism/common-core.prism @@ -234,7 +234,7 @@ prism:model common-core { } type AssignmentHolder { - superType Object; + supertype Object; itemName assignmentHolder; documentation """ Abstract supertype for all object types that can have assignments. @@ -360,7 +360,7 @@ prism:model common-core { } type Focus { - superType AssignmentHolder; + supertype AssignmentHolder; itemName focus; documentation """ Abstract supertype for all object types that can be focus of full midPoint computation. @@ -540,7 +540,7 @@ prism:model common-core { } type User { - superType Focus; + supertype Focus; documentation """ User object represents a physical user of the system. It differs from the account, as "account" represents a data structure in a target system while @@ -911,7 +911,7 @@ prism:model common-core { } object GenericObject { - superType Focus; + supertype Focus; itemName genericObject; documentation """ Generic object for storing unknown (unexpected) object types. diff --git a/infra/axiom/src/test/resources/prism/prism.axiom b/infra/axiom/src/test/resources/prism/prism.axiom index dc7e0ea813f..e066455b3b8 100644 --- a/infra/axiom/src/test/resources/prism/prism.axiom +++ b/infra/axiom/src/test/resources/prism/prism.axiom @@ -27,7 +27,7 @@ model prism { } type PrismModel { - superType axiom:AxiomModel; + supertype axiom:AxiomModel; item type { // {}:type type PrismTypeDefinition; } @@ -54,23 +54,23 @@ model prism { } type PrismTypeDefinition { - superType axiom:AxiomTypeDefinition; + supertype axiom:AxiomTypeDefinition; } type PrismObjectDefinition { - superType PrismTypeDefinition; + supertype PrismTypeDefinition; } type PrismContainerDefinition { - superType PrismTypeDefinition; + supertype PrismTypeDefinition; } type PrismReferenceDefinition { - superType PrismTypeDefinition; + supertype PrismTypeDefinition; } type PrismItemDefinition { - superType PrismTypeDefinition; + supertype PrismTypeDefinition; } } diff --git a/infra/axiom/src/test/resources/scripting.axiom b/infra/axiom/src/test/resources/scripting.axiom index 97f3d5b7582..1eac0017932 100644 --- a/infra/axiom/src/test/resources/scripting.axiom +++ b/infra/axiom/src/test/resources/scripting.axiom @@ -65,7 +65,7 @@ model scripting { } type ExpressionPipeline { - superType ScriptingExpression; + supertype ScriptingExpression; documentation """ Pipeline of expressions - they are executed one after another, input sent to the pipeline as a whole is sent to the first expression. @@ -85,7 +85,7 @@ model scripting { } type ExpressionSequence { - superType ScriptingExpression; + supertype ScriptingExpression; documentation """ Sequence of expressions - they are executed one after another, input sent to the sequence as a whole is then sent individually @@ -104,7 +104,7 @@ model scripting { } type SearchExpression { - superType ScriptingExpression; + supertype ScriptingExpression; documentation """ Queries the model for objects of a given type, optionally fulfilling given condition. """; From 5f0884785ce5c87f8e9d4c10619a1feac37e6d94 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 11 Jun 2020 12:30:43 +0200 Subject: [PATCH 58/60] Axiom: Reordered axiom-model to logical groups Signed-off-by: Tony Tkacik --- .../src/main/resources/axiom-model.axiom | 224 ++++++++++-------- 1 file changed, 130 insertions(+), 94 deletions(-) diff --git a/infra/axiom/src/main/resources/axiom-model.axiom b/infra/axiom/src/main/resources/axiom-model.axiom index ddd4818739c..930ab977434 100644 --- a/infra/axiom/src/main/resources/axiom-model.axiom +++ b/infra/axiom/src/main/resources/axiom-model.axiom @@ -24,6 +24,19 @@ model axiom-model { // Axiom Infra Model + type AxiomItem { + item name { + type AxiomName; + } + item definition { + type AxiomItemDefinition; + operational true; + } + item value { + type AxiomValue; + } + } + type AxiomValue { item type { type AxiomTypeReference; @@ -48,99 +61,7 @@ model axiom-model { } } - type AxiomItem { - item definition { - type AxiomItemDefinition; - operational true; - } - item value { - type AxiomValue; - } - } - - type AxiomModel { - supertype AxiomBaseDefinition; - - item namespace { - type string; - documentation """ - Namespace of model. - """; - } - - item version { - type SemanticVersion; - documentation """ - Version of model. - - Model versioning follows Semantic Versioning 2.0. - """; - } - - item import { - type AxiomImportDeclaration; - documentation """ - Declaration of model imports. - - Type definitions from imported models are referencable and - visible to all definition contained in this model. - """; - } - - item root { - documentation """ - Defines allowed root type for value serialization / deserialization. - """; - type AxiomRootDefinition; - } - - item type { - type AxiomTypeDefinition; - documentation """ - Declaration of a type. This type is visible to models - importing parent model namespace. - """; - } - - item mixin { - type AxiomMixinDefinition; - documentation """ - Declaration of mixin, a set of reusable item - definitions, which can be used in type definitions. - """; - } - - // FIXME: should be augmentation - item augmentation { - type AxiomAugmentationDefinition; - documentation """ - Declaration of augmentation. Augmentation adds new items - to already existing type, which can be defined in other - models (namespaces). - """; - } - } - - type AxiomImportDeclaration { - argument namespace; - - item prefix { - type AxiomName; - } - - item namespace { - type string; - } - } - - type AxiomRootDefinition { - supertype AxiomItemDefinition; - documentation """ - Root item definition. - - Root item is item which can be root of the serialized / deserialized document. - """; - } + // Axiom Schema type AxiomBaseDefinition { argument name; @@ -231,7 +152,7 @@ model axiom-model { item identifier { type AxiomIdentifierDefinition; documentation """ - Definition of value identifiers for this item. + Definition of value identifier for this item. """; minOccurs 0; } @@ -240,6 +161,7 @@ model axiom-model { type AxiomTypeReference; documentation """ Value type. + item minOccurs { All values must be instances or referenced type or it's subtypes. """; @@ -272,6 +194,120 @@ model axiom-model { type boolean; operational true; } + + item default { + type anyType; // This should somehow be same type as value of type + documentation """ + Declares default value for item. + """; + minOccurs 0; + maxOccurs 1; + } + + item infra { + type InfraSpecification; + //default { + // value AxiomValue; + // item AxiomItem; + //} + } + } + + type AxiomRootDefinition { + supertype AxiomItemDefinition; + documentation """ + Root item definition. + + Root item is item which can be root of the serialized / deserialized document. + """; + } + + // Axiom Model? + + type AxiomModel { + supertype AxiomBaseDefinition; + + item namespace { + type string; + documentation """ + Namespace of model. + """; + } + + item version { + type SemanticVersion; + documentation """ + Version of model. + + Model versioning follows Semantic Versioning 2.0. + """; + } + + item import { + type AxiomImportDeclaration; + documentation """ + Declaration of model imports. + + Type definitions from imported models are referencable and + visible to all definition contained in this model. + """; + } + + item root { + documentation """ + Defines allowed root type for value serialization / deserialization. + """; + type AxiomRootDefinition; + } + + item type { + type AxiomTypeDefinition; + documentation """ + Declaration of a type. This type is visible to models + importing parent model namespace. + """; + } + + item mixin { + type AxiomMixinDefinition; + documentation """ + Declaration of mixin, a set of reusable item + definitions, which can be used in type definitions. + """; + } + + // FIXME: should be augmentation + item augmentation { + type AxiomAugmentationDefinition; + documentation """ + Declaration of augmentation. Augmentation adds new items + to already existing type, which can be defined in other + models (namespaces). + """; + } + } + + type AxiomImportDeclaration { + argument namespace; + + item prefix { + type AxiomName; + } + + item namespace { + type string; + } + } + + type InfraSpecification { + item value { + type AxiomTypeReference; + // default AxiomValue; + } + item item { + type AxiomTypeReference; + // default AxiomItem; + } } type AxiomTypeReference { From 2bb09e71bf88e32a7759a57c5c113a46028481e9 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 11 Jun 2020 16:34:04 +0200 Subject: [PATCH 59/60] Axiom: Added metadata statement to language Signed-off-by: Tony Tkacik --- .../src/main/resources/axiom-model.axiom | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/infra/axiom/src/main/resources/axiom-model.axiom b/infra/axiom/src/main/resources/axiom-model.axiom index 930ab977434..a9be563338b 100644 --- a/infra/axiom/src/main/resources/axiom-model.axiom +++ b/infra/axiom/src/main/resources/axiom-model.axiom @@ -21,7 +21,8 @@ model axiom-model { supertype string; } - + type ItemCompleteness; // FIXME: Add definition + type ValueSignificance; // FIXME: Add definition // Axiom Infra Model type AxiomItem { @@ -35,12 +36,19 @@ model axiom-model { item value { type AxiomValue; } + + item completeness { + type ItemCompleteness; + } } type AxiomValue { item type { type AxiomTypeReference; } + item significance { + type ValueSignificance; + } item metadata { type AxiomItem; } @@ -285,6 +293,10 @@ model axiom-model { models (namespaces). """; } + + item metadata { + type AxiomMetadataDefinition; + } } type AxiomImportDeclaration { @@ -353,5 +365,12 @@ model axiom-model { } } + type AxiomMetadataDefinition { + supertype AxiomTypeDefinition; + //item itemName { + // type AxiomName; + //} + // TODO: Add limits for specific types + } } From f296694f8caa2e6d961a382e4061fe23c1dad7e4 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 11 Jun 2020 16:35:27 +0200 Subject: [PATCH 60/60] Axiom: Introduced ValueMetadata base type Signed-off-by: Tony Tkacik --- infra/axiom/src/main/resources/axiom-model.axiom | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/infra/axiom/src/main/resources/axiom-model.axiom b/infra/axiom/src/main/resources/axiom-model.axiom index a9be563338b..9d87f758ccb 100644 --- a/infra/axiom/src/main/resources/axiom-model.axiom +++ b/infra/axiom/src/main/resources/axiom-model.axiom @@ -23,6 +23,7 @@ model axiom-model { type ItemCompleteness; // FIXME: Add definition type ValueSignificance; // FIXME: Add definition + type ValueMetadata; // Axiom Infra Model type AxiomItem { @@ -50,7 +51,7 @@ model axiom-model { type ValueSignificance; } item metadata { - type AxiomItem; + type ValueMetadata; } }