* @return schema node with newest revision or absent if no schema node with matching qname is found
*/
public static Optional<DataSchemaNode> findFirstSchema(final QName qname,
- final Iterable<DataSchemaNode> dataSchemaNode) {
+ final Iterable<? extends DataSchemaNode> dataSchemaNode) {
DataSchemaNode schema = null;
if (dataSchemaNode != null && qname != null) {
for (final DataSchemaNode dsn : dataSchemaNode) {
schema = dsn;
}
} else if (dsn instanceof ChoiceSchemaNode) {
- for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases().values()) {
+ for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) {
final Optional<DataSchemaNode> dataChildByName = choiceCase.findDataChildByName(qname);
if (dataChildByName.isPresent()) {
return dataChildByName;
}
public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname,
- final Iterable<DataSchemaNode> childNodes) {
+ final Iterable<? extends DataSchemaNode> childNodes) {
final Optional<DataSchemaNode> childSchema = findFirstSchema(qname, childNodes);
checkState(childSchema.isPresent(), "Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname,
schema);
}
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<DataSchemaNode> childSchema = findFirstSchema(childPartialQName,
choiceCaseNode.getChildNodes());
if (childSchema.isPresent()) {
}
public static AugmentationSchemaNode findSchemaForAugment(final ChoiceSchemaNode schema, final Set<QName> qnames) {
- for (final CaseSchemaNode choiceCaseNode : schema.getCases().values()) {
+ for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
final Optional<AugmentationSchemaNode> schemaForAugment = findAugment(choiceCaseNode, qnames);
if (schemaForAugment.isPresent()) {
return schemaForAugment.get();
}
private static Map<QName, ChoiceSchemaNode> mapChildElementsFromChoices(final DataNodeContainer schema,
- final Iterable<DataSchemaNode> childNodes) {
+ final Iterable<? extends DataSchemaNode> childNodes) {
final Map<QName, ChoiceSchemaNode> mappedChoices = new LinkedHashMap<>();
for (final DataSchemaNode childSchema : childNodes) {
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);
}
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);
}
// 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;
}
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) {
final Set<DataSchemaNode> 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()));
}
return realChildNodes;
}
- public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema,
- final DataContainerChild<?, ?> child) {
- for (final CaseSchemaNode choiceCaseNode : schema.getCases().values()) {
+ public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema, final DataContainerChild child) {
+ for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
if (child instanceof AugmentationNode
- && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())) {
- return Optional.of(choiceCaseNode);
- } else if (choiceCaseNode.findDataChildByName(child.getNodeType()).isPresent()) {
+ && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())
+ || choiceCaseNode.findDataChildByName(child.getNodeType()).isPresent()) {
return Optional.of(choiceCaseNode);
}
}
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()) {
*/
public static Collection<SchemaNode> 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.
+ *
+ * <p>
+ * 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<SchemaNode> findParentSchemaNodesOnPath(final SchemaContext schemaContext,
+ final Iterable<QName> path) {
final Collection<SchemaNode> currentNodes = new ArrayList<>();
final Collection<SchemaNode> 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));
}