4e6d2944d1192d8ca9e6df88d24fe30d9b616a5e
[ccsdk/sli/plugins.git] / restconf-client / provider / src / main / java / org / onap / ccsdk / sli / plugins / yangserializers / dfserializer / SerializerHelper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - CCSDK
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
22
23 import java.util.Map;
24
25 /**
26  * Abstraction of an entity which helps the data format serializers to obtain
27  * schema context details and to build properties from data.
28  *
29  * @param <T> type of schema node
30  */
31 public abstract class SerializerHelper<T> {
32
33     private T rootSchema;
34     private String rootURI;
35
36     protected SerializerHelper(T t, String uri) {
37         rootSchema = t;
38     }
39
40     /**
41      * Returns root schema context node.
42      *
43      * @return root schema context node
44      */
45     protected abstract T getRootContext();
46
47     /**
48      * Returns current schema context node.
49      *
50      * @return current schema context node
51      */
52     protected abstract T getCurContext();
53
54     /**
55      * Returns child schema context node.
56      *
57      * @return child schema context node
58      */
59     protected abstract T getChildContext(T t, String name, String namespace);
60
61     /**
62      * Returns type of node
63      * @param t node
64      * @return node type
65      */
66     protected abstract NodeType getNodeType(T t);
67
68     /**
69      * Adds a node to current tree.
70      *
71      * @param name name of node
72      * @param namespace namespace of node, it can be either module name or
73      * namespace, null indicates parent namespace
74      * @param value value of node, in case it's leaf/leaf-list node
75      * @param valNamespace value namespace for identityref, could be module
76      * name or namespace
77      * @param type type of node if known like in case of JSON
78      */
79     protected abstract void addNode(String name, String namespace, String value,
80         String valNamespace, NodeType type);
81
82     /**
83      * Exits the node, in case if it's leaf node add to properties map.
84      */
85     protected abstract void exitNode();
86
87     /**
88      * Returns the properties built corresponding to data.
89      *
90      * @return properties map
91      */
92     protected abstract Map<String, String> getProperties();
93 }