X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fyang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Futil%2FSchemaContextUtil.java;h=2d6a78988752de136af601dd70ab40713cfa9a9e;hb=9ceed566491d172e02220b04ec6869867f2f2473;hp=39865a9ddf4e00eb3a9977687dfdfaa6411a7484;hpb=b571c5f3e6e9b2dcf2cff2314537c7b1c61533b4;p=controller.git diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/SchemaContextUtil.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/SchemaContextUtil.java index 39865a9ddf..2d6a789887 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/SchemaContextUtil.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/SchemaContextUtil.java @@ -24,6 +24,7 @@ import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; import org.opendaylight.controller.yang.model.api.SchemaContext; import org.opendaylight.controller.yang.model.api.SchemaNode; import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.TypeDefinition; public final class SchemaContextUtil { @@ -32,7 +33,7 @@ public final class SchemaContextUtil { public static DataSchemaNode findDataSchemaNode(final SchemaContext context, final SchemaPath schemaPath) { if (schemaPath != null) { final Module module = resolveModuleFromSchemaPath(context, schemaPath); - final Queue prefixedPath = new LinkedList(schemaPath.getPath()); + final Queue prefixedPath = new LinkedList(schemaPath.getPath()); if ((module != null) && (prefixedPath != null)) { return findSchemaNodeForGivenPath(context, module, prefixedPath); @@ -54,7 +55,7 @@ public final class SchemaContextUtil { final Queue qnamedPath = xpathToQNamePath(context, module, strXPath); if (qnamedPath != null) { - final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, + final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, module, qnamedPath); return dataNode; } @@ -64,7 +65,7 @@ public final class SchemaContextUtil { return null; } - public static DataSchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context, + public static DataSchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context, final Module module, final SchemaNode actualSchemaNode, final RevisionAwareXPath relativeXPath) { if ((actualSchemaNode != null) && (relativeXPath != null) @@ -72,11 +73,11 @@ public final class SchemaContextUtil { final SchemaPath actualNodePath = actualSchemaNode.getPath(); if (actualNodePath != null) { - final Queue qnamePath = resolveRelativeXPath(context, module, + final Queue qnamePath = resolveRelativeXPath(context, module, relativeXPath, actualNodePath); if (qnamePath != null) { - final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, + final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, module, qnamePath); return dataNode; } @@ -88,7 +89,8 @@ public final class SchemaContextUtil { public static Module resolveModuleFromSchemaPath(final SchemaContext context, final SchemaPath schemaPath) { if ((schemaPath != null) && (schemaPath.getPath() != null)) { - final QName qname = schemaPath.getPath().get(0); + List path = schemaPath.getPath(); + final QName qname = path.get(path.size()-1); if ((qname != null) && (qname.getNamespace() != null)) { return context.findModuleByNamespace(qname.getNamespace()); @@ -97,6 +99,30 @@ public final class SchemaContextUtil { return null; } + public static Module resolveModuleFromTypePath(final SchemaContext context, final TypeDefinition type) { + final SchemaPath schemaPath = type.getPath(); + if ((schemaPath != null) && (schemaPath.getPath() != null)) { + if(type instanceof ExtendedType) { + List path = schemaPath.getPath(); + final QName qname = path.get(path.size()-1); + + if ((qname != null) && (qname.getNamespace() != null)) { + return context.findModuleByNamespace(qname.getNamespace()); + } + } else { + LinkedList path = new LinkedList(schemaPath.getPath()); + path.removeLast(); + final QName qname = path.get(path.size()-1); + + if ((qname != null) && (qname.getNamespace() != null)) { + return context.findModuleByNamespace(qname.getNamespace()); + } + } + + } + return null; + } + public static Module findParentModule(final SchemaContext context, final SchemaNode schemaNode) { if (context == null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); @@ -133,7 +159,7 @@ public final class SchemaContextUtil { childNodeQName = qnamedPath.peek(); if (childNodeQName != null) { final URI childNodeNamespace = childNodeQName.getNamespace(); - + schemaNode = nextNode.getDataChildByName(childNodeQName); if (schemaNode != null) { if (schemaNode instanceof ContainerSchemaNode) { @@ -229,7 +255,7 @@ public final class SchemaContextUtil { } final List path = leafrefSchemaPath.getPath(); if (path != null) { - int lenght = path.size() - colCount; + int lenght = path.size() - colCount - 1; for (int i = 0; i < lenght; ++i) { absolutePath.add(path.get(i)); }