8152cbd6b1914bd654e9b4d12abc45d4467ddadb
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / dom / impl / SchemaServiceImplSingletonModule.java
1 /**
2  * Generated file
3
4  * Generated from: yang module name: opendaylight-sal-dom-broker-impl  yang module local name: schema-service-singleton
5  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6  * Generated at: Wed Nov 20 17:01:31 CET 2013
7  *
8  * Do not modify this file unless it is present under src/main directory
9  */
10 package org.opendaylight.controller.config.yang.md.sal.dom.impl;
11
12 import org.opendaylight.controller.sal.core.api.model.SchemaService;
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.SchemaServiceListener;
19 import org.osgi.framework.BundleContext;
20 import org.osgi.framework.ServiceReference;
21
22 /**
23 *
24 */
25 public final class SchemaServiceImplSingletonModule extends
26         org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
27
28     BundleContext bundleContext;
29
30     public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
31             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
32         super(identifier, dependencyResolver);
33     }
34
35     public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
36             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
37             SchemaServiceImplSingletonModule oldModule, java.lang.AutoCloseable oldInstance) {
38         super(identifier, dependencyResolver, oldModule, oldInstance);
39     }
40
41     @Override
42     public boolean canReuseInstance(AbstractSchemaServiceImplSingletonModule oldModule) {
43         return true;
44     }
45
46     public BundleContext getBundleContext() {
47         return bundleContext;
48     }
49
50     public void setBundleContext(BundleContext bundleContext) {
51         this.bundleContext = bundleContext;
52     }
53
54     @Override
55     public void validate() {
56         super.validate();
57     }
58
59     @Override
60     public java.lang.AutoCloseable createInstance() {
61         ServiceReference<SchemaService> ref = getBundleContext().getServiceReference(SchemaService.class);
62         if (ref != null) {
63             return new GlobalSchemaServiceProxy(getBundleContext(), ref);
64         }
65
66         GlobalBundleScanningSchemaServiceImpl newInstance = new GlobalBundleScanningSchemaServiceImpl();
67         newInstance.setContext(getBundleContext());
68         newInstance.start();
69         return newInstance;
70     }
71
72     public class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, Delegator<SchemaService> {
73
74         private BundleContext bundleContext;
75         private ServiceReference<SchemaService> reference;
76         private SchemaService delegate;
77
78         public GlobalSchemaServiceProxy(BundleContext bundleContext, ServiceReference<SchemaService> ref) {
79             this.bundleContext = bundleContext;
80             this.reference = ref;
81             this.delegate = bundleContext.getService(reference);
82         }
83
84         @Override
85         public void close() throws Exception {
86             if (delegate != null) {
87                 delegate = null;
88                 bundleContext.ungetService(reference);
89                 reference = null;
90                 bundleContext = null;
91             }
92         }
93
94         public void addModule(Module arg0) {
95             delegate.addModule(arg0);
96         }
97
98         public SchemaContext getGlobalContext() {
99             return delegate.getGlobalContext();
100         }
101
102         public SchemaContext getSessionContext() {
103             return delegate.getSessionContext();
104         }
105
106         public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(SchemaServiceListener arg0) {
107             return delegate.registerSchemaServiceListener(arg0);
108         }
109
110         public void removeModule(Module arg0) {
111             delegate.removeModule(arg0);
112         }
113
114         @Override
115         public SchemaService getDelegate() {
116             return delegate;
117         }
118
119     }
120 }