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.parser.stmt.reactor;
10 import com.google.common.annotations.Beta;
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.base.Verify;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.ImmutableMap;
15 import java.util.HashSet;
16 import java.util.List;
18 import java.util.function.Function;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
26 import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
29 public final class EffectiveSchemaContext extends SimpleSchemaContext implements EffectiveModelContext {
30 private final ImmutableList<DeclaredStatement<?>> rootDeclaredStatements;
31 private final ImmutableMap<QNameModule, ModuleEffectiveStatement> rootEffectiveStatements;
33 private EffectiveSchemaContext(final Set<Module> modules, final List<DeclaredStatement<?>> rootDeclaredStatements,
34 final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
36 this.rootDeclaredStatements = ImmutableList.copyOf(rootDeclaredStatements);
37 this.rootEffectiveStatements = rootEffectiveStatements.stream()
38 .filter(ModuleEffectiveStatement.class::isInstance).map(ModuleEffectiveStatement.class::cast)
39 .collect(ImmutableMap.toImmutableMap(ModuleEffectiveStatement::localQNameModule, Function.identity()));
42 static EffectiveSchemaContext create(final List<DeclaredStatement<?>> rootDeclaredStatements,
43 final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
44 final Set<Module> modules = new HashSet<>();
45 for (EffectiveStatement<?, ?> stmt : rootEffectiveStatements) {
46 if (stmt.getDeclared() instanceof ModuleStatement) {
47 Verify.verify(stmt instanceof Module);
48 modules.add((Module) stmt);
52 return new EffectiveSchemaContext(modules, rootDeclaredStatements, rootEffectiveStatements);
56 public List<DeclaredStatement<?>> getRootDeclaredStatements() {
57 return rootDeclaredStatements;
61 public ImmutableMap<QNameModule, ModuleEffectiveStatement> getModuleStatements() {
62 return rootEffectiveStatements;