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