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 * Value of the current JSON node.
61 * Value namespace of the current JSON node.
63 private String valueNs;
66 * Creates an instance of default json listener with its serializer helper.
68 * @param serializerHelper serializer helper
70 public DefaultJsonListener(SerializerHelper serializerHelper) {
71 this.serializerHelper = serializerHelper;
75 public void enterJsonNode(String nodeName, JsonNode node,
76 NodeType nodeType) throws SvcLogicException {
77 getNodeName(nodeName, false);
80 case SINGLE_INSTANCE_LEAF_NODE:
81 getNodeName(node.asText(), true);
82 serializerHelper.addNode(name, modName, value, valueNs,
83 SINGLE_INSTANCE_LEAF_NODE);
86 case MULTI_INSTANCE_LEAF_NODE:
87 getNodeName(node.asText(), true);
88 serializerHelper.addNode(name, modName, value, valueNs,
89 MULTI_INSTANCE_LEAF_NODE);
92 case SINGLE_INSTANCE_NODE:
93 serializerHelper.addNode(name, modName, null, null,
94 SINGLE_INSTANCE_NODE);
97 case MULTI_INSTANCE_NODE:
98 serializerHelper.addNode(name, modName, null, null,
103 throw new SvcLogicException(format(NODE_TYPE_ERR,
104 nodeType.toString()));
109 public void exitJsonNode(JsonNode node) throws SvcLogicException {
110 serializerHelper.exitNode();
114 public SerializerHelper serializerHelper() {
115 return serializerHelper;
119 * Parses the abstract JSON name and fills the node name and node
120 * namespace or value and value namespace of the current JSON node .
122 * @param abstractName full name value
123 * @param isVal if it is for value parsing
125 private void getNodeName(String abstractName, boolean isVal) {
126 String[] val = abstractName.split(":");
127 if (val.length == 2) {