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