2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.infra.distro.schema;
19 import com.google.common.collect.ClassToInstanceMap;
20 import com.google.common.collect.ImmutableClassToInstanceMap;
21 import com.google.common.util.concurrent.ListenableFuture;
22 import com.google.inject.Inject;
23 import io.fd.honeycomb.binding.init.ProviderTrait;
24 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
25 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
26 import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
27 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
31 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
32 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
34 public final class SchemaServiceProvider extends ProviderTrait<DOMSchemaService> {
37 private ModuleInfoBackedContext mibCtx;
40 public StaticSchemaService create() {
41 return new StaticSchemaService(mibCtx);
45 * Static schema context provider service.
47 private static final class StaticSchemaService implements DOMSchemaService, DOMYangTextSourceProvider {
48 private final ModuleInfoBackedContext moduleInfoBackedContext;
50 StaticSchemaService(ModuleInfoBackedContext moduleInfoBackedContext) {
51 this.moduleInfoBackedContext = moduleInfoBackedContext;
55 public SchemaContext getSessionContext() {
56 return moduleInfoBackedContext.getSchemaContext();
60 public SchemaContext getGlobalContext() {
61 return moduleInfoBackedContext.getSchemaContext();
65 public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
66 final SchemaContextListener listener) {
67 listener.onGlobalContextUpdated(moduleInfoBackedContext.getSchemaContext());
68 return new ListenerRegistration<SchemaContextListener>() {
70 public void close() {}
73 public SchemaContextListener getInstance() {
81 public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
82 return ImmutableClassToInstanceMap.of(DOMYangTextSourceProvider.class, this);
86 public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
87 return moduleInfoBackedContext.getSource(sourceIdentifier);