Bug 3874: Support of yang modeled AnyXML - XML deserialization
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / transform / base / parser / NodeParserDispatcher.java
index 220b2cb04d4058e081bee585bc516bc0e9608319..d38b39868a3caa025af64db5b4eaff36836ea052 100644 (file)
@@ -13,11 +13,12 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParserFactory;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.YangModeledAnyXmlSchemaNode;
 
 /**
  *
@@ -33,7 +34,7 @@ public interface NodeParserDispatcher<E> {
      * Abstract implementation that implements the dispatch conditions. Only requires parsers to be provided.
      * The same instance of parser can be provided in case it is immutable.
      */
-    public static abstract class BaseNodeParserDispatcher<E> implements NodeParserDispatcher<E> {
+    abstract class BaseNodeParserDispatcher<E> implements NodeParserDispatcher<E> {
         private final ToNormalizedNodeParserFactory<E> factory;
 
         protected BaseNodeParserDispatcher(final ToNormalizedNodeParserFactory<E> factory) {
@@ -41,7 +42,7 @@ public interface NodeParserDispatcher<E> {
         }
 
         @Override
-        public final DataContainerChild<?, ?> dispatchChildElement(Object schema, List<E> childNodes) {
+        public final DataContainerChild<?, ?> dispatchChildElement(final Object schema, final List<E> childNodes) {
             Preconditions.checkArgument(!childNodes.isEmpty());
 
             if (schema instanceof ContainerSchemaNode) {
@@ -51,11 +52,20 @@ public interface NodeParserDispatcher<E> {
             } else if (schema instanceof LeafListSchemaNode) {
                 return factory.getLeafSetNodeParser().parse(childNodes, (LeafListSchemaNode) schema);
             } else if (schema instanceof ListSchemaNode) {
-                return factory.getMapNodeParser().parse(childNodes, (ListSchemaNode) schema);
-            } else if (schema instanceof ChoiceNode) {
-                return factory.getChoiceNodeParser().parse(childNodes, (ChoiceNode) schema);
+                final ListSchemaNode listSchemaNode = (ListSchemaNode)schema;
+                if (listSchemaNode.getKeyDefinition().isEmpty()) {
+                    return factory.getUnkeyedListNodeParser().parse(childNodes, listSchemaNode);
+                } else if (listSchemaNode.isUserOrdered()) {
+                    return factory.getOrderedListNodeParser().parse(childNodes, listSchemaNode);
+                } else {
+                    return factory.getMapNodeParser().parse(childNodes, listSchemaNode);
+                }
+            } else if (schema instanceof ChoiceSchemaNode) {
+                return factory.getChoiceNodeParser().parse(childNodes, (ChoiceSchemaNode) schema);
             } else if (schema instanceof AugmentationSchema) {
                 return factory.getAugmentationNodeParser().parse(childNodes, (AugmentationSchema) schema);
+            } else if (schema instanceof YangModeledAnyXmlSchemaNode) {
+                return factory.getYangModeledAnyXmlNodeParser().parse(childNodes,(YangModeledAnyXmlSchemaNode)schema);
             } else if (schema instanceof AnyXmlSchemaNode) {
                 return factory.getAnyXmlNodeParser().parse(childNodes,(AnyXmlSchemaNode)schema);
             }