ed6308bbdb026f346d6fe5d3bce7fed4070d2a1d
[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 Y3gppNotNotifyable extends ExtensionStatement {
41
42     public Y3gppNotNotifyable(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__NOT_NOTIFYABLE;
54     }
55
56     private static final List<StatementModuleAndName> REQUIRED_PARENTS = Arrays.asList(CY.STMT_LEAF, CY.STMT_LEAF_LIST,
57             CY.STMT_LIST, CY.STMT_CONTAINER, CY.STMT_ANYDATA, CY.STMT_ANYXML);
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 data change notifications shall not be sent
70          * for this attribute. If the extension is not present and other
71          * conditions are fulfilled data change notification should be sent.
72          * If a list or container already has the notNotifyable
73          * extension, that is also valid for all contained data nodes.
74          *
75          * The statement MUST only be a substatement of a leaf, leaf-list, list,
76          * container statement that is contained within the 'attributes'
77          * container of an IOC and that represents an attribute or sub-parts of
78          * an attribute .
79          *
80          * Zero or one notNotifyable statement is allowed per parent statement.
81          * NO substatements are allowed.
82          *
83          * Adding this statement is an NBC change, removing it is BC.";
84          */
85         checkParentAlsoAllowDeviateOrRefine(context);
86         checkCardinalityUnderParent(context, 1);
87
88         if (getValue() != null) {
89             context.addFinding(new Finding(this, ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT,
90                     "'notNotifyable' extension does not allow for an argument."));
91         }
92     }
93 }