Leafref and identityref types to Json
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / OsgiProviderContext.xtend
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.impl;
9
10 import java.util.HashMap;
11 import java.util.Hashtable;
12 import java.util.Map;
13
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.yangtools.yang.binding.RpcService;
16 import org.osgi.framework.BundleContext;
17
18 import static org.opendaylight.controller.sal.binding.impl.osgi.Constants.*;
19 import static extension org.opendaylight.controller.sal.binding.impl.osgi.PropertiesUtils.*;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
22 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality
23 import static com.google.common.base.Preconditions.*
24
25 class OsgiProviderContext extends OsgiConsumerContext implements ProviderContext {
26
27     @Property
28     val Map<Class<? extends RpcService>, RpcRegistration<? extends RpcService>> registeredServices
29
30     new(BundleContext ctx, BindingAwareBrokerImpl broker) {
31         super(ctx, broker);
32         _registeredServices = new HashMap();
33     }
34
35     override <T extends RpcService> addRpcImplementation(Class<T> type, T implementation) {
36
37         // TODO Auto-generated method stub
38         val properties = new Hashtable<String, String>();
39         properties.salServiceType = SAL_SERVICE_TYPE_PROVIDER
40
41         // Fill requirements
42         val salReg = broker.registerRpcImplementation(type, implementation, this, properties)
43         registeredServices.put(type, salReg)
44         return salReg;
45     }
46
47     override <T extends RpcService> addRoutedRpcImplementation(Class<T> type, T implementation) throws IllegalStateException {
48         checkNotNull(type, "Service type should not be null")
49         checkNotNull(implementation, "Service type should not be null")
50         
51         val salReg = broker.registerRoutedRpcImplementation(type, implementation, this)
52         registeredServices.put(type, salReg)
53         return salReg;
54     }
55
56     override registerFunctionality(ProviderFunctionality functionality) {
57         // NOOP for now
58     }
59
60     override unregisterFunctionality(ProviderFunctionality functionality) {
61         // NOOP for now
62     }
63 }