Class SchemaInferenceStack
- java.lang.Object
-
- org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack
-
- All Implemented Interfaces:
Mutable
,MutationBehaviour<Mutable>
,EffectiveModelContextProvider
,LeafrefResolver
@Beta public final class SchemaInferenceStack extends Object implements Mutable, EffectiveModelContextProvider, LeafrefResolver
A state tracking utility for walkingEffectiveModelContext
's contents along schema/grouping namespaces. This is conceptually a stack, trackingEffectiveStatement
s encountered along traversal.This is meant to be a replacement concept for the use of
SchemaPath
in various places, notably inSchemaContextUtil
methods.This class is designed for single-threaded uses and does not make any guarantees around concurrent access.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SchemaInferenceStack.Inference
Semantic binding ofEffectiveStatementInference
produced bySchemaInferenceStack
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clear()
Reset this stack to empty state.@NonNull SchemaInferenceStack
copy()
Create a deep copy of this object.@NonNull ModuleEffectiveStatement
currentModule()
Return current module the stack has entered.@NonNull EffectiveStatement<?,?>
currentStatement()
Return the statement at the top of the stack.@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 EffectiveStatement<?,?>
exit()
Pop the current statement from the stack.@NonNull DataTreeEffectiveStatement<?>
exitToDataTree()
Pop the current statement from the stack, asserting it is aDataTreeEffectiveStatement
and that subsequententerDataTree(QName)
will find it again.EffectiveModelContext
getEffectiveModelContext()
Return theEffectiveModelContext
attached to this object.boolean
inInstantiatedContext()
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
ofInstantiatedPath(EffectiveModelContext effectiveModel, SchemaPath path)
Deprecated.TypeDefinition<?>
resolveLeafref(LeafrefTypeDefinition type)
Resolve specifiedLeafrefTypeDefinition
until a non-leafref
type is found.@NonNull EffectiveStatement<?,?>
resolvePathExpression(PathExpression path)
Resolve aPathExpression
.@NonNull Iterator<QName>
schemaPathIterator()
Deprecated.@NonNull SchemaInferenceStack.Inference
toInference()
Return anSchemaInferenceStack.Inference
equivalent of current state.@NonNull SchemaNodeIdentifier.Absolute
toSchemaNodeIdentifier()
Convert current state into an absolute schema node identifier.@NonNull SchemaPath
toSchemaPath()
Deprecated.This method is meant only for interoperation with SchemaPath-based APIs.@NonNull SchemaTreeInference
toSchemaTreeInference()
Return anSchemaTreeInference
equivalent of current state.String
toString()
-
-
-
Method Detail
-
of
public static @NonNull SchemaInferenceStack of(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(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
is nullIllegalArgumentException
- ifpath
cannot be resolved in the effective model
-
ofInference
public static @NonNull SchemaInferenceStack ofInference(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(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
-
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 is null or path contains a null elementIllegalArgumentException
- if a path element cannot be found
-
ofInstantiatedPath
@Deprecated public static @NonNull SchemaInferenceStack ofInstantiatedPath(EffectiveModelContext effectiveModel, SchemaPath path)
Deprecated.Create a new stack backed by an effective model, pointing to specified schema node identified by an absoluteSchemaPath
and itsSchemaPath.getPathFromRoot()
.- 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 EffectiveModelContext getEffectiveModelContext()
Description copied from interface:EffectiveModelContextProvider
Return theEffectiveModelContext
attached to this object.- Specified by:
getEffectiveModelContext
in interfaceEffectiveModelContextProvider
- Returns:
- An EffectiveModelContext instance.
-
copy
public @NonNull SchemaInferenceStack 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 EffectiveStatement<?,?> currentStatement()
Return the statement at the top of the stack.- Returns:
- Top statement
- Throws:
IllegalStateException
- if the stack is empty
-
currentModule
public @NonNull 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 is no grouping (or similar construct) present in the stack.- Returns:
- False if the stack is empty or contains a grouping, true otherwise.
-
clear
public void clear()
Reset this stack to empty state.
-
enterChoice
public @NonNull 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 grouping to enter- Returns:
- Resolved choice
- Throws:
NullPointerException
- ifnodeIdentifier
is nullIllegalArgumentException
- if the corresponding choice cannot be found
-
enterGrouping
public @NonNull 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 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 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
is nullIllegalArgumentException
- if the corresponding node cannot be found
-
enterDataTree
public @NonNull 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
-
exit
public @NonNull EffectiveStatement<?,?> exit()
Pop the current statement from the stack.- Returns:
- Previous statement
- Throws:
NoSuchElementException
- if this stack is empty
-
exitToDataTree
public @NonNull 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 TypeDefinition<?> resolveLeafref(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 EffectiveStatement<?,?> resolvePathExpression(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 foundVerifyException
- if path expression is invalid
-
toInference
public @NonNull SchemaInferenceStack.Inference toInference()
Return anSchemaInferenceStack.Inference
equivalent of current state.- Returns:
- An
SchemaInferenceStack.Inference
-
toSchemaTreeInference
public @NonNull SchemaTreeInference toSchemaTreeInference()
Return anSchemaTreeInference
equivalent of current state.- Returns:
- An
SchemaTreeInference
- Throws:
IllegalStateException
- if current state cannot be converted to aSchemaTreeInference
-
toSchemaNodeIdentifier
public @NonNull 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 public @NonNull SchemaPath toSchemaPath()
Deprecated.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 public @NonNull Iterator<QName> schemaPathIterator()
Deprecated.Return an iterator alongSchemaPath.getPathFromRoot()
. This method is a faster equivalent oftoSchemaPath().getPathFromRoot().iterator()
.- Returns:
- An unmodifiable iterator
-
-