Binding v2 DOM Codec - generator - base implementation 43/58443/2
authorJakub Toth <jakub.toth@pantheon.tech>
Mon, 5 Jun 2017 14:00:09 +0000 (16:00 +0200)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Thu, 8 Jun 2017 07:06:24 +0000 (07:06 +0000)
 * prototype of implementation of tree node serializer
 * static property for Binding objects

Change-Id: I67ba59924044adf12bed0bd2293f91ddf3f02025
Signed-off-by: Jakub Toth <jakub.toth@pantheon.tech>
(cherry picked from commit 3cd9677453fa4346fdd6fd732bf9ce0e4b30ed2c)

binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/generator/impl/StaticBindingProperty.java [new file with mode: 0644]
binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/generator/impl/TreeNodeSerializerPrototype.java [new file with mode: 0644]

diff --git a/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/generator/impl/StaticBindingProperty.java b/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/generator/impl/StaticBindingProperty.java
new file mode 100644 (file)
index 0000000..7bfde80
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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.dom.codec.generator.impl;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of static property for Binding objects
+ * <p>
+ * This definition consists of
+ * <ul>
+ * <li>name - property name</li>
+ * <li>type - Java type for property</li>
+ * <li>value - value to which property should be initialized</li>
+ * </ul>
+ */
+@Beta
+public class StaticBindingProperty {
+
+    private final String name;
+    private final Class<?> type;
+    private final Object value;
+
+    public StaticBindingProperty(final String name, final Class<?> type, final Object value) {
+        super();
+        this.name = Preconditions.checkNotNull(name);
+        this.type = Preconditions.checkNotNull(type);
+        this.value = Preconditions.checkNotNull(value);
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public Class<?> getType() {
+        return this.type;
+    }
+
+    public Object getValue() {
+        return this.value;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + this.name.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final StaticBindingProperty other = (StaticBindingProperty) obj;
+        if (!this.name.equals(other.name)) {
+            return false;
+        }
+        return true;
+    }
+}
diff --git a/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/generator/impl/TreeNodeSerializerPrototype.java b/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/generator/impl/TreeNodeSerializerPrototype.java
new file mode 100644 (file)
index 0000000..b108193
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.dom.codec.generator.impl;
+
+import com.google.common.annotations.Beta;
+import java.io.IOException;
+import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingStreamEventWriter;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.TreeNodeSerializerImplementation;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.TreeNodeSerializerRegistry;
+
+/**
+ * Prototype of a TreeNodeSerializerImplementation. This is a template class, which the stream writer
+ * generator uses to instantiate {@link TreeNodeSerializerImplementation} on a per-type basis. During that
+ * time, the {@link #serialize(TreeNodeSerializerRegistry, TreeNode, BindingStreamEventWriter)} method will be
+ * replaced by the real implementation.
+ */
+@Beta
+public final class TreeNodeSerializerPrototype implements TreeNodeSerializerImplementation {
+
+    private static final TreeNodeSerializerPrototype INSTANCE = new TreeNodeSerializerPrototype();
+
+    private TreeNodeSerializerPrototype() {
+        // Intentionally hidden, subclasses can replace it
+    }
+
+    /**
+     * Return the shared serializer instance.
+     *
+     * @return Global singleton instance.
+     */
+    public static TreeNodeSerializerPrototype getInstance() {
+        return INSTANCE;
+    }
+
+    @Override
+    public void serialize(final TreeNodeSerializerRegistry reg, final TreeNode obj, final BindingStreamEventWriter stream)
+            throws IOException {
+        throw new UnsupportedOperationException("Prototype body, this code should never be invoked.");
+    }
+
+}