BUG-620: replace xtend version of classes with Java versions
[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.sal.core.api.BrokerService;
13 import org.osgi.framework.ServiceReference;
14 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
15 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
16 import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService;
17 import org.opendaylight.controller.sal.core.api.notify.NotificationService;
18 import org.opendaylight.controller.sal.core.api.model.SchemaService;
19 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
20 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
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     private static Object _createProxyImpl(final ServiceReference<?> ref,
35             final DataBrokerService service) {
36
37         return new DataBrokerServiceProxy(
38                 ((ServiceReference<DataBrokerService>) ref), service);
39     }
40
41     private static Object _createProxyImpl(final ServiceReference<?> ref,
42             final DataProviderService service) {
43
44         return new DataProviderServiceProxy(
45                 ((ServiceReference<DataProviderService>) ref), service);
46     }
47
48     private static Object _createProxyImpl(final ServiceReference<?> ref,
49             final NotificationPublishService service) {
50
51         return new NotificationPublishServiceProxy(
52                 ((ServiceReference<NotificationPublishService>) ref), service);
53     }
54
55     private static Object _createProxyImpl(final ServiceReference<?> ref,
56             final NotificationService service) {
57
58         return new NotificationServiceProxy(
59                 ((ServiceReference<NotificationService>) ref), service);
60     }
61
62     private static Object _createProxyImpl(final ServiceReference<?> ref,
63             final MountProvisionService service) {
64
65         return new MountProviderServiceProxy(
66                 ((ServiceReference<MountProvisionService>) ref), service);
67     }
68
69     private static Object _createProxyImpl(final ServiceReference<?> ref,
70             final SchemaService service) {
71
72         return new SchemaServiceProxy(((ServiceReference<SchemaService>) ref),
73                 service);
74     }
75
76     private static Object _createProxyImpl(final ServiceReference<?> ref,
77             final RpcProvisionRegistry service) {
78
79         return new RpcProvisionRegistryProxy(
80                 ((ServiceReference<RpcProvisionRegistry>) ref), service);
81     }
82
83     private static DOMDataBrokerProxy _createProxyImpl(
84             final ServiceReference<?> ref, final DOMDataBroker service) {
85
86         return new DOMDataBrokerProxy(((ServiceReference<DOMDataBroker>) ref),
87                 service);
88     }
89
90     private static Object _createProxyImpl(final ServiceReference<?> reference,
91             final BrokerService service) {
92
93         throw new IllegalArgumentException("Not supported class: "
94                 + service.getClass().getName());
95     }
96
97     private static Object createProxyImpl(final ServiceReference<?> ref,
98             final BrokerService service) {
99
100         if (service instanceof DOMDataBroker) {
101             return _createProxyImpl(ref, (DOMDataBroker) service);
102         } else if (service instanceof RpcProvisionRegistry) {
103             return _createProxyImpl(ref, (RpcProvisionRegistry) service);
104         } else if (service instanceof DataProviderService) {
105             return _createProxyImpl(ref, (DataProviderService) service);
106         } else if (service instanceof MountProvisionService) {
107             return _createProxyImpl(ref, (MountProvisionService) service);
108         } else if (service instanceof NotificationPublishService) {
109             return _createProxyImpl(ref, (NotificationPublishService) service);
110         } else if (service instanceof DataBrokerService) {
111             return _createProxyImpl(ref, (DataBrokerService) service);
112         } else if (service instanceof SchemaService) {
113             return _createProxyImpl(ref, (SchemaService) service);
114         } else if (service instanceof NotificationService) {
115             return _createProxyImpl(ref, (NotificationService) service);
116         } else if (service != null) {
117             return _createProxyImpl(ref, service);
118         } else {
119             throw new IllegalArgumentException("Unhandled parameter types: "
120                     + Arrays.<Object> asList(ref, service).toString());
121         }
122     }
123 }