X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2FSchemaUtils.java;h=a93ff38ebdd7754b1b162aed00d6046112fb284f;hb=bb60da5fe2d1928defb46ed92b290cfff93dcd81;hp=9747829b393cfc7c777546a486d0714e2137fb0c;hpb=19efe56f8f20f5692a100e765a581fbc8f0b4aca;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java index 9747829b39..a93ff38ebd 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java @@ -43,7 +43,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; public final class SchemaUtils { private SchemaUtils() { - throw new UnsupportedOperationException(); + // Hidden on purpose } /** @@ -54,7 +54,7 @@ public final class SchemaUtils { * @return schema node with newest revision or absent if no schema node with matching qname is found */ public static Optional findFirstSchema(final QName qname, - final Iterable dataSchemaNode) { + final Iterable dataSchemaNode) { DataSchemaNode schema = null; if (dataSchemaNode != null && qname != null) { for (final DataSchemaNode dsn : dataSchemaNode) { @@ -64,7 +64,7 @@ public final class SchemaUtils { schema = dsn; } } else if (dsn instanceof ChoiceSchemaNode) { - for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases().values()) { + for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) { final Optional dataChildByName = choiceCase.findDataChildByName(qname); if (dataChildByName.isPresent()) { return dataChildByName; @@ -110,7 +110,7 @@ public final class SchemaUtils { } public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, - final Iterable childNodes) { + final Iterable childNodes) { final Optional childSchema = findFirstSchema(qname, childNodes); checkState(childSchema.isPresent(), "Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname, schema); @@ -118,7 +118,7 @@ public final class SchemaUtils { } public static DataSchemaNode findSchemaForChild(final ChoiceSchemaNode schema, final QName childPartialQName) { - for (final CaseSchemaNode choiceCaseNode : schema.getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : schema.getCases()) { final Optional childSchema = findFirstSchema(childPartialQName, choiceCaseNode.getChildNodes()); if (childSchema.isPresent()) { @@ -140,7 +140,7 @@ public final class SchemaUtils { } public static AugmentationSchemaNode findSchemaForAugment(final ChoiceSchemaNode schema, final Set qnames) { - for (final CaseSchemaNode choiceCaseNode : schema.getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : schema.getCases()) { final Optional schemaForAugment = findAugment(choiceCaseNode, qnames); if (schemaForAugment.isPresent()) { return schemaForAugment.get(); @@ -175,7 +175,7 @@ public final class SchemaUtils { } private static Map mapChildElementsFromChoices(final DataNodeContainer schema, - final Iterable childNodes) { + final Iterable childNodes) { final Map mappedChoices = new LinkedHashMap<>(); for (final DataSchemaNode childSchema : childNodes) { @@ -185,7 +185,7 @@ public final class SchemaUtils { continue; } - for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) { for (final QName qname : getChildNodesRecursive(choiceCaseNode)) { mappedChoices.put(qname, (ChoiceSchemaNode) childSchema); } @@ -246,7 +246,7 @@ public final class SchemaUtils { childNodesToAugmentation.put(qname, mostTopAugmentation); } } else if (child instanceof ChoiceSchemaNode) { - for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) child).getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) child).getCases()) { for (final QName qname : getChildNodesRecursive(choiceCaseNode)) { childNodesToAugmentation.put(qname, mostTopAugmentation); } @@ -259,7 +259,7 @@ public final class SchemaUtils { // Choice Node has to map child nodes from all its cases if (schema instanceof ChoiceSchemaNode) { - for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) schema).getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) schema).getCases()) { if (!augments.containsKey(choiceCaseNode.getQName())) { continue; } @@ -284,7 +284,7 @@ public final class SchemaUtils { for (final DataSchemaNode childSchema : nodeContainer.getChildNodes()) { if (childSchema instanceof ChoiceSchemaNode) { - for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) { allChildNodes.addAll(getChildNodesRecursive(choiceCaseNode)); } } else if (childSchema instanceof AugmentationSchemaNode || childSchema instanceof CaseSchemaNode) { @@ -319,7 +319,7 @@ public final class SchemaUtils { final Set realChildNodes = new HashSet<>(); if (targetSchema instanceof ChoiceSchemaNode) { for (final DataSchemaNode dataSchemaNode : augmentSchema.getChildNodes()) { - for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) targetSchema).getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) targetSchema).getCases()) { if (getChildNodesRecursive(choiceCaseNode).contains(dataSchemaNode.getQName())) { realChildNodes.add(choiceCaseNode.getDataChildByName(dataSchemaNode.getQName())); } @@ -342,7 +342,7 @@ public final class SchemaUtils { public static Optional detectCase(final ChoiceSchemaNode schema, final DataContainerChild child) { - for (final CaseSchemaNode choiceCaseNode : schema.getCases().values()) { + for (final CaseSchemaNode choiceCaseNode : schema.getCases()) { if (child instanceof AugmentationNode && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())) { return Optional.of(choiceCaseNode); @@ -429,7 +429,7 @@ public final class SchemaUtils { */ public static @Nullable SchemaNode findDataChildSchemaByQName(final SchemaNode node, final QName qname) { if (node instanceof DataNodeContainer) { - SchemaNode child = ((DataNodeContainer) node).getDataChildByName(qname); + SchemaNode child = ((DataNodeContainer) node).dataChildByName(qname); if (child == null && node instanceof SchemaContext) { child = tryFind(((SchemaContext) node).getOperations(), qname).orElse(null); } @@ -443,7 +443,7 @@ public final class SchemaUtils { return child; } if (node instanceof ChoiceSchemaNode) { - return ((ChoiceSchemaNode) node).getCases().get(qname); + return ((ChoiceSchemaNode) node).findCase(qname).orElse(null); } if (node instanceof OperationDefinition) { switch (qname.getLocalName()) { @@ -477,10 +477,29 @@ public final class SchemaUtils { */ public static Collection findParentSchemaNodesOnPath(final SchemaContext schemaContext, final SchemaPath path) { + return findParentSchemaNodesOnPath(schemaContext, path.getPathFromRoot()); + } + + /** + * Finds schema node for given path in schema context. This method performs lookup in both the namespace + * of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions, + * notifications, anydatas and anyxmls according to Rfc6050/Rfc7950 section 6.2.1. + * + *

+ * This method returns collection of SchemaNodes, because name conflicts can occur between the namespace + * of groupings and namespace of data nodes. This method finds and collects all schema nodes that matches supplied + * SchemaPath and returns them all as collection of schema nodes. + * + * @param schemaContext schema context + * @param path path + * @return collection of schema nodes on path + */ + public static Collection findParentSchemaNodesOnPath(final SchemaContext schemaContext, + final Iterable path) { final Collection currentNodes = new ArrayList<>(); final Collection childNodes = new ArrayList<>(); currentNodes.add(requireNonNull(schemaContext)); - for (final QName qname : path.getPathFromRoot()) { + for (final QName qname : path) { for (final SchemaNode current : currentNodes) { childNodes.addAll(findChildSchemaNodesByQName(current, qname)); }