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 org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
24 import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
27 * Abstraction of an entity which helps the data format serializers to obtain
28 * schema context details and to build properties from data.
30 * @param <T> type of schema node
31 * @param <P> type of schema context
33 public abstract class SerializerHelper<T, P> {
36 * Schema node of the last element in the URI.
38 protected T schemaNode;
41 * Root schema context.
43 protected P schemaCtx;
48 protected String rootUri;
51 * Creates an instance of the serializer helper with the schema node,
52 * schema context and the URI.
54 * @param t schema node
55 * @param p schema context
58 protected SerializerHelper(T t, P p, String u) {
65 * Returns schema node of the last element in the URI.
69 protected abstract T getSchemaNode();
72 * Returns the root schema context.
74 * @return schema context
76 protected abstract P getSchemaCtx();
79 * Returns the current schema context node.
81 * @return current schema context node
83 protected abstract T getCurSchema();
86 * Adds a node to the properties node tree.
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
94 * @param type type of node if known like in case of JSON
96 protected abstract void addNode(String name, String nameSpace, String value,
97 String valNameSpace, NodeType type);
100 * Exits the node, in case if it's leaf node then it adds to the properties
103 protected abstract void exitNode();
106 * Returns the built properties corresponding to the data.
108 * @return properties node.
110 protected abstract PropertiesNode getPropertiesNode();