fix ServiceHandler SpotBugs false positives
[transportpce.git] / tests / honeynode / 2.2.1 / minimal-distribution-core / src / main / java / io / fd / honeycomb / infra / distro / schema / SchemaServiceProvider.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.infra.distro.schema;
18
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;
33
34 public final class SchemaServiceProvider extends ProviderTrait<DOMSchemaService> {
35
36     @Inject
37     private ModuleInfoBackedContext mibCtx;
38
39     @Override
40     public StaticSchemaService create() {
41         return new StaticSchemaService(mibCtx);
42     }
43
44     /**
45      * Static schema context provider service.
46      */
47     private static final class StaticSchemaService implements DOMSchemaService, DOMYangTextSourceProvider {
48         private final ModuleInfoBackedContext moduleInfoBackedContext;
49
50         StaticSchemaService(ModuleInfoBackedContext moduleInfoBackedContext) {
51             this.moduleInfoBackedContext = moduleInfoBackedContext;
52         }
53
54         @Override
55         public SchemaContext getSessionContext() {
56             return moduleInfoBackedContext.getSchemaContext();
57         }
58
59         @Override
60         public SchemaContext getGlobalContext() {
61             return moduleInfoBackedContext.getSchemaContext();
62         }
63
64         @Override
65         public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
66                 final SchemaContextListener listener) {
67             listener.onGlobalContextUpdated(moduleInfoBackedContext.getSchemaContext());
68             return new ListenerRegistration<SchemaContextListener>() {
69                 @Override
70                 public void close() {}
71
72                 @Override
73                 public SchemaContextListener getInstance() {
74                     return listener;
75                 }
76
77             };
78         }
79
80         @Override
81         public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
82             return ImmutableClassToInstanceMap.of(DOMYangTextSourceProvider.class, this);
83         }
84
85         @Override
86         public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
87             return moduleInfoBackedContext.getSource(sourceIdentifier);
88         }
89     }
90 }