/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.sal.dom.broker.osgi; import java.util.Arrays; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.sal.core.api.BrokerService; import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.osgi.framework.ServiceReference; @SuppressWarnings("unchecked") public final class ProxyFactory { private ProxyFactory() { } public static T createProxy(final ServiceReference serviceRef, final T service) { Object createProxyImpl = ProxyFactory.createProxyImpl(serviceRef, service); return ((T) createProxyImpl); } private static Object createProxyImpl(final ServiceReference ref, final DOMMountPointService service) { return new DOMMountPointServiceProxy(((ServiceReference) ref), service); } private static Object createProxyImpl(final ServiceReference ref, final SchemaService service) { return new SchemaServiceProxy(((ServiceReference) ref), service); } private static DOMDataBrokerProxy createProxyImpl(final ServiceReference ref, final DOMDataBroker service) { return new DOMDataBrokerProxy(((ServiceReference) ref), service); } private static Object createProxyImpl(final ServiceReference ref, final BrokerService service) { if (service instanceof DOMDataBroker) { return createProxyImpl(ref, (DOMDataBroker) service); } else if (service instanceof SchemaService) { return createProxyImpl(ref, (SchemaService) service); } else if (service instanceof DOMMountPointService) { return createProxyImpl(ref, (DOMMountPointService) service); } else if (service != null) { return createProxyImplFallback(ref, service); } else { throw new IllegalArgumentException( "Unhandled parameter types: " + Arrays.asList(ref, service).toString()); } } private static Object createProxyImplFallback(final ServiceReference reference, final BrokerService service) { return service; } }