Skip to content

Package: ServiceResolver

ServiceResolver

nameinstructionbranchcomplexitylinemethod
ServiceResolver(Class, Class)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getImplementationClass()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getServiceClass()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
newInstance(Class, Class)
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: * Red Hat Inc
13: *******************************************************************************/
14: package org.eclipse.kapua.locator.guice;
15:
16: import org.eclipse.kapua.locator.KapuaLocatorErrorCodes;
17: import org.eclipse.kapua.locator.KapuaLocatorException;
18: import org.eclipse.kapua.service.KapuaService;
19:
20: public class ServiceResolver<S extends KapuaService, I extends S> {
21:
22: private final Class<S> serviceClass;
23: private final Class<I> implementationClass;
24:
25: private ServiceResolver(Class<S> service, Class<I> implementation) {
26: this.serviceClass = service;
27: this.implementationClass = implementation;
28: }
29:
30: @SuppressWarnings("unchecked")
31: public static <S extends KapuaService, I extends S> ServiceResolver<S,I> newInstance(Class<?> service, Class<?> implementation)
32: throws KapuaLocatorException {
33:
34:• if (!service.isAssignableFrom(implementation)) {
35: throw new KapuaLocatorException(KapuaLocatorErrorCodes.SERVICE_PROVIDER_INVALID, implementation, service);
36: }
37:
38: return new ServiceResolver<S,I>((Class<S>)service, (Class<I>)implementation);
39: }
40:
41: public Class<S> getServiceClass() {
42: return serviceClass;
43: }
44:
45: public Class<I> getImplementationClass() {
46: return implementationClass;
47: }
48:
49: }