Add abstract properties node tree
[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 Multimap<Object, PropertiesNode> augmentations = ArrayListMultimap.create();
42
43     /**
44      * Creates an instance of properties node.
45      *
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
53      */
54     protected PropertiesNode(String name, Namespace namespace, String uri,
55                              PropertiesNode parent, Object appInfo, NodeType nodeType) {
56         this.name = name;
57         this.namespace = namespace;
58         this.uri = uri;
59         this.parent = parent;
60         this.appInfo = appInfo;
61         this.nodeType = nodeType;
62     }
63
64     /**
65      * Sets name.
66      *
67      * @param name name of the node
68      */
69     public void name(String name) {
70         this.name = name;
71     }
72
73     /**
74      * Sets namespace.
75      *
76      * @param namespace namespace of the node
77      */
78     public void namespace(Namespace namespace) {
79         this.namespace = namespace;
80     }
81
82     /**
83      * Sets uri.
84      *
85      * @param uri uri of the node
86      */
87     public void uri(String uri) {
88         this.uri = uri;
89     }
90
91     /**
92      * Sets parent node.
93      *
94      * @param parent parent node
95      */
96     public void parent(PropertiesNode parent) {
97         this.parent = parent;
98     }
99
100     /**
101      * Sets application info.
102      *
103      * @param appInfo application info
104      */
105     public void appInfo(Object appInfo) {
106         this.appInfo = appInfo;
107     }
108
109     /**
110      * Returns parent.
111      *
112      * @return parent node
113      */
114     public PropertiesNode parent() {
115         return parent;
116     }
117
118     /**
119      * Returns name.
120      *
121      * @return name of the node
122      */
123     public String name() {
124         return name;
125     }
126
127     /**
128      * Returns namespace.
129      *
130      * @return namespace of the node
131      */
132     public Namespace namespace() {
133         return namespace;
134     }
135
136     /**
137      * Returns uri.
138      *
139      * @return uri of the node
140      */
141     public String uri() {
142         return uri;
143     }
144
145     /**
146      * Returns application info.
147      *
148      * @return application info
149      */
150     public Object appInfo() {
151         return appInfo;
152     }
153
154     /**
155      * Returns node type.
156      *
157      * @return node type
158      */
159     public NodeType nodeType() {
160         return nodeType;
161     }
162
163     /**
164      * Returns augmentations.
165      *
166      * @return augmentations
167      */
168     public Multimap<Object, PropertiesNode> augmentations() {
169         return augmentations;
170     }
171
172     /**
173      * Sets augmentations.
174      *
175      * @param augmentations augmentations of the node
176      */
177     public void augmentations(Multimap<Object, PropertiesNode> augmentations) {
178         this.augmentations = augmentations;
179     }
180
181     /**
182      * Adds a child to a current node.
183      *
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
189      */
190     public abstract PropertiesNode addChild(String name, Namespace namespace,
191                                             NodeType type,
192                                             Object appInfo) throws SvcLogicException;
193
194     /**
195      * Adds a child with value to a current node.
196      *
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
205      */
206     public abstract PropertiesNode addChild(String name, Namespace namespace,
207                                             NodeType type, String value,
208                                             Namespace valueNs,
209                                             Object appInfo) throws SvcLogicException;
210
211     /**
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.
214      *
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
222      */
223     public abstract PropertiesNode addChild(String index, String name,
224                                             Namespace namespace,
225                                             NodeType type,
226                                             Object appInfo) throws SvcLogicException;
227
228     /**
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.
231      *
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
241      */
242     public abstract PropertiesNode addChild(String index, String name,
243                                             Namespace namespace, NodeType type,
244                                             String value, Namespace valueNs,
245                                             Object appInfo) throws SvcLogicException;
246
247     /**
248      * Returns root node.
249      *
250      * @return root node
251      */
252     public PropertiesNode endNode() {
253         PropertiesNode node = this;
254         while (node.parent() != null){
255             node = node.parent();
256         }
257         return node;
258     }
259 }
260