Remove sal.core.api.model
[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 org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
11 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
12 import org.opendaylight.controller.sal.core.api.BrokerService;
13 import org.osgi.framework.ServiceReference;
14
15 @SuppressWarnings("unchecked")
16 public final class ProxyFactory {
17
18     private ProxyFactory() {
19     }
20
21     public static <T extends BrokerService> T createProxy(final ServiceReference<T> serviceRef, final T service) {
22
23         Object createProxyImpl = ProxyFactory.createProxyImpl(serviceRef, service);
24         return (T) createProxyImpl;
25     }
26
27     private static Object createProxyImpl(final ServiceReference<?> ref, final DOMMountPointService service) {
28
29         return new DOMMountPointServiceProxy((ServiceReference<DOMMountPointService>) ref, service);
30     }
31
32     private static DOMDataBrokerProxy createProxyImpl(final ServiceReference<?> ref, final DOMDataBroker service) {
33
34         return new DOMDataBrokerProxy((ServiceReference<DOMDataBroker>) ref, service);
35     }
36
37     private static Object createProxyImpl(final ServiceReference<?> ref, final BrokerService service) {
38         if (service == null) {
39             throw new IllegalArgumentException("service can't be null");
40         }
41
42         if (service instanceof DOMDataBroker) {
43             return createProxyImpl(ref, (DOMDataBroker) service);
44         } else if (service instanceof DOMMountPointService) {
45             return createProxyImpl(ref, (DOMMountPointService) service);
46         }
47
48         return createProxyImplFallback(ref, service);
49     }
50
51     private static Object createProxyImplFallback(final ServiceReference<?> reference, final BrokerService service) {
52
53         return service;
54     }
55 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.