994d3f40a85946299693d285d61e79f308f01e6e
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / AbstractBindingAwareProvider.java
1 package org.opendaylight.controller.sal.binding.api;
2
3 import java.util.Collection;
4
5 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
6 import org.opendaylight.yangtools.yang.binding.RpcService;
7 import org.osgi.framework.BundleActivator;
8 import org.osgi.framework.BundleContext;
9 import org.osgi.framework.ServiceReference;
10
11 public abstract class AbstractBindingAwareProvider implements BindingAwareProvider, BundleActivator {
12
13     @Override
14     public final void start(BundleContext context) throws Exception {
15             ServiceReference<BindingAwareBroker> brokerRef = context.getServiceReference(BindingAwareBroker.class);
16             BindingAwareBroker broker = context.getService(brokerRef);
17             
18             ProviderContext ctx = broker.registerProvider(this, context);
19             registerRpcImplementations(ctx);
20             registerFunctionality(ctx);
21             
22             startImpl(context);
23     }
24     
25     private void registerFunctionality(ProviderContext ctx) {
26         Collection<? extends ProviderFunctionality> functionality = this.getFunctionality();
27         if(functionality == null || functionality.isEmpty()) {
28             return;
29         }
30         for (ProviderFunctionality providerFunctionality : functionality) {
31             ctx.registerFunctionality(providerFunctionality);
32         }
33         
34     }
35
36     private void registerRpcImplementations(ProviderContext ctx) {
37         Collection<? extends RpcService> rpcs = this.getImplementations();
38         if(rpcs == null || rpcs.isEmpty()) {
39             return;
40         }
41         for (RpcService rpcService : rpcs) {
42             //ctx.addRpcImplementation(type, implementation);
43         }
44         
45     }
46
47     protected void startImpl(BundleContext context) {
48         // NOOP
49     }
50     
51     @Override
52     public final void stop(BundleContext context) throws Exception {
53             
54             
55     }
56     
57     @Override
58     public Collection<? extends ProviderFunctionality> getFunctionality() {
59         return null;
60     }
61     
62     @Override
63     public Collection<? extends RpcService> getImplementations() {
64         return null;
65     }
66 }