Bug fix to add anyxml node.
[ccsdk/sli/plugins.git] / restconf-client / provider / src / main / java / org / onap / ccsdk / sli / plugins / yangserializers / pnserializer / PropertiesNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - CCSDK
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
22
23 import com.google.common.collect.ArrayListMultimap;
24 import com.google.common.collect.Multimap;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
26
27 /**
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
31  * serializers.
32  */
33 public abstract class PropertiesNode {
34
35     private String name;
36     private Namespace namespace;
37     private String uri;
38     private PropertiesNode parent;
39     private Object appInfo;
40     private NodeType nodeType;
41     private boolean nonAppend;
42     private Multimap<Object, PropertiesNode> augmentations = ArrayListMultimap.create();
43
44     /**
45      * Creates an instance of properties node.
46      *
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
54      */
55     protected PropertiesNode(String name, Namespace namespace, String uri,
56                              PropertiesNode parent, Object appInfo, NodeType nodeType) {
57         this.name = name;
58         this.namespace = namespace;
59         this.uri = uri;
60         this.parent = parent;
61         this.appInfo = appInfo;
62         this.nodeType = nodeType;
63     }
64
65     /**
66      * Sets name.
67      *
68      * @param name name of the node
69      */
70     public void name(String name) {
71         this.name = name;
72     }
73
74     /**
75      * Sets namespace.
76      *
77      * @param namespace namespace of the node
78      */
79     public void namespace(Namespace namespace) {
80         this.namespace = namespace;
81     }
82
83     /**
84      * Sets uri.
85      *
86      * @param uri uri of the node
87      */
88     public void uri(String uri) {
89         this.uri = uri;
90     }
91
92     /**
93      * Sets parent node.
94      *
95      * @param parent parent node
96      */
97     public void parent(PropertiesNode parent) {
98         this.parent = parent;
99     }
100
101     /**
102      * Sets application info.
103      *
104      * @param appInfo application info
105      */
106     public void appInfo(Object appInfo) {
107         this.appInfo = appInfo;
108     }
109
110     /**
111      * Sets to true if module name is required in forming a request; false
112      * otherwise.
113      *
114      * @param isNotReq true if required; false otherwise
115      */
116     public void nonAppend(boolean isNotReq) {
117         this.nonAppend = isNotReq;
118     }
119
120     /**
121      * Returns parent.
122      *
123      * @return parent node
124      */
125     public PropertiesNode parent() {
126         return parent;
127     }
128
129     /**
130      * Returns name.
131      *
132      * @return name of the node
133      */
134     public String name() {
135         return name;
136     }
137
138     /**
139      * Returns namespace.
140      *
141      * @return namespace of the node
142      */
143     public Namespace namespace() {
144         return namespace;
145     }
146
147     /**
148      * Returns uri.
149      *
150      * @return uri of the node
151      */
152     public String uri() {
153         return uri;
154     }
155
156     /**
157      * Returns application info.
158      *
159      * @return application info
160      */
161     public Object appInfo() {
162         return appInfo;
163     }
164
165     /**
166      * Returns node type.
167      *
168      * @return node type
169      */
170     public NodeType nodeType() {
171         return nodeType;
172     }
173
174     /**
175      * Returns if module name is required.
176      *
177      * @return status of module name if required
178      */
179     public boolean nonAppend() {
180         return nonAppend;
181     }
182
183     /**
184      * Returns augmentations.
185      *
186      * @return augmentations
187      */
188     public Multimap<Object, PropertiesNode> augmentations() {
189         return augmentations;
190     }
191
192     /**
193      * Sets augmentations.
194      *
195      * @param augmentations augmentations of the node
196      */
197     public void augmentations(Multimap<Object, PropertiesNode> augmentations) {
198         this.augmentations = augmentations;
199     }
200
201     /**
202      * Adds a child to a current node.
203      *
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
209      */
210     public abstract PropertiesNode addChild(String name, Namespace namespace,
211                                             NodeType type,
212                                             Object appInfo) throws SvcLogicException;
213
214     /**
215      * Adds a child with value to a current node.
216      *
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
225      */
226     public abstract PropertiesNode addChild(String name, Namespace namespace,
227                                             NodeType type, String value,
228                                             Namespace valueNs,
229                                             Object appInfo) throws SvcLogicException;
230
231     /**
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.
234      *
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
242      */
243     public abstract PropertiesNode addChild(String index, String name,
244                                             Namespace namespace,
245                                             NodeType type,
246                                             Object appInfo) throws SvcLogicException;
247
248     /**
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.
251      *
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
261      */
262     public abstract PropertiesNode addChild(String index, String name,
263                                             Namespace namespace, NodeType type,
264                                             String value, Namespace valueNs,
265                                             Object appInfo) throws SvcLogicException;
266
267     /**
268      * Returns root node.
269      *
270      * @return root node
271      */
272     public PropertiesNode endNode() {
273         PropertiesNode node = this;
274         while (node.parent() != null){
275             node = node.parent();
276         }
277         return node;
278     }
279 }
280