This is forward-port on the Lithium fix, migrated to the mdsal project.
Change-Id: I46d94c281b904125fecb9636e513daa0c65c93cf
Signed-off-by: Robert Varga <rovarga@cisco.com>
} 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()));
b.append(forEach(getterName, valueType, tryToUseCacheElse(CURRENT,statement(staticInvokeEmitter(valueType, CURRENT)))));
b.append(statement(endNode()));
}
-}
\ No newline at end of file
+}
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);
}
final String className = this.generator.loadSerializerFor(cls) + ".getInstance()";
return invoke(className, AbstractStreamWriterGenerator.SERIALIZE_METHOD_NAME, REGISTRY, name, STREAM);
}
-}
\ No newline at end of file
+}
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();
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 {
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{
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;
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<>();
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(
leaf-list top-level-leaf-list {
type string;
}
+
+ leaf-list top-level-ordered-leaf-list {
+ type string;
+ ordered-by user;
+ }
}
grouping choice {
*/
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
*