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 boolean nonAppend;
42 private Multimap<Object, PropertiesNode> augmentations = ArrayListMultimap.create();
45 * Creates an instance of properties node.
47 * @param name name of node
48 * @param namespace namespace of node, null indicates parent namespace
49 * @param uri URI of this node, if null its calculated based on parent and
50 * current value of name and namespace
51 * @param parent parent's node
52 * @param appInfo application related information
53 * @param nodeType node type
55 protected PropertiesNode(String name, Namespace namespace, String uri,
56 PropertiesNode parent, Object appInfo, NodeType nodeType) {
58 this.namespace = namespace;
61 this.appInfo = appInfo;
62 this.nodeType = nodeType;
68 * @param name name of the node
70 public void name(String name) {
77 * @param namespace namespace of the node
79 public void namespace(Namespace namespace) {
80 this.namespace = namespace;
86 * @param uri uri of the node
88 public void uri(String uri) {
95 * @param parent parent node
97 public void parent(PropertiesNode parent) {
102 * Sets application info.
104 * @param appInfo application info
106 public void appInfo(Object appInfo) {
107 this.appInfo = appInfo;
111 * Sets to true if module name is required in forming a request; false
114 * @param isNotReq true if required; false otherwise
116 public void nonAppend(boolean isNotReq) {
117 this.nonAppend = isNotReq;
123 * @return parent node
125 public PropertiesNode parent() {
132 * @return name of the node
134 public String name() {
141 * @return namespace of the node
143 public Namespace namespace() {
150 * @return uri of the node
152 public String uri() {
157 * Returns application info.
159 * @return application info
161 public Object appInfo() {
170 public NodeType nodeType() {
175 * Returns if module name is required.
177 * @return status of module name if required
179 public boolean nonAppend() {
184 * Returns augmentations.
186 * @return augmentations
188 public Multimap<Object, PropertiesNode> augmentations() {
189 return augmentations;
193 * Sets augmentations.
195 * @param augmentations augmentations of the node
197 public void augmentations(Multimap<Object, PropertiesNode> augmentations) {
198 this.augmentations = augmentations;
202 * Adds a child to a current node.
204 * @param name name of child
205 * @param namespace namespace of child, null represents parent namespace
206 * @param type type of node
207 * @param appInfo application info
208 * @return added properties node
210 public abstract PropertiesNode addChild(String name, Namespace namespace,
212 Object appInfo) throws SvcLogicException;
215 * Adds a child with value to a current node.
217 * @param name name of child
218 * @param namespace namespace of child, null represents parent namespace
219 * @param type type of node
220 * @param value value of node
221 * @param valueNs value namespace
222 * @param appInfo application info
223 * @throws SvcLogicException if failed to add child
224 * @return added properties node
226 public abstract PropertiesNode addChild(String name, Namespace namespace,
227 NodeType type, String value,
229 Object appInfo) throws SvcLogicException;
232 * Adds a child at a given index to a current node. To be used in case of
233 * leaf holder child's which is multi instance node.
235 * @param index index at which node is to be added
236 * @param name name of child
237 * @param namespace namespace of child, null represents parent namespace
238 * @param type type of node
239 * @param appInfo application info
240 * @throws SvcLogicException if failed to add child
241 * @return added properties node
243 public abstract PropertiesNode addChild(String index, String name,
246 Object appInfo) throws SvcLogicException;
249 * Adds a child at a given index to a current node. To be used in case of
250 * leaf holder child's which is multi instance node.
252 * @param index index at which node is to be added
253 * @param name name of child
254 * @param namespace namespace of child, null represents parent namespace
255 * @param type type of node
256 * @param value value of node
257 * @param valueNs value namespace
258 * @param appInfo application info
259 * @throws SvcLogicException if failed to add child
260 * @return added properties node
262 public abstract PropertiesNode addChild(String index, String name,
263 Namespace namespace, NodeType type,
264 String value, Namespace valueNs,
265 Object appInfo) throws SvcLogicException;
272 public PropertiesNode endNode() {
273 PropertiesNode node = this;
274 while (node.parent() != null){
275 node = node.parent();