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 org.onap.ccsdk.sli.core.sli.SvcLogicException;
28 * Implementation of properties node walker which helps in forming a new tree from properties node.
30 * @param <T> node child of properties node.
32 public class DefaultPropertiesNodeWalker<T extends NodeChild> implements PropertiesNodeWalker {
35 public void walk(PropertiesNodeListener listener,
36 PropertiesNode propertiesNode) throws SvcLogicException {
37 listener.start(propertiesNode);
38 walkChildNode(listener, propertiesNode);
39 listener.end(propertiesNode);
43 * Walks the children node from the parent node.
45 * @param listener properties node listener
46 * @param propertiesNode properties node
47 * @throws SvcLogicException when properties node walking fails
49 public void walkChildNode(PropertiesNodeListener listener,
50 PropertiesNode propertiesNode)
51 throws SvcLogicException {
52 Map<String, T> children = getChildren(propertiesNode);
53 if (children != null) {
54 for (Map.Entry<String, T> entry : children.entrySet()) {
55 PropertiesNode node = ((PropertiesNode) entry.getValue());
56 listener.enterPropertiesNode(node);
57 walkChildNode(listener, node);
58 listener.exitPropertiesNode(node);
64 * Returns the children node according to the property node type.
66 * @param value property node
67 * @return property node children
69 private Map<String,T> getChildren(PropertiesNode value) {
70 if (value instanceof RootNode) {
71 return ((RootNode) value).children();
73 switch (value.nodeType()) {
74 case SINGLE_INSTANCE_NODE:
75 return ((InnerNode) value).children();
76 case MULTI_INSTANCE_HOLDER_NODE:
77 return ((Map<String, T>) ((ListHolderNode) value).children());
78 case MULTI_INSTANCE_NODE:
79 return ((Map<String, T>) ((MultiInstanceNode) value)
81 case MULTI_INSTANCE_LEAF_HOLDER_NODE:
82 return ((Map<String, T>) ((LeafListHolderNode) value)
84 case SINGLE_INSTANCE_LEAF_NODE:
85 case MULTI_INSTANCE_LEAF_NODE:
88 throw new IllegalArgumentException("No more types allowed");