blob: a5b65560d1a5e1aeb261b5e4da1e046c0056f3ae [file] [log] [blame]
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
sonu guptaeff184b2016-11-24 12:43:49 +053017package org.onosproject.yms.app.ypm;
18
19import org.onosproject.yangutils.datamodel.YangSchemaNode;
20import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
21import org.onosproject.yms.app.ydt.AppType;
22import org.onosproject.yms.app.ydt.YdtExtendedContext;
23import org.onosproject.yms.app.ydt.YdtNode;
24import org.onosproject.yms.ydt.YdtContext;
25import org.onosproject.yms.ydt.YdtContextOperationType;
26import org.onosproject.yms.ydt.YdtExtendedInfoType;
27import org.onosproject.yms.ydt.YdtType;
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +053028
29import java.util.HashMap;
30import java.util.List;
31import java.util.Map;
32import java.util.Set;
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +053033
34/**
35 * Represents implementation of interfaces to build and obtain YANG data tree.
36 */
37public class YdtNodeAdapter<T> implements YdtExtendedContext {
38
39 /**
40 * Parent reference.
41 */
42 private YdtNodeAdapter parent;
43
44 /**
45 * First child reference.
46 */
47 private YdtNodeAdapter child;
48
49 /**
50 * Next sibling reference.
51 */
52 private YdtNodeAdapter nextSibling;
53
54 /**
55 * Previous sibling reference.
56 */
57 private YdtNodeAdapter previousSibling;
58
59 /**
60 * Last child reference.
61 */
62 private YdtNode lastChild;
63
64 /**
65 * Type of node.
66 */
67 private YdtType ydtType;
68
69 /**
70 * Flag to keep the track of context switch.
71 */
72 private boolean isContextSwitch;
73
74 private T ydtExtendedInfo;
75
76 /**
77 * YDT extended information type.
78 */
79 YdtExtendedInfoType ydtExtendedInfoType;
80
81 /**
82 * Ydt map to keep the track of node added in YDT.
83 */
84 private Map<YangSchemaNodeIdentifier, List<YdtNode<T>>> ydtNodeMap = new HashMap<>();
85
86 /**
87 * Reference for data-model schema node.
88 */
89 private YangSchemaNode yangSchemaNode;
90
91 /**
92 * Reference for ydt node operation type.
93 */
94 private YdtContextOperationType ydtContextOperationType;
95
96 /**
97 * Key object for ydtNodeMap.
98 */
99 protected YangSchemaNodeIdentifier nodeIdentifier;
100
101 /**
102 * Ydt map to keep the track of application information object with respective type.
103 */
104 Map<AppType, Object> ydtAppInfoMap = new HashMap<>();
105
106
107 /**
108 * Creation of YANG node object.
109 */
110 public YdtNodeAdapter() {
111 }
112
113 /**
114 * Creates a specific type of node.
115 *
116 * @param type of YDT node
117 * @param name name of the YDT node
118 */
119 public YdtNodeAdapter(YdtType type, String name) {
120 setYdtType(type);
121 }
122
123 @Override
124 public String getName() {
125 return this.nodeIdentifier.getName();
126 }
127
128 @Override
129 public String getNamespace() {
sonu guptaeff184b2016-11-24 12:43:49 +0530130 return yangSchemaNode.getNameSpace().getModuleNamespace();
131 }
132
133 @Override
134 public String getModuleNameAsNameSpace() {
135 return null;
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +0530136 }
137
138 @Override
139 public <T> T getYdtContextExtendedInfo() {
140 return (T) ydtExtendedInfo;
141 }
142
143 @Override
144 public YdtExtendedInfoType getYdtExtendedInfoType() {
145 return ydtExtendedInfoType;
146 }
147
148 @Override
149 public YdtType getYdtType() {
150 return ydtType;
151 }
152
153 /**
154 * Sets the node type.
155 *
156 * @param ydtType type of YDT attribute
157 */
158 public void setYdtType(YdtType ydtType) {
159 this.ydtType = ydtType;
160 }
161
162 @Override
163 public YdtNodeAdapter getParent() {
164 return parent;
165 }
166
167 /**
168 * Sets the parent of node.
169 *
170 * @param parent node
171 */
172 public void setParent(YdtNodeAdapter parent) {
173 this.parent = parent;
174 }
175
176 @Override
177 public YdtNodeAdapter getFirstChild() {
178 return child;
179 }
180
181 @Override
182 public YdtNodeAdapter getNextSibling() {
183 return nextSibling;
184 }
185
186 /**
187 * Sets the next sibling of node.
188 *
189 * @param sibling YANG node
190 */
191 public void setNextSibling(YdtNodeAdapter sibling) {
192 nextSibling = sibling;
193 }
194
195 @Override
196 public YdtNodeAdapter getPreviousSibling() {
197 return previousSibling;
198 }
199
200 /**
201 * Sets the previous sibling.
202 *
203 * @param previousSibling points to predecessor sibling
204 */
205 public void setPreviousSibling(YdtNodeAdapter previousSibling) {
206 this.previousSibling = previousSibling;
207 }
208
209 /**
210 * Returns data-model node reference for of a given node.
211 *
212 * @return yang schema data node of a data-model.
213 */
214 public YangSchemaNode getYangSchemaNode() {
215 return yangSchemaNode;
216 }
217
218 /**
219 * Sets the data-model node reference for of a given node..
220 *
221 * @param yangSchemaNode YANG data node.
222 */
223 public void setYangSchemaNode(YangSchemaNode yangSchemaNode) {
224 this.yangSchemaNode = yangSchemaNode;
225 }
226
227 @Override
228 public YdtNode getLastChild() {
229 return lastChild;
230 }
231
232 /**
233 * Sets the last instance of a child node.
234 *
235 * @param child is last child to be set
236 */
237 public void setLastChild(YdtNode child) {
238 this.lastChild = child;
239 }
240
241 public void setNodeIdentifier(YangSchemaNodeIdentifier nodeIdentifier) {
242 this.nodeIdentifier = nodeIdentifier;
243 }
244
245 /**
246 * Adds a child node.
247 *
248 * @param newChild refers to a child to be added
249 */
250 public void addChild(YdtContext newChild) {
251
252 ((YdtNodeAdapter) newChild).setParent(this);
253
254 if (this.child == null) {
255 this.child = (YdtNodeAdapter) newChild;
256 return;
257 }
258
259 YdtNodeAdapter currNode = this.child;
260 while (currNode.getNextSibling() != null) {
261 currNode = currNode.getNextSibling();
262 }
263 currNode.setNextSibling((YdtNodeAdapter) newChild);
264 ((YdtNodeAdapter) newChild).setPreviousSibling(currNode);
265 }
266
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +0530267 /**
268 * Adds a sibling to YANG data tree.
269 *
270 * @param newSibling context of sibling to be added
271 */
272 public void addSibling(YdtContext newSibling) {
273
274 ((YdtNodeAdapter) newSibling).setParent(this.getParent());
275
276 YdtNodeAdapter currNode = this;
277
278 while (currNode.getNextSibling() != null) {
279 currNode = currNode.getNextSibling();
280 }
281 currNode.setNextSibling((YdtNodeAdapter) newSibling);
282 ((YdtNodeAdapter) newSibling).setPreviousSibling(currNode);
283 }
284
285 /**
286 * Gets the flag for node if context switch.
287 *
288 * @return isContextSwitch flag of a node.
289 */
290 public boolean getContextSwitch() {
291 return isContextSwitch;
292 }
293
294 /**
295 * Sets the flag to keep the track of context switch.
296 *
297 * @param contextSwitch boolean flag.
298 */
299 public void setContextSwitch(boolean contextSwitch) {
300 isContextSwitch = contextSwitch;
301 }
302
303 @Override
304 public String getValue() {
305 return null;
306 }
307
308 @Override
309 public Set<String> getValueSet() {
310 return null;
311 }
312
313 @Override
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +0530314 public Object getAppInfo(AppType appType) {
315 return null;
316 }
317
318 @Override
sonu guptaeff184b2016-11-24 12:43:49 +0530319 public void addAppInfo(AppType appType, Object object) {
320
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +0530321 }
Ray Milkeyb2fdb742016-11-23 10:12:42 -0800322
323 @Override
sonu guptaeff184b2016-11-24 12:43:49 +0530324 public YdtContextOperationType getYdtContextOperationType() {
325 return ydtContextOperationType;
Ray Milkeyb2fdb742016-11-23 10:12:42 -0800326 }
Mahesh Poojary Huaweia330c582016-08-26 10:38:10 +0530327}