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.impl;
11 import java.util.Date;
12 import java.util.HashSet;
13 import java.util.LinkedHashSet;
14 import java.util.List;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
21 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
25 final class SchemaContextImpl implements SchemaContext {
26 private final Set<Module> modules;
28 SchemaContextImpl(final Set<Module> modules) {
29 this.modules = modules;
33 public Set<DataSchemaNode> getDataDefinitions() {
34 final Set<DataSchemaNode> dataDefs = new HashSet<DataSchemaNode>();
35 for (Module m : modules) {
36 dataDefs.addAll(m.getChildNodes());
42 public Set<Module> getModules() {
43 List<Module> sorted = ModuleDependencySort.sort(modules.toArray(new Module[modules.size()]));
44 return new LinkedHashSet<Module>(sorted);
48 public Set<NotificationDefinition> getNotifications() {
49 final Set<NotificationDefinition> notifications = new HashSet<NotificationDefinition>();
50 for (Module m : modules) {
51 notifications.addAll(m.getNotifications());
57 public Set<RpcDefinition> getOperations() {
58 final Set<RpcDefinition> rpcs = new HashSet<RpcDefinition>();
59 for (Module m : modules) {
60 rpcs.addAll(m.getRpcs());
66 public Set<ExtensionDefinition> getExtensions() {
67 final Set<ExtensionDefinition> extensions = new HashSet<ExtensionDefinition>();
68 for (Module m : modules) {
69 extensions.addAll(m.getExtensionSchemaNodes());
75 public Module findModuleByName(final String name, final Date revision) {
77 for (final Module module : modules) {
78 if (revision == null) {
79 if (module.getName().equals(name)) {
82 } else if (module.getName().equals(name) && module.getRevision().equals(revision)) {
91 public Set<Module> findModuleByNamespace(final URI namespace) {
92 final Set<Module> ret = new HashSet<Module>();
93 if (namespace != null) {
94 for (final Module module : modules) {
95 if (module.getNamespace().equals(namespace)) {
104 public Module findModuleByNamespaceAndRevision(URI namespace, Date revision) {
105 if (namespace != null) {
106 for (final Module module : modules) {
107 if (module.getNamespace().equals(namespace) && module.getRevision().equals(revision)) {