Remove global BindingToNormalizedNodeCodec instance
[controller.git] / opendaylight / md-sal / sal-binding-config / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / RuntimeMappingModule.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.binding.impl;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
12 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
13 import org.osgi.framework.BundleContext;
14
15 /**
16  * @deprecated Replaced by blueprint wiring
17  */
18 @Deprecated
19 public final class RuntimeMappingModule extends AbstractRuntimeMappingModule {
20     private BundleContext bundleContext;
21
22     public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
23             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
24         super(identifier, dependencyResolver);
25     }
26
27     public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
28             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
29             final RuntimeMappingModule oldModule, final java.lang.AutoCloseable oldInstance) {
30         super(identifier, dependencyResolver, oldModule, oldInstance);
31     }
32
33     @Override
34     public void validate() {
35         super.validate();
36         Preconditions.checkNotNull(bundleContext);
37         // Add custom validation for module attributes here.
38     }
39
40     @Override
41     public boolean canReuseInstance(final AbstractRuntimeMappingModule oldModule) {
42         return true;
43     }
44
45     @Override
46     public AutoCloseable createInstance() {
47         // We need to return the concrete BindingToNormalizedNodeCodec instance for backwards compatibility
48         // for CSS users that inject the binding-dom-mapping-service.
49         final WaitingServiceTracker<BindingToNormalizedNodeCodec> tracker =
50                 WaitingServiceTracker.create(BindingToNormalizedNodeCodec.class, bundleContext);
51         final BindingToNormalizedNodeCodec service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
52
53         // Ideally we would close the ServiceTracker via the returned AutoCloseable but then we'd have to
54         // proxy the BindingToNormalizedNodeCodec instance which is problematic. It's OK to close the
55         // ServiceTracker here.
56         tracker.close();
57         return service;
58     }
59
60     public void setBundleContext(final BundleContext bundleContext) {
61         this.bundleContext = bundleContext;
62     }
63 }