This method's logic eagerly strips the xpath, even when we may
end up not needing it. Refactor implementation to initialize
later (and bail quicker).
Change-Id: I7a54d14dcc3def1cc01f65523c5cf6e1277a0fce
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
c8c1ed80b2949b5eda8bdb57bc9a25ef0db1aef0)
}
private boolean isLeafRefSelfReference(final LeafrefTypeDefinition leafref, final SchemaNode parentNode) {
}
private boolean isLeafRefSelfReference(final LeafrefTypeDefinition leafref, final SchemaNode parentNode) {
- final SchemaNode leafRefValueNode;
- final PathExpression leafRefXPath = leafref.getPathStatement();
- final PathExpression leafRefStrippedXPath = new PathExpressionImpl(
- GROUPS_PATTERN.matcher(leafRefXPath.getOriginalString()).replaceAll(""), leafRefXPath.isAbsolute());
-
- ///// skip leafrefs in augments - they're checked once augments are resolved
- final Iterator<QName> iterator = parentNode.getPath().getPathFromRoot().iterator();
- boolean isAugmenting = false;
+ /*
+ * First check if the leafref is an augment. If that is the case, skip it as it will be checked once augments
+ * are resolved.
+ */
DataNodeContainer current = null;
DataSchemaNode dataChildByName;
DataNodeContainer current = null;
DataSchemaNode dataChildByName;
-
- while (iterator.hasNext() && !isAugmenting) {
- final QName next = iterator.next();
+ for (QName next : parentNode.getPath().getPathFromRoot()) {
if (current == null) {
dataChildByName = schemaContext.getDataChildByName(next);
} else {
dataChildByName = current.getDataChildByName(next);
}
if (current == null) {
dataChildByName = schemaContext.getDataChildByName(next);
} else {
dataChildByName = current.getDataChildByName(next);
}
- if (dataChildByName != null) {
- isAugmenting = dataChildByName.isAugmenting();
- } else {
+ if (dataChildByName == null) {
+ return false;
+ }
+ if (dataChildByName.isAugmenting()) {
return false;
}
if (dataChildByName instanceof DataNodeContainer) {
current = (DataNodeContainer) dataChildByName;
}
}
return false;
}
if (dataChildByName instanceof DataNodeContainer) {
current = (DataNodeContainer) dataChildByName;
}
}
- if (isAugmenting) {
- return false;
- }
- /////
+ // Then try to look up the expression.
+ final PathExpression leafRefXPath = leafref.getPathStatement();
+ final PathExpression leafRefStrippedXPath = new PathExpressionImpl(
+ GROUPS_PATTERN.matcher(leafRefXPath.getOriginalString()).replaceAll(""), leafRefXPath.isAbsolute());
final Module parentModule = getParentModule(parentNode);
final Module parentModule = getParentModule(parentNode);
+ final SchemaNode leafRefValueNode;
if (!leafRefStrippedXPath.isAbsolute()) {
leafRefValueNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, parentModule,
parentNode, leafRefStrippedXPath);
if (!leafRefStrippedXPath.isAbsolute()) {
leafRefValueNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, parentModule,
parentNode, leafRefStrippedXPath);