aboutsummaryrefslogtreecommitdiffstats
path: root/restconf-client
diff options
context:
space:
mode:
authorjanani b <janani.b@huawei.com>2018-08-17 15:32:26 +0530
committerjanani b <janani.b@huawei.com>2018-08-17 15:32:26 +0530
commit06f4a6531b11b1e841f4c63b968d2b8a7a65eaf6 (patch)
treeb46baf495655d207001afeb28f30e48ae5da775b /restconf-client
parent21190939f08b40c46f908fefabf8cc13e7365f2a (diff)
Outline code for Restconf Api Call Node
Initial level implementation for Restconf api call node Issue-ID: CCSDK-372 Change-Id: I9d77f4c7806b0e239a3ecb134424f4fc09d6865e Signed-off-by: janani b <janani.b@huawei.com>
Diffstat (limited to 'restconf-client')
-rwxr-xr-xrestconf-client/provider/pom.xml20
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/Annotation.java7
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormat.java8
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializer.java19
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerContext.java52
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonListener.java71
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonWalker.java60
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlListener.java58
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlWalker.java34
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfListenerFactory.java74
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerFactory.java75
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonListener.java51
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java12
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonWalker.java41
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java58
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java70
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java80
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/SerializerHelper.java86
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlListener.java49
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlNodeType.java (renamed from restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/NodeType.java)18
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java12
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlWalker.java41
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/YangParameters.java41
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java87
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeListener.java55
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeWalker.java35
26 files changed, 1132 insertions, 82 deletions
diff --git a/restconf-client/provider/pom.xml b/restconf-client/provider/pom.xml
index 46e00009..8995f1dd 100755
--- a/restconf-client/provider/pom.xml
+++ b/restconf-client/provider/pom.xml
@@ -75,6 +75,24 @@
<artifactId>yang-data-impl</artifactId>
<version>2.0.3</version>
</dependency>
-
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>restapi-call-node-provider</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
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
index 7271c3d7..185f70ba 100644
--- 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
@@ -25,7 +25,14 @@ package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
*/
public class Annotation {
+ /**
+ * Name of the annotation.
+ */
private String name;
+
+ /**
+ * Value of the annotation.
+ */
private String 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
index 6fb11e70..c692f1dd 100644
--- 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
@@ -24,6 +24,14 @@ package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
* Representation of data format.
*/
public enum DataFormat {
+
+ /**
+ * XML data format.
+ */
XML,
+
+ /**
+ * JSON data format.
+ */
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
index e703b173..57280e2e 100644
--- 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
@@ -29,19 +29,26 @@ import java.util.Map;
*/
public abstract class DataFormatSerializer {
+ /**
+ * Data format type of the serializer.
+ */
private DataFormat dataFormat;
+
+ /**
+ * Data format serializer context.
+ */
private DataFormatSerializerContext serializerContext;
/**
* Creates an instance of data format serializer.
*
- * @param dataFormat type of data format
- * @param serializerContext data format serializer context
+ * @param d type of data format
+ * @param s data format serializer context
*/
- protected DataFormatSerializer(DataFormat dataFormat,
- DataFormatSerializerContext serializerContext) {
- this.dataFormat = dataFormat;
- this.serializerContext = serializerContext;
+ protected DataFormatSerializer(DataFormat d,
+ DataFormatSerializerContext s) {
+ this.dataFormat = d;
+ this.serializerContext = s;
}
/**
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
index e2ead53f..919e82af 100644
--- 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
@@ -20,6 +20,8 @@
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeSerializer;
+
import java.util.Map;
/**
@@ -27,26 +29,45 @@ import java.util.Map;
*/
public class DataFormatSerializerContext {
+ /**
+ * Data format listener.
+ */
private Listener listener;
+
+ /**
+ * URI corresponding to the instance identifier.
+ */
private String uri;
+
+ /**
+ * Protocol annotation.
+ */
private Map<String, String> protocolAnnotation;
/**
+ * Properties node serializer.
+ */
+ private PropertiesNodeSerializer propNodeSerializer;
+
+ /**
* Creates an instance of data format serializer context.
*
- * @param listener data format listener
- * @param uri URI corresponding to instance identifier
- * @param protocolAnnotation protocol annotations
+ * @param l data format listener
+ * @param u URI corresponding to instance identifier
+ * @param p protocol annotations
+ * @param s properties node serializer
*/
- public DataFormatSerializerContext(Listener listener, String uri,
- Map<String, String> protocolAnnotation) {
- this.listener = listener;
- this.uri = uri;
- this.protocolAnnotation = protocolAnnotation;
+ public DataFormatSerializerContext(Listener l, String u,
+ Map<String, String> p,
+ PropertiesNodeSerializer s) {
+ listener = l;
+ uri = u;
+ protocolAnnotation = p;
+ propNodeSerializer = s;
}
/**
- * Retruns data format listener.
+ * Returns the data format listener.
*
* @return data format listener
*/
@@ -55,7 +76,7 @@ public class DataFormatSerializerContext {
}
/**
- * Returns URI.
+ * Returns the URI.
*
* @return URI
*/
@@ -64,11 +85,20 @@ public class DataFormatSerializerContext {
}
/**
- * Returns protocol annotations.
+ * Returns the protocol annotations.
*
* @return protocol annotations
*/
public Map<String, String> getProtocolAnnotation() {
return protocolAnnotation;
}
+
+ /**
+ * Returns the properties node serializer.
+ *
+ * @return properties node serializer
+ */
+ public PropertiesNodeSerializer getPropNodeSerializer() {
+ return propNodeSerializer;
+ }
} \ No newline at end of file
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonListener.java
new file mode 100644
index 00000000..5e71eea3
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonListener.java
@@ -0,0 +1,71 @@
+/*-
+ * ============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 com.fasterxml.jackson.databind.JsonNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+
+
+/**
+ * Representation of default implementation of JSON listener.
+ */
+public class DefaultJsonListener implements JsonListener {
+
+ /**
+ * Serializer helper to convert to properties node.
+ */
+ private SerializerHelper serializerHelper;
+
+ /**
+ * Name of the current JSON node.
+ */
+ private String name;
+
+ /**
+ * Module name of the current JSON node.
+ */
+ private String modName;
+
+ /**
+ * Creates an instance of default json listener with its serializer helper.
+ *
+ * @param serializerHelper serializer helper
+ */
+ public DefaultJsonListener(SerializerHelper serializerHelper) {
+ this.serializerHelper = serializerHelper;
+ }
+
+ @Override
+ public void enterJsonNode(String nodeName, JsonNode node, NodeType nodeType) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitJsonNode(JsonNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public SerializerHelper serializerHelper() {
+ return serializerHelper;
+ }
+
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonWalker.java
new file mode 100644
index 00000000..20d4fa77
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultJsonWalker.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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 com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Implementation of JSON walker to walk through the nodes and process it.
+ */
+public class DefaultJsonWalker implements JsonWalker {
+
+ @Override
+ public void walk(JsonListener listener, JsonNode jsonNode) {
+ //TODO: Implementation code.
+ }
+
+ /**
+ * Processes single instance node or leaf, by adding the node to from
+ * JSON and walking through all its children recursively.
+ *
+ * @param key JSON name
+ * @param value JSON node
+ * @param listener JSON listener
+ */
+ private void processSingleNode(String key, JsonNode value,
+ JsonListener listener) {
+ //TODO: Implementation code.
+ }
+
+ /**
+ * Processes multi instance node or leaf, by adding the node to from JSON
+ * and walking through all its instance recursively.
+ *
+ * @param key JSON name
+ * @param value JSON node
+ * @param listener JSON listener
+ */
+ private void processMultiNodes(String key, JsonNode value,
+ JsonListener listener) {
+ //TODO: Implementation code.
+ }
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlListener.java
new file mode 100644
index 00000000..7946d8d0
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlListener.java
@@ -0,0 +1,58 @@
+/*-
+ * ============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 org.dom4j.Element;
+
+/**
+ * Representation of default implementation of XML listener.
+ */
+public class DefaultXmlListener implements XmlListener {
+
+ /**
+ * Serializer helper to convert to properties node.
+ */
+ private SerializerHelper serializerHelper;
+
+ /**
+ * Creates an instance of default XML listener with its serializer helper.
+ *
+ * @param serializerHelper serializer helper
+ */
+ public DefaultXmlListener(SerializerHelper serializerHelper) {
+ this.serializerHelper = serializerHelper;
+ }
+
+ @Override
+ public void enterXmlElement(Element element, XmlNodeType nodeType) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitXmlElement(Element element) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public SerializerHelper serializerHelper() {
+ return serializerHelper;
+ }
+ }
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlWalker.java
new file mode 100644
index 00000000..cd2a3d49
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DefaultXmlWalker.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;
+
+import org.dom4j.Element;
+
+/**
+ * Implementation of XML walker to walk through the nodes and process it.
+ */
+public class DefaultXmlWalker implements XmlWalker {
+
+ @Override
+ public void walk(XmlListener listener, Element xmlElement) {
+ //TODO: Implementation code.
+ }
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfListenerFactory.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfListenerFactory.java
new file mode 100644
index 00000000..851f1b48
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfListenerFactory.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;
+
+/**
+ * Represents the data format listener factory which will return JSON or XML
+ * listener according to the serializer helper.
+ */
+public final class DfListenerFactory {
+
+ /**
+ * Returns the instance of the data format listener factory.
+ *
+ * @return instance of the data format listener factory
+ */
+ public static DfListenerFactory instance() {
+ return DfListenerFactory.LazyHolder.INSTANCE;
+ }
+
+ /**
+ * Bill pugh singleton pattern. Instance will not be instantiated until
+ * the lazy holder class is loaded via a call to the instance of method
+ * below.
+ */
+ private static class LazyHolder {
+ private static final DfListenerFactory INSTANCE =
+ new DfListenerFactory();
+ }
+
+ /**
+ * Returns the data format listener by deciding it based on the format of
+ * the parameter.
+ *
+ * @param serHelper serializer helper
+ * @param params parameters
+ * @return data format listener
+ */
+ public Listener getListener(SerializerHelper serHelper,
+ YangParameters params) {
+ Listener listener;
+ switch (params.format) {
+ case JSON:
+ listener = new DefaultJsonListener(serHelper);
+ break;
+
+ case XML:
+ listener = new DefaultXmlListener(serHelper);
+ break;
+
+ //TODO: DataFormat Exception code to be added.
+ default:
+ throw new IllegalArgumentException("In correct format");
+ }
+ return listener;
+ }
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerFactory.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerFactory.java
new file mode 100644
index 00000000..25b23fe2
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerFactory.java
@@ -0,0 +1,75 @@
+/*-
+ * ============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;
+
+/**
+ * Represents the data format serializer factory which will return JSON or XML
+ * serializer according to the serializer context.
+ */
+public final class DfSerializerFactory {
+
+ /**
+ * Returns the instance of the data format serializer factory.
+ *
+ * @return instance of the data format serializer factory
+ */
+ public static DfSerializerFactory instance() {
+ return DfSerializerFactory.LazyHolder.INSTANCE;
+ }
+
+ /**
+ * Bill pugh singleton pattern. Instance will not be instantiated until
+ * the lazy holder class is loaded via a call to the instance of method
+ * below.
+ */
+ private static class LazyHolder {
+ private static final DfSerializerFactory INSTANCE =
+ new DfSerializerFactory();
+ }
+
+ /**
+ * Returns the data format serializer by deciding it based on the format of
+ * the parameter.
+ *
+ * @param serCtx serializer context
+ * @param params parameters
+ * @return data format serializer
+ */
+ public DataFormatSerializer getSerializer(DataFormatSerializerContext
+ serCtx,
+ YangParameters params) {
+ DataFormatSerializer serializer;
+ switch (params.format) {
+ case JSON:
+ serializer = new JsonSerializer(serCtx);
+ break;
+
+ case XML:
+ serializer = new XmlSerializer(serCtx);
+ break;
+
+ //TODO: DataFormat Exception code to be added.
+ default:
+ throw new IllegalArgumentException("In correct format");
+ }
+ return serializer;
+ }
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonListener.java
new file mode 100644
index 00000000..2a9220ac
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonListener.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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 com.fasterxml.jackson.databind.JsonNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+
+/**
+ * Abstraction of an entity which provides call back methods, which in turn
+ * are called by JSON walker while walking the JSON tree. This interface
+ * needs to be implemented by protocol, implementing listener based call
+ * while doing JSON walk.
+ */
+public interface JsonListener extends Listener {
+
+ /**
+ * Call back invoked during JSON node entry. All other related
+ * information can be obtained from the JSON node.
+ *
+ * @param nodeName JSON node name
+ * @param node JSON node
+ * @param nodeType JSON node type
+ */
+ void enterJsonNode(String nodeName, JsonNode node, NodeType nodeType);
+
+ /**
+ * Call back invoked during JSON node exit. All the related information
+ * can be obtained from the JSON node.
+ *
+ * @param node JSON node
+ */
+ void exitJsonNode(JsonNode node);
+}
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
index 6013664c..b562e71d 100644
--- 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
@@ -23,8 +23,11 @@ package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
import java.util.List;
import java.util.Map;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormat.JSON;
+
/**
- * Representation of JSON serializer.
+ * Representation of JSON serializer which encodes properties to JSON and
+ * decodes properties from JSON with the data format serializer.
*/
public class JsonSerializer extends DataFormatSerializer {
@@ -34,16 +37,19 @@ public class JsonSerializer extends DataFormatSerializer {
* @param serializerContext data format serializer context
*/
protected JsonSerializer(DataFormatSerializerContext serializerContext) {
- super(DataFormat.JSON, serializerContext);
+ super(JSON, serializerContext);
}
@Override
- public String encode(Map<String, String> param, Map<String, List<Annotation>> annotations) {
+ public String encode(Map<String, String> param,
+ Map<String, List<Annotation>> annotations) {
+ //TODO: Implementation code.
return null;
}
@Override
public Map<String, String> decode(String dataFormatBody) {
+ //TODO: Implementation code.
return null;
}
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonWalker.java
new file mode 100644
index 00000000..e3fb4d51
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonWalker.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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 com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Abstraction of an entity which provides interface for JSON walk. This
+ * interface serves as a common tool for anyone who needs to parse the JSON
+ * node with depth-first algorithm.
+ */
+public interface JsonWalker {
+
+ /**
+ * Walks the JSON data tree. Protocols implement JSON listener service
+ * and walks the JSON tree with input as implemented object. JSON walker
+ * provides call back to the implemented methods.
+ *
+ * @param listener JSON listener implemented by the protocol
+ * @param jsonNode root node of the JSON data tree
+ */
+ void walk(JsonListener listener, JsonNode jsonNode);
+}
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
index 311fc2d6..1f8195e2 100644
--- 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
@@ -20,48 +20,70 @@
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
-import java.util.Map;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
/**
- * Representation of MDSAL based schema helper.
+ * Representation of MDSAL based serializer helper, which adds properties
+ * node to the properties tree based on its types.
*/
-public class MdsalSerializerHelper extends SerializerHelper<SchemaNode> {
+public class MdsalSerializerHelper extends SerializerHelper<SchemaNode, SchemaContext> {
- protected MdsalSerializerHelper(SchemaNode node, String uri) {
- super(node, uri);
- }
+ /**
+ * Current properties node.
+ */
+ private PropertiesNode propNode;
- @Override
- public SchemaNode getRootContext() {
- return null;
+ /**
+ * Current schema node.
+ */
+ private SchemaNode curSchemaNode;
+
+
+ /**
+ * Creates MDSAL serializer helper with root schema node, schema context
+ * and URI.
+ *
+ * @param n schema node of the URI's last node
+ * @param c schema context
+ * @param u URI of the request
+ */
+ protected MdsalSerializerHelper(SchemaNode n, SchemaContext c,
+ String u) {
+ super(n, c, u);
}
@Override
- public SchemaNode getCurContext() {
- return null;
+ protected SchemaNode getSchemaNode() {
+ return schemaNode;
}
@Override
- public SchemaNode getChildContext(SchemaNode schemaNode, String name, String namespace) {
- return null;
+ protected SchemaContext getSchemaCtx() {
+ return schemaCtx;
}
@Override
- public NodeType getNodeType(SchemaNode schemaNode) {
- return null;
+ protected SchemaNode getCurSchema() {
+ return curSchemaNode;
}
@Override
- public void addNode(String name, String namespace, String value, String valNamespace, NodeType type) {
+ protected void addNode(String name, String nameSpace, String value,
+ String valNameSpace, NodeType type) {
+ //TODO: Implementation code.
}
@Override
- public void exitNode() {
+ protected void exitNode() {
+ //TODO: Implementation code.
}
@Override
- public Map<String, String> getProperties() {
+ protected PropertiesNode getPropertiesNode() {
+ //TODO: Implementation code.
return null;
}
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java
new file mode 100644
index 00000000..ec130673
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java
@@ -0,0 +1,70 @@
+/*-
+ * ============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 com.google.gson.stream.JsonWriter;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeListener;
+
+import java.io.Writer;
+
+/**
+ * Representation of JSON implementation of properties node listener.
+ */
+public class PropertiesNodeJsonListener implements PropertiesNodeListener{
+
+ /**
+ * JSON writer to write the JSON data format.
+ */
+ private JsonWriter jsonWriter;
+
+ /**
+ * Writer to write the JSON.
+ */
+ private Writer writer;
+
+ /**
+ * Creates the properties node JSON listener by instantiating and
+ * indenting the writer.
+ */
+ public PropertiesNodeJsonListener() {
+ }
+
+ @Override
+ public void start(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void end(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void enterPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java
new file mode 100644
index 00000000..cfc59ca1
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java
@@ -0,0 +1,80 @@
+/*-
+ * ============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 org.dom4j.Element;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeListener;
+
+import java.io.Writer;
+import java.util.Stack;
+
+/**
+ * Representation of XML implementation of properties node listener.
+ */
+public class PropertiesNodeXmlListener implements PropertiesNodeListener {
+
+ /**
+ * XML data from the element.
+ */
+ private String xmlData;
+
+ /**
+ * Root element of the XML document.
+ */
+ private Element rootElement;
+
+ /**
+ * Writer to write the XML.
+ */
+ private Writer writer;
+
+ /**
+ * XML element stack to store the elements.
+ */
+ private final Stack<Element> elementStack = new Stack<>();
+
+ /**
+ * Creates the properties node XML listener.
+ */
+ public PropertiesNodeXmlListener() {
+ }
+
+ @Override
+ public void start(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void end(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void enterPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+}
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
index 4e6d2944..2466023f 100644
--- 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
@@ -20,74 +20,92 @@
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
-import java.util.Map;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
/**
* Abstraction of an entity which helps the data format serializers to obtain
* schema context details and to build properties from data.
*
* @param <T> type of schema node
+ * @param <P> type of schema context
*/
-public abstract class SerializerHelper<T> {
+public abstract class SerializerHelper<T, P> {
- private T rootSchema;
- private String rootURI;
+ /**
+ * Schema node of the last element in the URI.
+ */
+ protected T schemaNode;
- protected SerializerHelper(T t, String uri) {
- rootSchema = t;
- }
+ /**
+ * Root schema context.
+ */
+ protected P schemaCtx;
+
+ /**
+ * Root URI.
+ */
+ protected String rootUri;
/**
- * Returns root schema context node.
+ * Creates an instance of the serializer helper with the schema node,
+ * schema context and the URI.
*
- * @return root schema context node
+ * @param t schema node
+ * @param p schema context
+ * @param u root URI
*/
- protected abstract T getRootContext();
+ protected SerializerHelper(T t, P p, String u) {
+ schemaNode = t;
+ schemaCtx = p;
+ rootUri = u;
+ }
/**
- * Returns current schema context node.
+ * Returns schema node of the last element in the URI.
*
- * @return current schema context node
+ * @return schema node
*/
- protected abstract T getCurContext();
+ protected abstract T getSchemaNode();
/**
- * Returns child schema context node.
+ * Returns the root schema context.
*
- * @return child schema context node
+ * @return schema context
*/
- protected abstract T getChildContext(T t, String name, String namespace);
+ protected abstract P getSchemaCtx();
/**
- * Returns type of node
- * @param t node
- * @return node type
+ * Returns the current schema context node.
+ *
+ * @return current schema context node
*/
- protected abstract NodeType getNodeType(T t);
+ protected abstract T getCurSchema();
/**
- * Adds a node to current tree.
+ * Adds a node to the properties node 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
+ * @param name name of the node
+ * @param nameSpace name space of the node, it can be either module
+ * name or namespace; null indicates parent namespace
+ * @param value value of the node; applicable for 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);
+ 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.
+ * Exits the node, in case if it's leaf node then it adds to the properties
+ * map.
*/
protected abstract void exitNode();
/**
- * Returns the properties built corresponding to data.
+ * Returns the built properties corresponding to the data.
*
- * @return properties map
+ * @return properties node.
*/
- protected abstract Map<String, String> getProperties();
+ protected abstract PropertiesNode getPropertiesNode();
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlListener.java
new file mode 100644
index 00000000..0fbf4c33
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlListener.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 org.dom4j.Element;
+
+/**
+ * Abstraction of an entity which provides call back methods, which in turn
+ * are called by XML walker while walking the XML tree. This interface needs
+ * to be implemented by protocol implementing listener based call while doing
+ * XML walk.
+ */
+public interface XmlListener extends Listener {
+
+ /**
+ * Callback invoked during a node entry. All the related information
+ * about the node can be obtained from the element.
+ *
+ * @param element current XML element
+ * @param nodeType node type of the element
+ */
+ void enterXmlElement(Element element, XmlNodeType nodeType);
+
+ /**
+ * Callback invoked during a node exit. All the related information about
+ * the node can be obtained from the element.
+ *
+ * @param element current xml element.
+ */
+ void exitXmlElement(Element element);
+}
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/XmlNodeType.java
index ffa35e2b..7a6db3c8 100644
--- 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/XmlNodeType.java
@@ -21,11 +21,17 @@
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
/**
- * Representation of type of data node.
+ * Represents the XML node type.
*/
-public enum NodeType {
- SINGLE_INSTANCE,
- MULTI_INSTANCE,
- SINGLE_INSTANCE_LEAF,
- MULTI_INSTANCE_LEAF
+public enum XmlNodeType {
+
+ /**
+ * Object XML node type.
+ */
+ OBJECT_NODE,
+
+ /**
+ * Text XML node type.
+ */
+ TEXT_NODE
}
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
index 0cfb4d17..51647005 100644
--- 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
@@ -23,8 +23,11 @@ package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
import java.util.List;
import java.util.Map;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormat.XML;
+
/**
- * Representation of XML serializer.
+ * Representation of XML serializer which encodes properties to XML and
+ * decodes properties from XML with the data format serializer.
*/
public class XmlSerializer extends DataFormatSerializer {
@@ -34,16 +37,19 @@ public class XmlSerializer extends DataFormatSerializer {
* @param serializerContext data format serializer context
*/
protected XmlSerializer(DataFormatSerializerContext serializerContext) {
- super(DataFormat.XML, serializerContext);
+ super(XML, serializerContext);
}
@Override
- public String encode(Map<String, String> param, Map<String, List<Annotation>> annotations) {
+ public String encode(Map<String, String> param,
+ Map<String, List<Annotation>> annotations) {
+ //TODO: Implementation code.
return null;
}
@Override
public Map<String, String> decode(String dataFormatBody) {
+ //TODO: Implementation code.
return null;
}
} \ No newline at end of file
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlWalker.java
new file mode 100644
index 00000000..6fed510a
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlWalker.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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 org.dom4j.Element;
+
+/**
+ * Abstraction of an entity which provides interface for XML walk. This
+ * interface serves as a common tool for anyone who needs to parse the XML
+ * node with depth-first algorithm.
+ */
+public interface XmlWalker {
+
+ /**
+ * Walks the XML data tree. Protocols implement XML listener service and
+ * walks the XML tree with input as implemented object. XML walker
+ * provides call back to the implemented methods.
+ *
+ * @param listener XML listener implemented by the protocol
+ * @param xmlElement root element of the XML data tree
+ */
+ void walk(XmlListener listener, Element xmlElement);
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/YangParameters.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/YangParameters.java
new file mode 100644
index 00000000..c94a2297
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/YangParameters.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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 org.onap.ccsdk.sli.plugins.restapicall.Parameters;
+
+/**
+ * Representation of the YANG parameters for the restconf api call node.
+ */
+public class YangParameters extends Parameters {
+
+ /**
+ * Creates an instance of the YANG parameters.
+ */
+ public YangParameters() {
+ super();
+ }
+
+ /**
+ * Directory path of the YANG file.
+ */
+ public String dirPath;
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java
new file mode 100644
index 00000000..041210f2
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java
@@ -0,0 +1,87 @@
+/*-
+ * ============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;
+
+/**
+ * Implementation of properties node walker which helps in forming a new tree from properties node.
+ *
+ * @param <T> node child of properties node.
+ */
+public class DefaultPropertiesNodeWalker<T extends NodeChild> implements PropertiesNodeWalker {
+
+ @Override
+ public void walk(PropertiesNodeListener listener,
+ PropertiesNode propertiesNode) {
+ listener.start(propertiesNode);
+ walkChildNode(listener, propertiesNode);
+ listener.end(propertiesNode);
+ }
+
+ /**
+ * Walks the children node from the parent node.
+ *
+ * @param listener properties node listener
+ * @param propertiesNode properties node
+ */
+ public void walkChildNode(PropertiesNodeListener listener,
+ PropertiesNode propertiesNode) {
+ Map<String, T> children = getChildren(propertiesNode);
+ if (children != null) {
+ for (Map.Entry<String, T> entry : children.entrySet()) {
+ PropertiesNode node = ((PropertiesNode) entry.getValue());
+ listener.enterPropertiesNode(node);
+ walkChildNode(listener, node);
+ listener.exitPropertiesNode(node);
+ }
+ }
+ }
+
+ /**
+ * Returns the children node according to the property node type.
+ *
+ * @param value property node
+ * @return property node children
+ */
+ private Map<String,T> getChildren(PropertiesNode value) {
+ if (value instanceof RootNode) {
+ return ((RootNode) value).children();
+ }
+ switch (value.nodeType()) {
+ case SINGLE_INSTANCE_NODE:
+ return ((InnerNode) value).children();
+ case MULTI_INSTANCE_HOLDER_NODE:
+ return ((Map<String, T>) ((ListHolderNode) value).children());
+ case MULTI_INSTANCE_NODE:
+ return ((Map<String, T>) ((MultiInstanceNode) value)
+ .children());
+ case MULTI_INSTANCE_LEAF_HOLDER_NODE:
+ return ((Map<String, T>) ((LeafListHolderNode) value)
+ .children());
+ case SINGLE_INSTANCE_LEAF_NODE:
+ case MULTI_INSTANCE_LEAF_NODE:
+ return null;
+ default:
+ throw new IllegalArgumentException("No more types allowed");
+ }
+ }
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeListener.java
new file mode 100644
index 00000000..5bf7fe9d
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeListener.java
@@ -0,0 +1,55 @@
+/*-
+ * ============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 listener.
+ */
+public interface PropertiesNodeListener {
+
+ /**
+ * Pre-configurations required before starting the walking.
+ *
+ * @param node properties node
+ */
+ void start(PropertiesNode node);
+
+ /**
+ * Post-configurations required after starting the walking.
+ *
+ * @param node properties node
+ */
+ void end(PropertiesNode node);
+
+ /**
+ * Enters the properties node.
+ *
+ * @param node properties node
+ */
+ void enterPropertiesNode(PropertiesNode node);
+
+ /**
+ * Enters the properties node.
+ *
+ * @param node properties node
+ */
+ void exitPropertiesNode(PropertiesNode node);
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeWalker.java
new file mode 100644
index 00000000..48433e2b
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNodeWalker.java
@@ -0,0 +1,35 @@
+/*-
+ * ============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 walker
+ */
+public interface PropertiesNodeWalker {
+
+ /**
+ * Walks the properties node with the listener.
+ *
+ * @param listener properties node listener.
+ * @param propertiesNode properties node
+ */
+ void walk(PropertiesNodeListener listener, PropertiesNode propertiesNode);
+}