2466023fafb7b7f37b37fd3f28bec5bf2fe057f9
[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 org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
24 import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
25
26 /**
27  * Abstraction of an entity which helps the data format serializers to obtain
28  * schema context details and to build properties from data.
29  *
30  * @param <T> type of schema node
31  * @param <P> type of schema context
32  */
33 public abstract class SerializerHelper<T, P> {
34
35     /**
36      * Schema node of the last element in the URI.
37      */
38     protected T schemaNode;
39
40     /**
41      * Root schema context.
42      */
43     protected P schemaCtx;
44
45     /**
46      * Root URI.
47      */
48     protected String rootUri;
49
50     /**
51      * Creates an instance of the serializer helper with the schema node,
52      * schema context and the URI.
53      *
54      * @param t schema node
55      * @param p schema context
56      * @param u root URI
57      */
58     protected SerializerHelper(T t, P p, String u) {
59         schemaNode = t;
60         schemaCtx = p;
61         rootUri = u;
62     }
63
64     /**
65      * Returns schema node of the last element in the URI.
66      *
67      * @return schema node
68      */
69     protected abstract T getSchemaNode();
70
71     /**
72      * Returns the root schema context.
73      *
74      * @return schema context
75      */
76     protected abstract P getSchemaCtx();
77
78     /**
79      * Returns the current schema context node.
80      *
81      * @return current schema context node
82      */
83     protected abstract T getCurSchema();
84
85     /**
86      * Adds a node to the properties node tree.
87      *
88      * @param name         name of the node
89      * @param nameSpace    name space of the node, it can be either module
90      *                     name or namespace; null indicates parent namespace
91      * @param value        value of the node; applicable for leaf/leaf-list node
92      * @param valNameSpace value namespace for identityref, could be module
93      *                     name or namespace
94      * @param type         type of node if known like in case of JSON
95      */
96     protected abstract void addNode(String name, String nameSpace, String value,
97                                     String valNameSpace, NodeType type);
98
99     /**
100      * Exits the node, in case if it's leaf node then it adds to the properties
101      * map.
102      */
103     protected abstract void exitNode();
104
105     /**
106      * Returns the built properties corresponding to the data.
107      *
108      * @return properties node.
109      */
110     protected abstract PropertiesNode getPropertiesNode();
111 }