Modify config Module impls to co-exist with blueprint
[controller.git] / opendaylight / md-sal / sal-dom-broker-config / src / main / java / org / opendaylight / controller / config / yang / md / sal / dom / impl / SchemaServiceImplSingletonModule.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.yang.md.sal.dom.impl;
9
10 import com.google.common.util.concurrent.CheckedFuture;
11 import org.opendaylight.controller.sal.core.api.model.SchemaService;
12 import org.opendaylight.controller.sal.core.api.model.YangTextSourceProvider;
13 import org.opendaylight.controller.sal.dom.broker.GlobalBundleScanningSchemaServiceImpl;
14 import org.opendaylight.yangtools.concepts.Delegator;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
19 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
20 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
21 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
22 import org.osgi.framework.BundleContext;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public final class SchemaServiceImplSingletonModule extends
27 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
28
29     private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
30
31     BundleContext bundleContext;
32
33     public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
34             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
35         super(identifier, dependencyResolver);
36     }
37
38     public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
39             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
40             final SchemaServiceImplSingletonModule oldModule, final java.lang.AutoCloseable oldInstance) {
41         super(identifier, dependencyResolver, oldModule, oldInstance);
42     }
43
44     @Override
45     public boolean canReuseInstance(final AbstractSchemaServiceImplSingletonModule oldModule) {
46         return true;
47     }
48
49     public BundleContext getBundleContext() {
50         return bundleContext;
51     }
52
53     public void setBundleContext(final BundleContext bundleContext) {
54         this.bundleContext = bundleContext;
55     }
56
57     @Override
58     public void validate() {
59         super.validate();
60     }
61
62     @Override
63     public java.lang.AutoCloseable createInstance() {
64         return new GlobalSchemaServiceProxy(GlobalBundleScanningSchemaServiceImpl.getInstance());
65     }
66
67     private static class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, YangTextSourceProvider,
68             Delegator<SchemaService> {
69         private final GlobalBundleScanningSchemaServiceImpl delegate;
70
71         public GlobalSchemaServiceProxy(GlobalBundleScanningSchemaServiceImpl service) {
72             this.delegate = service;
73         }
74
75         @Override
76         public void close() {
77             // Intentional noop as the life-cycle is controlled via blueprint.
78         }
79
80         @Override
81         public void addModule(final Module arg0) {
82             delegate.addModule(arg0);
83         }
84
85         @Override
86         public SchemaContext getGlobalContext() {
87             return delegate.getGlobalContext();
88         }
89
90         @Override
91         public SchemaContext getSessionContext() {
92             return delegate.getSessionContext();
93         }
94
95         @Override
96         public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(final SchemaContextListener arg0) {
97             return delegate.registerSchemaContextListener(arg0);
98         }
99
100         @Override
101         public void removeModule(final Module arg0) {
102             delegate.removeModule(arg0);
103         }
104
105         @Override
106         public SchemaService getDelegate() {
107             return delegate;
108         }
109
110         @Override
111         public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(
112                 SourceIdentifier sourceIdentifier) {
113             return delegate.getSource(sourceIdentifier);
114         }
115     }
116 }