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);
36 private static Object _createProxyImpl(final ServiceReference<?> ref,
37 final DataBrokerService service) {
39 return new DataBrokerServiceProxy(
40 ((ServiceReference<DataBrokerService>) ref), service);
44 private static Object _createProxyImpl(final ServiceReference<?> ref,
45 final DataProviderService service) {
47 return new DataProviderServiceProxy(
48 ((ServiceReference<DataProviderService>) ref), service);
51 private static Object _createProxyImpl(final ServiceReference<?> ref,
52 final NotificationPublishService service) {
54 return new NotificationPublishServiceProxy(
55 ((ServiceReference<NotificationPublishService>) ref), service);
58 private static Object _createProxyImpl(final ServiceReference<?> ref,
59 final NotificationService service) {
61 return new NotificationServiceProxy(
62 ((ServiceReference<NotificationService>) ref), service);
66 private static Object _createProxyImpl(final ServiceReference<?> ref,
67 final MountProvisionService service) {
69 return new MountProviderServiceProxy(
70 ((ServiceReference<MountProvisionService>) ref), service);
73 private static Object _createProxyImpl(final ServiceReference<?> ref,
74 final DOMMountPointService service) {
76 return new DOMMountPointServiceProxy(
77 ((ServiceReference<DOMMountPointService>) ref), service);
80 private static Object _createProxyImpl(final ServiceReference<?> ref,
81 final SchemaService service) {
83 return new SchemaServiceProxy(((ServiceReference<SchemaService>) ref),
87 private static Object _createProxyImpl(final ServiceReference<?> ref,
88 final RpcProvisionRegistry service) {
90 return new RpcProvisionRegistryProxy(
91 ((ServiceReference<RpcProvisionRegistry>) ref), service);
94 private static DOMDataBrokerProxy _createProxyImpl(
95 final ServiceReference<?> ref, final DOMDataBroker service) {
97 return new DOMDataBrokerProxy(((ServiceReference<DOMDataBroker>) ref),
101 private static Object _createProxyImpl(final ServiceReference<?> reference,
102 final BrokerService service) {
104 throw new IllegalArgumentException("Not supported class: "
105 + service.getClass().getName());
108 private static Object createProxyImpl(final ServiceReference<?> ref,
109 final BrokerService service) {
111 if (service instanceof DOMDataBroker) {
112 return _createProxyImpl(ref, (DOMDataBroker) service);
113 } else if (service instanceof RpcProvisionRegistry) {
114 return _createProxyImpl(ref, (RpcProvisionRegistry) service);
115 } else if (service instanceof DataProviderService) {
116 return _createProxyImpl(ref, (DataProviderService) service);
117 } else if (service instanceof MountProvisionService) {
118 return _createProxyImpl(ref, (MountProvisionService) service);
119 } else if (service instanceof NotificationPublishService) {
120 return _createProxyImpl(ref, (NotificationPublishService) service);
121 } else if (service instanceof DataBrokerService) {
122 return _createProxyImpl(ref, (DataBrokerService) service);
123 } else if (service instanceof SchemaService) {
124 return _createProxyImpl(ref, (SchemaService) service);
125 } else if (service instanceof NotificationService) {
126 return _createProxyImpl(ref, (NotificationService) service);
127 } else if (service instanceof DOMMountPointService) {
128 return _createProxyImpl(ref, (DOMMountPointService) service);
129 } else if (service != null) {
130 return _createProxyImpl(ref, service);
132 throw new IllegalArgumentException("Unhandled parameter types: "
133 + Arrays.<Object> asList(ref, service).toString());