X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fyang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Futil%2FSchemaContextUtil.java;h=13c2ba7cb55455800e763c754f53883d8e0986eb;hp=2d6a78988752de136af601dd70ab40713cfa9a9e;hb=37ff82351675cc5c279dfe88c6daf10cbbf9f48b;hpb=8398f3adb544427642694be13abe9c3bc1a4e192 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 2d6a789887..13c2ba7cb5 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 @@ -33,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); @@ -87,32 +87,35 @@ public final class SchemaContextUtil { return null; } - public static Module resolveModuleFromSchemaPath(final SchemaContext context, final SchemaPath schemaPath) { + private static Module resolveModuleFromSchemaPath(final SchemaContext + context, final SchemaPath schemaPath) { if ((schemaPath != null) && (schemaPath.getPath() != null)) { - List path = schemaPath.getPath(); - final QName qname = path.get(path.size()-1); + final List path = schemaPath.getPath(); + if (!path.isEmpty()) { + final QName qname = path.get(path.size() - 1); - if ((qname != null) && (qname.getNamespace() != null)) { - return context.findModuleByNamespace(qname.getNamespace()); + if ((qname != null) && (qname.getNamespace() != null)) { + return context.findModuleByNamespace(qname.getNamespace()); + } } } return null; } - public static Module resolveModuleFromTypePath(final SchemaContext context, final TypeDefinition type) { + public static Module findParentModuleForTypeDefinition( + 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); + 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); + List path = schemaPath.getPath(); + final QName qname = path.get(path.size() - 2); if ((qname != null) && (qname.getNamespace() != null)) { return context.findModuleByNamespace(qname.getNamespace()); @@ -142,7 +145,7 @@ public final class SchemaContextUtil { "The Schema Path MUST contain at least ONE QName which defines namespace and Local name" + "of path."); } - final QName qname = qnamedPath.get(0); + final QName qname = qnamedPath.get(qnamedPath.size() - 1); return context.findModuleByNamespace(qname.getNamespace()); } @@ -186,7 +189,7 @@ public final class SchemaContextUtil { private static Queue xpathToQNamePath(final SchemaContext context, final Module parentModule, final String xpath) { - final Queue path = new LinkedList(); + final Queue path = new LinkedList<>(); if (xpath != null) { final String[] prefixedPath = xpath.split("/"); @@ -240,7 +243,7 @@ public final class SchemaContextUtil { private static Queue resolveRelativeXPath(final SchemaContext context, final Module module, final RevisionAwareXPath relativeXPath, final SchemaPath leafrefSchemaPath) { - final Queue absolutePath = new LinkedList(); + final Queue absolutePath = new LinkedList<>(); if ((module != null) && (relativeXPath != null) && !relativeXPath.isAbsolute() && (leafrefSchemaPath != null)) {