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;
35 private final ImmutableList<DeclaredStatement<?>> rootDeclaredStatements;
36 private final ImmutableList<EffectiveStatement<?,?>> rootEffectiveStatements;
38 public EffectiveSchemaContext(List<DeclaredStatement<?>> rootDeclaredStatements, List<EffectiveStatement<?,?>> rootEffectiveStatements) {
39 this.rootDeclaredStatements = ImmutableList.copyOf(rootDeclaredStatements);
40 this.rootEffectiveStatements = ImmutableList.copyOf(rootEffectiveStatements);
42 HashSet<Module> modules = new HashSet<Module>();
43 for (EffectiveStatement<?, ?> rootEffectiveStatement : rootEffectiveStatements) {
44 if(rootEffectiveStatement instanceof Module) {
45 Module module = (Module) rootEffectiveStatement;
49 this.modules = ImmutableSet.copyOf(modules);
51 final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
52 new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
53 final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(
54 new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);
56 for (Module m : modules) {
57 nameMap.put(m.getName(), m);
58 nsMap.put(m.getNamespace(), m);
61 namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
62 nameToModules = ImmutableSetMultimap.copyOf(nameMap);
65 //this.identifiersToSources = ImmutableMap.copyOf(identifiersToSources);
66 this.identifiersToSources = null;
70 public ImmutableList<DeclaredStatement<?>> getRootDeclaredStatements() {
71 return rootDeclaredStatements;
74 public ImmutableList<EffectiveStatement<?,?>> getRootEffectiveStatements() {
75 return rootEffectiveStatements;
79 protected Map<ModuleIdentifier, String> getIdentifiersToSources(){
81 return identifiersToSources;
85 public Set<Module> getModules(){
91 protected SetMultimap<URI, Module> getNamespaceToModules() {
93 return namespaceToModules;
97 protected SetMultimap<String, Module> getNameToModules() {
103 public String toString() {
105 return String.format("SchemaContextImpl{modules=%s}", modules);