Bug 488: Removed requirement for DOM providers to supply BundleContext.
[controller.git] / opendaylight / md-sal / sal-dom-broker / 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 org.opendaylight.controller.sal.core.api.model.SchemaService;
11 import org.opendaylight.controller.sal.dom.broker.GlobalBundleScanningSchemaServiceImpl;
12 import org.opendaylight.yangtools.concepts.Delegator;
13 import org.opendaylight.yangtools.concepts.ListenerRegistration;
14 import org.opendaylight.yangtools.yang.model.api.Module;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
17 import org.osgi.framework.BundleContext;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public final class SchemaServiceImplSingletonModule extends
22 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
23
24     private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
25
26     BundleContext bundleContext;
27
28     public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
29             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
30         super(identifier, dependencyResolver);
31     }
32
33     public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
34             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
35             final SchemaServiceImplSingletonModule oldModule, final java.lang.AutoCloseable oldInstance) {
36         super(identifier, dependencyResolver, oldModule, oldInstance);
37     }
38
39     @Override
40     public boolean canReuseInstance(final AbstractSchemaServiceImplSingletonModule oldModule) {
41         return true;
42     }
43
44     public BundleContext getBundleContext() {
45         return bundleContext;
46     }
47
48     public void setBundleContext(final BundleContext bundleContext) {
49         this.bundleContext = bundleContext;
50     }
51
52     @Override
53     public void validate() {
54         super.validate();
55     }
56
57     @Override
58     public java.lang.AutoCloseable createInstance() {
59         return GlobalBundleScanningSchemaServiceImpl.getInstance();
60     }
61
62     public class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, Delegator<SchemaService> {
63
64         private SchemaService delegate;
65
66         public GlobalSchemaServiceProxy() {
67             this.delegate = GlobalBundleScanningSchemaServiceImpl.getInstance();
68         }
69
70         @Override
71         public void close() throws Exception {
72             if (delegate != null) {
73                 delegate = null;
74             }
75         }
76
77         @Override
78         public void addModule(final Module arg0) {
79             delegate.addModule(arg0);
80         }
81
82         @Override
83         public SchemaContext getGlobalContext() {
84             return delegate.getGlobalContext();
85         }
86
87         @Override
88         public SchemaContext getSessionContext() {
89             return delegate.getSessionContext();
90         }
91
92         @Override
93         public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(final SchemaServiceListener arg0) {
94             return delegate.registerSchemaServiceListener(arg0);
95         }
96
97         @Override
98         public void removeModule(final Module arg0) {
99             delegate.removeModule(arg0);
100         }
101
102         @Override
103         public SchemaService getDelegate() {
104             return delegate;
105         }
106
107     }
108 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.