2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.util;
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
14 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
16 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 // FIXME: 8.0.0: re-examine usefulness of these methods
22 public final class NormalizedNodeSchemaUtils {
23 private NormalizedNodeSchemaUtils() {
27 public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema, final DataContainerChild child) {
28 final QName childId = child.getIdentifier().getNodeType();
29 for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
30 if (choiceCaseNode.dataChildByName(childId) != null) {
31 return Optional.of(choiceCaseNode);
34 return Optional.empty();
38 * Tries to find in {@code parent} which is dealed as augmentation target node with QName as {@code child}. If such
39 * node is found then it is returned, else null.
41 * @param parent parent node
42 * @param child child node
43 * @return augmentation schema
45 public static AugmentationSchemaNode findCorrespondingAugment(final DataSchemaNode parent,
46 final DataSchemaNode child) {
47 if (parent instanceof AugmentationTarget target && !(parent instanceof ChoiceSchemaNode)) {
48 for (final AugmentationSchemaNode augmentation : target.getAvailableAugmentations()) {
49 if (augmentation.dataChildByName(child.getQName()) != null) {