X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fleafref%2FLeafRefUtils.java;h=f17f766ed72615f85814f5bd011af73f94c864ea;hb=bb60da5fe2d1928defb46ed92b290cfff93dcd81;hp=3f7e41c0d0511f2a112a22e8d296e9fbd245b228;hpb=c07aad0f89c57a66089df3c431c1767ab4a04eea;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefUtils.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefUtils.java index 3f7e41c0d0..f17f766ed7 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefUtils.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefUtils.java @@ -22,7 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; public final class LeafRefUtils { private LeafRefUtils() { - throw new UnsupportedOperationException(); + // Hidden on purpose } /** @@ -36,7 +36,6 @@ public final class LeafRefUtils { public static LeafRefPath createAbsoluteLeafRefPath( final LeafRefPath leafRefPath, final SchemaPath contextNodeSchemaPath, final Module module) { - if (leafRefPath.isAbsolute()) { return leafRefPath; } @@ -57,50 +56,34 @@ public final class LeafRefUtils { return LeafRefPath.create(absoluteLeafRefTargetPathList, true); } - private static Deque schemaPathToXPathQNames( - final SchemaPath nodePath, final Module module) { - + private static Deque schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) { final Deque xpath = new LinkedList<>(); - - final Iterator nodePathIterator = nodePath.getPathFromRoot() - .iterator(); + final Iterator nodePathIterator = nodePath.getPathFromRoot().iterator(); DataNodeContainer currenDataNodeContainer = module; while (nodePathIterator.hasNext()) { final QName qname = nodePathIterator.next(); - final DataSchemaNode child = currenDataNodeContainer - .getDataChildByName(qname); + final DataSchemaNode child = currenDataNodeContainer.dataChildByName(qname); if (child instanceof DataNodeContainer) { if (!(child instanceof CaseSchemaNode)) { - final QNameWithPredicate newQName = new QNameWithPredicateBuilder( - qname.getModule(), qname.getLocalName()).build(); - xpath.add(newQName); + xpath.add(new SimpleQNameWithPredicate(qname)); } currenDataNodeContainer = (DataNodeContainer) child; } else if (child instanceof ChoiceSchemaNode) { if (nodePathIterator.hasNext()) { - currenDataNodeContainer = ((ChoiceSchemaNode) child) - .getCaseNodeByName(nodePathIterator.next()); + currenDataNodeContainer = ((ChoiceSchemaNode) child).findCase(nodePathIterator.next()).orElse(null); } else { break; } - } else if (child instanceof LeafSchemaNode - || child instanceof LeafListSchemaNode) { - - final QNameWithPredicate newQName = new QNameWithPredicateBuilder( - qname.getModule(), qname.getLocalName()).build(); - xpath.add(newQName); + } else if (child instanceof LeafSchemaNode || child instanceof LeafListSchemaNode) { + xpath.add(new SimpleQNameWithPredicate(qname)); break; - } else if (child == null) { - throw new IllegalArgumentException("No child " + qname - + " found in node container " + currenDataNodeContainer - + " in module " + module.getName()); + throw new IllegalArgumentException("No child " + qname + " found in node container " + + currenDataNodeContainer + " in module " + module.getName()); } else { - throw new IllegalStateException( - "Illegal schema node type in the path: " - + child.getClass()); + throw new IllegalStateException("Illegal schema node type in the path: " + child.getClass()); } }