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.dfserializer;
23 import com.fasterxml.jackson.databind.JsonNode;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
27 import static java.lang.String.format;
28 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerUtil.NODE_TYPE_ERR;
29 import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.MULTI_INSTANCE_LEAF_NODE;
30 import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.MULTI_INSTANCE_NODE;
31 import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.SINGLE_INSTANCE_LEAF_NODE;
32 import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.SINGLE_INSTANCE_NODE;
36 * Representation of default implementation of JSON listener.
38 public class DefaultJsonListener implements JsonListener {
41 * Serializer helper to convert to properties node.
43 private SerializerHelper serializerHelper;
46 * Name of the current JSON node.
51 * Module name of the current JSON node.
53 private String modName;
56 * Creates an instance of default json listener with its serializer helper.
58 * @param serializerHelper serializer helper
60 public DefaultJsonListener(SerializerHelper serializerHelper) {
61 this.serializerHelper = serializerHelper;
65 public void enterJsonNode(String nodeName, JsonNode node,
66 NodeType nodeType) throws SvcLogicException {
67 getNodeName(nodeName);
70 case SINGLE_INSTANCE_LEAF_NODE:
71 serializerHelper.addNode(name, modName, node.asText(), null,
72 SINGLE_INSTANCE_LEAF_NODE);
75 case MULTI_INSTANCE_LEAF_NODE:
76 serializerHelper.addNode(name, modName, node.asText(), null,
77 MULTI_INSTANCE_LEAF_NODE);
80 case SINGLE_INSTANCE_NODE:
81 serializerHelper.addNode(name, modName, null, null,
82 SINGLE_INSTANCE_NODE);
85 case MULTI_INSTANCE_NODE:
86 serializerHelper.addNode(name, modName, null, null,
91 throw new SvcLogicException(format(NODE_TYPE_ERR,
92 nodeType.toString()));
97 public void exitJsonNode(JsonNode node) throws SvcLogicException {
98 serializerHelper.exitNode();
102 public SerializerHelper serializerHelper() {
103 return serializerHelper;
107 * Parses the abstract JSON name and fills the node name and node
108 * namespace of the current JSON node.
110 * @param abstractName abstract JSON name
112 private void getNodeName(String abstractName) {
113 String[] val = abstractName.split(":");
114 if (val.length == 2) {