Migrate OSGI compendium reference
[controller.git] / opendaylight / blueprint / src / main / java / org / opendaylight / controller / blueprint / ext / RoutedRpcRegistrationConverter.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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.blueprint.ext;
9
10 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
11 import org.osgi.service.blueprint.container.Converter;
12 import org.osgi.service.blueprint.container.ReifiedType;
13
14 /**
15  * Implements a Converter that converts RoutedRpcRegistration instances. This is to work around an issue
16  * when injecting a RoutedRpcRegistration instance into a bean where Aries is not able to convert the instance
17  * returned from the RpcRegistryProvider to the desired generic RoutedRpcRegistration type specified in the
18  * bean's setter method. This is because the actual instance class specifies a generic type variable T and,
19  * even though it extends RpcService and should match, Aries doesn't handle it correctly.
20  *
21  * @author Thomas Pantelis
22  */
23 public class RoutedRpcRegistrationConverter implements Converter {
24     @Override
25     public boolean canConvert(final Object sourceObject, final ReifiedType targetType) {
26         return sourceObject instanceof RoutedRpcRegistration
27                 && RoutedRpcRegistration.class.isAssignableFrom(targetType.getRawClass());
28     }
29
30     @Override
31     public Object convert(final Object sourceObject, final ReifiedType targetType) {
32         return sourceObject;
33     }
34 }