Rework NormalizedNode type hierarchy
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / InstanceIdToNodes.java
index 473957c423def73412116a3f3a0a015f43fabe88..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;
@@ -33,7 +34,7 @@ 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();
 
@@ -116,16 +117,16 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
         }
 
         @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();
         }
     }
@@ -136,15 +137,15 @@ abstract class InstanceIdToNodes<T extends PathArgument> extends AbstractIdentif
         }
 
         @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,7 +172,7 @@ 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()) {
                 if (findChildSchemaNode(caze, child).isPresent()) {
@@ -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) {