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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.model.statements.threegpp;
23 import java.util.Arrays;
24 import java.util.List;
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;
34 * Type-safe 3GPP statement.
36 * @author Mark Hollmann
38 public class Y3gppInitialValue extends ExtensionStatement {
40 public Y3gppInitialValue(final AbstractStatement parentStatement, final YangDomElement domNode) {
41 super(parentStatement, domNode);
45 public StatementArgumentType getArgumentType() {
46 return StatementArgumentType.VALUE;
50 public StatementModuleAndName getStatementModuleAndName() {
51 return C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__INITIAL_VALUE;
55 public boolean argumentIsMandatory() {
60 public boolean orderUnderParentMatters() {
64 public String getInitialValue() {
65 return getValue() != null ? getValue() : "";
69 public MaxCardinality getMaxCardinalityUnderParent() {
70 return getParentStatement().is(CY.STMT_LEAF) ? MaxCardinality.ONE : MaxCardinality.MULTIPLE;
73 private static final List<StatementModuleAndName> REQUIRED_PARENTS = Arrays.asList(CY.STMT_LEAF, CY.STMT_LEAF_LIST);
76 public boolean canBeChildOf(final StatementModuleAndName parentSman) {
77 return REQUIRED_PARENTS.contains(parentSman);
80 protected void validate(final ParserExecutionContext context) {
82 * From module _3gpp-common-yang-extensions:
84 * Specifies a value that the system will set for a leaf
85 * leaf-list if a value is not specified for it when its parent list
86 * or container is created. The value has no effect in any other
87 * modification e.g. changing or removing the value.
89 * The description statement of the parent statement SHOULD contain
90 * the label 'Initial-value: ' followed by the text from the argument.
92 * The statement MUST only be a substatement of a leaf or leaf-list.
93 * The statement MUST NOT be present if the leaf or the leaf-list
94 * has a default statement or the type used for the data node
95 * has a default value.
96 * The statement MUST NOT be used for config=false data or in an
97 * action, rpc or notification.
98 * Zero or one initial-value statements are allowed for a leaf parent
99 * statement. Zero or more initial-value statements are allowed for a
100 * leaf-list parent statement. If the leaf-list is ordered-by user, the
101 * initial values are stored in the order they appear in the YANG definition.
102 * NO substatements are allowed.
104 * Always consider using a YANG-default statement instead.
106 * Modification of the initial-value is a non-backwards-compatible change.
108 * The argument specifies a single initial value for a leaf or leaf-list.
109 * The value MUST be part of the valuespace of the leaf/leaf-list.
110 * It follows the same rules as the argument of the default statement.
112 validateArgumentNotNull(context);
113 checkParentAlsoAllowDeviateOrRefine(context);
115 if (getParentStatement().is(CY.STMT_LEAF)) {
116 checkCardinalityUnderParent(context, 1);