From be3d4606d9627e5dfb461b72140f7be52e1c7776 Mon Sep 17 00:00:00 2001 From: gaurav Date: Wed, 25 Jul 2018 11:33:13 +0530 Subject: Adding additional APIs for YANG serializers Adding APIs for YANG based properties node serializer Change-Id: Ic76204e0292fdbaede4ff47f4ddda91dcfa3b764 Issue-ID: CCSDK-377 Signed-off-by: Gaurav Agrawal --- .../sli/plugins/yangserializers/Annotation.java | 59 ---------- .../sli/plugins/yangserializers/DataFormat.java | 29 ----- .../yangserializers/DataFormatSerializer.java | 82 -------------- .../DataFormatSerializerContext.java | 74 ------------ .../plugins/yangserializers/JsonSerializer.java | 49 -------- .../sli/plugins/yangserializers/Listener.java | 34 ------ .../yangserializers/MdsalSerializerHelper.java | 67 ----------- .../sli/plugins/yangserializers/NodeType.java | 31 ------ .../plugins/yangserializers/SerializerHelper.java | 93 ---------------- .../sli/plugins/yangserializers/XmlSerializer.java | 49 -------- .../yangserializers/dfserializer/Annotation.java | 59 ++++++++++ .../yangserializers/dfserializer/DataFormat.java | 29 +++++ .../dfserializer/DataFormatSerializer.java | 82 ++++++++++++++ .../dfserializer/DataFormatSerializerContext.java | 74 ++++++++++++ .../dfserializer/JsonSerializer.java | 49 ++++++++ .../yangserializers/dfserializer/Listener.java | 34 ++++++ .../dfserializer/MdsalSerializerHelper.java | 67 +++++++++++ .../yangserializers/dfserializer/NodeType.java | 31 ++++++ .../dfserializer/SerializerHelper.java | 93 ++++++++++++++++ .../dfserializer/XmlSerializer.java | 49 ++++++++ .../MdsalPropertiesNodeSerializer.java | 59 ++++++++++ .../yangserializers/pnserializer/NodeType.java | 33 ++++++ .../pnserializer/PropertiesNode.java | 124 +++++++++++++++++++++ .../pnserializer/PropertiesNodeSerializer.java | 108 ++++++++++++++++++ 24 files changed, 891 insertions(+), 567 deletions(-) delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java delete mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Annotation.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormat.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializer.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerContext.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Listener.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/NodeType.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/SerializerHelper.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeSerializer.java diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java deleted file mode 100644 index 13f1c323..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -/** - * Representation of an entity that represents annotated attribute. - */ -public class Annotation { - - private String name; - private String value; - - /** - * Creates an instance of annotation. - * - * @param n annotation name - * @param v annotation value - */ - public Annotation(String n, String v) { - name = n; - value = v; - } - - /** - * Returns name of annotation. - * - * @return name of annotation - */ - public String name() { - return name; - } - - /** - * Returns value of annotation. - * - * @return value of annotation - */ - public String value() { - return value; - } -} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java deleted file mode 100644 index 0d1928b3..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -/** - * Representation of data format. - */ -public enum DataFormat { - XML, - JSON -} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java deleted file mode 100644 index bcd5991d..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -import java.util.List; -import java.util.Map; - -/** - * Abstraction of serializer to encode/decode context memory parameters - * to/from specified data format. - */ -public abstract class DataFormatSerializer { - - private DataFormat dataFormat; - private DataFormatSerializerContext serializerContext; - - /** - * Creates an instance of data format serializer. - * - * @param dataFormat type of data format - * @param serializerContext data format serializer context - */ - protected DataFormatSerializer(DataFormat dataFormat, - DataFormatSerializerContext serializerContext) { - this.dataFormat = dataFormat; - this.serializerContext = serializerContext; - } - - /** - * Encodes context memory parameters to data format. - * - * @param param context memory parameter - * @param annotations annotations - * @return data format body - */ - public abstract String encode(Map param, - Map> annotations); - - /** - * Decodes data format body to context memory parameters. - * - * @param dataFormatBody abstract node - * @return context memory parameters - */ - public abstract Map decode(String dataFormatBody); - - /** - * Returns data format serializer context. - * - * @return data format serializer context - */ - public DataFormatSerializerContext serializerContext() { - return serializerContext; - } - - /** - * Returns supported data format. - * - * @return supported data format - */ - public DataFormat dataFormat() { - return dataFormat; - } -} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java deleted file mode 100644 index 50cb2daf..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -import java.util.Map; - -/** - * Abstraction of data format serializer context. - */ -public class DataFormatSerializerContext { - - private Listener listener; - private String uri; - private Map protocolAnnotation; - - /** - * Creates an instance of data format serializer context. - * - * @param listener data format listener - * @param uri URI corresponding to instance identifier - * @param protocolAnnotation protocol annotations - */ - public DataFormatSerializerContext(Listener listener, String uri, - Map protocolAnnotation) { - this.listener = listener; - this.uri = uri; - this.protocolAnnotation = protocolAnnotation; - } - - /** - * Retruns data format listener. - * - * @return data format listener - */ - public Listener listener() { - return listener; - } - - /** - * Returns URI. - * - * @return URI - */ - public String uri() { - return uri; - } - - /** - * Returns protocol annotations. - * - * @return protocol annotations - */ - public Map getProtocolAnnotation() { - return protocolAnnotation; - } -} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java deleted file mode 100644 index 072cfb09..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -import java.util.List; -import java.util.Map; - -/** - * Representation of JSON serializer. - */ -public class JsonSerializer extends DataFormatSerializer { - - /** - * Creates an instance of data format serializer. - * - * @param serializerContext data format serializer context - */ - protected JsonSerializer(DataFormatSerializerContext serializerContext) { - super(DataFormat.JSON, serializerContext); - } - - @Override - public String encode(Map param, Map> annotations) { - return null; - } - - @Override - public Map decode(String dataFormatBody) { - return null; - } -} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java deleted file mode 100644 index a0976822..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -/** - * Abstraction of listener. - */ -public interface Listener { - - /** - * Returns serializer helper for this listener. - * - * @return serializer helper - */ - SerializerHelper serializerHelper(); -} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java deleted file mode 100644 index c9bda511..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -import java.util.Map; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; - -/** - * Representation of MDSAL based schema helper. - */ -public class MdsalSerializerHelper extends SerializerHelper { - - protected MdsalSerializerHelper(SchemaNode node, String uri) { - super(node, uri); - } - - @Override - public SchemaNode getRootContext() { - return null; - } - - @Override - public SchemaNode getCurContext() { - return null; - } - - @Override - public SchemaNode getChildContext(SchemaNode schemaNode, String name, String namespace) { - return null; - } - - @Override - public NodeType getNodeType(SchemaNode schemaNode) { - return null; - } - - @Override - public void addNode(String name, String namespace, String value, String valNamespace, NodeType type) { - } - - @Override - public void exitNode() { - } - - @Override - public Map getProperties() { - return null; - } -} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java deleted file mode 100644 index 5a63d632..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -/** - * Representation of type of data node. - */ -public enum NodeType { - SINGLE_INSTANCE, - MULTI_INSTANCE, - SINGLE_INSTANCE_LEAF, - MULTI_INSTANCE_LEAF -} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java deleted file mode 100644 index a4bbce52..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -import java.util.Map; - -/** - * Abstraction of an entity which helps the data format serializers to obtain - * schema context details and to build properties from data. - * - * @param type of schema node - */ -public abstract class SerializerHelper { - - private T rootSchema; - private String rootURI; - - protected SerializerHelper(T t, String uri) { - rootSchema = t; - } - - /** - * Returns root schema context node. - * - * @return root schema context node - */ - protected abstract T getRootContext(); - - /** - * Returns current schema context node. - * - * @return current schema context node - */ - protected abstract T getCurContext(); - - /** - * Returns child schema context node. - * - * @return child schema context node - */ - protected abstract T getChildContext(T t, String name, String namespace); - - /** - * Returns type of node - * @param t node - * @return node type - */ - protected abstract NodeType getNodeType(T t); - - /** - * Adds a node to current tree. - * - * @param name name of node - * @param namespace namespace of node, it can be either module name or - * namespace, null indicates parent namespace - * @param value value of node, in case it's leaf/leaf-list node - * @param valNamespace value namespace for identityref, could be module - * name or namespace - * @param type type of node if known like in case of JSON - */ - protected abstract void addNode(String name, String namespace, String value, - String valNamespace, NodeType type); - - /** - * Exits the node, in case if it's leaf node add to properties map. - */ - protected abstract void exitNode(); - - /** - * Returns the properties built corresponding to data. - * - * @return properties map - */ - protected abstract Map getProperties(); -} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java deleted file mode 100644 index ba5d8ed2..00000000 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - CCSDK - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.plugins.yangserializers; - -import java.util.List; -import java.util.Map; - -/** - * Representation of XML serializer. - */ -public class XmlSerializer extends DataFormatSerializer { - - /** - * Creates an instance of XML serializer. - * - * @param serializerContext data format serializer context - */ - protected XmlSerializer(DataFormatSerializerContext serializerContext) { - super(DataFormat.XML, serializerContext); - } - - @Override - public String encode(Map param, Map> annotations) { - return null; - } - - @Override - public Map decode(String dataFormatBody) { - return null; - } -} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Annotation.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Annotation.java new file mode 100644 index 00000000..7271c3d7 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Annotation.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +/** + * Representation of an entity that represents annotated attribute. + */ +public class Annotation { + + private String name; + private String value; + + /** + * Creates an instance of annotation. + * + * @param n annotation name + * @param v annotation value + */ + public Annotation(String n, String v) { + name = n; + value = v; + } + + /** + * Returns name of annotation. + * + * @return name of annotation + */ + public String name() { + return name; + } + + /** + * Returns value of annotation. + * + * @return value of annotation + */ + public String value() { + return value; + } +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormat.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormat.java new file mode 100644 index 00000000..6fb11e70 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormat.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +/** + * Representation of data format. + */ +public enum DataFormat { + XML, + JSON +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializer.java new file mode 100644 index 00000000..e703b173 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializer.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import java.util.List; +import java.util.Map; + +/** + * Abstraction of serializer to encode/decode context memory parameters + * to/from specified data format. + */ +public abstract class DataFormatSerializer { + + private DataFormat dataFormat; + private DataFormatSerializerContext serializerContext; + + /** + * Creates an instance of data format serializer. + * + * @param dataFormat type of data format + * @param serializerContext data format serializer context + */ + protected DataFormatSerializer(DataFormat dataFormat, + DataFormatSerializerContext serializerContext) { + this.dataFormat = dataFormat; + this.serializerContext = serializerContext; + } + + /** + * Encodes context memory parameters to data format. + * + * @param param context memory parameter + * @param annotations annotations + * @return data format body + */ + public abstract String encode(Map param, + Map> annotations); + + /** + * Decodes data format body to context memory parameters. + * + * @param dataFormatBody abstract node + * @return context memory parameters + */ + public abstract Map decode(String dataFormatBody); + + /** + * Returns data format serializer context. + * + * @return data format serializer context + */ + public DataFormatSerializerContext serializerContext() { + return serializerContext; + } + + /** + * Returns supported data format. + * + * @return supported data format + */ + public DataFormat dataFormat() { + return dataFormat; + } +} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerContext.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerContext.java new file mode 100644 index 00000000..e2ead53f --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerContext.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import java.util.Map; + +/** + * Abstraction of data format serializer context. + */ +public class DataFormatSerializerContext { + + private Listener listener; + private String uri; + private Map protocolAnnotation; + + /** + * Creates an instance of data format serializer context. + * + * @param listener data format listener + * @param uri URI corresponding to instance identifier + * @param protocolAnnotation protocol annotations + */ + public DataFormatSerializerContext(Listener listener, String uri, + Map protocolAnnotation) { + this.listener = listener; + this.uri = uri; + this.protocolAnnotation = protocolAnnotation; + } + + /** + * Retruns data format listener. + * + * @return data format listener + */ + public Listener listener() { + return listener; + } + + /** + * Returns URI. + * + * @return URI + */ + public String uri() { + return uri; + } + + /** + * Returns protocol annotations. + * + * @return protocol annotations + */ + public Map getProtocolAnnotation() { + return protocolAnnotation; + } +} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java new file mode 100644 index 00000000..6013664c --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import java.util.List; +import java.util.Map; + +/** + * Representation of JSON serializer. + */ +public class JsonSerializer extends DataFormatSerializer { + + /** + * Creates an instance of data format serializer. + * + * @param serializerContext data format serializer context + */ + protected JsonSerializer(DataFormatSerializerContext serializerContext) { + super(DataFormat.JSON, serializerContext); + } + + @Override + public String encode(Map param, Map> annotations) { + return null; + } + + @Override + public Map decode(String dataFormatBody) { + return null; + } +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Listener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Listener.java new file mode 100644 index 00000000..e5812dbb --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Listener.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +/** + * Abstraction of listener. + */ +public interface Listener { + + /** + * Returns serializer helper for this listener. + * + * @return serializer helper + */ + SerializerHelper serializerHelper(); +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java new file mode 100644 index 00000000..311fc2d6 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import java.util.Map; +import org.opendaylight.yangtools.yang.model.api.SchemaNode; + +/** + * Representation of MDSAL based schema helper. + */ +public class MdsalSerializerHelper extends SerializerHelper { + + protected MdsalSerializerHelper(SchemaNode node, String uri) { + super(node, uri); + } + + @Override + public SchemaNode getRootContext() { + return null; + } + + @Override + public SchemaNode getCurContext() { + return null; + } + + @Override + public SchemaNode getChildContext(SchemaNode schemaNode, String name, String namespace) { + return null; + } + + @Override + public NodeType getNodeType(SchemaNode schemaNode) { + return null; + } + + @Override + public void addNode(String name, String namespace, String value, String valNamespace, NodeType type) { + } + + @Override + public void exitNode() { + } + + @Override + public Map getProperties() { + return null; + } +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/NodeType.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/NodeType.java new file mode 100644 index 00000000..ffa35e2b --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/NodeType.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +/** + * Representation of type of data node. + */ +public enum NodeType { + SINGLE_INSTANCE, + MULTI_INSTANCE, + SINGLE_INSTANCE_LEAF, + MULTI_INSTANCE_LEAF +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/SerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/SerializerHelper.java new file mode 100644 index 00000000..4e6d2944 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/SerializerHelper.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import java.util.Map; + +/** + * Abstraction of an entity which helps the data format serializers to obtain + * schema context details and to build properties from data. + * + * @param type of schema node + */ +public abstract class SerializerHelper { + + private T rootSchema; + private String rootURI; + + protected SerializerHelper(T t, String uri) { + rootSchema = t; + } + + /** + * Returns root schema context node. + * + * @return root schema context node + */ + protected abstract T getRootContext(); + + /** + * Returns current schema context node. + * + * @return current schema context node + */ + protected abstract T getCurContext(); + + /** + * Returns child schema context node. + * + * @return child schema context node + */ + protected abstract T getChildContext(T t, String name, String namespace); + + /** + * Returns type of node + * @param t node + * @return node type + */ + protected abstract NodeType getNodeType(T t); + + /** + * Adds a node to current tree. + * + * @param name name of node + * @param namespace namespace of node, it can be either module name or + * namespace, null indicates parent namespace + * @param value value of node, in case it's leaf/leaf-list node + * @param valNamespace value namespace for identityref, could be module + * name or namespace + * @param type type of node if known like in case of JSON + */ + protected abstract void addNode(String name, String namespace, String value, + String valNamespace, NodeType type); + + /** + * Exits the node, in case if it's leaf node add to properties map. + */ + protected abstract void exitNode(); + + /** + * Returns the properties built corresponding to data. + * + * @return properties map + */ + protected abstract Map getProperties(); +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java new file mode 100644 index 00000000..0cfb4d17 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import java.util.List; +import java.util.Map; + +/** + * Representation of XML serializer. + */ +public class XmlSerializer extends DataFormatSerializer { + + /** + * Creates an instance of XML serializer. + * + * @param serializerContext data format serializer context + */ + protected XmlSerializer(DataFormatSerializerContext serializerContext) { + super(DataFormat.XML, serializerContext); + } + + @Override + public String encode(Map param, Map> annotations) { + return null; + } + + @Override + public Map decode(String dataFormatBody) { + return null; + } +} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java new file mode 100644 index 00000000..67e9c1e5 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer; + +import java.util.Map; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaNode; +import org.slf4j.Logger; +import static org.slf4j.LoggerFactory.getLogger; + +/** + * Representation of mdsal based properties node serializer implementation. + */ +public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer { + + private SchemaNode curSchema; + private PropertiesNode node; + private static final Logger LOG = getLogger(MdsalPropertiesNodeSerializer.class); + + /** + * Creates the properties node serializer. + * + * @param schemaNode schema node. + * @param schemaCtx schema context + * @param uri URL of the request + */ + public MdsalPropertiesNodeSerializer(SchemaNode schemaNode, SchemaContext schemaCtx, String uri) { + super(schemaNode, schemaCtx, uri); + } + + @Override + public PropertiesNode encode(Map paramMap) { + return null; + } + + @Override + public Map decode(PropertiesNode propertiesNode) { + return null; + } + +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java new file mode 100644 index 00000000..94f2915a --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer; + +/** + * Representation of types of node in properties node tree. + */ +public enum NodeType { + SINGLE_INSTANCE_NODE, + MULTI_INSTANCE_NODE, + SINGLE_INSTANCE_LEAF_NODE, + MULTI_INSTANCE_LEAF_NODE, + MULTI_INSTANCE_HOLDER_NODE, + MULTI_INSTANCE_LEAF_HOLDER_NODE +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java new file mode 100644 index 00000000..fccfa6a9 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer; + +/** + * Abstraction of properties node data tree. This intermediate representation + * will enable data format serializers to be agnostic of DG context memory + * nuances and thereby will enable faster development of new data faormat + * serializers. + */ +public abstract class PropertiesNode { + + private String name; + private String namespace; + private String uri; + private PropertiesNode parent; + + /** + * Creates an instance of properties node. + */ + protected PropertiesNode() { + } + + /** + * Creates an instance of properties node. + * + * @param name name of node + * @param namespace namespace of node, null indicates parent namespace + * @param uri URI of this node, if null its calculated based on parent and + * current value of name and namespace + * @param parent parent's node + */ + protected PropertiesNode(String name, String namespace, String uri, PropertiesNode parent) { + this.name = name; + this.namespace = namespace; + this.uri = uri; + this.parent = parent; + } + + /** + * Adds a child to a current node. + * + * @param name name of child + * @param namespace namespace of child, null represents parent namespace + * @param type type of node + * @return added properties node + */ + public abstract PropertiesNode addChild(String name, String namespace, NodeType type); + + /** + * Adds a child with value to a current node. + * + * @param name name of child + * @param namespace namespace of child, null represents parent namespace + * @param type type of node + * @param value value of node + * @return added properties node + */ + public abstract PropertiesNode addChild(String name, String namespace, NodeType type, String value); + + /** + * Adds a child at a given index to a current node. To be used in case of + * leaf holder child's which is multi instance node. + * + * @param index index at which node is to be added + * @param name name of child + * @param namespace namespace of child, null represents parent namespace + * @param type type of node + * @return added properties node + */ + public abstract PropertiesNode addChild(String index, String name, String namespace, NodeType type); + + public void name(String name) { + this.name = name; + } + + public void namespace(String namespace) { + this.namespace = namespace; + } + + public void uri(String uri) { + this.uri = uri; + } + + public void parent(PropertiesNode parent) { + this.parent = parent; + } + + public PropertiesNode parent() { + return parent; + } + + public String name() { + return name; + } + + public String namespace() { + return namespace; + } + + public String uri() { + return uri; + } + +} + diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeSerializer.java new file mode 100644 index 00000000..81609a6d --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeSerializer.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer; + +import java.util.Map; + +/** + * Abstraction of an entity to enable encoding and decoding of properties + * to an abstract properties node tree using YANG based schema. + * This serializer will be used by other data format serializers and will keep + * them abstract from properties nuances thereby enabling quick addition of any + * new data format serializer. + * + * @param type of schema node + * @param

schema context of the model + */ +public abstract class PropertiesNodeSerializer { + + /** + * Schema node from which the property is made. + */ + private T schemaNode; + + /** + * Schema context of the model. + */ + private P schemaCtx; + + /** + * URL pointing to the schema node. + */ + private String uri; + + /** + * Creates the properties node serializer. + * + * @param schemaNode schema node. + * @param schemaCtx schema context + * @param uri URL of the request + */ + public PropertiesNodeSerializer(T schemaNode, P schemaCtx, String uri) { + this.schemaNode = schemaNode; + this.schemaCtx = schemaCtx; + this.uri = uri; + } + + + /** + * Encodes from properties to properties-node tree. + * + * @param paramMap parameter map + * @return properties node + */ + public abstract PropertiesNode encode(Map paramMap); + + /** + * Decodes from properties-node to properties map. + * + * @param propertiesNode properties-node + * @return parameter map + */ + public abstract Map decode(PropertiesNode propertiesNode); + + /** + * Returns the schema node of the property + * + * @return schema node + */ + public T getSchemaNode(){ + return schemaNode; + } + + /** + * Returns the schema context + * + * @return schema node + */ + public P getSchemaCtx() { + return schemaCtx; + } + + /** + * Returns the URI. + * + * @return uri + */ + public String getUri() { + return uri; + } +} -- cgit 1.2.3-korg