Skip to content

Package: FactoryResolver

FactoryResolver

nameinstructionbranchcomplexitylinemethod
FactoryResolver(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%
getFactoryClass()
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%
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%
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.model.KapuaObjectFactory;
19:
20: public class FactoryResolver<F extends KapuaObjectFactory, I extends F> {
21:
22: private final Class<F> factoryClass;
23: private final Class<I> implementationClass;
24:
25: private FactoryResolver(Class<F> factory, Class<I> implementation) {
26: this.factoryClass = factory;
27: this.implementationClass = implementation;
28: }
29:
30: @SuppressWarnings("unchecked")
31: public static <F extends KapuaObjectFactory, I extends F> FactoryResolver<F, I> newInstance(Class<?> factory, Class<?> implementation)
32: throws KapuaLocatorException {
33:• if (!factory.isAssignableFrom(implementation)) {
34: throw new KapuaLocatorException(KapuaLocatorErrorCodes.FACTORY_PROVIDER_INVALID, implementation, factory);
35: }
36:
37: return new FactoryResolver<F,I>((Class<F>)factory, (Class<I>)implementation);
38: }
39:
40: public Class<F> getFactoryClass() {
41: return factoryClass;
42: }
43:
44: public Class<I> getImplementationClass() {
45: return implementationClass;
46: }
47:
48: }