Fix checkstyle issues in module sal-dom-broker
[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 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.model.SchemaService;
15 import org.osgi.framework.ServiceReference;
16
17 @SuppressWarnings("unchecked")
18 public final class ProxyFactory {
19
20     private ProxyFactory() {
21     }
22
23     public static <T extends BrokerService> T createProxy(final ServiceReference<T> serviceRef, final T service) {
24
25         Object createProxyImpl = ProxyFactory.createProxyImpl(serviceRef, service);
26         return ((T) createProxyImpl);
27     }
28
29     private static Object createProxyImpl(final ServiceReference<?> ref, final DOMMountPointService service) {
30
31         return new DOMMountPointServiceProxy(((ServiceReference<DOMMountPointService>) ref), service);
32     }
33
34     private static Object createProxyImpl(final ServiceReference<?> ref, final SchemaService service) {
35
36         return new SchemaServiceProxy(((ServiceReference<SchemaService>) ref), service);
37     }
38
39     private static DOMDataBrokerProxy createProxyImpl(final ServiceReference<?> ref, final DOMDataBroker service) {
40
41         return new DOMDataBrokerProxy(((ServiceReference<DOMDataBroker>) ref), service);
42     }
43
44     private static Object createProxyImpl(final ServiceReference<?> ref, final BrokerService service) {
45
46         if (service instanceof DOMDataBroker) {
47             return createProxyImpl(ref, (DOMDataBroker) service);
48         } else if (service instanceof SchemaService) {
49             return createProxyImpl(ref, (SchemaService) service);
50         } else if (service instanceof DOMMountPointService) {
51             return createProxyImpl(ref, (DOMMountPointService) service);
52         } else if (service != null) {
53             return createProxyImplFallback(ref, service);
54         } else {
55             throw new IllegalArgumentException(
56                     "Unhandled parameter types: " + Arrays.<Object>asList(ref, service).toString());
57         }
58     }
59
60     private static Object createProxyImplFallback(final ServiceReference<?> reference, final BrokerService service) {
61
62         return service;
63     }
64 }