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