Binding spec runtime v2 - TreeNodeSerializer & relatives 24/58324/4
authorMartin Ciglan <martin.ciglan@pantheon.tech>
Wed, 31 May 2017 07:54:10 +0000 (09:54 +0200)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Tue, 6 Jun 2017 19:30:29 +0000 (19:30 +0000)
Change-Id: I6ad9cf2f0fc6fb9b55c7ba788fa6ece86ba7f8c0
Signed-off-by: Martin Ciglan <martin.ciglan@pantheon.tech>
(cherry picked from commit ebbf805a1d97ddb8988f5ad698b5c37245830194)

binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/TreeNodeSerializer.java
binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/TreeNodeSerializerImplementation.java [new file with mode: 0644]
binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/TreeNodeSerializerRegistry.java [new file with mode: 0644]

index a2313ca31c4095c81aa174cc0f04170b1b0d5237..3e95a75010b654efe373db7c46f88fe8389ff6e0 100644 (file)
@@ -12,14 +12,14 @@ import com.google.common.annotations.Beta;
 import java.io.IOException;
 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
 
-/*
+/**
  * A serializer which writes TreeNode to supplied stream event writer.
  */
 @Beta
 public interface TreeNodeSerializer {
 
     /**
-     * Writes stream events representing object to supplied stream
+     * Writes stream events representing object to supplied stream.
      *
      * @param obj
      *            Source of stream events
diff --git a/binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/TreeNodeSerializerImplementation.java b/binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/TreeNodeSerializerImplementation.java
new file mode 100644 (file)
index 0000000..b38810a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.binding.javav2.spec.runtime;
+
+import java.io.IOException;
+import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
+
+/**
+ * Contract for implementations of {@link TreeNodeSerializer}.
+ * The contract is kept between implementation of {@link TreeNodeSerializerRegistry},
+ * which maintains the lookup context required for recursive serialization.
+ */
+public interface TreeNodeSerializerImplementation {
+
+    /**
+     * Writes stream events for supplied data object to provided stream.
+     *
+     * DataObjectSerializerRegistry may be used to lookup serializers
+     * for other generated classes  in order to support writing
+     * their events.
+     */
+    void serialize(TreeNodeSerializerRegistry reg, TreeNode obj, BindingStreamEventWriter stream) throws IOException;
+}
diff --git a/binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/TreeNodeSerializerRegistry.java b/binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/runtime/TreeNodeSerializerRegistry.java
new file mode 100644 (file)
index 0000000..5f8f26d
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.binding.javav2.spec.runtime;
+
+import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
+
+/**
+ * Contract for registry of {@link TreeNodeSerializer}.
+ * The contract is kept between implementation of {@link TreeNodeSerializerImplementation},
+ * Registry provides lookup for serializers to support recursive
+ * serialization of nested {@link TreeNode}s.
+ */
+public interface TreeNodeSerializerRegistry {
+
+    /**
+     * Returns implementation of requested serializer.
+     * @param binding input binding class
+     * @return returns serializer, based on input binding class
+     */
+    TreeNodeSerializer getSerializer(Class<? extends TreeNode> binding);
+}