X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Futil%2FSchemaContextUtil.java;h=7ad5070f195a118faf8590d75e3671208029c578;hb=e704e6a6d1cc4db7ac1e1f53b54ec3bf51aaecc3;hp=10594211833df3fb15a86fad6ba32dd091bf4112;hpb=fce70654f7d387a8454c8441459ffff03ad0f1a2;p=yangtools.git
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
index 1059421183..7ad5070f19 100644
--- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
+++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
@@ -640,7 +640,7 @@ public final class SchemaContextUtil {
}
}
- Module parentModule = findParentModuleByType(schemaContext, baseSchema);
+ Module parentModule = findParentModuleOfReferencingType(schemaContext, baseSchema);
final DataSchemaNode dataSchemaNode;
if(pathStatement.isAbsolute()) {
@@ -665,7 +665,33 @@ public final class SchemaContextUtil {
}
}
+ private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext,
+ final SchemaNode schemaNode) {
+ Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!");
+ Preconditions.checkArgument(schemaNode != null, "Schema Node cannot be NULL!");
+ TypeDefinition> nodeType = null;
+
+ if (schemaNode instanceof LeafSchemaNode) {
+ nodeType = ((LeafSchemaNode) schemaNode).getType();
+ } else if (schemaNode instanceof LeafListSchemaNode) {
+ nodeType = ((LeafListSchemaNode) schemaNode).getType();
+ }
+
+ if (nodeType.getBaseType() != null) {
+ while (nodeType.getBaseType() != null) {
+ nodeType = nodeType.getBaseType();
+ }
+
+ final QNameModule typeDefModuleQname = nodeType.getQName().getModule();
+ return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(),
+ typeDefModuleQname.getRevision());
+ }
+
+ return SchemaContextUtil.findParentModule(schemaContext, schemaNode);
+ }
+
/**
+ * @deprecated due to expensive lookup
* Returns parent Yang Module for specified Schema Context in which Schema
* Node is declared. If Schema Node is of type 'ExtendedType' it tries to find parent module
* in which the type was originally declared (needed for correct leafref path resolution).
@@ -684,6 +710,7 @@ public final class SchemaContextUtil {
* Schema Node is NOT present, the method will returns
* null
*/
+ @Deprecated
public static Module findParentModuleByType(final SchemaContext schemaContext, final SchemaNode schemaNode) {
Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!");
Preconditions.checkArgument(schemaNode != null, "Schema Node cannot be NULL!");
@@ -695,8 +722,8 @@ public final class SchemaContextUtil {
nodeType = ((LeafListSchemaNode) schemaNode).getType();
}
- if (nodeType instanceof ExtendedType) {
- while (nodeType.getBaseType() instanceof ExtendedType) {
+ if (!BaseTypes.isYangBuildInType(nodeType) && nodeType.getBaseType() != null) {
+ while (nodeType.getBaseType() != null && !BaseTypes.isYangBuildInType(nodeType.getBaseType())) {
nodeType = nodeType.getBaseType();
}