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 EffectiveStatements 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

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Semantic binding of EffectiveStatementInference produced by SchemaInferenceStack.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Reset this stack to empty state.
    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 a choice by its node identifier and push it to the stack.
    @NonNull org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement<?>
    enterDataTree(QName nodeIdentifier)
    Lookup a schema 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 a grouping by its node identifier and push it to the stack.
    @NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement<?>
    enterSchemaTree(QName nodeIdentifier)
    Lookup a schema 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 a schema 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 a typedef by its node identifier and push it to the stack.
    @NonNull org.opendaylight.yangtools.rfc8040.model.api.YangDataEffectiveStatement
    enterYangData(QNameModule namespace, String name)
    Lookup a rc:yang-data by the module namespace where it is defined and its template name.
    @NonNull org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement<?,?>
    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 a DataTreeEffectiveStatement and that subsequent enterDataTree(QName) will find it again.
    org.opendaylight.yangtools.yang.model.api.EffectiveModelContext
     
    boolean
    Check if the stack is in a grouping context.
    boolean
    Check if the stack is in instantiated context.
    boolean
    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 by SchemaNodeIdentifier.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 an EffectiveStatementInference.
    static @NonNull SchemaInferenceStack
    ofInference(org.opendaylight.yangtools.yang.model.api.SchemaTreeInference inference)
    Create a new stack from an SchemaTreeInference.
    static @NonNull SchemaInferenceStack
    ofInference(org.opendaylight.yangtools.yang.model.spi.DefaultSchemaTreeInference inference)
    Create a new stack from an DefaultSchemaTreeInference.
    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 specified LeafrefTypeDefinition 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 a PathExpression.
    @NonNull Iterator<QName>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return an SchemaInferenceStack.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 an SchemaTreeInference equivalent of current state.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 - if effectiveModel 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 by SchemaNodeIdentifier.Absolute.
      Parameters:
      effectiveModel - EffectiveModelContext to which this stack is attached
      Returns:
      A new stack
      Throws:
      NullPointerException - if effectiveModel is null
      IllegalArgumentException - if path 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 an EffectiveStatementInference.
      Parameters:
      inference - Inference to use for initialization
      Returns:
      A new stack
      Throws:
      NullPointerException - if inference is null
      IllegalArgumentException - if inference implementation is not supported
    • ofInference

      public static @NonNull SchemaInferenceStack ofInference(org.opendaylight.yangtools.yang.model.api.SchemaTreeInference inference)
      Create a new stack from an SchemaTreeInference.
      Parameters:
      inference - SchemaTreeInference to use for initialization
      Returns:
      A new stack
      Throws:
      NullPointerException - if inference is null
      IllegalArgumentException - if inference 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 an DefaultSchemaTreeInference. 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 to true.

      Parameters:
      inference - DefaultSchemaTreeInference to use for initialization
      Returns:
      A new stack
      Throws:
      NullPointerException - if inference is null
      IllegalArgumentException - if inference 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 element
      IllegalArgumentException - 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 absolute SchemaPath and its SchemaPath.getPathFromRoot() interpreted as a schema node identifier.
      Parameters:
      effectiveModel - EffectiveModelContext to which this stack is attached
      Returns:
      A new stack
      Throws:
      NullPointerException - effectiveModel is null
      IllegalArgumentException - if path 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 absolute SchemaPath and its SchemaPath.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 null
      IllegalArgumentException - if path 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 interface org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider
    • 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 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 a grouping 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 a choice by its node identifier and push it to the stack. This step is very similar to enterSchemaTree(QName), except it handles the use case where traversal ignores actual case intermediate schema tree children.
      Parameters:
      nodeIdentifier - Node identifier of the choice to enter
      Returns:
      Resolved choice
      Throws:
      NullPointerException - if nodeIdentifier is null
      IllegalArgumentException - if the corresponding choice cannot be found
    • enterGrouping

      public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement enterGrouping(QName nodeIdentifier)
      Lookup a grouping by its node identifier and push it to the stack.
      Parameters:
      nodeIdentifier - Node identifier of the grouping to enter
      Returns:
      Resolved grouping
      Throws:
      NullPointerException - if nodeIdentifier is null
      IllegalArgumentException - if the corresponding grouping cannot be found
    • enterSchemaTree

      public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement<?> enterSchemaTree(QName nodeIdentifier)
      Lookup a schema 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 - if nodeIdentifier is null
      IllegalArgumentException - 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 a schema 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 - if nodeIdentifier is null
      IllegalArgumentException - if the corresponding node cannot be found
    • enterDataTree

      public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement<?> enterDataTree(QName nodeIdentifier)
      Lookup a schema 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 - if nodeIdentifier is null
      IllegalArgumentException - if the corresponding child cannot be found
    • enterTypedef

      public @NonNull org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement enterTypedef(QName nodeIdentifier)
      Lookup a typedef by its node identifier and push it to the stack.
      Parameters:
      nodeIdentifier - Node identifier of the typedef to enter
      Returns:
      Resolved typedef
      Throws:
      NullPointerException - if nodeIdentifier is null
      IllegalArgumentException - if the corresponding typedef cannot be found
    • enterYangData

      public @NonNull org.opendaylight.yangtools.rfc8040.model.api.YangDataEffectiveStatement enterYangData(QNameModule namespace, String name)
      Lookup a rc:yang-data by the module namespace where it is defined and its template name.
      Parameters:
      namespace - Module namespace in which to lookup the template
      name - Template name
      Returns:
      Resolved yang-data
      Throws:
      NullPointerException - if any argument is null
      IllegalArgumentException - if the corresponding yang-data cannot be found
      IllegalStateException - 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 a DataTreeEffectiveStatement and that subsequent enterDataTree(QName) will find it again.
      Returns:
      Previous statement
      Throws:
      NoSuchElementException - if this stack is empty
      IllegalStateException - if current statement is not a DataTreeEffectiveStatement or if its parent is not a DataTreeAwareEffectiveStatement
    • 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 specified LeafrefTypeDefinition until a non-leafref type is found.
      Specified by:
      resolveLeafref in interface LeafrefResolver
      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 a PathExpression.

      Note if this method throws, this stack may be in an undefined state.

      Parameters:
      path - Requested path
      Returns:
      Resolved schema tree child
      Throws:
      NullPointerException - if path is null
      IllegalArgumentException - if the target node cannot be found
      com.google.common.base.VerifyException - if path expression is invalid
    • toInference

      public @NonNull SchemaInferenceStack.Inference toInference()
      Return an SchemaInferenceStack.Inference equivalent of current state.
      Returns:
      An SchemaInferenceStack.Inference
    • toSchemaTreeInference

      public @NonNull org.opendaylight.yangtools.yang.model.api.SchemaTreeInference toSchemaTreeInference()
      Return an SchemaTreeInference equivalent of current state.
      Returns:
      An SchemaTreeInference
      Throws:
      IllegalStateException - if current state cannot be converted to a SchemaTreeInference
    • 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(since="5.0.0", forRemoval=true) public @NonNull Iterator<QName> schemaPathIterator()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return an iterator along SchemaPath.getPathFromRoot(). This method is a faster equivalent of toSchemaPath().getPathFromRoot().iterator().
      Returns:
      An unmodifiable iterator
    • toString

      public String toString()
      Overrides:
      toString in class Object