2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.dom.broker.osgi;
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;
23 @SuppressWarnings("unchecked")
24 public class ProxyFactory {
26 public static <T extends BrokerService> T createProxy(
27 final ServiceReference<T> serviceRef, final T service) {
29 Object _createProxyImpl = ProxyFactory.createProxyImpl(serviceRef,
31 return ((T) _createProxyImpl);
35 private static Object _createProxyImpl(final ServiceReference<?> ref,
36 final DataBrokerService service) {
38 return new DataBrokerServiceProxy(
39 ((ServiceReference<DataBrokerService>) ref), service);
43 private static Object _createProxyImpl(final ServiceReference<?> ref,
44 final DataProviderService service) {
46 return new DataProviderServiceProxy(
47 ((ServiceReference<DataProviderService>) ref), service);
50 private static Object _createProxyImpl(final ServiceReference<?> ref,
51 final NotificationPublishService service) {
53 return new NotificationPublishServiceProxy(
54 ((ServiceReference<NotificationPublishService>) ref), service);
57 private static Object _createProxyImpl(final ServiceReference<?> ref,
58 final NotificationService service) {
60 return new NotificationServiceProxy(
61 ((ServiceReference<NotificationService>) ref), service);
65 private static Object _createProxyImpl(final ServiceReference<?> ref,
66 final MountProvisionService service) {
68 return new MountProviderServiceProxy(
69 ((ServiceReference<MountProvisionService>) ref), service);
72 private static Object _createProxyImpl(final ServiceReference<?> ref,
73 final DOMMountPointService service) {
75 return new DOMMountPointServiceProxy(
76 ((ServiceReference<DOMMountPointService>) ref), service);
79 private static Object _createProxyImpl(final ServiceReference<?> ref,
80 final SchemaService service) {
82 return new SchemaServiceProxy(((ServiceReference<SchemaService>) ref),
86 private static Object _createProxyImpl(final ServiceReference<?> ref,
87 final RpcProvisionRegistry service) {
89 return new RpcProvisionRegistryProxy(
90 ((ServiceReference<RpcProvisionRegistry>) ref), service);
93 private static DOMDataBrokerProxy _createProxyImpl(
94 final ServiceReference<?> ref, final DOMDataBroker service) {
96 return new DOMDataBrokerProxy(((ServiceReference<DOMDataBroker>) ref),
100 private static Object _createProxyImpl(final ServiceReference<?> reference,
101 final BrokerService service) {
106 private static Object createProxyImpl(final ServiceReference<?> ref,
107 final BrokerService service) {
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);
130 throw new IllegalArgumentException("Unhandled parameter types: "
131 + Arrays.<Object> asList(ref, service).toString());