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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.context;
23 import com.google.gson.JsonElement;
25 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
26 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
29 * This interface is implemented by plugin classes that use a particular schema to convert Apex context objects to an
30 * understandable form.
32 * @author Liam Fallon (liam.fallon@ericsson.com)
34 public interface SchemaHelper {
37 * Initialize the schema helper with its properties.
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
43 void init(AxKey userKey, AxContextSchema schema) throws ContextRuntimeException;
46 * Get the user key of the schema helper.
48 * @return the user key
53 * Get the schema of the schema helper.
57 AxContextSchema getSchema();
60 * The Java class that this schema produces on the Java side.
62 * @return the schema class
64 Class<?> getSchemaClass();
67 * The Java class that handles the schema for the schema technology in use.
69 * @return the schema object
71 Object getSchemaObject();
74 * Create a new instance of the schema class using whatever schema technology is being used.
76 * @return the new instance
78 Object createNewInstance();
81 * Create a new instance of the schema class using whatever schema technology is being used.
83 * @param stringValue the string represents the value the new instance should have
84 * @return the new instance
86 Object createNewInstance(String stringValue);
89 * Create a new instance of the schema class from a GSON JsonElement using whatever schema technology is being used.
91 * @param jsonElement the JSON element that holds the Json representation of the object
92 * @return the new instance
94 Object createNewInstance(JsonElement jsonElement);
97 * Unmarshal an object in schema format into a Java object.
99 * @param object the object as a Java object
100 * @return the object in schema format
102 Object unmarshal(Object object);
105 * Marshal a Java object into Json format.
107 * @param schemaObject the object in schema format
108 * @return the object as a Json string
110 String marshal2Json(Object schemaObject);
113 * Marshal a Java object into a GSON json element.
115 * @param schemaObject the object in schema format
116 * @return the object as a GSON Json element
118 JsonElement marshal2JsonElement(Object schemaObject);