2 * Copyright (c) 2013 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.rfc6020.effective;
10 import java.util.HashSet;
11 import com.google.common.collect.ImmutableList;
12 import java.util.List;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import com.google.common.collect.ImmutableSet;
16 import com.google.common.collect.ImmutableSetMultimap;
17 import com.google.common.collect.Multimaps;
18 import com.google.common.collect.SetMultimap;
20 import java.util.Collection;
23 import java.util.TreeMap;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
27 public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
29 private final Map<ModuleIdentifier, String> identifiersToSources;
30 private final SetMultimap<URI, Module> namespaceToModules;
31 private final SetMultimap<String, Module> nameToModules;
32 private final Set<Module> modules;
34 private final ImmutableList<DeclaredStatement<?>> rootDeclaredStatements;
35 private final ImmutableList<EffectiveStatement<?, ?>> rootEffectiveStatements;
37 public EffectiveSchemaContext(
38 List<DeclaredStatement<?>> rootDeclaredStatements,
39 List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
40 this.rootDeclaredStatements = ImmutableList
41 .copyOf(rootDeclaredStatements);
42 this.rootEffectiveStatements = ImmutableList
43 .copyOf(rootEffectiveStatements);
45 Set<Module> modulesInit = new HashSet<>();
46 for (EffectiveStatement<?, ?> rootEffectiveStatement : rootEffectiveStatements) {
47 if (rootEffectiveStatement instanceof Module) {
48 Module module = (Module) rootEffectiveStatement;
49 modulesInit.add(module);
52 this.modules = ImmutableSet.copyOf(modulesInit);
54 final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
55 new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
56 final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(
57 new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);
59 for (Module m : modulesInit) {
60 nameMap.put(m.getName(), m);
61 nsMap.put(m.getNamespace(), m);
64 namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
65 nameToModules = ImmutableSetMultimap.copyOf(nameMap);
68 // this.identifiersToSources =
69 // ImmutableMap.copyOf(identifiersToSources);
70 this.identifiersToSources = null;
74 public ImmutableList<DeclaredStatement<?>> getRootDeclaredStatements() {
75 return rootDeclaredStatements;
78 public ImmutableList<EffectiveStatement<?, ?>> getRootEffectiveStatements() {
79 return rootEffectiveStatements;
83 protected Map<ModuleIdentifier, String> getIdentifiersToSources() {
85 return identifiersToSources;
89 public Set<Module> getModules() {
95 protected SetMultimap<URI, Module> getNamespaceToModules() {
97 return namespaceToModules;
101 protected SetMultimap<String, Module> getNameToModules() {
103 return nameToModules;
107 public String toString() {
109 return String.format("SchemaContextImpl{modules=%s}", modules);