101fc4b32d3d4d3cc4aa77c1e42a5c5e565aba43
[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.yang;
22
23 import java.util.List;
24
25 import org.oran.smo.yangtools.parser.ParserExecutionContext;
26 import org.oran.smo.yangtools.parser.model.statements.AbstractStatement;
27 import org.oran.smo.yangtools.parser.model.statements.StatementModuleAndName;
28 import org.oran.smo.yangtools.parser.model.yangdom.YangDomElement;
29
30 /**
31  * Type-safe Yang core statement.
32  *
33  * @author Mark Hollmann
34  */
35 public class YSubmodule extends AbstractStatement {
36
37     public YSubmodule(final AbstractStatement modelRoot, final YangDomElement domNode) {
38         super(modelRoot, domNode);
39     }
40
41     @Override
42     public String getStatementIdentifier() {
43         return getSubmoduleName();
44     }
45
46     @Override
47     public StatementArgumentType getArgumentType() {
48         return StatementArgumentType.NAME;
49     }
50
51     @Override
52     public StatementModuleAndName getStatementModuleAndName() {
53         return CY.STMT_SUBMODULE;
54     }
55
56     /**
57      * The submodule name will always be non-null.
58      */
59     public String getSubmoduleName() {
60         return domElement.getValue();
61     }
62
63     public List<YAnydata> getAnydata() {
64         return getChildren(CY.STMT_ANYDATA);
65     }
66
67     public List<YAnyxml> getAnyxmls() {
68         return getChildren(CY.STMT_ANYXML);
69     }
70
71     public List<YAugment> getAugments() {
72         return getChildren(CY.STMT_AUGMENT);
73     }
74
75     /**
76      * Returns the 'belongs-to' statement, if any, under the 'submodule'. To get the actual value of the submodule's
77      * belongs-to, invoke mySubmodule.getBelongsToValue();
78      */
79     public YBelongsTo getBelongsTo() {
80         return getChild(CY.STMT_BELONGS_TO);
81     }
82
83     /**
84      * Returns the value, if any, of the 'belongs-to' statement under the 'submodule'.
85      */
86     public String getBelongsToValue() {
87         final YBelongsTo yBelongsTo = getBelongsTo();
88         return yBelongsTo == null ? null : yBelongsTo.getBelongsToModuleName();
89     }
90
91     public List<YChoice> getChoices() {
92         return getChildren(CY.STMT_CHOICE);
93     }
94
95     public YContact getContact() {
96         return getChild(CY.STMT_CONTACT);
97     }
98
99     public List<YContainer> getContainers() {
100         return getChildren(CY.STMT_CONTAINER);
101     }
102
103     public List<YDeviation> getDeviations() {
104         return getChildren(CY.STMT_DEVIATION);
105     }
106
107     public List<YExtension> getExtensions() {
108         return getChildren(CY.STMT_EXTENSION);
109     }
110
111     public List<YFeature> getFeatures() {
112         return getChildren(CY.STMT_FEATURE);
113     }
114
115     public List<YGrouping> getGroupings() {
116         return getChildren(CY.STMT_GROUPING);
117     }
118
119     public List<YIdentity> getIdentities() {
120         return getChildren(CY.STMT_IDENTITY);
121     }
122
123     public List<YImport> getImports() {
124         return getChildren(CY.STMT_IMPORT);
125     }
126
127     public List<YInclude> getIncludes() {
128         return getChildren(CY.STMT_INCLUDE);
129     }
130
131     public List<YLeaf> getLeafs() {
132         return getChildren(CY.STMT_LEAF);
133     }
134
135     public List<YLeafList> getLeafLists() {
136         return getChildren(CY.STMT_LEAF_LIST);
137     }
138
139     public List<YList> getLists() {
140         return getChildren(CY.STMT_LIST);
141     }
142
143     public List<YNotification> getNotifications() {
144         return getChildren(CY.STMT_NOTIFICATION);
145     }
146
147     public YOrganization getOrganization() {
148         return getChild(CY.STMT_ORGANIZATION);
149     }
150
151     public List<YRevision> getRevisions() {
152         return getChildren(CY.STMT_REVISION);
153     }
154
155     public List<YRpc> getRpcs() {
156         return getChildren(CY.STMT_RPC);
157     }
158
159     public List<YTypedef> getTypedefs() {
160         return getChildren(CY.STMT_TYPEDEF);
161     }
162
163     public List<YUses> getUses() {
164         return getChildren(CY.STMT_USES);
165     }
166
167     public YYangVersion getYangVersion() {
168         return getChild(CY.STMT_YANG_VERSION);
169     }
170
171     public boolean is10Version() {
172         final YYangVersion yYangVersion = getYangVersion();
173         return yYangVersion == null ? false : yYangVersion.is10Version();
174     }
175
176     public boolean is11Version() {
177         final YYangVersion yYangVersion = getYangVersion();
178         return yYangVersion == null ? false : yYangVersion.is11Version();
179     }
180
181     protected void validate(final ParserExecutionContext context) {
182         validateArgumentNotNullNotEmpty(context);
183         validateIsYangIdentifier(context, getSubmoduleName());
184     }
185 }