11f68d6e04fb41a64c26d6a4a0a92833390f6e1b
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / ProviderContextImpl.xtend
1 package org.opendaylight.controller.sal.dom.broker
2
3 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession
4 import org.opendaylight.controller.sal.core.api.Provider
5 import org.opendaylight.yangtools.yang.common.QName
6 import org.opendaylight.controller.sal.core.api.RpcImplementation
7 import org.osgi.framework.BundleContext
8 import static java.util.Collections.*
9 import java.util.Collections
10 import java.util.HashMap
11
12 class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession {
13
14     @Property
15     private val Provider provider;
16
17     private val rpcImpls = Collections.synchronizedMap(new HashMap<QName, RpcImplementation>());
18
19     new(Provider provider, BundleContext ctx) {
20         super(null, ctx);
21         this._provider = provider;
22     }
23
24     override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
25         if(rpcType == null) {
26             throw new IllegalArgumentException("rpcType must not be null");
27         }
28         if(implementation == null) {
29             throw new IllegalArgumentException("Implementation must not be null");
30         }
31         broker.addRpcImplementation(rpcType, implementation);
32         rpcImpls.put(rpcType, implementation);
33         //FIXME: Return registration
34         return null;
35     }
36
37     def removeRpcImplementation(QName rpcType, RpcImplementation implToRemove) throws IllegalArgumentException {
38         val localImpl = rpcImpls.get(rpcType);
39         if(localImpl != implToRemove) {
40             throw new IllegalStateException(
41                 "Implementation was not registered in this session");
42         }
43
44         broker.removeRpcImplementation(rpcType, implToRemove);
45         rpcImpls.remove(rpcType);
46     }
47     
48     override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) {
49         throw new UnsupportedOperationException("TODO: auto-generated method stub")
50     }
51     
52     override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
53         throw new UnsupportedOperationException("TODO: auto-generated method stub")
54     }
55     
56 }