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 something that carries data, e.g. a leaf, a leaf-list instance.
31 * @author Mark Hollmann
33 public abstract class AbstractContentInstance extends AbstractDataInstance {
35 private final Object value;
37 private final String cachedToString;
40 * Constructor for a content instance that carries data.
42 public AbstractContentInstance(final AbstractStatement schemaNode, final YangDataDomNode dataDomNode,
43 final AbstractStructureInstance parent, final Object value) {
44 super(schemaNode, dataDomNode, parent);
46 this.value = Objects.requireNonNull(value);
47 this.cachedToString = "(" + getNamespace() + "):" + getName() + "=" + Objects.toString(value);
51 * Constructor for a content instance that carries a default value.
53 public AbstractContentInstance(final AbstractStatement schemaNode, final AbstractStructureInstance parent,
55 super(schemaNode, parent);
58 this.cachedToString = "(" + getNamespace() + "):" + getName() + "=" + Objects.toString(value);
62 * The type of the returned value depends on how the value was originally encoded. If it
63 * was encoded in XML, the value will be of type String. If it was encoded in JSON, it
64 * will be of type String, Boolean or Double.
66 public Object getValue() {
71 public String toString() {
72 return cachedToString;