aa6ea9ffeb1bedc2ba681645a3b08b8267748d40
[policy/apex-pdp.git] / context / context-management / src / main / java / org / onap / policy / apex / context / SchemaHelper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.context;
22
23 import com.google.gson.JsonElement;
24
25 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
26 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
27
28 /**
29  * This interface is implemented by plugin classes that use a particular schema to convert Apex context objects to an
30  * understandable form.
31  *
32  * @author Liam Fallon (liam.fallon@ericsson.com)
33  */
34 public interface SchemaHelper {
35
36     /**
37      * Initialize the schema helper with its properties.
38      *
39      * @param userKey The key that identifies the user of the schema helper
40      * @param schema the schema
41      * @throws ContextRuntimeException the context runtime exception
42      */
43     void init(AxKey userKey, AxContextSchema schema) throws ContextRuntimeException;
44
45     /**
46      * Get the user key of the schema helper.
47      *
48      * @return the user key
49      */
50     AxKey getUserKey();
51
52     /**
53      * Get the schema of the schema helper.
54      *
55      * @return the schema
56      */
57     AxContextSchema getSchema();
58
59     /**
60      * The Java class that this schema produces on the Java side.
61      *
62      * @return the schema class
63      */
64     Class<?> getSchemaClass();
65
66     /**
67      * The Java class that handles the schema for the schema technology in use.
68      *
69      * @return the schema object
70      */
71     Object getSchemaObject();
72
73     /**
74      * Create a new instance of the schema class using whatever schema technology is being used.
75      *
76      * @return the new instance
77      */
78     Object createNewInstance();
79
80     /**
81      * Create a new instance of the schema class using whatever schema technology is being used.
82      *
83      * @param stringValue the string represents the value the new instance should have
84      * @return the new instance
85      */
86     Object createNewInstance(String stringValue);
87
88     /**
89      * Create a new instance of the schema class from a GSON JsonElement using whatever schema technology is being used.
90      *
91      * @param jsonElement the JSON element that holds the Json representation of the object
92      * @return the new instance
93      */
94     Object createNewInstance(JsonElement jsonElement);
95
96     /**
97      * Unmarshal an object in schema format into a Java object.
98      *
99      * @param object the object as a Java object
100      * @return the object in schema format
101      */
102     Object unmarshal(Object object);
103
104     /**
105      * Marshal a Java object into Json format.
106      *
107      * @param schemaObject the object in schema format
108      * @return the object as a Json string
109      */
110     String marshal2Json(Object schemaObject);
111
112     /**
113      * Marshal a Java object into a GSON json element.
114      *
115      * @param schemaObject the object in schema format
116      * @return the object as a GSON Json element
117      */
118     JsonElement marshal2JsonElement(Object schemaObject);
119 }