2b6143c3d85f3bb11f60db4b16a5bfaec872b157
[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.oran;
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.model.statements.AbstractStatement;
28 import org.oran.smo.yangtools.parser.model.statements.ExtensionStatement;
29 import org.oran.smo.yangtools.parser.model.statements.StatementModuleAndName;
30 import org.oran.smo.yangtools.parser.model.statements.yang.CY;
31 import org.oran.smo.yangtools.parser.model.yangdom.YangDomElement;
32
33 public class YOranSmoTeivASide extends ExtensionStatement {
34
35     public YOranSmoTeivASide(final AbstractStatement parentStatement, final YangDomElement domNode) {
36         super(parentStatement, domNode);
37     }
38
39     @Override
40     public StatementArgumentType getArgumentType() {
41         return StatementArgumentType.NAME;
42     }
43
44     @Override
45     public StatementModuleAndName getStatementModuleAndName() {
46         return CORAN.ORAN_SMO_TEIV_COMMON_YANG_EXTENSIONS__A_SIDE;
47     }
48
49     @Override
50     public boolean argumentIsMandatory() {
51         return true;
52     }
53
54     public String getTeivTypeName() {
55         return getValue() != null ? getValue() : "";
56     }
57
58     private static final List<StatementModuleAndName> REQUIRED_PARENTS = Arrays.asList(CY.STMT_LEAF, CY.STMT_LEAF_LIST);
59
60     @Override
61     public boolean canBeChildOf(final StatementModuleAndName parentSman) {
62         return REQUIRED_PARENTS.contains(parentSman);
63     }
64
65     @Override
66     protected void validate(final ParserExecutionContext context) {
67         /*
68          * From o-ran-smo-teiv-common-yang-extensions:
69          *
70          * Defines the A-side of a relationship.
71          *
72          * The statement MUST only be a substatement of a 'leaf' or 'leaf-list'
73          * statement, which itself must be a substatement of the
74          * 'uni-directional-topology-relationship' statement.
75          *
76          * The data type of the parent 'leaf' or 'leaf-list' MUST be
77          * 'instance-identifier'. Constraints MAY be used as part of the parent
78          * 'leaf' or 'leaf-list' to enforce cardinality.
79          *
80          * The identifier of the parent 'leaf' or 'leaf-list' is used as name of
81          * the role of the A-side of the relationship. The name of the role is
82          * scoped to the type on which the A-side is defined and MUST be unique
83          * within the scope.
84          *
85          * While the parent 'leaf' or 'leaf-list' does not result in a property of
86          * the relationship, it is RECOMMENDED to avoid using the name of an
87          * existing type property as role name to avoid potential ambiguities
88          * between properties of a type, and roles of a relationship on the type.
89          *
90          * The argument is the name of the type on which the A-side resides. If the
91          * type is declared in another module, the type must be prefixed, and a
92          * corresponding 'import' statement be used to declare the prefix.";
93          */
94         validateArgumentNotNullNotEmpty(context);
95
96         checkParent(context);
97         checkCardinalityUnderParent(context, 1);
98     }
99 }