BUG-2062: handle ordered leaf-lists 61/32261/2
authorRobert Varga <rovarga@cisco.com>
Fri, 8 Jan 2016 08:11:07 +0000 (09:11 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 12 Jan 2016 13:48:54 +0000 (14:48 +0100)
This is forward-port on the Lithium fix, migrated to the mdsal project.

Change-Id: I46d94c281b904125fecb9636e513daa0c65c93cf
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/gen/impl/DataNodeContainerSerializerSource.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/gen/impl/DataObjectSerializerSource.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/ForwardingBindingStreamEventWriter.java
binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/yangtools/binding/data/codec/test/NormalizedNodeSerializeDeserializeTest.java
binding/mdsal-binding-test-model/src/main/yang/opendaylight-mdsal-binding-test.yang
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/BindingStreamEventWriter.java

index d9094acc31cbab5624f5332e937f63570d67f546..8fc57dca2e75a22643d3b0466829d0527ffd6e39 100644 (file)
@@ -168,7 +168,13 @@ abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSou
         } else if (child instanceof AnyXmlSchemaNode) {
             b.append(statement(anyxmlNode(child.getQName().getLocalName(), getterName)));
         } else if (child instanceof LeafListSchemaNode) {
-            b.append(statement(startLeafSet(child.getQName().getLocalName(),invoke(getterName, "size"))));
+            final CharSequence startEvent;
+            if (((LeafListSchemaNode) child).isUserOrdered()) {
+                startEvent = startOrderedLeafSet(child.getQName().getLocalName(),invoke(getterName, "size"));
+            } else {
+                startEvent = startLeafSet(child.getQName().getLocalName(),invoke(getterName, "size"));
+            }
+            b.append(statement(startEvent));
             final Type valueType = ((ParameterizedType) childType).getActualTypeArguments()[0];
             b.append(forEach(getterName, valueType, statement(leafSetEntryNode(CURRENT))));
             b.append(statement(endNode()));
@@ -213,4 +219,4 @@ abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSou
         b.append(forEach(getterName, valueType, tryToUseCacheElse(CURRENT,statement(staticInvokeEmitter(valueType, CURRENT)))));
         b.append(statement(endNode()));
     }
-}
\ No newline at end of file
+}
index 30f5f7737694adb336dd3e5f68cac5c000a00573..54df9d80a95eb616c9cf957fa64ff0bc27039370 100644 (file)
@@ -66,6 +66,10 @@ abstract class DataObjectSerializerSource extends AbstractSource {
         return invoke(STREAM, "startLeafSet", escape(localName),expected);
     }
 
+    protected final CharSequence startOrderedLeafSet(final String localName, final CharSequence expected) {
+        return invoke(STREAM, "startOrderedLeafSet", escape(localName),expected);
+    }
+
     protected final CharSequence leafSetEntryNode(final CharSequence value) {
         return invoke(STREAM, "leafSetEntryNode", value);
     }
@@ -137,4 +141,4 @@ abstract class DataObjectSerializerSource extends AbstractSource {
         final String className = this.generator.loadSerializerFor(cls) + ".getInstance()";
         return invoke(className, AbstractStreamWriterGenerator.SERIALIZE_METHOD_NAME, REGISTRY, name, STREAM);
     }
-}
\ No newline at end of file
+}
index ed4bb470024eebbc1344f2d0c10c4eb6d5cdff46..65a870282a20ffb86736ce4b061287c5c27de6f0 100644 (file)
@@ -150,6 +150,11 @@ class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Deleg
         getDelegate().startLeafSet(enter(localName, NodeIdentifier.class), childSizeHint);
     }
 
+    @Override
+    public void startOrderedLeafSet(final String localName, final int childSizeHint) throws IOException {
+        getDelegate().startOrderedLeafSet(enter(localName, NodeIdentifier.class), childSizeHint);
+    }
+
     @Override
     public void startMapEntryNode(final Identifier<?> key, final int childSizeHint) throws IOException {
         duplicateSchemaEnter();
index d6323dfe6a81884fb1ba6a892151487ff77cac36..5b2c092194a0270c4cbdbee724ef2bd8486fc443 100644 (file)
@@ -31,6 +31,10 @@ abstract class ForwardingBindingStreamEventWriter implements BindingStreamEventW
         delegate().startLeafSet(localName, childSizeHint);
     }
 
+    @Override
+    public void startOrderedLeafSet(final String localName, final int childSizeHint) throws IOException, IllegalArgumentException {
+        delegate().startOrderedLeafSet(localName, childSizeHint);
+    }
 
     @Override
     public void leafSetEntryNode(final Object value) throws IOException, IllegalArgumentException {
index f595dc5b8b5f801ef9283b7464262759658c7382..3a9ce5ae5d76ae3bf715ac9e707d3da1030b516b 100644 (file)
@@ -67,6 +67,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableCo
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
 
 public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRuntimeTest{
@@ -78,6 +79,7 @@ public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRunti
     public static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
     public static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
     public static final QName TOP_LEVEL_LEAF_LIST_QNAME = QName.create(TOP_QNAME, "top-level-leaf-list");
+    public static final QName TOP_LEVEL_ORDERED_LEAF_LIST_QNAME = QName.create(TOP_QNAME, "top-level-ordered-leaf-list");
     public static final QName NESTED_LIST_QNAME = QName.create(TOP_QNAME, "nested-list");
     public static final QName NESTED_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
     public static final QName CHOICE_CONTAINER_QNAME = ChoiceContainer.QNAME;
@@ -182,6 +184,28 @@ public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRunti
         assertEquals(new TreeLeafOnlyAugmentBuilder().setSimpleValue("simpleValue").build(), entry.getValue());
     }
 
+    @Test
+    public void orderedleafListToNormalized() {
+        List<String> topLevelLeafList = new ArrayList<>();
+        topLevelLeafList.add("foo");
+        Top top = new TopBuilder().setTopLevelOrderedLeafList(topLevelLeafList).build();
+
+        Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
+                registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top);
+        ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
+                .withChild(ImmutableOrderedLeafSetNodeBuilder.create()
+                        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME))
+                        .withChild(
+                                ImmutableLeafSetEntryNodeBuilder.create()
+                                        .withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME, "foo"))
+                                        .withValue("foo")
+                                        .build())
+                        .build())
+                .build();
+        assertEquals(containerNode, entry.getValue());
+    }
+
     @Test
     public void leafListToNormalized() {
         final List<String> topLevelLeafList = new ArrayList<>();
@@ -219,6 +243,22 @@ public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRunti
         assertEquals(top, entry.getValue());
     }
 
+    @Test
+    public void orderedLeafListFromNormalized() {
+        ContainerNode topWithLeafList = ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
+                .withChild(ImmutableOrderedLeafSetNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier
+                        (TOP_LEVEL_ORDERED_LEAF_LIST_QNAME))
+                        .withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
+                                new YangInstanceIdentifier.NodeWithValue(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME, "foo")).withValue("foo").build()).build())
+                .build();
+        Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topWithLeafList);
+        List<String> topLevelLeafList = new ArrayList<>();
+        topLevelLeafList.add("foo");
+        Top top = new TopBuilder().setTopLevelOrderedLeafList(topLevelLeafList).build();
+        assertEquals(top, entry.getValue());
+    }
+
     @Test
     public void choiceToNormalized() {
         final ChoiceContainer choiceContainerBA = new ChoiceContainerBuilder().setIdentifier(new ExtendedBuilder().setExtendedId(
index 4b1201d2ade8a0f742373730eb4b9a67dd57e844..e1b5e9c7e3f674fffd0ad90b7a091ec7ed55b5cc 100644 (file)
@@ -72,6 +72,11 @@ module opendaylight-mdsal-binding-test {
         leaf-list top-level-leaf-list {
             type string;
         }
+
+        leaf-list top-level-ordered-leaf-list {
+            type string;
+            ordered-by user;
+        }
     }
 
     grouping choice {
index 4aeb309dd50de7b394255cddb7403b34345ea3d7..8215f164210a731ccc019bfcb9b82fd8694363e2 100644 (file)
@@ -151,6 +151,32 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      */
     void startLeafSet(String localName, int childSizeHint) throws IOException, IllegalArgumentException;
 
+    /**
+     *
+     * Emits a start of leaf set (leaf-list).
+     * <p>
+     * Emits start of leaf set, during writing leaf set event, only
+     * {@link #leafSetEntryNode(Object)} calls are valid. Leaf set event is
+     * finished by calling {@link #endNode()}.
+     *
+     * @param localName
+     *            name of node as defined in schema, namespace and revision are
+     *            derived from parent node.
+     * @param childSizeHint
+     *            Non-negative count of expected direct child nodes or
+     *            {@link #UNKNOWN_SIZE} if count is unknown. This is only hint
+     *            and should not fail writing of child events, if there are more
+     *            events than count.
+     * @throws IllegalArgumentException
+     *             If emitted leaf node is invalid in current context or was
+     *             emitted multiple times.
+     * @throws IllegalStateException
+     *             If node was emitted inside <code>map</code>,
+     *             <code>choice</code> <code>unkeyed list</code> node.
+     * @throws IOException if an underlying IO error occurs
+     */
+    void startOrderedLeafSet(String localName, int childSizeHint) throws IOException, IllegalArgumentException;
+
     /**
      * Emits a leaf set entry node
      *