Bug 2578 - Added Binding Adapters for new Notification Broker
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / osgi / ProxyFactory.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.sal.dom.broker.osgi;
9
10 import java.util.Arrays;
11 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
12 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
13 import org.opendaylight.controller.sal.core.api.BrokerService;
14 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
15 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
16 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
17 import org.opendaylight.controller.sal.core.api.model.SchemaService;
18 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
19 import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService;
20 import org.opendaylight.controller.sal.core.api.notify.NotificationService;
21 import org.osgi.framework.ServiceReference;
22
23 @SuppressWarnings("unchecked")
24 public class ProxyFactory {
25
26     public static <T extends BrokerService> T createProxy(
27             final ServiceReference<T> serviceRef, final T service) {
28
29         Object _createProxyImpl = ProxyFactory.createProxyImpl(serviceRef,
30                 service);
31         return ((T) _createProxyImpl);
32     }
33
34     @Deprecated
35     private static Object _createProxyImpl(final ServiceReference<?> ref,
36             final DataBrokerService service) {
37
38         return new DataBrokerServiceProxy(
39                 ((ServiceReference<DataBrokerService>) ref), service);
40     }
41
42     @Deprecated
43     private static Object _createProxyImpl(final ServiceReference<?> ref,
44             final DataProviderService service) {
45
46         return new DataProviderServiceProxy(
47                 ((ServiceReference<DataProviderService>) ref), service);
48     }
49
50     private static Object _createProxyImpl(final ServiceReference<?> ref,
51             final NotificationPublishService service) {
52
53         return new NotificationPublishServiceProxy(
54                 ((ServiceReference<NotificationPublishService>) ref), service);
55     }
56
57     private static Object _createProxyImpl(final ServiceReference<?> ref,
58             final NotificationService service) {
59
60         return new NotificationServiceProxy(
61                 ((ServiceReference<NotificationService>) ref), service);
62     }
63
64     @Deprecated
65     private static Object _createProxyImpl(final ServiceReference<?> ref,
66             final MountProvisionService service) {
67
68         return new MountProviderServiceProxy(
69                 ((ServiceReference<MountProvisionService>) ref), service);
70     }
71
72     private static Object _createProxyImpl(final ServiceReference<?> ref,
73             final DOMMountPointService service) {
74
75         return new DOMMountPointServiceProxy(
76                 ((ServiceReference<DOMMountPointService>) ref), service);
77     }
78
79     private static Object _createProxyImpl(final ServiceReference<?> ref,
80             final SchemaService service) {
81
82         return new SchemaServiceProxy(((ServiceReference<SchemaService>) ref),
83                 service);
84     }
85
86     private static Object _createProxyImpl(final ServiceReference<?> ref,
87             final RpcProvisionRegistry service) {
88
89         return new RpcProvisionRegistryProxy(
90                 ((ServiceReference<RpcProvisionRegistry>) ref), service);
91     }
92
93     private static DOMDataBrokerProxy _createProxyImpl(
94             final ServiceReference<?> ref, final DOMDataBroker service) {
95
96         return new DOMDataBrokerProxy(((ServiceReference<DOMDataBroker>) ref),
97                 service);
98     }
99
100     private static Object _createProxyImpl(final ServiceReference<?> reference,
101             final BrokerService service) {
102
103        return service;
104     }
105
106     private static Object createProxyImpl(final ServiceReference<?> ref,
107             final BrokerService service) {
108
109         if (service instanceof DOMDataBroker) {
110             return _createProxyImpl(ref, (DOMDataBroker) service);
111         } else if (service instanceof RpcProvisionRegistry) {
112             return _createProxyImpl(ref, (RpcProvisionRegistry) service);
113         } else if (service instanceof DataProviderService) {
114             return _createProxyImpl(ref, (DataProviderService) service);
115         } else if (service instanceof MountProvisionService) {
116             return _createProxyImpl(ref, (MountProvisionService) service);
117         } else if (service instanceof NotificationPublishService) {
118             return _createProxyImpl(ref, (NotificationPublishService) service);
119         } else if (service instanceof DataBrokerService) {
120             return _createProxyImpl(ref, (DataBrokerService) service);
121         } else if (service instanceof SchemaService) {
122             return _createProxyImpl(ref, (SchemaService) service);
123         } else if (service instanceof NotificationService) {
124             return _createProxyImpl(ref, (NotificationService) service);
125         } else if (service instanceof DOMMountPointService) {
126             return _createProxyImpl(ref, (DOMMountPointService) service);
127         } else if (service != null) {
128             return _createProxyImpl(ref, service);
129         } else {
130             throw new IllegalArgumentException("Unhandled parameter types: "
131                     + Arrays.<Object> asList(ref, service).toString());
132         }
133     }
134 }