Class SchemaContextUtil


  • public final class SchemaContextUtil
    extends Object
    The Schema Context Util contains support methods for searching through Schema Context modules for specified schema nodes via Schema Path or Revision Aware XPath. The Schema Context Util is designed as mixin, so it is not instantiable.
    • Method Detail

      • findDataSchemaNode

        public static SchemaNode findDataSchemaNode​(SchemaContext context,
                                                    SchemaPath schemaPath)
        Method attempts to find DataSchemaNode in Schema Context via specified Schema Path. The returned DataSchemaNode from method will be the node at the end of the SchemaPath. If the DataSchemaNode is not present in the Schema Context the method will return null.

        In case that Schema Context or Schema Path are not specified correctly (i.e. contains null values) the method will throw IllegalArgumentException.

        Parameters:
        context - Schema Context
        schemaPath - Schema Path to search for
        Returns:
        SchemaNode from the end of the Schema Path or null if the Node is not present.
        Throws:
        NullPointerException - if context or schemaPath is null
      • findDataSchemaNode

        @Deprecated
        public static SchemaNode findDataSchemaNode​(SchemaContext context,
                                                    Module module,
                                                    PathExpression nonCondXPath)
        Method attempts to find DataSchemaNode inside of provided Schema Context and Yang Module accordingly to Non-conditional Revision Aware XPath. The specified Module MUST be present in Schema Context otherwise the operation would fail and return null.
        The Revision Aware XPath MUST be specified WITHOUT the conditional statement (i.e. without [cond]) in path, because in this state the Schema Context is completely unaware of data state and will be not able to properly resolve XPath. If the XPath contains condition the method will return IllegalArgumentException.
        If the Revision Aware XPath is correct and desired Data Schema Node is present in Yang module or in depending module in Schema Context the method will return specified Data Schema Node, otherwise the operation will fail and method will return null.
        Parameters:
        context - Schema Context
        module - Yang Module
        nonCondXPath - Non Conditional Revision Aware XPath
        Returns:
        Returns Data Schema Node for specified Schema Context for given Non-conditional Revision Aware XPath, or null if the DataSchemaNode is not present in Schema Context.
        Throws:
        NullPointerException - if any of the arguments is null
      • findDataSchemaNodeForRelativeXPath

        public static SchemaNode findDataSchemaNodeForRelativeXPath​(SchemaContext context,
                                                                    Module module,
                                                                    SchemaNode actualSchemaNode,
                                                                    PathExpression relativeXPath)
        Method attempts to find DataSchemaNode inside of provided Schema Context and Yang Module accordingly to Non-conditional relative Revision Aware XPath. The specified Module MUST be present in Schema Context otherwise the operation would fail and return null.
        The relative Revision Aware XPath MUST be specified WITHOUT the conditional statement (i.e. without [cond]) in path, because in this state the Schema Context is completely unaware of data state and will be not able to properly resolve XPath. If the XPath contains condition the method will return IllegalArgumentException.
        The Actual Schema Node MUST be specified correctly because from this Schema Node will search starts. If the Actual Schema Node is not correct the operation will simply fail, because it will be unable to find desired DataSchemaNode.
        If the Revision Aware XPath doesn't have flag isAbsolute == false the method will throw IllegalArgumentException.
        If the relative Revision Aware XPath is correct and desired Data Schema Node is present in Yang module or in depending module in Schema Context the method will return specified Data Schema Node, otherwise the operation will fail and method will return null.
        Parameters:
        context - Schema Context
        module - Yang Module
        actualSchemaNode - Actual Schema Node
        relativeXPath - Relative Non Conditional Revision Aware XPath
        Returns:
        DataSchemaNode if is present in specified Schema Context for given relative Revision Aware XPath, otherwise will return null.
        Throws:
        NullPointerException - if any argument is null
      • findParentModule

        public static Module findParentModule​(SchemaContext context,
                                              SchemaNode schemaNode)
        Returns parent Yang Module for specified Schema Context in which Schema Node is declared. If the Schema Node is not present in Schema Context the operation will return null.
        Parameters:
        context - Schema Context
        schemaNode - Schema Node
        Returns:
        Yang Module for specified Schema Context and Schema Node, if Schema Node is NOT present, the method will return null
        Throws:
        NullPointerException - if any of the arguments is null
      • getNotificationSchema

        @Beta
        public static @Nullable NotificationDefinition getNotificationSchema​(@NonNull SchemaContext schema,
                                                                             @NonNull SchemaPath path)
        Returns NotificationDefinition from Schema Context.
        Parameters:
        schema - SchemaContext in which lookup should be performed.
        path - Schema Path of notification
        Returns:
        Notification schema or null, if notification is not present in schema context.
      • getRpcDataSchema

        @Beta
        public static @Nullable ContainerLike getRpcDataSchema​(@NonNull SchemaContext schema,
                                                               @NonNull SchemaPath path)
        Returns RPC Input or Output Data container from RPC definition.
        Parameters:
        schema - SchemaContext in which lookup should be performed.
        path - Schema path of RPC input/output data container
        Returns:
        Notification schema or null, if notification is not present in schema context.
      • getConstituentModuleIdentifiers

        public static Set<SourceIdentifier> getConstituentModuleIdentifiers​(SchemaContext context)
        Extract the identifiers of all modules and submodules which were used to create a particular SchemaContext.
        Parameters:
        context - SchemaContext to be examined
        Returns:
        Set of ModuleIdentifiers.
      • getBaseTypeForLeafRef

        public static TypeDefinition<?> getBaseTypeForLeafRef​(LeafrefTypeDefinition typeDefinition,
                                                              SchemaContext schemaContext,
                                                              SchemaNode schema)
        Extracts the base type of node on which schema node points to. If target node is again of type LeafrefTypeDefinition, methods will be call recursively until it reach concrete type definition.
        Parameters:
        typeDefinition - type of node which will be extracted
        schemaContext - Schema Context
        schema - Schema Node
        Returns:
        recursively found type definition this leafref is pointing to or null if the xpath is incorrect (null is there to preserve backwards compatibility)
      • getBaseTypeForLeafRef

        public static TypeDefinition<?> getBaseTypeForLeafRef​(LeafrefTypeDefinition typeDefinition,
                                                              SchemaContext schemaContext,
                                                              QName qname)
        Returns base type for typeDefinition which belongs to module specified via qname. This handle the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other module as typedef which is then imported to referenced module.

        Because typeDefinition is definied via typedef statement, only absolute path is meaningful.