import java.util.Iterator;
import java.util.LinkedList;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
public final class LeafRefUtils {
private LeafRefUtils() {
- throw new UnsupportedOperationException();
+ // Hidden on purpose
}
/**
public static LeafRefPath createAbsoluteLeafRefPath(
final LeafRefPath leafRefPath, final SchemaPath contextNodeSchemaPath,
final Module module) {
-
if (leafRefPath.isAbsolute()) {
return leafRefPath;
}
return LeafRefPath.create(absoluteLeafRefTargetPathList, true);
}
- private static Deque<QNameWithPredicate> schemaPathToXPathQNames(
- final SchemaPath nodePath, final Module module) {
-
+ private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) {
final Deque<QNameWithPredicate> xpath = new LinkedList<>();
-
- final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot()
- .iterator();
+ final Iterator<QName> 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 ChoiceCaseNode)) {
- final QNameWithPredicate newQName = new QNameWithPredicateBuilder(
- qname.getModule(), qname.getLocalName()).build();
- xpath.add(newQName);
+ if (!(child instanceof CaseSchemaNode)) {
+ 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());
}
}