2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
23 import com.google.common.collect.ArrayListMultimap;
24 import com.google.common.collect.Multimap;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
28 * Abstraction of properties node data tree. This intermediate representation
29 * will enable data format serializers to be agnostic of DG context memory
30 * nuances and thereby will enable faster development of new data format
33 public abstract class PropertiesNode {
36 private Namespace namespace;
38 private PropertiesNode parent;
39 private Object appInfo;
40 private NodeType nodeType;
41 private Multimap<Object, PropertiesNode> augmentations = ArrayListMultimap.create();
44 * Creates an instance of properties node.
46 * @param name name of node
47 * @param namespace namespace of node, null indicates parent namespace
48 * @param uri URI of this node, if null its calculated based on parent and
49 * current value of name and namespace
50 * @param parent parent's node
51 * @param appInfo application related information
52 * @param nodeType node type
54 protected PropertiesNode(String name, Namespace namespace, String uri,
55 PropertiesNode parent, Object appInfo, NodeType nodeType) {
57 this.namespace = namespace;
60 this.appInfo = appInfo;
61 this.nodeType = nodeType;
67 * @param name name of the node
69 public void name(String name) {
76 * @param namespace namespace of the node
78 public void namespace(Namespace namespace) {
79 this.namespace = namespace;
85 * @param uri uri of the node
87 public void uri(String uri) {
94 * @param parent parent node
96 public void parent(PropertiesNode parent) {
101 * Sets application info.
103 * @param appInfo application info
105 public void appInfo(Object appInfo) {
106 this.appInfo = appInfo;
112 * @return parent node
114 public PropertiesNode parent() {
121 * @return name of the node
123 public String name() {
130 * @return namespace of the node
132 public Namespace namespace() {
139 * @return uri of the node
141 public String uri() {
146 * Returns application info.
148 * @return application info
150 public Object appInfo() {
159 public NodeType nodeType() {
164 * Returns augmentations.
166 * @return augmentations
168 public Multimap<Object, PropertiesNode> augmentations() {
169 return augmentations;
173 * Sets augmentations.
175 * @param augmentations augmentations of the node
177 public void augmentations(Multimap<Object, PropertiesNode> augmentations) {
178 this.augmentations = augmentations;
182 * Adds a child to a current node.
184 * @param name name of child
185 * @param namespace namespace of child, null represents parent namespace
186 * @param type type of node
187 * @param appInfo application info
188 * @return added properties node
190 public abstract PropertiesNode addChild(String name, Namespace namespace,
192 Object appInfo) throws SvcLogicException;
195 * Adds a child with value to a current node.
197 * @param name name of child
198 * @param namespace namespace of child, null represents parent namespace
199 * @param type type of node
200 * @param value value of node
201 * @param valueNs value namespace
202 * @param appInfo application info
203 * @throws SvcLogicException if failed to add child
204 * @return added properties node
206 public abstract PropertiesNode addChild(String name, Namespace namespace,
207 NodeType type, String value,
209 Object appInfo) throws SvcLogicException;
212 * Adds a child at a given index to a current node. To be used in case of
213 * leaf holder child's which is multi instance node.
215 * @param index index at which node is to be added
216 * @param name name of child
217 * @param namespace namespace of child, null represents parent namespace
218 * @param type type of node
219 * @param appInfo application info
220 * @throws SvcLogicException if failed to add child
221 * @return added properties node
223 public abstract PropertiesNode addChild(String index, String name,
226 Object appInfo) throws SvcLogicException;
229 * Adds a child at a given index to a current node. To be used in case of
230 * leaf holder child's which is multi instance node.
232 * @param index index at which node is to be added
233 * @param name name of child
234 * @param namespace namespace of child, null represents parent namespace
235 * @param type type of node
236 * @param value value of node
237 * @param valueNs value namespace
238 * @param appInfo application info
239 * @throws SvcLogicException if failed to add child
240 * @return added properties node
242 public abstract PropertiesNode addChild(String index, String name,
243 Namespace namespace, NodeType type,
244 String value, Namespace valueNs,
245 Object appInfo) throws SvcLogicException;
252 public PropertiesNode endNode() {
253 PropertiesNode node = this;
254 while (node.parent() != null){
255 node = node.parent();