Class StmtContextUtils


  • public final class StmtContextUtils
    extends Object
    • Method Detail

      • firstSubstatementAttributeOf

        public static <A,​D extends DeclaredStatement<A>> A firstSubstatementAttributeOf​(StmtContext<?,​?,​?> ctx,
                                                                                              Class<D> declaredType)
      • findFirstSubstatement

        public static <A,​D extends DeclaredStatement<A>> StmtContext<A,​?,​?> findFirstSubstatement​(StmtContext<?,​?,​?> stmtContext,
                                                                                                                    Class<D> declaredType)
        Searches for the first substatement of the specified type in the specified statement context. First, it tries to find the substatement in the effective substatements of the statement context. If it was not found, then it proceeds to search in the declared substatements. If it still was not found, the method returns null.
        Type Parameters:
        A - statement argument type
        D - declared statement type
        Parameters:
        stmtContext - statement context to search in
        declaredType - substatement type to search for
        Returns:
        statement context that was searched for or null if was not found
      • findFirstDeclaredSubstatementOnSublevel

        public static <D extends DeclaredStatement<?>> StmtContext<?,​?,​?> findFirstDeclaredSubstatementOnSublevel​(StmtContext<?,​?,​?> stmtContext,
                                                                                                                              Class<D> declaredType,
                                                                                                                              int sublevel)
      • isInExtensionBody

        public static boolean isInExtensionBody​(StmtContext<?,​?,​?> stmtCtx)
      • isUnknownStatement

        public static boolean isUnknownStatement​(StmtContext<?,​?,​?> stmtCtx)
        Returns true if supplied statement context represents unknown statement, otherwise returns false.
        Parameters:
        stmtCtx - statement context to be checked
        Returns:
        true if supplied statement context represents unknown statement, otherwise false
        Throws:
        NullPointerException - if supplied statement context is null
      • isUnrecognizedStatement

        public static boolean isUnrecognizedStatement​(StmtContext<?,​?,​?> stmtCtx)
        Returns true if supplied statement context represents unrecognized statement, otherwise returns false.
        Parameters:
        stmtCtx - statement context to be checked
        Returns:
        true if supplied statement context represents unrecognized statement, otherwise false
        Throws:
        NullPointerException - if supplied statement context is null
      • checkFeatureSupport

        public static boolean checkFeatureSupport​(StmtContext<?,​?,​?> stmtContext,
                                                  Set<QName> supportedFeatures)
      • isPresenceContainer

        public static boolean isPresenceContainer​(StmtContext<?,​?,​?> stmtCtx)
        Checks whether statement context is a presence container or not.
        Parameters:
        stmtCtx - statement context
        Returns:
        true if it is a presence container
      • isNonPresenceContainer

        public static boolean isNonPresenceContainer​(StmtContext<?,​?,​?> stmtCtx)
        Checks whether statement context is a non-presence container or not.
        Parameters:
        stmtCtx - statement context
        Returns:
        true if it is a non-presence container
      • isMandatoryNode

        public static boolean isMandatoryNode​(StmtContext<?,​?,​?> stmtCtx)
        Checks whether statement context is a mandatory leaf, choice, anyxml, list or leaf-list according to RFC6020 or not.
        Parameters:
        stmtCtx - statement context
        Returns:
        true if it is a mandatory leaf, choice, anyxml, list or leaf-list according to RFC6020.
      • isNotMandatoryNodeOfType

        public static boolean isNotMandatoryNodeOfType​(StmtContext<?,​?,​?> stmtCtx,
                                                       StatementDefinition stmtDef)
        Checks whether a statement context is a statement of supplied statement definition and whether it is not mandatory leaf, choice, anyxml, list or leaf-list according to RFC6020.
        Parameters:
        stmtCtx - statement context
        stmtDef - statement definition
        Returns:
        true if supplied statement context is a statement of supplied statement definition and if it is not mandatory leaf, choice, anyxml, list or leaf-list according to RFC6020
      • hasAncestorOfType

        public static boolean hasAncestorOfType​(StmtContext<?,​?,​?> ctx,
                                                Collection<StatementDefinition> ancestorTypes)
        Checks whether at least one ancestor of a StatementContext matches one from a collection of statement definitions.
        Parameters:
        ctx - StatementContext to be checked
        ancestorTypes - collection of statement definitions
        Returns:
        true if at least one ancestor of a StatementContext matches one from collection of statement definitions, otherwise false.
      • hasAncestorOfTypeWithChildOfType

        public static <A,​D extends DeclaredStatement<A>> boolean hasAncestorOfTypeWithChildOfType​(StmtContext<?,​?,​?> ctx,
                                                                                                        StatementDefinition ancestorType,
                                                                                                        StatementDefinition ancestorChildType)
        Checks whether all of StmtContext's ancestors of specified type have a child of specified type.
        Parameters:
        ctx - StmtContext to be checked
        ancestorType - type of ancestor to search for
        ancestorChildType - type of child to search for in the specified ancestor type
        Returns:
        true if all of StmtContext's ancestors of specified type have a child of specified type, otherwise false
      • hasParentOfType

        public static boolean hasParentOfType​(StmtContext<?,​?,​?> ctx,
                                              StatementDefinition parentType)
        Checks whether the parent of StmtContext is of specified type.
        Parameters:
        ctx - StmtContext to be checked
        parentType - type of parent to check
        Returns:
        true if the parent of StmtContext is of specified type, otherwise false
      • validateIfFeatureAndWhenOnListKeys

        public static void validateIfFeatureAndWhenOnListKeys​(StmtContext<?,​?,​?> ctx)
        Validates the specified statement context with regards to if-feature and when statement on list keys. The context can either be a leaf which is defined directly in the substatements of a keyed list or a uses statement defined in a keyed list (a uses statement may add leaves into the list).

        If one of the list keys contains an if-feature or a when statement in YANG 1.1 model, an exception is thrown.

        Parameters:
        ctx - statement context to be validated
      • parseIdentifier

        public static QName parseIdentifier​(StmtContext<?,​?,​?> ctx,
                                            String str)
        Parse a YANG identifier string in context of a statement.
        Parameters:
        ctx - Statement context
        str - String to be parsed
        Returns:
        An interned QName
        Throws:
        NullPointerException - if any of the arguments are null
        SourceException - if the string is not a valid YANG identifier
      • parseNodeIdentifier

        public static QName parseNodeIdentifier​(StmtContext<?,​?,​?> ctx,
                                                String str)
        Parse a YANG node identifier string in context of a statement.
        Parameters:
        ctx - Statement context
        str - String to be parsed
        Returns:
        An interned QName
        Throws:
        NullPointerException - if any of the arguments are null
        SourceException - if the string is not a valid YANG node identifier