2 * Copyright (c) 2015 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.cache.CacheBuilder;
11 import com.google.common.cache.CacheLoader;
12 import com.google.common.cache.LoadingCache;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
21 * Semantic tree binding a {@link EffectiveModelContext} to a {@link NormalizedNode} tree. Since the layout of the
22 * schema and data has differences, the mapping is not trivial -- which is where this class comes in.
24 * @author Robert Varga
26 public final class DataSchemaContextTree extends AbstractEffectiveModelContextProvider {
27 private static final LoadingCache<EffectiveModelContext, @NonNull DataSchemaContextTree> TREES =
28 CacheBuilder.newBuilder().weakKeys().weakValues().build(new CacheLoader<>() {
30 public DataSchemaContextTree load(final EffectiveModelContext key) {
31 return new DataSchemaContextTree(key);
35 private final @NonNull ContainerContextNode root;
37 private DataSchemaContextTree(final EffectiveModelContext ctx) {
39 root = new ContainerContextNode(ctx);
42 public static @NonNull DataSchemaContextTree from(final @NonNull EffectiveModelContext ctx) {
43 return TREES.getUnchecked(ctx);
47 * Find a child node as identified by an absolute {@link YangInstanceIdentifier}.
49 * @param path Path towards the child node
50 * @return Child node if present, or empty when corresponding child is not found.
51 * @throws NullPointerException if {@code path} is null
53 public @NonNull Optional<@NonNull DataSchemaContextNode<?>> findChild(final @NonNull YangInstanceIdentifier path) {
54 return root.findChild(path);
57 public @NonNull DataSchemaContextNode<?> getRoot() {