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;
26 * Implementation of properties node walker which helps in forming a new tree from properties node.
28 * @param <T> node child of properties node.
30 public class DefaultPropertiesNodeWalker<T extends NodeChild> implements PropertiesNodeWalker {
33 public void walk(PropertiesNodeListener listener,
34 PropertiesNode propertiesNode) {
35 listener.start(propertiesNode);
36 walkChildNode(listener, propertiesNode);
37 listener.end(propertiesNode);
41 * Walks the children node from the parent node.
43 * @param listener properties node listener
44 * @param propertiesNode properties node
46 public void walkChildNode(PropertiesNodeListener listener,
47 PropertiesNode propertiesNode) {
48 Map<String, T> children = getChildren(propertiesNode);
49 if (children != null) {
50 for (Map.Entry<String, T> entry : children.entrySet()) {
51 PropertiesNode node = ((PropertiesNode) entry.getValue());
52 listener.enterPropertiesNode(node);
53 walkChildNode(listener, node);
54 listener.exitPropertiesNode(node);
60 * Returns the children node according to the property node type.
62 * @param value property node
63 * @return property node children
65 private Map<String,T> getChildren(PropertiesNode value) {
66 if (value instanceof RootNode) {
67 return ((RootNode) value).children();
69 switch (value.nodeType()) {
70 case SINGLE_INSTANCE_NODE:
71 return ((InnerNode) value).children();
72 case MULTI_INSTANCE_HOLDER_NODE:
73 return ((Map<String, T>) ((ListHolderNode) value).children());
74 case MULTI_INSTANCE_NODE:
75 return ((Map<String, T>) ((MultiInstanceNode) value)
77 case MULTI_INSTANCE_LEAF_HOLDER_NODE:
78 return ((Map<String, T>) ((LeafListHolderNode) value)
80 case SINGLE_INSTANCE_LEAF_NODE:
81 case MULTI_INSTANCE_LEAF_NODE:
84 throw new IllegalArgumentException("No more types allowed");