Remove NormalizedNode.getNodeType() 11/95411/13
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 4 Mar 2021 14:50:32 +0000 (15:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Apr 2021 13:02:45 +0000 (15:02 +0200)
This method is a shortcut through getIdentifier().getNodeType(),
except it does not work in all circumstances. Remove it and let
users deal with augmentation specifics.

JIRA: YANGTOOLS-1074
Change-Id: If112167e2d98c59d92d6e071c510c8e3db97ca0c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/rfc8528-data-api/src/main/java/org/opendaylight/yangtools/rfc8528/data/api/MountPointNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/NormalizedNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeWriter.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/AnyXmlWithParamsParsingTest.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefValidation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriter.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeSchemaUtils.java

index a1136f344cc56d26e550142e903e47babc3f9112..fecb648ecebdfc08136ee4a061098548c09b73ca 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.rfc8528.data.api;
 
 import com.google.common.annotations.Beta;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MixinNode;
@@ -31,12 +30,6 @@ public interface MountPointNode extends DataContainerNode, DataContainerChild, M
     @Override
     MountPointIdentifier getIdentifier();
 
-    @Override
-    @Deprecated
-    default QName getNodeType() {
-        return getIdentifier().getLabel();
-    }
-
     /**
      * Return the underlying mount point context.
      *
index e9c03d49d4a48c340a87d920e353a5a6ba1c365c..da1ed92067989dd2da81d9bd60e2952c0c175cd4 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.data.api.schema;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Identifiable;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 /**
@@ -46,18 +45,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
  *               data. Nevertheless, this interface should be named 'NormalizedData'.
  */
 public interface NormalizedNode extends Identifiable<PathArgument> {
-    /**
-     * QName of the node as defined in YANG schema.
-     *
-     * @return QName of this node, non-null.
-     */
-    // FIXME: YANGTOOLS-1074: eliminate this method: the problem is that it does not work with AugmentationIdentifier
-    //                        At least we need a 'QNameModule namespace()' method, as that is the common contract.
-    @Deprecated(forRemoval = true)
-    default @NonNull QName getNodeType() {
-        return getIdentifier().getNodeType();
-    }
-
     @Override
     // We override here, so that NormalizedNode.getIdentifier() has fewer implementations
     PathArgument getIdentifier();
index 49e1129fe562134b3498f5673f8d2326069048d7..13b14435a3a0cf180865c8881ac5cbb42b28291b 100644 (file)
@@ -279,7 +279,7 @@ public class NormalizedNodeWriter implements Closeable, Flushable {
                 if (input instanceof AugmentationNode) {
                     return true;
                 }
-                if (!qnames.contains(input.getNodeType())) {
+                if (!qnames.contains(input.getIdentifier().getNodeType())) {
                     return true;
                 }
 
index 8ec4f078a93d737c7aa7f215db10987a5c2e178d..64098c18e77a2653c15cc24480c6a75f37af3565 100644 (file)
@@ -81,7 +81,7 @@ public class AnyXmlWithParamsParsingTest {
     }
 
     private static NodeIdentifier getNodeId(final NormalizedNode parsed, final String localName) {
-        return new NodeIdentifier(QName.create(parsed.getNodeType(), localName));
+        return new NodeIdentifier(QName.create(parsed.getIdentifier().getNodeType(), localName));
     }
 
     private static String toStringDom(final DOMSource source) {
index 2cd9c5845dea0cdf6768d8833eb960b71e1ed123..5dc9938b69ff2da062d663d77d1355c21b5ecd36 100644 (file)
@@ -205,7 +205,7 @@ public final class LeafRefValidation {
             final LeafRefContext referencingCtx, final ModificationType modificationType,
             final YangInstanceIdentifier current) {
         for (final DataContainerChild child : node.body()) {
-            final QName qname = child.getNodeType();
+            final QName qname = child.getIdentifier().getNodeType();
             final LeafRefContext childReferencedByCtx = referencedByCtx == null ? null
                     : findReferencedByCtxUnderChoice(referencedByCtx, qname);
             final LeafRefContext childReferencingCtx = referencingCtx == null ? null
@@ -251,7 +251,7 @@ public final class LeafRefValidation {
     private void validateChildNodeData(final DataContainerChild child, final LeafRefContext referencedByCtx,
             final LeafRefContext referencingCtx, final ModificationType modificationType,
             final YangInstanceIdentifier current) {
-        final QName qname = child.getNodeType();
+        final QName qname = child.getIdentifier().getNodeType();
         final LeafRefContext childReferencedByCtx = referencedByCtx == null ? null
                 : referencedByCtx.getReferencedChildByName(qname);
         final LeafRefContext childReferencingCtx = referencingCtx == null ? null
@@ -310,11 +310,11 @@ public final class LeafRefValidation {
 
                 LOG.debug("Invalid leafref value [{}] allowed values {} by validation of leafref TARGET node: {} path "
                         + "of invalid LEAFREF node: {} leafRef target path: {} {}", leafRefsValue,
-                        leafRefTargetNodeValues, leaf.getNodeType(), leafRefContext.getCurrentNodePath(),
+                        leafRefTargetNodeValues, leaf.getIdentifier(), leafRefContext.getCurrentNodePath(),
                         leafRefContext.getAbsoluteLeafRefTargetPath(), FAILED);
                 errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s by validation of leafref"
                         + " TARGET node: %s path of invalid LEAFREF node: %s leafRef target path: %s %s", leafRefsValue,
-                        leafRefTargetNodeValues, leaf.getNodeType(), leafRefContext.getCurrentNodePath(),
+                        leafRefTargetNodeValues, leaf.getIdentifier(), leafRefContext.getCurrentNodePath(),
                         leafRefContext.getAbsoluteLeafRefTargetPath(),
                         FAILED));
             });
@@ -338,9 +338,9 @@ public final class LeafRefValidation {
         LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType,
             referencingCtx.getNodeName(), leaf.body(), FAILED);
         LOG.debug("Invalid leafref value [{}] allowed values {} of LEAFREF node: {} leafRef target path: {}",
-            leaf.body(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath());
+            leaf.body(), values, leaf.getIdentifier(), referencingCtx.getAbsoluteLeafRefTargetPath());
         errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s of LEAFREF node: %s leafRef "
-                + "target path: %s", leaf.body(), values, leaf.getNodeType(),
+                + "target path: %s", leaf.body(), values, leaf.getIdentifier(),
                 referencingCtx.getAbsoluteLeafRefTargetPath()));
     }
 
index 3c1d0f4dd3fea9af12d0429cedac64e60530acec..5a364ee6b8910f4ba356e4c8210671f96de881c0 100644 (file)
@@ -79,7 +79,7 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
     @Override
     public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode node) throws IOException {
         if (schemaContext.equals(root)) {
-            currentSchemaNode = schemaContext.dataChildByName(node.getNodeType());
+            currentSchemaNode = schemaContext.dataChildByName(node.getIdentifier().getNodeType());
         } else {
             currentSchemaNode = root;
         }
@@ -184,7 +184,7 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
                 putChild(qnameToNodes, grandChild);
             }
         } else {
-            qnameToNodes.put(child.getNodeType(), child);
+            qnameToNodes.put(child.getIdentifier().getNodeType(), child);
         }
     }
 
index 383b1b6db4058c922f65caf0b623870e025bf750..d1e1d72fb6c68b637e34a79529854e360457b34c 100644 (file)
@@ -177,10 +177,8 @@ public class BuilderTest {
                 .build();
         final UnkeyedListEntryNode unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder
                 .create(unkeyedListEntryNode).build();
-        assertEquals(unkeyedListEntryNode.getNodeType().getLocalName(), unkeyedListEntryNodeSize.getNodeType()
-                .getLocalName());
-        assertEquals(unkeyedListEntryNodeSize.getNodeType().getLocalName(), unkeyedListEntryNodeNode.getNodeType()
-                .getLocalName());
+        assertEquals(unkeyedListEntryNode.getIdentifier(), unkeyedListEntryNodeSize.getIdentifier());
+        assertEquals(unkeyedListEntryNodeSize.getIdentifier(), unkeyedListEntryNodeNode.getIdentifier());
     }
 
     @Test
@@ -204,7 +202,7 @@ public class BuilderTest {
 
         assertNotNull(unkeyedListNodeSize.body());
         assertEquals(unkeyedListEntryNode, unkeyedListNodeCreated.childAt(0));
-        assertEquals(unkeyedListNode.getNodeType().getLocalName(), unkeyedListNodeSize.getNodeType().getLocalName());
+        assertEquals(unkeyedListNode.getIdentifier(), unkeyedListNodeSize.getIdentifier());
         assertNotNull(unkeyedListNodeCreated);
     }
 
index d3a8c02c343cdc655630653a885b4befafdfbe98..02ddfdadc5f1d379439b1f587cbec7868b33f3f1 100644 (file)
@@ -33,13 +33,12 @@ public final class NormalizedNodeSchemaUtils {
             return detectCase(schema, (AugmentationNode) child);
         }
 
-        final QName childId = child.getNodeType();
+        final QName childId = child.getIdentifier().getNodeType();
         for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
             if (choiceCaseNode.dataChildByName(childId) != null) {
                 return Optional.of(choiceCaseNode);
             }
         }
-
         return Optional.empty();
     }