a2bb4904c2100ee9a4b1cffbbd427dc8b1fe6b8c
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Ericsson
4  *  Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.yangtools.parser.model.statements.threegpp;
22
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.oran.smo.yangtools.parser.ParserExecutionContext;
27 import org.oran.smo.yangtools.parser.findings.Finding;
28 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
29 import org.oran.smo.yangtools.parser.model.statements.AbstractStatement;
30 import org.oran.smo.yangtools.parser.model.statements.ExtensionStatement;
31 import org.oran.smo.yangtools.parser.model.statements.StatementModuleAndName;
32 import org.oran.smo.yangtools.parser.model.statements.yang.CY;
33 import org.oran.smo.yangtools.parser.model.yangdom.YangDomElement;
34
35 /**
36  * Type-safe 3GPP statement.
37  *
38  * @author Mark Hollmann
39  */
40 public class Y3gppInVariant extends ExtensionStatement {
41
42     public Y3gppInVariant(final AbstractStatement parentStatement, final YangDomElement domNode) {
43         super(parentStatement, domNode);
44     }
45
46     @Override
47     public StatementArgumentType getArgumentType() {
48         return StatementArgumentType.NO_ARG;
49     }
50
51     @Override
52     public StatementModuleAndName getStatementModuleAndName() {
53         return C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__IN_VARIANT;
54     }
55
56     private static final List<StatementModuleAndName> REQUIRED_PARENTS = Arrays.asList(CY.STMT_LEAF, CY.STMT_LEAF_LIST,
57             CY.STMT_LIST);
58
59     @Override
60     public boolean canBeChildOf(final StatementModuleAndName parentSman) {
61         return REQUIRED_PARENTS.contains(parentSman);
62     }
63
64     @Override
65     protected void validate(final ParserExecutionContext context) {
66         /*
67          * From module _3gpp-common-yang-extensions:
68          *
69          * Indicates that the value for the data node can only be set when its
70          * parent data node is being created. To change the value after that, the
71          * parent data node must be deleted and recreated with the data node
72          * having the new value.
73          *
74          * It is unnecessary to use and MUST NOT be used for key leafs.
75          *
76          * The statement MUST only be a substatement of a leaf, leaf-list, list
77          * statements that is config=true.
78          * Zero or one inVariant statement is allowed per parent statement.
79          * NO substatements are allowed.
80          *
81          * Adding this statement is an NBC change, removing it is BC.
82          */
83         checkParentAlsoAllowDeviateOrRefine(context);
84         checkCardinalityUnderParent(context, 1);
85
86         if (getValue() != null) {
87             context.addFinding(new Finding(this, ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT,
88                     "'inVariant' extension does not allow for an argument."));
89         }
90     }
91 }