Add Honeynode emulator for device221
[transportpce.git] / tests / honeynode / 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.inject.Inject;
20 import io.fd.honeycomb.binding.init.ProviderTrait;
21 import org.opendaylight.controller.sal.core.api.model.SchemaService;
22 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
23 import org.opendaylight.yangtools.concepts.ListenerRegistration;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
27
28 public final class SchemaServiceProvider extends ProviderTrait<SchemaService> {
29
30     @Inject
31     private ModuleInfoBackedContext mibCtx;
32
33     @Override
34     public StaticSchemaService create() {
35         return new StaticSchemaService(mibCtx.getSchemaContext());
36     }
37
38     /**
39      * Static schema context provider service.
40      */
41     private static final class StaticSchemaService implements SchemaService {
42         private final SchemaContext schemaContext;
43
44         StaticSchemaService(SchemaContext schemaContext) {
45             this.schemaContext = schemaContext;
46         }
47
48         @Override
49         public void addModule(final Module module) {
50             throw new UnsupportedOperationException("Static service");
51         }
52
53         @Override
54         public void removeModule(final Module module) {
55             throw new UnsupportedOperationException("Static service");
56         }
57
58         @Override
59         public SchemaContext getSessionContext() {
60             return schemaContext;
61         }
62
63         @Override
64         public SchemaContext getGlobalContext() {
65             return schemaContext;
66         }
67
68         @Override
69         public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
70                 final SchemaContextListener listener) {
71             listener.onGlobalContextUpdated(schemaContext);
72             return new ListenerRegistration<SchemaContextListener>() {
73                 @Override
74                 public void close() {}
75
76                 @Override
77                 public SchemaContextListener getInstance() {
78                     return listener;
79                 }
80
81             };
82         }
83     }
84 }