Reformulate LeafRefContext without SchemaPath 12/94412/20
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Feb 2021 09:55:54 +0000 (10:55 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Sep 2021 09:54:47 +0000 (11:54 +0200)
The use of SchemaNode.getPath() is a mistake, which we really want to
correct. Use SchemaNodeIdentifier to identify nodes, as that is really
what we need -- and the methods are really belong to LeafRefContext, not
into a separate LeafRefContextUtils class.

JIRA: YANGTOOLS-1092
Change-Id: I012861b8f4ad580b86b49a1265eba785958e3437
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
Signed-off-by: Michal Banik <michal.banik@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContext.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextUtils.java [deleted file]
data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java
data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java

index da800460fceaf2f8f19a362921ac246d5df8d36a..8c6d32b3eb5a3f9daec94b5e46a763115ec4681d 100644 (file)
@@ -7,12 +7,20 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.leafref;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableMap;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
 
 public final class LeafRefContext extends AbstractEffectiveModelContextProvider {
@@ -128,6 +136,118 @@ public final class LeafRefContext extends AbstractEffectiveModelContextProvider
         return referencedByLeafRefCtx;
     }
 
+    @Beta
+    public LeafRefContext getLeafRefReferencingContext(final SchemaNodeIdentifier node) {
+        final Iterator<QName> iterator = descendantIterator(node);
+        LeafRefContext leafRefCtx = null;
+        LeafRefContext current = this;
+        while (iterator.hasNext() && current != null) {
+            final QName qname = iterator.next();
+            leafRefCtx = current.getReferencingChildByName(qname);
+            if (iterator.hasNext()) {
+                current = leafRefCtx;
+            }
+        }
+
+        return leafRefCtx;
+    }
+
+    @Beta
+    public LeafRefContext getLeafRefReferencedByContext(final SchemaNodeIdentifier node) {
+        final Iterator<QName> iterator = descendantIterator(node);
+        LeafRefContext leafRefCtx = null;
+        LeafRefContext current = this;
+        while (iterator.hasNext() && current != null) {
+            final QName qname = iterator.next();
+            leafRefCtx = current.getReferencedChildByName(qname);
+            if (iterator.hasNext()) {
+                current = leafRefCtx;
+            }
+        }
+
+        return leafRefCtx;
+    }
+
+    private Iterator<QName> descendantIterator(final SchemaNodeIdentifier node) {
+        final Iterator<QName> nodeSteps = node.getNodeIdentifiers().iterator();
+        if (node instanceof SchemaNodeIdentifier.Absolute) {
+            final Iterator<QName> mySteps = currentNodePath.getPathFromRoot().iterator();
+            while (mySteps.hasNext()) {
+                final QName myNext = mySteps.next();
+                checkArgument(nodeSteps.hasNext(), "Node %s is an ancestor of %s", node, currentNodePath);
+                final QName nodeNext = nodeSteps.next();
+                checkArgument(myNext.equals(nodeNext), "Node %s is not a descendant of %s", node, currentNodePath);
+            }
+        }
+        return nodeSteps;
+    }
+
+    @Beta
+    public boolean isLeafRef(final SchemaNodeIdentifier node) {
+        final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node);
+        return leafRefReferencingContext != null && leafRefReferencingContext.isReferencing();
+    }
+
+    @Beta
+    public boolean hasLeafRefChild(final SchemaNodeIdentifier node) {
+        final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node);
+        return leafRefReferencingContext != null && leafRefReferencingContext.hasReferencingChild();
+    }
+
+    @Beta
+    public boolean isReferencedByLeafRef(final SchemaNodeIdentifier node) {
+        final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node);
+        return leafRefReferencedByContext != null && leafRefReferencedByContext.isReferenced();
+    }
+
+    @Beta
+    public boolean hasChildReferencedByLeafRef(final SchemaNodeIdentifier node) {
+        final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node);
+        return leafRefReferencedByContext != null && leafRefReferencedByContext.hasReferencedChild();
+    }
+
+    @Beta
+    public List<LeafRefContext> findAllLeafRefChilds(final SchemaNodeIdentifier node) {
+        final LeafRefContext ctx = getLeafRefReferencingContext(node);
+        return ctx == null ? List.of() : ctx.findAllLeafRefChilds();
+    }
+
+    private List<LeafRefContext> findAllLeafRefChilds() {
+        if (isReferencing()) {
+            return List.of(this);
+        }
+
+        final List<LeafRefContext> leafRefChilds = new ArrayList<>();
+        for (final Entry<QName, LeafRefContext> child : getReferencingChilds().entrySet()) {
+            leafRefChilds.addAll(child.getValue().findAllLeafRefChilds());
+        }
+        return leafRefChilds;
+    }
+
+    @Beta
+    public List<LeafRefContext> findAllChildsReferencedByLeafRef(final SchemaNodeIdentifier node) {
+        final LeafRefContext ctx = getLeafRefReferencedByContext(node);
+        return ctx == null ? List.of() : ctx.findAllChildsReferencedByLeafRef();
+    }
+
+    private List<LeafRefContext> findAllChildsReferencedByLeafRef() {
+        if (isReferenced()) {
+            return List.of(this);
+        }
+
+        final List<LeafRefContext> childsReferencedByLeafRef = new ArrayList<>();
+        for (final Entry<QName, LeafRefContext> child : getReferencedByChilds().entrySet()) {
+            childsReferencedByLeafRef.addAll(child.getValue().findAllChildsReferencedByLeafRef());
+        }
+        return childsReferencedByLeafRef;
+    }
+
+    @Beta
+    public Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(final SchemaNodeIdentifier node) {
+        final LeafRefContext referencedByContext = getLeafRefReferencedByContext(node);
+        return referencedByContext == null ? Map.of() : referencedByContext.getAllReferencedByLeafRefCtxs();
+    }
+
     LeafRefPath getLeafRefNodePath() {
         LeafRefPath ret = leafRefNodePath;
         if (ret == null) {
index 420e213bf5c981fd2786a8fb5459c6857c659b35..472d09d7571b494a6febe6e1c7211b2c1327978b 100644 (file)
@@ -40,8 +40,7 @@ final class LeafRefContextBuilder implements Builder<LeafRefContext> {
             final EffectiveModelContext schemaContext) {
         this.currentNodeQName = requireNonNull(currentNodeQName);
         this.currentNodePath = requireNonNull(currentNodePath);
-        // FIXME: requireNonNull
-        this.schemaContext = schemaContext;
+        this.schemaContext = requireNonNull(schemaContext);
     }
 
     @Override
diff --git a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextUtils.java b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextUtils.java
deleted file mode 100644 (file)
index 43615f5..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.leafref;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-public final class LeafRefContextUtils {
-    private LeafRefContextUtils() {
-        // Hidden on purpose
-    }
-
-    public static LeafRefContext getLeafRefReferencingContext(final SchemaNode node, final LeafRefContext root) {
-        final SchemaPath schemaPath = node.getPath();
-        return getLeafRefReferencingContext(schemaPath, root);
-    }
-
-    public static LeafRefContext getLeafRefReferencingContext(
-            final SchemaPath schemaPath, final LeafRefContext root) {
-        final Iterable<QName> pathFromRoot = schemaPath.getPathFromRoot();
-        return getLeafRefReferencingContext(pathFromRoot, root);
-    }
-
-    public static LeafRefContext getLeafRefReferencingContext(final Iterable<QName> pathFromRoot, LeafRefContext root) {
-        LeafRefContext leafRefCtx = null;
-        final Iterator<QName> iterator = pathFromRoot.iterator();
-        while (iterator.hasNext() && root != null) {
-            final QName qname = iterator.next();
-            leafRefCtx = root.getReferencingChildByName(qname);
-            if (iterator.hasNext()) {
-                root = leafRefCtx;
-            }
-        }
-
-        return leafRefCtx;
-    }
-
-    public static LeafRefContext getLeafRefReferencedByContext(final SchemaNode node, final LeafRefContext root) {
-        final SchemaPath schemaPath = node.getPath();
-        return getLeafRefReferencedByContext(schemaPath, root);
-    }
-
-    public static LeafRefContext getLeafRefReferencedByContext(
-            final SchemaPath schemaPath, final LeafRefContext root) {
-        final Iterable<QName> pathFromRoot = schemaPath.getPathFromRoot();
-        return getLeafRefReferencedByContext(pathFromRoot, root);
-    }
-
-    public static LeafRefContext getLeafRefReferencedByContext(final Iterable<QName> pathFromRoot,
-            LeafRefContext root) {
-
-        LeafRefContext leafRefCtx = null;
-        final Iterator<QName> iterator = pathFromRoot.iterator();
-        while (iterator.hasNext() && root != null) {
-            final QName qname = iterator.next();
-            leafRefCtx = root.getReferencedChildByName(qname);
-            if (iterator.hasNext()) {
-                root = leafRefCtx;
-            }
-        }
-
-        return leafRefCtx;
-    }
-
-    public static boolean isLeafRef(final SchemaNode node, final LeafRefContext root) {
-        if (node == null || root == null) {
-            return false;
-        }
-
-        final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node, root);
-        if (leafRefReferencingContext == null) {
-            return false;
-        }
-
-        return leafRefReferencingContext.isReferencing();
-    }
-
-    public static boolean hasLeafRefChild(final SchemaNode node, final LeafRefContext root) {
-        if (node == null || root == null) {
-            return false;
-        }
-
-        final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node, root);
-        if (leafRefReferencingContext == null) {
-            return false;
-        }
-
-        return leafRefReferencingContext.hasReferencingChild();
-    }
-
-    public static boolean isReferencedByLeafRef(final SchemaNode node, final LeafRefContext root) {
-        if (node == null || root == null) {
-            return false;
-        }
-
-        final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node, root);
-        if (leafRefReferencedByContext == null) {
-            return false;
-        }
-
-        return leafRefReferencedByContext.isReferenced();
-    }
-
-    public static boolean hasChildReferencedByLeafRef(final SchemaNode node, final LeafRefContext root) {
-        if (node == null || root == null) {
-            return false;
-        }
-
-        final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node, root);
-        if (leafRefReferencedByContext == null) {
-            return false;
-        }
-
-        return leafRefReferencedByContext.hasReferencedChild();
-    }
-
-    public static List<LeafRefContext> findAllLeafRefChilds(final SchemaNode node, final LeafRefContext root) {
-        return findAllLeafRefChilds(node.getPath(), root);
-    }
-
-    public static List<LeafRefContext> findAllLeafRefChilds(final SchemaPath schemaPath, final LeafRefContext root) {
-        return findAllLeafRefChilds(schemaPath.getPathFromRoot(), root);
-    }
-
-    public static List<LeafRefContext> findAllLeafRefChilds(final Iterable<QName> pathFromRoot,
-            final LeafRefContext root) {
-        final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(pathFromRoot, root);
-        final List<LeafRefContext> allLeafRefsChilds = findAllLeafRefChilds(leafRefReferencingContext);
-
-        return allLeafRefsChilds;
-    }
-
-    public static List<LeafRefContext> findAllLeafRefChilds(final LeafRefContext parent) {
-        final LinkedList<LeafRefContext> leafRefChilds = new LinkedList<>();
-        if (parent == null) {
-            return leafRefChilds;
-        }
-
-        if (parent.isReferencing()) {
-            leafRefChilds.add(parent);
-            return leafRefChilds;
-        }
-
-        final Set<Entry<QName, LeafRefContext>> childs = parent.getReferencingChilds().entrySet();
-        for (final Entry<QName, LeafRefContext> child : childs) {
-            leafRefChilds.addAll(findAllLeafRefChilds(child.getValue()));
-        }
-        return leafRefChilds;
-    }
-
-    public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final SchemaNode node,
-            final LeafRefContext root) {
-        return findAllChildsReferencedByLeafRef(node.getPath(), root);
-    }
-
-    public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final SchemaPath schemaPath,
-            final LeafRefContext root) {
-        return findAllChildsReferencedByLeafRef(schemaPath.getPathFromRoot(), root);
-    }
-
-    public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final Iterable<QName> pathFromRoot,
-            final LeafRefContext root) {
-
-        final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(pathFromRoot, root);
-        final List<LeafRefContext> allChildsReferencedByLeafRef =
-                findAllChildsReferencedByLeafRef(leafRefReferencedByContext);
-
-        return allChildsReferencedByLeafRef;
-    }
-
-    public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final LeafRefContext parent) {
-        final LinkedList<LeafRefContext> childsReferencedByLeafRef = new LinkedList<>();
-        if (parent == null) {
-            return childsReferencedByLeafRef;
-        }
-
-        if (parent.isReferenced()) {
-            childsReferencedByLeafRef.add(parent);
-            return childsReferencedByLeafRef;
-        }
-
-        final Set<Entry<QName, LeafRefContext>> childs = parent.getReferencedByChilds().entrySet();
-        for (final Entry<QName, LeafRefContext> child : childs) {
-            childsReferencedByLeafRef.addAll(findAllChildsReferencedByLeafRef(child.getValue()));
-        }
-        return childsReferencedByLeafRef;
-    }
-
-    public static Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(
-            final SchemaNode node, final LeafRefContext root) {
-        return getAllLeafRefsReferencingThisNode(node.getPath(), root);
-    }
-
-    public static Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(final SchemaPath path,
-            final LeafRefContext root) {
-        return getAllLeafRefsReferencingThisNode(path.getPathFromRoot(), root);
-    }
-
-    public static Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(final Iterable<QName> pathFromRoot,
-            final LeafRefContext root) {
-
-        final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(pathFromRoot, root);
-        if (leafRefReferencedByContext == null) {
-            return new HashMap<>();
-        }
-
-        return leafRefReferencedByContext.getAllReferencedByLeafRefCtxs();
-    }
-}
index e9c650fb05f9b22caed7b999f1cf56f1ca04352a..7d993ea50fba328620d7b0e2f84de97f177a7147 100644 (file)
@@ -18,10 +18,9 @@ import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
-import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class LeafRefContextTest {
@@ -54,7 +53,6 @@ public class LeafRefContextTest {
 
     @Test
     public void test() {
-
         final QName q1 = QName.create(root, "ref1");
         final QName q2 = QName.create(root, "leaf1");
         final QName q3 = QName.create(root, "cont1");
@@ -62,28 +60,27 @@ public class LeafRefContextTest {
         final QName q5 = QName.create(root, "list1");
         final QName q6 = QName.create(root, "name");
 
-        final DataSchemaNode leafRefNode = rootMod.findDataChildByName(q1).get();
-        final DataSchemaNode targetNode = rootMod.findDataChildByName(q2).get();
-        final DataSchemaNode cont1Node = rootMod.findDataChildByName(q3).get();
-        final DataSchemaNode cont2Node = rootMod.findDataChildByName(q4).get();
-        final DataSchemaNode name1Node = rootMod.findDataChildByName(q3, q5, q6).get();
+        final Absolute leafRefNode = Absolute.of(q1);
+        final Absolute targetNode = Absolute.of(q2);
+        final Absolute cont1Node = Absolute.of(q3);
+        final Absolute cont2Node = Absolute.of(q4);
+        final Absolute name1Node = Absolute.of(q3, q5, q6);
 
-        assertTrue(LeafRefContextUtils.isLeafRef(leafRefNode, rootLeafRefContext));
-        assertFalse(LeafRefContextUtils.isLeafRef(targetNode, rootLeafRefContext));
+        assertTrue(rootLeafRefContext.isLeafRef(leafRefNode));
+        assertFalse(rootLeafRefContext.isLeafRef(targetNode));
 
-        assertTrue(LeafRefContextUtils.hasLeafRefChild(cont1Node, rootLeafRefContext));
-        assertFalse(LeafRefContextUtils.hasLeafRefChild(leafRefNode, rootLeafRefContext));
+        assertTrue(rootLeafRefContext.hasLeafRefChild(cont1Node));
+        assertFalse(rootLeafRefContext.hasLeafRefChild(leafRefNode));
 
-        assertTrue(LeafRefContextUtils.isReferencedByLeafRef(targetNode, rootLeafRefContext));
-        assertFalse(LeafRefContextUtils.isReferencedByLeafRef(leafRefNode, rootLeafRefContext));
+        assertTrue(rootLeafRefContext.isReferencedByLeafRef(targetNode));
+        assertFalse(rootLeafRefContext.isReferencedByLeafRef(leafRefNode));
 
-        assertTrue(LeafRefContextUtils.hasChildReferencedByLeafRef(cont2Node, rootLeafRefContext));
-        assertFalse(LeafRefContextUtils.hasChildReferencedByLeafRef(leafRefNode, rootLeafRefContext));
+        assertTrue(rootLeafRefContext.hasChildReferencedByLeafRef(cont2Node));
+        assertFalse(rootLeafRefContext.hasChildReferencedByLeafRef(leafRefNode));
 
-        Map<QName, LeafRefContext> leafRefs = LeafRefContextUtils.getAllLeafRefsReferencingThisNode(name1Node,
-                rootLeafRefContext);
+        Map<QName, LeafRefContext> leafRefs = rootLeafRefContext.getAllLeafRefsReferencingThisNode(name1Node);
         assertEquals(4, leafRefs.size());
-        leafRefs = LeafRefContextUtils.getAllLeafRefsReferencingThisNode(leafRefNode, rootLeafRefContext);
+        leafRefs = rootLeafRefContext.getAllLeafRefsReferencingThisNode(leafRefNode);
         assertTrue(leafRefs.isEmpty());
     }
 }
index 7536d1495c42a558c4ed0f8a9c9bb79ae0790157..7032c0a5ef7e76fdf130f190119cb3f0981be739 100644 (file)
@@ -24,10 +24,9 @@ import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
-import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@@ -155,18 +154,12 @@ public class LeafRefContextTreeBuilderTest {
         final QName q2 = QName.create(tst, "contributor");
         final QName q3 = QName.create(tst, "odl-project-name");
 
-        final LeafRefContext odlContrProjNameCtx = rootLeafRefContext.getReferencingChildByName(q1)
-                .getReferencingChildByName(q2).getReferencingChildByName(q3);
-
-        final DataSchemaNode odlContrProjNameNode = tstMod.findDataChildByName(q1, q2, q3).get();
-
-        final LeafRefContext foundOdlContrProjNameCtx = LeafRefContextUtils.getLeafRefReferencingContext(
-                odlContrProjNameNode, rootLeafRefContext);
-
-        assertNotNull(foundOdlContrProjNameCtx);
-        assertTrue(foundOdlContrProjNameCtx.isReferencing());
-        assertNotNull(foundOdlContrProjNameCtx.getLeafRefTargetPath());
-        assertEquals(odlContrProjNameCtx, foundOdlContrProjNameCtx);
+        final LeafRefContext found = rootLeafRefContext.getLeafRefReferencingContext(Absolute.of(q1, q2, q3));
+        assertNotNull(found);
+        assertTrue(found.isReferencing());
+        assertNotNull(found.getLeafRefTargetPath());
+        assertEquals(rootLeafRefContext
+            .getReferencingChildByName(q1).getReferencingChildByName(q2).getReferencingChildByName(q3), found);
     }
 
     @Test
@@ -175,46 +168,39 @@ public class LeafRefContextTreeBuilderTest {
         final QName q2 = QName.create(tst, "project");
         final QName q3 = QName.create(tst, "name");
 
-        final LeafRefContext leafRefCtx = rootLeafRefContext.getReferencedChildByName(q1).getReferencedChildByName(q2)
-                .getReferencedChildByName(q3);
+        final Absolute node = Absolute.of(q1, q2, q3);
+        LeafRefContext found = rootLeafRefContext.getLeafRefReferencingContext(node);
+        assertNull(found);
 
-        final DataSchemaNode odlProjNameNode = tstMod.findDataChildByName(q1, q2, q3).get();
+        found = rootLeafRefContext.getLeafRefReferencedByContext(node);
 
-        LeafRefContext foundOdlProjNameCtx = LeafRefContextUtils.getLeafRefReferencingContext(odlProjNameNode,
-                rootLeafRefContext);
-
-        assertNull(foundOdlProjNameCtx);
-
-        foundOdlProjNameCtx = LeafRefContextUtils.getLeafRefReferencedByContext(odlProjNameNode, rootLeafRefContext);
-
-        assertNotNull(foundOdlProjNameCtx);
-        assertTrue(foundOdlProjNameCtx.isReferenced());
-        assertFalse(foundOdlProjNameCtx.getAllReferencedByLeafRefCtxs().isEmpty());
-        assertEquals(6, foundOdlProjNameCtx.getAllReferencedByLeafRefCtxs().size());
-        assertEquals(leafRefCtx, foundOdlProjNameCtx);
+        assertNotNull(found);
+        assertTrue(found.isReferenced());
+        assertFalse(found.getAllReferencedByLeafRefCtxs().isEmpty());
+        assertEquals(6, found.getAllReferencedByLeafRefCtxs().size());
+        assertEquals(rootLeafRefContext
+            .getReferencedChildByName(q1).getReferencedChildByName(q2).getReferencedChildByName(q3), found);
     }
 
     @Test
     public void leafRefContextUtilsTest3() {
         final QName q16 = QName.create(tst, "con1");
-        final DataSchemaNode con1 = tstMod.findDataChildByName(q16).get();
-        final List<LeafRefContext> allLeafRefChilds = LeafRefContextUtils.findAllLeafRefChilds(con1,
-            rootLeafRefContext);
+        final Absolute con1 = Absolute.of(q16);
+
+        final List<LeafRefContext> allLeafRefChilds = rootLeafRefContext.findAllLeafRefChilds(con1);
 
         assertNotNull(allLeafRefChilds);
         assertFalse(allLeafRefChilds.isEmpty());
         assertEquals(4, allLeafRefChilds.size());
 
-        final QName q17 = QName.create(tst, "odl-contributor");
-        final DataSchemaNode odlContributorNode = tstMod.findDataChildByName(q17).get();
-        List<LeafRefContext> allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef(
-                odlContributorNode, rootLeafRefContext);
+        List<LeafRefContext> allChildsReferencedByLeafRef = rootLeafRefContext.findAllChildsReferencedByLeafRef(
+            Absolute.of(QName.create(tst, "odl-contributor")));
 
         assertNotNull(allChildsReferencedByLeafRef);
         assertFalse(allChildsReferencedByLeafRef.isEmpty());
         assertEquals(1, allChildsReferencedByLeafRef.size());
 
-        allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef(con1, rootLeafRefContext);
+        allChildsReferencedByLeafRef = rootLeafRefContext.findAllChildsReferencedByLeafRef(con1);
 
         assertNotNull(allChildsReferencedByLeafRef);
         assertTrue(allChildsReferencedByLeafRef.isEmpty());