Rework NormalizedNode type hierarchy
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / InstanceIdToNodes.java
index c9e9b258b49ab9cafad929492e41eeca84795c0b..8590557411cde7e07f639c1199650a61837c1df6 100644 (file)
@@ -16,7 +16,8 @@ import java.util.List;
 import java.util.Optional;
 import javax.xml.transform.dom.DOMSource;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -27,13 +28,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.AnyDataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerLike;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
@@ -44,7 +45,7 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
  * Base strategy for converting an instance identifier into a normalized node structure.
  * Use provided static methods for generic YangInstanceIdentifier -> NormalizedNode translation in ImmutableNodes.
  */
-abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentifiable<T> {
+abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractSimpleIdentifiable<T> {
     InstanceIdToNodes(final T identifier) {
         super(identifier);
     }
@@ -55,7 +56,7 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
      * @param child child identifier
      * @return transformation strategy for a specific child
      */
-    abstract InstanceIdToNodes<?> getChild(PathArgument child);
+    abstract @Nullable InstanceIdToNodes<?> getChild(PathArgument child);
 
     /**
      * Convert instance identifier into a NormalizedNode structure.
@@ -65,8 +66,8 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
      * @param operation Optional modify operation to be set on the last child
      * @return NormalizedNode structure corresponding to submitted instance ID
      */
-    abstract @NonNull NormalizedNode<?, ?> create(PathArgument first, Iterator<PathArgument> others,
-            Optional<NormalizedNode<?, ?>> deepestChild);
+    abstract @NonNull NormalizedNode create(PathArgument first, Iterator<PathArgument> others,
+            Optional<NormalizedNode> deepestChild);
 
     abstract boolean isMixin();
 
@@ -111,40 +112,40 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
     }
 
     private static final class AnydataNormalization extends AbstractOpaqueNormalization {
-        AnydataNormalization(final AnyDataSchemaNode schema) {
+        AnydataNormalization(final AnydataSchemaNode schema) {
             super(schema);
         }
 
         @Override
-        NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others,
-                final Optional<NormalizedNode<?, ?>> deepestChild) {
+        NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others,
+                final Optional<NormalizedNode> deepestChild) {
             checkState(deepestChild.isPresent(), "Cannot instantiate anydata node without a value");
-            final NormalizedNode<?, ?> child = deepestChild.get();
+            final NormalizedNode child = deepestChild.get();
             checkState(child instanceof AnydataNode, "Invalid child %s", child);
             return createAnydata((AnydataNode<?>) child);
         }
 
         private <T> AnydataNode<T> createAnydata(final AnydataNode<T> child) {
-            return Builders.anydataBuilder(child.getValueObjectModel()).withValue(child.getValue())
+            return Builders.anydataBuilder(child.bodyObjectModel()).withValue(child.body())
             .withNodeIdentifier(getIdentifier()).build();
         }
     }
 
     private static final class AnyXmlNormalization extends AbstractOpaqueNormalization {
-        AnyXmlNormalization(final AnyXmlSchemaNode schema) {
+        AnyXmlNormalization(final AnyxmlSchemaNode schema) {
             super(schema);
         }
 
         @Override
-        NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others,
-                final Optional<NormalizedNode<?, ?>> deepestChild) {
+        NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others,
+                final Optional<NormalizedNode> deepestChild) {
             final NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> builder =
                     Builders.anyXmlBuilder()
                     .withNodeIdentifier(getIdentifier());
             if (deepestChild.isPresent()) {
-                final NormalizedNode<?, ?> child = deepestChild.get();
+                final NormalizedNode child = deepestChild.get();
                 checkState(child instanceof DOMSourceAnyxmlNode, "Invalid child %s", child);
-                builder.withValue(((DOMSourceAnyxmlNode) child).getValue());
+                builder.withValue(((DOMSourceAnyxmlNode) child).body());
             }
 
             return builder.build();
@@ -157,7 +158,7 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
             findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child));
     }
 
-    static InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
+    static @Nullable InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
         final Optional<DataSchemaNode> potential = findChildSchemaNode(schema, child);
         checkArgument(potential.isPresent(),
                 "Supplied QName %s is not valid according to schema %s, potential children nodes: %s", child, schema,
@@ -171,9 +172,9 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
         return fromDataSchemaNode(result);
     }
 
-    private static ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
+    private static @Nullable ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
         for (final ChoiceSchemaNode choice : choices) {
-            for (final CaseSchemaNode caze : choice.getCases().values()) {
+            for (final CaseSchemaNode caze : choice.getCases()) {
                 if (findChildSchemaNode(caze, child).isPresent()) {
                     return choice;
                 }
@@ -190,7 +191,7 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
      * otherwise returns a SchemaPathUtil for child as
      * call for {@link #fromDataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode)}.
      */
-    private static InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
+    private static @Nullable InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
             final AugmentationTarget parentAug, final DataSchemaNode child) {
         for (final AugmentationSchemaNode aug : parentAug.getAvailableAugmentations()) {
             final Optional<DataSchemaNode> potential = aug.findDataChildByName(child.getQName());
@@ -201,9 +202,9 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
         return fromDataSchemaNode(child);
     }
 
-    static InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) {
-        if (potential instanceof ContainerSchemaNode) {
-            return new InstanceIdToCompositeNodes.ContainerTransformation((ContainerSchemaNode) potential);
+    static @Nullable InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) {
+        if (potential instanceof ContainerLike) {
+            return new InstanceIdToCompositeNodes.ContainerTransformation((ContainerLike) potential);
         } else if (potential instanceof ListSchemaNode) {
             return fromListSchemaNode((ListSchemaNode) potential);
         } else if (potential instanceof LeafSchemaNode) {
@@ -212,10 +213,10 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
             return new InstanceIdToCompositeNodes.ChoiceNodeNormalization((ChoiceSchemaNode) potential);
         } else if (potential instanceof LeafListSchemaNode) {
             return fromLeafListSchemaNode((LeafListSchemaNode) potential);
-        } else if (potential instanceof AnyDataSchemaNode) {
-            return new AnydataNormalization((AnyDataSchemaNode) potential);
-        } else if (potential instanceof AnyXmlSchemaNode) {
-            return new AnyXmlNormalization((AnyXmlSchemaNode) potential);
+        } else if (potential instanceof AnydataSchemaNode) {
+            return new AnydataNormalization((AnydataSchemaNode) potential);
+        } else if (potential instanceof AnyxmlSchemaNode) {
+            return new AnyXmlNormalization((AnyxmlSchemaNode) potential);
         }
         return null;
     }