Java Code Examples for org.opendaylight.yangtools.yang.model.api.SchemaPath#getPathFromRoot()

The following examples show how to use org.opendaylight.yangtools.yang.model.api.SchemaPath#getPathFromRoot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaUtils.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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) {
    final Collection<SchemaNode> currentNodes = new ArrayList<>();
    final Collection<SchemaNode> childNodes = new ArrayList<>();
    currentNodes.add(requireNonNull(schemaContext));
    for (final QName qname : path.getPathFromRoot()) {
        for (final SchemaNode current : currentNodes) {
            childNodes.addAll(findChildSchemaNodesByQName(current, qname));
        }
        currentNodes.clear();
        currentNodes.addAll(childNodes);
        childNodes.clear();
    }

    return currentNodes;
}
 
Example 2
Source File: YangParserTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testTypePath() throws ParseException {
    final Collection<? extends TypeDefinition<?>> types = bar.getTypeDefinitions();

    // int32-ext1
    final Int32TypeDefinition int32ext1 = (Int32TypeDefinition) TestUtils.findTypedef(types, "int32-ext1");
    final QName int32TypedefQName = QName.create(BAR, "int32-ext1");
    assertEquals(int32TypedefQName, int32ext1.getQName());

    final SchemaPath typeSchemaPath = int32ext1.getPath();
    final Iterable<QName> typePath = typeSchemaPath.getPathFromRoot();
    final Iterator<QName> typePathIt = typePath.iterator();
    assertEquals(int32TypedefQName, typePathIt.next());
    assertFalse(typePathIt.hasNext());

    // int32-ext1/int32
    final Int32TypeDefinition int32 = int32ext1.getBaseType();
    assertEquals(BaseTypes.int32Type(), int32);
}
 
Example 3
Source File: YangParserTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTypePath2() throws ParseException {
    final Collection<? extends TypeDefinition<?>> types = bar.getTypeDefinitions();

    // my-decimal-type
    final DecimalTypeDefinition myDecType = (DecimalTypeDefinition) TestUtils.findTypedef(types, "my-decimal-type");
    final QName myDecTypeQName = myDecType.getQName();

    assertEquals(BAR, myDecTypeQName.getModule());
    assertEquals("my-decimal-type", myDecTypeQName.getLocalName());

    final SchemaPath typeSchemaPath = myDecType.getPath();
    final Iterable<QName> typePath = typeSchemaPath.getPathFromRoot();
    final Iterator<QName> typePathIt = typePath.iterator();
    assertEquals(myDecTypeQName, typePathIt.next());
    assertFalse(typePathIt.hasNext());

    // my-base-int32-type/int32
    final DecimalTypeDefinition dec64 = myDecType.getBaseType();
    final QName dec64QName = dec64.getQName();

    assertEquals(BAR, dec64QName.getModule());
    assertEquals("decimal64", dec64QName.getLocalName());

    final SchemaPath dec64SchemaPath = dec64.getPath();
    final Iterable<QName> dec64Path = dec64SchemaPath.getPathFromRoot();
    final Iterator<QName> dec64PathIt = dec64Path.iterator();
    assertEquals(myDecTypeQName, dec64PathIt.next());
    assertEquals(dec64QName, dec64PathIt.next());
    assertFalse(dec64PathIt.hasNext());
}
 
Example 4
Source File: LeafRefContextUtils.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
public static LeafRefContext getLeafRefReferencingContext(
        final SchemaPath schemaPath, final LeafRefContext root) {
    final Iterable<QName> pathFromRoot = schemaPath.getPathFromRoot();
    return getLeafRefReferencingContext(pathFromRoot, root);
}
 
Example 5
Source File: LeafRefContextUtils.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
public static LeafRefContext getLeafRefReferencedByContext(
        final SchemaPath schemaPath, final LeafRefContext root) {
    final Iterable<QName> pathFromRoot = schemaPath.getPathFromRoot();
    return getLeafRefReferencedByContext(pathFromRoot, root);
}
 
Example 6
Source File: SchemaUtils.java    From yangtools with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Method attempts to find DataSchemaNode in Schema Context via specified Schema Path. The returned DataSchemaNode
 * from method will be the node at the end of the SchemaPath. If the DataSchemaNode is not present in the Schema
 * Context the method will return {@code null}.
 *
 * <p>
 * In case that Schema Context or Schema Path are not specified correctly (i.e. contains {@code null} values) the
 * method will throw IllegalArgumentException.
 *
 * @param context Schema Context
 * @param schemaPath Schema Path to search for
 * @return SchemaNode from the end of the Schema Path or {@code null} if the Node is not present.
 * @throws NullPointerException if context or schemaPath is null
 */
public static SchemaNode findDataSchemaNode(final SchemaContext context, final SchemaPath schemaPath) {
    final Iterable<QName> prefixedPath = schemaPath.getPathFromRoot();
    if (prefixedPath == null) {
        LOG.debug("Schema path {} has null path", schemaPath);
        return null;
    }

    LOG.trace("Looking for path {} in context {}", schemaPath, context);
    return findNodeInSchemaContext(context, prefixedPath);
}