Updated BindingAware Activators to prevent premature initialization
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / AbstractBindingAwareProvider.java
1 /*
2  * Copyright (c) 2013 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.sal.binding.api;
9
10 import java.util.Collection;
11 import java.util.Collections;
12
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.yangtools.yang.binding.RpcService;
16 import org.osgi.framework.BundleActivator;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.ServiceReference;
19
20 public abstract class AbstractBindingAwareProvider extends AbstractBrokerAwareActivator implements BindingAwareProvider {
21     
22     @Override
23     protected final void onBrokerAvailable(BindingAwareBroker broker, BundleContext context) {
24         ProviderContext ctx = broker.registerProvider(this, context);
25         registerRpcImplementations(ctx);
26         registerFunctionality(ctx);
27     }
28
29     private void registerFunctionality(ProviderContext ctx) {
30         Collection<? extends ProviderFunctionality> functionality = this.getFunctionality();
31         if (functionality == null || functionality.isEmpty()) {
32             return;
33         }
34         for (ProviderFunctionality providerFunctionality : functionality) {
35             ctx.registerFunctionality(providerFunctionality);
36         }
37
38     }
39
40     private void registerRpcImplementations(ProviderContext ctx) {
41         Collection<? extends RpcService> rpcs = this.getImplementations();
42         if (rpcs == null || rpcs.isEmpty()) {
43             return;
44         }
45         for (RpcService rpcService : rpcs) {
46             // ctx.addRpcImplementation(type, implementation);
47         }
48
49     }
50
51     @Override
52     public Collection<? extends ProviderFunctionality> getFunctionality() {
53         return Collections.emptySet();
54     }
55
56     @Override
57     public Collection<? extends RpcService> getImplementations() {
58         return Collections.emptySet();
59     }
60     
61     /**
62      * Initialization of consumer context.
63      * 
64      * {@link ProviderContext} is replacement of {@link ConsumerContext}
65      * so this method is not needed in case of Provider.
66      * 
67      */
68     @Deprecated
69     @Override
70     public final void onSessionInitialized(ConsumerContext session) {
71         // NOOP
72     }
73 }