From af4085125e4c1e3550ffdb051b55ec5712730dab Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 24 Mar 2021 09:51:29 +0100 Subject: [PATCH] Add SchemaInferenceStack.enterSchemaTree(SchemaNodeIdentifier) SchemaNodeIdentifier is a well-known concept which we are integrating with in multiple aspects. One key component is the ability to resolve a SchemaNodeIdentifier in the context of an existing stack. While users can do this easily themselves, it is more natural to provide this ability out of the box. JIRA: YANGTOOLS-1231 Change-Id: I9818f175d09fd4e6e4f610127929ee8553c3116e Signed-off-by: Robert Varga --- .../yang/model/util/SchemaInferenceStack.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaInferenceStack.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaInferenceStack.java index b8f50c4752..86e026ecff 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaInferenceStack.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaInferenceStack.java @@ -51,6 +51,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeAwareEffectiveStat import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement; @@ -392,6 +393,28 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex return pushSchema(requireNonNull(nodeIdentifier)); } + /** + * Lookup a {@code schema tree} node by its schema node identifier and push it to the stack. + * + * @param nodeIdentifier Schema node identifier of the schema tree node to enter + * @return Resolved schema tree node + * @throws NullPointerException if {@code nodeIdentifier} is null + * @throws IllegalArgumentException if the corresponding node cannot be found + */ + public @NonNull SchemaTreeEffectiveStatement enterSchemaTree(final SchemaNodeIdentifier nodeIdentifier) { + if (nodeIdentifier instanceof Absolute) { + clear(); + } + + final Iterator it = nodeIdentifier.getNodeIdentifiers().iterator(); + SchemaTreeEffectiveStatement ret; + do { + ret = enterSchemaTree(it.next()); + } while (it.hasNext()); + + return ret; + } + /** * Lookup a {@code schema tree} child by its node identifier and push it to the stack. * -- 2.36.6