These methods are not used anywhere except tests, remove them now.
JIRA: YANGTOOLS-1230
Change-Id: I3ca3d7bd7bf1e6f27fea634ee138d3f1769e5666
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
package org.opendaylight.yangtools.yang.data.impl.schema;
import static com.google.common.base.Preconditions.checkState;
-import static java.util.Objects.requireNonNull;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public final class SchemaUtils {
private SchemaUtils() {
return null;
}
- /**
- * Finds schema node for given path in schema context. This method performs
- * lookup in the namespace of all leafs, leaf-lists, lists, containers,
- * choices, rpcs, actions, notifications, anydatas, and anyxmls according to
- * Rfc6050/Rfc7950 section 6.2.1.
- *
- * @param schemaContext
- * schema context
- * @param path
- * path
- * @return schema node on path
- */
- public static SchemaNode findDataParentSchemaOnPath(final SchemaContext schemaContext, final SchemaPath path) {
- SchemaNode current = requireNonNull(schemaContext);
- for (final QName qname : path.getPathFromRoot()) {
- current = findDataChildSchemaByQName(current, qname);
- }
- return current;
- }
-
/**
* Find child data schema node identified by its QName within a provided schema node. This method performs lookup
* in the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions, notifications, anydatas
throw new IllegalArgumentException(String.format("Schema node %s does not allow children.", node));
}
- /**
- * 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 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) {
- for (final SchemaNode current : currentNodes) {
- childNodes.addAll(findChildSchemaNodesByQName(current, qname));
- }
- currentNodes.clear();
- currentNodes.addAll(childNodes);
- childNodes.clear();
- }
-
- return currentNodes;
- }
-
/**
* Find child schema node identified by its QName within a provided schema node. This method performs lookup in both
* the namespace of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs,
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collection;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-public class SchemaUtilsTest {
- private static final String NS = "my-namespace";
-
- @Test
- public void test() {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/schema-utils-test/foo.yang");
- assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name"), qN("my-name-a"))) instanceof ContainerSchemaNode);
- assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name-2"), qN("my-name-b"))) instanceof NotificationDefinition);
- assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name-2"), qN("my-name-2-b"))) instanceof ActionDefinition);
- }
-
- @Test
- public void testNameConflicts() {
- final SchemaContext schemaContext = YangParserTestUtils
- .parseYangResource("/schema-utils-test/name-conflicts.yang");
- // test my-name conflicts
- assertEquals(8, SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name"), qN("my-name-nested"), qN("my-name-nested2"))).size());
-
- // test target container
- final Collection<SchemaNode> target = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name-2"), qN("my-name-nested"), qN("target")));
- assertEquals(1, target.size());
- assertTrue(target.iterator().next() instanceof ContainerSchemaNode);
-
- // test l schema nodes (i.e. container and two leafs)
- Collection<SchemaNode> schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-3"), qN("l")));
- assertEquals(1, schema.size());
- assertTrue(schema.iterator().next() instanceof ContainerSchemaNode);
-
- schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-1"), qN("l")));
- assertEquals(1, schema.size());
- assertTrue(schema.iterator().next() instanceof LeafSchemaNode);
-
- schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-2"), qN("l")));
- assertTrue(schema.isEmpty());
-
- schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
- SchemaPath.create(true, qN("my-name-3"), qN("output"), qN("con-2"), qN("l")));
- assertEquals(1, schema.size());
- assertTrue(schema.iterator().next() instanceof LeafSchemaNode);
- }
-
- private static QName qN(final String localName) {
- return QName.create(NS, localName);
- }
-}
+++ /dev/null
-module foo {
- namespace my-namespace;
- prefix p;
- yang-version 1.1;
-
- feature my-name;
-
- identity my-name;
-
- extension my-name;
-
- typedef my-name {
- type string;
- }
-
- grouping my-name {
- }
-
- grouping my-name-2 {
- }
-
- notification my-name {
- grouping my-name-a {
- }
- container my-name-a {
- }
- }
-
- container my-name-2 {
- grouping my-name-b {
- }
- notification my-name-b {
- }
- grouping my-name-2-b {
- }
- action my-name-2-b {
- }
- }
-}
+++ /dev/null
-module name-conflicts {
- namespace "my-namespace";
- prefix nc;
-
- grouping my-name {
- grouping my-name-nested {
- grouping my-name-nested2 {
- }
- container my-name-nested2 {
- }
- }
- container my-name-nested {
- grouping my-name-nested2 {
- }
- container my-name-nested2 {
- }
- }
- }
-
- container my-name {
- grouping my-name-nested {
- grouping my-name-nested2 {
- }
- container my-name-nested2 {
- }
- }
- container my-name-nested {
- grouping my-name-nested2 {
- }
- container my-name-nested2 {
- }
- }
- }
-
- grouping my-name-2 {
- grouping my-name-nested {
- grouping my-name-nested2 {
- }
- container my-name-nested2 {
- }
- }
- container my-name-2 {
- grouping my-name-nested2 {
- }
- container my-name-nested2 {
- }
- }
- }
-
- container my-name-2 {
- grouping my-name-nested {
- grouping my-name-nested2 {
- }
- container target {
- }
- }
- container my-name-nested {
- grouping my-name-nested2 {
- }
- container my-name-nested2 {
- }
- }
- }
-
- rpc my-name-3 {
- input {
- container con-1 {
- leaf l {
- type string;
- }
- }
- }
- output {
- container con-2 {
- leaf l {
- type string;
- }
- }
- }
- }
-
- grouping my-name-3 {
- container input {
- container con-3 {
- container l {
- }
- }
- }
- }
-}