Class SchemaInferenceStack
java.lang.Object
org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack
- All Implemented Interfaces:
Mutable
,org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider
,LeafrefResolver
@Beta
public final class SchemaInferenceStack
extends Object
implements Mutable, org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider, LeafrefResolver
A state tracking utility for walking
EffectiveModelContext
's contents along schema/grouping namespaces. This
is conceptually a stack, tracking EffectiveStatement
s encountered along traversal.
This is meant to be a replacement concept for the use of SchemaPath
in various places, notably
in SchemaContextUtil
methods.
This class is designed for single-threaded uses and does not make any guarantees around concurrent access.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Semantic binding ofEffectiveStatementInference
produced bySchemaInferenceStack
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Reset this stack to empty state.@NonNull SchemaInferenceStack
copy()
Create a deep copy of this object.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement
Return current module the stack has entered.@NonNull org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement<?,
?> Return the statement at the top of the stack.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement
enterChoice
(QName nodeIdentifier) Lookup achoice
by its node identifier and push it to the stack.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement<?>
enterDataTree
(QName nodeIdentifier) Lookup aschema tree
child by its node identifier and push it to the stack.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement
enterGrouping
(QName nodeIdentifier) Lookup agrouping
by its node identifier and push it to the stack.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement<?>
enterSchemaTree
(QName nodeIdentifier) Lookup aschema tree
child by its node identifier and push it to the stack.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement<?>
enterSchemaTree
(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier nodeIdentifier) Lookup aschema tree
node by its schema node identifier and push it to the stack.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement
enterTypedef
(QName nodeIdentifier) Lookup atypedef
by its node identifier and push it to the stack.@NonNull org.opendaylight.yangtools.rfc8040.model.api.YangDataEffectiveStatement
enterYangData
(QNameModule namespace, String name) Lookup arc:yang-data
by the module namespace where it is defined and its template name.@NonNull org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement<?,
?> exit()
Pop the current statement from the stack.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement<?>
Pop the current statement from the stack, asserting it is aDataTreeEffectiveStatement
and that subsequententerDataTree(QName)
will find it again.org.opendaylight.yangtools.yang.model.api.EffectiveModelContext
boolean
Check if the stack is in agrouping
context.boolean
Check if the stack is in instantiated context.boolean
isEmpty()
Check if this stack is empty.static @NonNull SchemaInferenceStack
of
(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel) Create a new empty stack backed by an effective model.static @NonNull SchemaInferenceStack
of
(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute path) Create a new stack backed by an effective model, pointing to specified schema node identified bySchemaNodeIdentifier.Absolute
.static @NonNull SchemaInferenceStack
ofDataTreePath
(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, QName... path) Create a new stack backed by an effective model and set up to point and specified data tree node.static @NonNull SchemaInferenceStack
ofInference
(org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference inference) Create a new stack from anEffectiveStatementInference
.static @NonNull SchemaInferenceStack
ofInference
(org.opendaylight.yangtools.yang.model.api.SchemaTreeInference inference) Create a new stack from anSchemaTreeInference
.static @NonNull SchemaInferenceStack
ofInference
(org.opendaylight.yangtools.yang.model.spi.DefaultSchemaTreeInference inference) Create a new stack from anDefaultSchemaTreeInference
.static @NonNull SchemaInferenceStack
ofInstantiatedPath
(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, org.opendaylight.yangtools.yang.model.api.SchemaPath path) Deprecated, for removal: This API element is subject to removal in a future version.static @NonNull SchemaInferenceStack
ofSchemaPath
(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, org.opendaylight.yangtools.yang.model.api.SchemaPath path) Deprecated, for removal: This API element is subject to removal in a future version.org.opendaylight.yangtools.yang.model.api.TypeDefinition<?>
resolveLeafref
(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition type) Resolve specifiedLeafrefTypeDefinition
until a non-leafref
type is found.@NonNull org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement<?,
?> resolvePathExpression
(org.opendaylight.yangtools.yang.model.api.PathExpression path) Resolve aPathExpression
.Deprecated, for removal: This API element is subject to removal in a future version.@NonNull SchemaInferenceStack.Inference
Return anSchemaInferenceStack.Inference
equivalent of current state.@NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute
Convert current state into an absolute schema node identifier.@NonNull org.opendaylight.yangtools.yang.model.api.SchemaPath
Deprecated, for removal: This API element is subject to removal in a future version.This method is meant only for interoperation with SchemaPath-based APIs.@NonNull org.opendaylight.yangtools.yang.model.api.SchemaTreeInference
Return anSchemaTreeInference
equivalent of current state.toString()
-
Method Details
-
of
public static @NonNull SchemaInferenceStack of(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel) Create a new empty stack backed by an effective model.- Parameters:
effectiveModel
- EffectiveModelContext to which this stack is attached- Returns:
- A new stack
- Throws:
NullPointerException
- ifeffectiveModel
is null
-
of
public static @NonNull SchemaInferenceStack of(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute path) Create a new stack backed by an effective model, pointing to specified schema node identified bySchemaNodeIdentifier.Absolute
.- Parameters:
effectiveModel
- EffectiveModelContext to which this stack is attached- Returns:
- A new stack
- Throws:
NullPointerException
- ifeffectiveModel
is nullIllegalArgumentException
- ifpath
cannot be resolved in the effective model
-
ofInference
public static @NonNull SchemaInferenceStack ofInference(org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference inference) Create a new stack from anEffectiveStatementInference
.- Parameters:
inference
- Inference to use for initialization- Returns:
- A new stack
- Throws:
NullPointerException
- ifinference
is nullIllegalArgumentException
- ifinference
implementation is not supported
-
ofInference
public static @NonNull SchemaInferenceStack ofInference(org.opendaylight.yangtools.yang.model.api.SchemaTreeInference inference) Create a new stack from anSchemaTreeInference
.- Parameters:
inference
- SchemaTreeInference to use for initialization- Returns:
- A new stack
- Throws:
NullPointerException
- ifinference
is nullIllegalArgumentException
- ifinference
cannot be resolved to a valid stack
-
ofInference
public static @NonNull SchemaInferenceStack ofInference(org.opendaylight.yangtools.yang.model.spi.DefaultSchemaTreeInference inference) Create a new stack from anDefaultSchemaTreeInference
. The argument is nominally trusted to be an accurate representation of the schema tree.Run-time verification of
inference
can be enabled by setting the "org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.verifyDefaultSchemaTreeInference" system property totrue
.- Parameters:
inference
- DefaultSchemaTreeInference to use for initialization- Returns:
- A new stack
- Throws:
NullPointerException
- ifinference
is nullIllegalArgumentException
- ifinference
refers to a missing module or when verification is enabled and it does not match its context's scheam tree
-
ofDataTreePath
public static @NonNull SchemaInferenceStack ofDataTreePath(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, QName... path) Create a new stack backed by an effective model and set up to point and specified data tree node.- Parameters:
effectiveModel
- EffectiveModelContext to which this stack is attached- Returns:
- A new stack
- Throws:
NullPointerException
- if any argument is null or path contains a null elementIllegalArgumentException
- if a path element cannot be found
-
ofInstantiatedPath
@Deprecated(since="7.0.0", forRemoval=true) public static @NonNull SchemaInferenceStack ofInstantiatedPath(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, org.opendaylight.yangtools.yang.model.api.SchemaPath path) Deprecated, for removal: This API element is subject to removal in a future version.Create a new stack backed by an effective model, pointing to specified schema node identified by an absoluteSchemaPath
and itsSchemaPath.getPathFromRoot()
interpreted as a schema node identifier.- Parameters:
effectiveModel
- EffectiveModelContext to which this stack is attached- Returns:
- A new stack
- Throws:
NullPointerException
-effectiveModel
is nullIllegalArgumentException
- ifpath
cannot be resolved in the effective model or if it is not an absolute path.
-
ofSchemaPath
@Deprecated(since="7.0.2", forRemoval=true) public static @NonNull SchemaInferenceStack ofSchemaPath(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext effectiveModel, org.opendaylight.yangtools.yang.model.api.SchemaPath path) Deprecated, for removal: This API element is subject to removal in a future version.Create a new stack backed by an effective model, pointing to specified schema node identified by an absoluteSchemaPath
and itsSchemaPath.getPathFromRoot()
, interpreted as a series of steps along primarily schema tree, with grouping namespace being the alternative lookup.- Parameters:
effectiveModel
- EffectiveModelContext to which this stack is attached- Returns:
- A new stack
- Throws:
NullPointerException
-effectiveModel
is nullIllegalArgumentException
- ifpath
cannot be resolved in the effective model or if it is not an absolute path.
-
getEffectiveModelContext
public org.opendaylight.yangtools.yang.model.api.EffectiveModelContext getEffectiveModelContext()- Specified by:
getEffectiveModelContext
in interfaceorg.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider
-
copy
Create a deep copy of this object.- Returns:
- An isolated copy of this object
-
isEmpty
public boolean isEmpty()Check if this stack is empty.- Returns:
- True if this stack has not entered any node.
-
currentStatement
public @NonNull org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement<?,?> currentStatement()Return the statement at the top of the stack.- Returns:
- Top statement
- Throws:
IllegalStateException
- if the stack is empty
-
currentModule
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement currentModule()Return current module the stack has entered.- Returns:
- Current module
- Throws:
IllegalStateException
- if the stack is empty
-
inInstantiatedContext
public boolean inInstantiatedContext()Check if the stack is in instantiated context. This indicates the stack is non-empty and there are only schema tree statements in the stack.- Returns:
- False if the stack is empty or contains a statement which is not a
SchemaTreeEffectiveStatement
, true otherwise.
-
inGrouping
public boolean inGrouping()Check if the stack is in agrouping
context.- Returns:
- False if the stack contains a grouping.
-
clear
public void clear()Reset this stack to empty state. -
enterChoice
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement enterChoice(QName nodeIdentifier) Lookup achoice
by its node identifier and push it to the stack. This step is very similar toenterSchemaTree(QName)
, except it handles the use case where traversal ignores actualcase
intermediate schema tree children.- Parameters:
nodeIdentifier
- Node identifier of the choice to enter- Returns:
- Resolved choice
- Throws:
NullPointerException
- ifnodeIdentifier
is nullIllegalArgumentException
- if the corresponding choice cannot be found
-
enterGrouping
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement enterGrouping(QName nodeIdentifier) Lookup agrouping
by its node identifier and push it to the stack.- Parameters:
nodeIdentifier
- Node identifier of the grouping to enter- Returns:
- Resolved grouping
- Throws:
NullPointerException
- ifnodeIdentifier
is nullIllegalArgumentException
- if the corresponding grouping cannot be found
-
enterSchemaTree
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement<?> enterSchemaTree(QName nodeIdentifier) Lookup aschema tree
child by its node identifier and push it to the stack.- Parameters:
nodeIdentifier
- Node identifier of the schema tree child to enter- Returns:
- Resolved schema tree child
- Throws:
NullPointerException
- ifnodeIdentifier
is nullIllegalArgumentException
- if the corresponding child cannot be found
-
enterSchemaTree
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement<?> enterSchemaTree(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier nodeIdentifier) Lookup aschema tree
node by its schema node identifier and push it to the stack.- Parameters:
nodeIdentifier
- Schema node identifier of the schema tree node to enter- Returns:
- Resolved schema tree node
- Throws:
NullPointerException
- ifnodeIdentifier
is nullIllegalArgumentException
- if the corresponding node cannot be found
-
enterDataTree
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement<?> enterDataTree(QName nodeIdentifier) Lookup aschema tree
child by its node identifier and push it to the stack.- Parameters:
nodeIdentifier
- Node identifier of the date tree child to enter- Returns:
- Resolved date tree child
- Throws:
NullPointerException
- ifnodeIdentifier
is nullIllegalArgumentException
- if the corresponding child cannot be found
-
enterTypedef
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement enterTypedef(QName nodeIdentifier) Lookup atypedef
by its node identifier and push it to the stack.- Parameters:
nodeIdentifier
- Node identifier of the typedef to enter- Returns:
- Resolved typedef
- Throws:
NullPointerException
- ifnodeIdentifier
is nullIllegalArgumentException
- if the corresponding typedef cannot be found
-
enterYangData
public @NonNull org.opendaylight.yangtools.rfc8040.model.api.YangDataEffectiveStatement enterYangData(QNameModule namespace, String name) Lookup arc:yang-data
by the module namespace where it is defined and its template name.- Parameters:
namespace
- Module namespace in which to lookup the templatename
- Template name- Returns:
- Resolved yang-data
- Throws:
NullPointerException
- if any argument is nullIllegalArgumentException
- if the corresponding yang-data cannot be foundIllegalStateException
- if this stack is not empty
-
exit
public @NonNull org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement<?,?> exit()Pop the current statement from the stack.- Returns:
- Previous statement
- Throws:
NoSuchElementException
- if this stack is empty
-
exitToDataTree
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement<?> exitToDataTree()Pop the current statement from the stack, asserting it is aDataTreeEffectiveStatement
and that subsequententerDataTree(QName)
will find it again.- Returns:
- Previous statement
- Throws:
NoSuchElementException
- if this stack is emptyIllegalStateException
- if current statement is not a DataTreeEffectiveStatement or if its parent is not aDataTreeAwareEffectiveStatement
-
resolveLeafref
public org.opendaylight.yangtools.yang.model.api.TypeDefinition<?> resolveLeafref(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition type) Description copied from interface:LeafrefResolver
Resolve specifiedLeafrefTypeDefinition
until a non-leafref
type is found.- Specified by:
resolveLeafref
in interfaceLeafrefResolver
- Parameters:
type
- leafref definition- Returns:
- Resolved type
-
resolvePathExpression
public @NonNull org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement<?,?> resolvePathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression path) Resolve aPathExpression
.Note if this method throws, this stack may be in an undefined state.
- Parameters:
path
- Requested path- Returns:
- Resolved schema tree child
- Throws:
NullPointerException
- ifpath
is nullIllegalArgumentException
- if the target node cannot be foundcom.google.common.base.VerifyException
- if path expression is invalid
-
toInference
Return anSchemaInferenceStack.Inference
equivalent of current state.- Returns:
- An
SchemaInferenceStack.Inference
-
toSchemaTreeInference
public @NonNull org.opendaylight.yangtools.yang.model.api.SchemaTreeInference toSchemaTreeInference()Return anSchemaTreeInference
equivalent of current state.- Returns:
- An
SchemaTreeInference
- Throws:
IllegalStateException
- if current state cannot be converted to aSchemaTreeInference
-
toSchemaNodeIdentifier
public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute toSchemaNodeIdentifier()Convert current state into an absolute schema node identifier.- Returns:
- Absolute schema node identifier representing current state
- Throws:
IllegalStateException
- if current state is not instantiated
-
toSchemaPath
@Deprecated(since="5.0.0", forRemoval=true) public @NonNull org.opendaylight.yangtools.yang.model.api.SchemaPath toSchemaPath()Deprecated, for removal: This API element is subject to removal in a future version.This method is meant only for interoperation with SchemaPath-based APIs.Convert current state into a SchemaPath.- Returns:
- Absolute SchemaPath representing current state
- Throws:
IllegalStateException
- if current state is not instantiated
-
schemaPathIterator
Deprecated, for removal: This API element is subject to removal in a future version.UsetoSchemaTreeInference()
instead.Return an iterator alongSchemaPath.getPathFromRoot()
. This method is a faster equivalent oftoSchemaPath().getPathFromRoot().iterator()
.- Returns:
- An unmodifiable iterator
-
toString
-
toSchemaTreeInference()
instead.