Merge "fixed restconf notification subscription parsing."
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / util / InstanceIdToNodes.java
index cb17b35a23348e553f014acc6fa2237a4f067358..d0b9efc8c02fa9c5020a93a0f19241f326374fd8 100644 (file)
@@ -26,11 +26,11 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -51,6 +51,7 @@ import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -167,8 +168,10 @@ public abstract class InstanceIdToNodes<T extends PathArgument> implements Ident
 
                 final YangInstanceIdentifier childId = YangInstanceIdentifier.create(Iterables.skip(id.getPathArguments(), 1));
                 builder.addChild(childOp.create(childId, lastChild, operation));
-            } else if(lastChild.isPresent()) {
-                builder.withValue(Lists.newArrayList((Collection<?>) lastChild.get().getValue()));
+            } else {
+                if(lastChild.isPresent()) {
+                    builder.withValue(Lists.newArrayList((Collection<?>) lastChild.get().getValue()));
+                }
                 if(operation.isPresent()) {
                     Preconditions.checkArgument(builder instanceof AttributesBuilder<?>);
                     addModifyOpIfPresent(operation, ((AttributesBuilder<?>) builder));
@@ -402,7 +405,7 @@ public abstract class InstanceIdToNodes<T extends PathArgument> implements Ident
 
         private final ImmutableMap<PathArgument, InstanceIdToNodes<?>> byArg;
 
-        protected ChoiceNodeNormalization(final org.opendaylight.yangtools.yang.model.api.ChoiceNode schema) {
+        protected ChoiceNodeNormalization(final ChoiceSchemaNode schema) {
             super(new NodeIdentifier(schema.getQName()));
             final ImmutableMap.Builder<PathArgument, InstanceIdToNodes<?>> byArgBuilder = ImmutableMap.builder();
 
@@ -441,14 +444,15 @@ public abstract class InstanceIdToNodes<T extends PathArgument> implements Ident
         public NormalizedNode<?, ?> create(final YangInstanceIdentifier legacyData, final Optional<NormalizedNode<?, ?>> deepestChild, final Optional<ModifyAction> operation) {
             if(deepestChild.isPresent()) {
                 Preconditions.checkState(deepestChild instanceof AnyXmlNode);
-                final NormalizedNodeAttrBuilder<NodeIdentifier, Node<?>, AnyXmlNode> anyXmlBuilder =
+                final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder =
                         Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier()).withValue(((AnyXmlNode) deepestChild).getValue());
                 addModifyOpIfPresent(operation, anyXmlBuilder);
                 return anyXmlBuilder.build();
             }
 
-            final NormalizedNodeAttrBuilder<NodeIdentifier, Node<?>, AnyXmlNode> builder =
+            final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> builder =
                     Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier());
+            addModifyOpIfPresent(operation, builder);
             return builder.build();
         }
 
@@ -457,8 +461,7 @@ public abstract class InstanceIdToNodes<T extends PathArgument> implements Ident
     private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) {
         DataSchemaNode potential = parent.getDataChildByName(child);
         if (potential == null) {
-            final Iterable<org.opendaylight.yangtools.yang.model.api.ChoiceNode> choices = FluentIterable.from(
-                    parent.getChildNodes()).filter(org.opendaylight.yangtools.yang.model.api.ChoiceNode.class);
+            final Iterable<ChoiceSchemaNode> choices = FluentIterable.from(parent.getChildNodes()).filter(ChoiceSchemaNode.class);
             potential = findChoice(choices, child);
         }
         return Optional.fromNullable(potential);
@@ -478,11 +481,10 @@ public abstract class InstanceIdToNodes<T extends PathArgument> implements Ident
         return fromDataSchemaNode(result);
     }
 
-    private static org.opendaylight.yangtools.yang.model.api.ChoiceNode findChoice(
-            final Iterable<org.opendaylight.yangtools.yang.model.api.ChoiceNode> choices, final QName child) {
-        org.opendaylight.yangtools.yang.model.api.ChoiceNode foundChoice = null;
+    private static ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
+        org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode foundChoice = null;
         choiceLoop:
-        for (final org.opendaylight.yangtools.yang.model.api.ChoiceNode choice : choices) {
+        for (final ChoiceSchemaNode choice : choices) {
             for (final ChoiceCaseNode caze : choice.getCases()) {
                 if (findChildSchemaNode(caze, child).isPresent()) {
                     foundChoice = choice;
@@ -542,8 +544,8 @@ public abstract class InstanceIdToNodes<T extends PathArgument> implements Ident
             return fromListSchemaNode((ListSchemaNode) potential);
         } else if (potential instanceof LeafSchemaNode) {
             return new LeafNormalization((LeafSchemaNode) potential);
-        } else if (potential instanceof org.opendaylight.yangtools.yang.model.api.ChoiceNode) {
-            return new ChoiceNodeNormalization((org.opendaylight.yangtools.yang.model.api.ChoiceNode) potential);
+        } else if (potential instanceof ChoiceSchemaNode) {
+            return new ChoiceNodeNormalization((ChoiceSchemaNode) potential);
         } else if (potential instanceof LeafListSchemaNode) {
             return fromLeafListSchemaNode((LeafListSchemaNode) potential);
         } else if (potential instanceof AnyXmlSchemaNode) {