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;
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;
24 @SuppressWarnings("unchecked")
25 public class ProxyFactory {
27 public static <T extends BrokerService> T createProxy(
28 final ServiceReference<T> serviceRef, final T service) {
30 Object _createProxyImpl = ProxyFactory.createProxyImpl(serviceRef,
32 return ((T) _createProxyImpl);
35 private static Object _createProxyImpl(final ServiceReference<?> ref,
36 final DataBrokerService service) {
38 return new DataBrokerServiceProxy(
39 ((ServiceReference<DataBrokerService>) ref), service);
42 private static Object _createProxyImpl(final ServiceReference<?> ref,
43 final DataProviderService service) {
45 return new DataProviderServiceProxy(
46 ((ServiceReference<DataProviderService>) ref), service);
49 private static Object _createProxyImpl(final ServiceReference<?> ref,
50 final NotificationPublishService service) {
52 return new NotificationPublishServiceProxy(
53 ((ServiceReference<NotificationPublishService>) ref), service);
56 private static Object _createProxyImpl(final ServiceReference<?> ref,
57 final NotificationService service) {
59 return new NotificationServiceProxy(
60 ((ServiceReference<NotificationService>) ref), service);
63 private static Object _createProxyImpl(final ServiceReference<?> ref,
64 final MountProvisionService service) {
66 return new MountProviderServiceProxy(
67 ((ServiceReference<MountProvisionService>) ref), service);
70 private static Object _createProxyImpl(final ServiceReference<?> ref,
71 final DOMMountPointService service) {
73 return new DOMMountPointServiceProxy(
74 ((ServiceReference<DOMMountPointService>) ref), service);
77 private static Object _createProxyImpl(final ServiceReference<?> ref,
78 final SchemaService service) {
80 return new SchemaServiceProxy(((ServiceReference<SchemaService>) ref),
84 private static Object _createProxyImpl(final ServiceReference<?> ref,
85 final RpcProvisionRegistry service) {
87 return new RpcProvisionRegistryProxy(
88 ((ServiceReference<RpcProvisionRegistry>) ref), service);
91 private static DOMDataBrokerProxy _createProxyImpl(
92 final ServiceReference<?> ref, final DOMDataBroker service) {
94 return new DOMDataBrokerProxy(((ServiceReference<DOMDataBroker>) ref),
98 private static Object _createProxyImpl(final ServiceReference<?> reference,
99 final BrokerService service) {
101 throw new IllegalArgumentException("Not supported class: "
102 + service.getClass().getName());
105 private static Object createProxyImpl(final ServiceReference<?> ref,
106 final BrokerService service) {
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);
129 throw new IllegalArgumentException("Unhandled parameter types: "
130 + Arrays.<Object> asList(ref, service).toString());