Class SchemaInferenceStack
java.lang.Object
org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack
- All Implemented Interfaces:
Mutable
,EffectiveModelContextProvider
,LeafrefResolver
@Beta
public final class SchemaInferenceStack
extends Object
implements Mutable, 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 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 ModuleEffectiveStatement
Return current module the stack has entered.@NonNull EffectiveStatement<?,
?> Return the statement at the top of the stack.@NonNull Status
Return the effectivestatus
of thecurrentStatement()
, if present.@NonNull ChoiceEffectiveStatement
enterChoice
(QName nodeIdentifier) Lookup achoice
by its node identifier and push it to the stack.@NonNull DataTreeEffectiveStatement<?>
enterDataTree
(QName nodeIdentifier) Lookup aschema tree
child by its node identifier and push it to the stack.@NonNull GroupingEffectiveStatement
enterGrouping
(QName nodeIdentifier) Lookup agrouping
by its node identifier and push it to the stack.@NonNull SchemaTreeEffectiveStatement<?>
enterSchemaTree
(QName nodeIdentifier) Lookup aschema tree
child by its node identifier and push it to the stack.@NonNull SchemaTreeEffectiveStatement<?>
enterSchemaTree
(SchemaNodeIdentifier nodeIdentifier) Lookup aschema tree
node by its schema node identifier and push it to the stack.@NonNull TypedefEffectiveStatement
enterTypedef
(QName nodeIdentifier) Lookup atypedef
by its node identifier and push it to the stack.@NonNull YangDataEffectiveStatement
enterYangData
(YangDataName name) Lookup arc:yang-data
by the module namespace where it is defined and its template name.@NonNull EffectiveStatement<?,
?> exit()
Pop the current statement from the stack.@NonNull DataTreeEffectiveStatement<?>
Pop the current statement from the stack, asserting it is aDataTreeEffectiveStatement
and that subsequententerDataTree(QName)
will find it again.Return theEffectiveModelContext
attached to this object.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
(EffectiveModelContext effectiveModel) Create a new empty stack backed by an effective model.static @NonNull SchemaInferenceStack
of
(EffectiveModelContext effectiveModel, SchemaNodeIdentifier.Absolute path) Create a new stack backed by an effective model, pointing to specified schema node identified bySchemaNodeIdentifier.Absolute
.static @NonNull SchemaInferenceStack
ofDataTreePath
(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
(EffectiveStatementInference inference) Create a new stack from anEffectiveStatementInference
.static @NonNull SchemaInferenceStack
ofInference
(SchemaTreeInference inference) Create a new stack from anSchemaTreeInference
.static @NonNull SchemaInferenceStack
ofInference
(DefaultSchemaTreeInference inference) Create a new stack from anDefaultSchemaTreeInference
.Resolve specifiedLeafrefTypeDefinition
until a non-leafref
type is found.@NonNull EffectiveStatement<?,
?> Resolve aPathExpression
.@NonNull SchemaInferenceStack.Inference
Return anSchemaInferenceStack.Inference
equivalent of current state.@NonNull SchemaNodeIdentifier.Absolute
Convert current state into an absolute schema node identifier.@NonNull SchemaTreeInference
Return anSchemaTreeInference
equivalent of current state.toString()
-
Method Details
-
of
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
isnull
-
of
public static @NonNull SchemaInferenceStack of(EffectiveModelContext effectiveModel, 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
isnull
IllegalArgumentException
- ifpath
cannot be resolved in the effective model
-
ofInference
Create a new stack from anEffectiveStatementInference
.- Parameters:
inference
- Inference to use for initialization- Returns:
- A new stack
- Throws:
NullPointerException
- ifinference
isnull
IllegalArgumentException
- ifinference
implementation is not supported
-
ofInference
Create a new stack from anSchemaTreeInference
.- Parameters:
inference
- SchemaTreeInference to use for initialization- Returns:
- A new stack
- Throws:
NullPointerException
- ifinference
isnull
IllegalArgumentException
- ifinference
cannot be resolved to a valid stack
-
ofInference
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
isnull
IllegalArgumentException
- ifinference
refers to a missing module or when verification is enabled and it does not match its context's schema tree
-
ofDataTreePath
public static @NonNull SchemaInferenceStack ofDataTreePath(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 isnull
or path contains anull
elementIllegalArgumentException
- if a path element cannot be found
-
getEffectiveModelContext
Description copied from interface:EffectiveModelContextProvider
Return theEffectiveModelContext
attached to this object.- Specified by:
getEffectiveModelContext
in interfaceEffectiveModelContextProvider
- Returns:
- An EffectiveModelContext instance.
-
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
Return the statement at the top of the stack.- Returns:
- Top statement
- Throws:
IllegalStateException
- if the stack is empty
-
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 aSchemaTreeEffectiveStatement
,true
otherwise.
-
inGrouping
public boolean inGrouping()Check if the stack is in agrouping
context.- Returns:
false
if the stack contains a grouping.
-
effectiveStatus
Return the effectivestatus
of thecurrentStatement()
, if present. This method operates on the effective view of the model and therefore does not reflect status the declaration hierarchy. Most notably this YANG snippet:module foo { grouping foo { status obsolete; leaf bar { type string; } } container foo { status deprecated; uses bar; } uses foo; }
leaf bar
as:Status.OBSOLETE
at its original declaration site ingrouping foo
Status.DEPRECATED
at its instantiation incontainer foo
Status.CURRENT
at its instantiation inmodule foo
- Returns:
Status.CURRENT
ifisEmpty()
, or the status of current statement as implied by its direct and its ancestors' substaments.
-
clear
public void clear()Reset this stack to empty state. -
enterChoice
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
isnull
IllegalArgumentException
- if the corresponding choice cannot be found
-
enterGrouping
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
isnull
IllegalArgumentException
- if the corresponding grouping cannot be found
-
enterSchemaTree
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
isnull
IllegalArgumentException
- if the corresponding child cannot be found
-
enterSchemaTree
public @NonNull SchemaTreeEffectiveStatement<?> enterSchemaTree(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
isnull
IllegalArgumentException
- if the corresponding node cannot be found
-
enterDataTree
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
isnull
IllegalArgumentException
- if the corresponding child cannot be found
-
enterTypedef
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
isnull
IllegalArgumentException
- if the corresponding typedef cannot be found
-
enterYangData
Lookup arc:yang-data
by the module namespace where it is defined and its template name.- Parameters:
name
- Template name- Returns:
- Resolved yang-data
- Throws:
NullPointerException
- if any argument isnull
IllegalArgumentException
- if the corresponding yang-data cannot be foundIllegalStateException
- if this stack is not empty
-
exit
Pop the current statement from the stack.- Returns:
- Previous statement
- Throws:
NoSuchElementException
- if this stack is empty
-
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
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
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
isnull
IllegalArgumentException
- if the target node cannot be foundVerifyException
- if path expression is invalid
-
toInference
Return anSchemaInferenceStack.Inference
equivalent of current state.- Returns:
- An
SchemaInferenceStack.Inference
-
toSchemaTreeInference
Return anSchemaTreeInference
equivalent of current state.- Returns:
- An
SchemaTreeInference
- Throws:
IllegalStateException
- if current state cannot be converted to aSchemaTreeInference
-
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
-
toString
-