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.data.instance;
23 import java.util.Objects;
25 import org.oran.smo.yangtools.parser.data.dom.YangDataDomNode;
26 import org.oran.smo.yangtools.parser.model.statements.AbstractStatement;
29 * Represents a piece of data in the data tree (e.g. a container, a leaf)
31 * @author Mark Hollmann
33 public abstract class AbstractDataInstance {
36 * The node in the schema that this data relates to. Will be null for the root instance.
38 private final AbstractStatement schemaNode;
41 * The data DOM node that backs this data instance. Will be null for the root instance or
44 private final YangDataDomNode dataDomNode;
47 * The parent structure instance (i.e., the parent container or list). Will be null for
50 private AbstractStructureInstance parent;
53 * Constructor for an instance that has been specified in data.
55 public AbstractDataInstance(final AbstractStatement schemaNode, final YangDataDomNode dataDomNode,
56 final AbstractStructureInstance parent) {
57 this.schemaNode = schemaNode;
58 this.dataDomNode = Objects.requireNonNull(dataDomNode);
63 * Constructor for an instance that has been specified as default value.
65 public AbstractDataInstance(final AbstractStatement schemaNode, final AbstractStructureInstance parent) {
66 this.schemaNode = schemaNode;
67 this.dataDomNode = null;
71 public void reparent(final AbstractStructureInstance newParent) {
76 * Returns the schema node (really, a data node) in the schema to which this data instance relates.
78 public AbstractStatement getSchemaNode() {
83 * Returns the data DOM node. May be null if NP-container or default value.
85 public YangDataDomNode getDataDomNode() {
89 public String getName() {
90 if (dataDomNode == null) {
91 return schemaNode.getStatementIdentifier();
93 return dataDomNode.getName();
97 * Returns the namespace. Where a data DOM node exists, will return that - otherwise, will return the effective
98 * namespace of the schema node. May return null.
100 public String getNamespace() {
101 if (dataDomNode == null) {
102 return schemaNode.getEffectiveNamespace();
104 return dataDomNode.getNamespace();
107 public AbstractStructureInstance getParent() {