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.core.sli.SvcLogicException;
24 import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
25 import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
28 * Abstraction of an entity which helps the data format serializers to obtain
29 * schema context details and to build properties from data.
31 * @param <T> type of schema node
32 * @param <P> type of schema context
34 public abstract class SerializerHelper<T, P> {
37 * Schema node of the last element in the URI.
39 protected T schemaNode;
42 * Root schema context.
44 protected P schemaCtx;
49 protected String rootUri;
52 * Creates an instance of the serializer helper with the schema node,
53 * schema context and the URI.
55 * @param t schema node
56 * @param p schema context
59 protected SerializerHelper(T t, P p, String u) {
66 * Returns schema node of the last element in the URI.
70 protected abstract T getSchemaNode();
73 * Returns the root schema context.
75 * @return schema context
77 protected abstract P getSchemaCtx();
80 * Returns the current schema context node.
82 * @return current schema context node
84 protected abstract T getCurSchema();
87 * Adds a node to the properties node tree.
89 * @param name name of the node
90 * @param nameSpace name space of the node, it can be either module
91 * name or namespace; null indicates parent namespace
92 * @param value value of the node; applicable for leaf/leaf-list node
93 * @param valNameSpace value namespace for identityref, could be module
95 * @param type type of node if known like in case of JSON
96 * @throws SvcLogicException when adding node fails
98 protected abstract void addNode(String name, String nameSpace, String value,
99 String valNameSpace, NodeType type)
100 throws SvcLogicException;
103 * Exits the node, in case if it's leaf node then it adds to the properties
106 * @throws SvcLogicException when properties node tree is improper
108 protected abstract void exitNode() throws SvcLogicException;
111 * Returns the built properties corresponding to the data.
113 * @return properties node.
115 protected abstract PropertiesNode getPropertiesNode();