Binding2 runtime - Codecs impl - codecs - part2 59/58959/1
authorJakub Toth <jakub.toth@pantheon.tech>
Thu, 8 Jun 2017 15:58:47 +0000 (17:58 +0200)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Wed, 14 Jun 2017 15:09:36 +0000 (15:09 +0000)
  * operation codecs

Change-Id: I8c08617ec52d47b424d41aa04c7bf574055f1662
Signed-off-by: Jakub Toth <jakub.toth@pantheon.tech>
(cherry picked from commit 346a1c7b7783f4a5e8da6e539ecbc1ae370436c2)

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

diff --git a/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/OperationInputCodec.java b/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/OperationInputCodec.java
new file mode 100644 (file)
index 0000000..fa6eecb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.impl;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.binding.javav2.dom.codec.api.BindingNormalizedNodeCodec;
+import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
+
+/**
+ * Marker interface for codecs dealing with operation input being potentially unmapped. We use this interface
+ * to mark both {@link UnmappedOperationInputCodec} and ContainerNodeCodecContext, which results in bimorphic
+ * invocation in BindingNormalizedNodeCodecRegistry.
+ *
+ * Without this interface we could end up with megamorphic invocation, as the two implementations cannot share
+ * class hierarchy.
+ *
+ * @param <D>
+ *            - Binding representation of data
+ */
+@Beta
+public interface OperationInputCodec<D extends TreeNode> extends BindingNormalizedNodeCodec<D> {
+
+}
diff --git a/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/UnmappedOperationInputCodec.java b/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/UnmappedOperationInputCodec.java
new file mode 100644 (file)
index 0000000..20d9c18
--- /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.impl;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+/**
+ * Singleton codec for translating operations with implicit input statements, which are not mapped by binding
+ * spec v2. Since there is no equivalent, we always return null.
+ *
+ * @param <D>
+ *            - TreeNode type
+ */
+@Beta
+public final class UnmappedOperationInputCodec<D extends TreeNode> implements OperationInputCodec<D> {
+
+    private static final UnmappedOperationInputCodec<?> INSTANCE = new UnmappedOperationInputCodec<>();
+
+    private UnmappedOperationInputCodec() {
+
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <D extends TreeNode> UnmappedOperationInputCodec<D> getInstance() {
+        return (UnmappedOperationInputCodec<D>) INSTANCE;
+    }
+
+    @Nonnull
+    @Override
+    public D deserialize(@Nonnull final NormalizedNode<?, ?> data) {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public NormalizedNode<?, ?> serialize(@Nonnull final D data) {
+        throw new UnsupportedOperationException("Serialization of " + data + " not supported");
+    }
+}
\ No newline at end of file