Merge "Bug 2924: DataCodecTree expose (de)serialization methods for path arguments."
authorRobert Varga <nite@hq.sk>
Tue, 31 Mar 2015 11:19:49 +0000 (11:19 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 31 Mar 2015 11:19:49 +0000 (11:19 +0000)
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/api/BindingCodecTreeNode.java
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/CaseNodeCodecContext.java
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/ChoiceNodeCodecContext.java
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/DataObjectCodecContext.java
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/KeyedListNodeCodecContext.java
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/LeafNodeCodecContext.java
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/SchemaRootCodecContext.java

index 4317ef354ec993c61bdaf001fe424ee69e550ecd..bc9c1a31c92a2a4d437b3f5539ab2e852206af08 100644 (file)
@@ -118,4 +118,28 @@ public interface BindingCodecTreeNode<T extends DataObject> extends BindingNorma
 
     @Beta
     void writeAsNormalizedNode(T data, NormalizedNodeStreamWriter writer);
+
+    /**
+     * Serializes path argument for current node.
+     *
+     * @param arg Binding Path Argument, may be null if Binding Instance Identifier does not have
+     *        representation for current node (e.g. choice or case).
+     * @return Yang Path Argument, may be null if Yang Instance Identifier does not have
+     *         representation for current node (e.g. case).
+     * @throws IllegalArgumentException If supplied {@code arg} is not valid.
+     */
+    @Beta
+    @Nullable YangInstanceIdentifier.PathArgument serializePathArgument(@Nullable InstanceIdentifier.PathArgument arg);
+
+    /**
+     * Deserializes path argument for current node.
+     *
+     * @param arg Yang Path Argument, may be null if Yang Instance Identifier does not have
+     *         representation for current node (e.g. case).
+     * @return Binding Path Argument, may be null if Binding Instance Identifier does not have
+     *        representation for current node (e.g. choice or case).
+     * @throws IllegalArgumentException If supplied {@code arg} is not valid.
+     */
+    @Beta
+    @Nullable InstanceIdentifier.PathArgument deserializePathArgument(@Nullable YangInstanceIdentifier.PathArgument arg);
 }
index 1b84553f1151df8ceb1d9ec108896ef56fd55cd2..d392285f2f09c12a466b7d809434499fdfa2a248 100644 (file)
@@ -36,4 +36,18 @@ final class CaseNodeCodecContext<D extends DataObject> extends DataObjectCodecCo
     protected Object deserializeObject(NormalizedNode<?, ?> normalizedNode) {
         return deserialize(normalizedNode);
     }
+
+    @Override
+    public org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument serializePathArgument(
+            PathArgument arg) {
+        Preconditions.checkArgument(arg == null);
+        return null;
+    }
+
+    @Override
+    public PathArgument deserializePathArgument(
+            org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument arg) {
+        Preconditions.checkArgument(arg == null);
+        return null;
+    }
 }
\ No newline at end of file
index 60da344ba109f300920fa1ee27c4e89ddaa2eb67..5240ecf6104ea600ad9cd092871b957362386657 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -162,4 +163,17 @@ final class ChoiceNodeCodecContext<D extends DataObject> extends DataContainerCo
         return deserialize(normalizedNode);
     }
 
+    @Override
+    public PathArgument deserializePathArgument(YangInstanceIdentifier.PathArgument arg) {
+        Preconditions.checkArgument(getDomPathArgument().equals(arg));
+        return null;
+    }
+
+    @Override
+    public YangInstanceIdentifier.PathArgument serializePathArgument(
+            PathArgument arg) {
+        // FIXME: check for null, since binding container is null.
+        return getDomPathArgument();
+    }
+
 }
index 6066064c8076daf4b482c8633f10b8abecb52cd2..074a20a790d602416ade8b4246d52c92a4c7888d 100644 (file)
@@ -309,4 +309,15 @@ abstract class DataObjectCodecContext<D extends DataObject,T extends DataNodeCon
         return byMethod.keySet();
     }
 
+    @Override
+    public InstanceIdentifier.PathArgument deserializePathArgument(YangInstanceIdentifier.PathArgument arg) {
+        Preconditions.checkArgument(getDomPathArgument().equals(arg));
+        return bindingArg();
+    }
+
+    @Override
+    public YangInstanceIdentifier.PathArgument serializePathArgument(InstanceIdentifier.PathArgument arg) {
+        Preconditions.checkArgument(bindingArg().equals(arg));
+        return getDomPathArgument();
+    }
 }
index a5b2a97f980ee7617284da394d5c87beacd85ee0..865a4ed478f1338790224eb7d21976ab7146649a 100644 (file)
@@ -79,4 +79,22 @@ final class KeyedListNodeCodecContext<D extends DataObject & Identifiable<?>> ex
     NodeIdentifierWithPredicates serialize(final Identifier<?> key) {
         return codec.serialize(new IdentifiableItem(getBindingClass(), key));
     }
+
+    @Override
+    public YangInstanceIdentifier.PathArgument serializePathArgument(InstanceIdentifier.PathArgument arg) {
+        if(arg instanceof IdentifiableItem) {
+            return codec.serialize((IdentifiableItem<?,?>) arg);
+        }
+        return super.serializePathArgument(arg);
+    }
+
+    @Override
+    public InstanceIdentifier.PathArgument deserializePathArgument(YangInstanceIdentifier.PathArgument arg) {
+        if(arg instanceof NodeIdentifierWithPredicates) {
+            return codec.deserialize((NodeIdentifierWithPredicates) arg);
+        }
+        return super.deserializePathArgument(arg);
+    }
+
+
 }
index f74b109cd8731de731e991bfbf0ea5c05e3a09b1..e8d115c16da8a71fa8fe51bde68d4fa16edbbcb8 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.binding.data.codec.impl;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableCollection;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -17,6 +18,7 @@ import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTreeNode;
 import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeCachingCodec;
 import org.opendaylight.yangtools.concepts.Codec;
 import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
@@ -121,4 +123,15 @@ final class LeafNodeCodecContext<D extends DataObject> extends NodeCodecContext<
         return null;
     }
 
+    @Override
+    public InstanceIdentifier.PathArgument deserializePathArgument(YangInstanceIdentifier.PathArgument arg) {
+        Preconditions.checkArgument(getDomPathArgument().equals(arg));
+        return null;
+    }
+
+    @Override
+    public YangInstanceIdentifier.PathArgument serializePathArgument(InstanceIdentifier.PathArgument arg) {
+        return getDomPathArgument();
+    }
+
 }
\ No newline at end of file
index ff8310266c25781b24c9c670ae9bed6421527304..b2fb7d0867a7cf5a470121819e4661546d66017c 100644 (file)
@@ -18,10 +18,12 @@ import org.opendaylight.yangtools.yang.binding.ChildOf;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.DataRoot;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
@@ -228,4 +230,16 @@ final class SchemaRootCodecContext<D extends DataObject> extends DataContainerCo
         throw new UnsupportedOperationException("Unable to deserialize root");
     }
 
+    @Override
+    public InstanceIdentifier.PathArgument deserializePathArgument(YangInstanceIdentifier.PathArgument arg) {
+        Preconditions.checkArgument(arg == null);
+        return null;
+    }
+
+    @Override
+    public YangInstanceIdentifier.PathArgument serializePathArgument(InstanceIdentifier.PathArgument arg) {
+        Preconditions.checkArgument(arg == null);
+        return null;
+    }
+
 }
\ No newline at end of file