81609a6da7c1d5a5c98e4352f2dc371d61ba31c4
[ccsdk/sli/plugins.git] / restconf-client / provider / src / main / java / org / onap / ccsdk / sli / plugins / yangserializers / pnserializer / PropertiesNodeSerializer.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.pnserializer;
22
23 import java.util.Map;
24
25 /**
26  * Abstraction of an entity to enable encoding and decoding of properties
27  * to an abstract properties node tree using YANG based schema.
28  * This serializer will be used by other data format serializers and will keep
29  * them abstract from properties nuances thereby enabling quick addition of any
30  * new data format serializer.
31  *
32  * @param <T> type of schema node
33  * @param <P> schema context of the model
34  */
35 public abstract class PropertiesNodeSerializer<T, P> {
36
37     /**
38      * Schema node from which the property is made.
39      */
40     private T schemaNode;
41
42     /**
43      * Schema context of the model.
44      */
45     private P schemaCtx;
46
47     /**
48      * URL pointing to the schema node.
49      */
50     private String uri;
51
52     /**
53      * Creates the properties node serializer.
54      *
55      * @param schemaNode schema node.
56      * @param schemaCtx schema context
57      * @param uri URL of the request
58      */
59     public PropertiesNodeSerializer(T schemaNode, P schemaCtx, String uri) {
60         this.schemaNode = schemaNode;
61         this.schemaCtx = schemaCtx;
62         this.uri = uri;
63     }
64
65
66     /**
67      * Encodes from properties to properties-node tree.
68      *
69      * @param paramMap parameter map
70      * @return properties node
71      */
72     public abstract PropertiesNode encode(Map<String, String> paramMap);
73
74     /**
75      * Decodes from properties-node to properties map.
76      *
77      * @param propertiesNode properties-node
78      * @return parameter map
79      */
80     public abstract Map<String, String> decode(PropertiesNode propertiesNode);
81
82     /**
83      * Returns the schema node of the property
84      *
85      * @return schema node
86      */
87     public T getSchemaNode(){
88         return schemaNode;
89     }
90
91     /**
92      * Returns the schema context
93      *
94      * @return schema node
95      */
96     public P getSchemaCtx() {
97         return schemaCtx;
98     }
99
100     /**
101      * Returns the URI.
102      *
103      * @return uri
104      */
105     public String getUri() {
106         return uri;
107     }
108 }