X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2FClassBasedModuleFactory.java;h=93661699c4712debfc4cba9d4306e4a8e06e2913;hp=3c237d37f00f52ecde36938b87d9478dcd835b13;hb=f43b01b81319959b1907e3e04537f5169e7f33d8;hpb=4497e2212e73e13356447b9644bbdc935411949a diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ClassBasedModuleFactory.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ClassBasedModuleFactory.java index 3c237d37f0..93661699c4 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ClassBasedModuleFactory.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ClassBasedModuleFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 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, @@ -26,9 +26,9 @@ import org.osgi.framework.BundleContext; /** * Creates new modules by reflection. Provided class must have this constructor: - * ctor(DynamicMBeanWithInstance.class, ModuleIdentifier.class). - * When reconfiguring, both parameters will be non null. When creating new - * instance first parameter will be null. + * ctor(DynamicMBeanWithInstance.class, ModuleIdentifier.class). When + * reconfiguring, both parameters will be non null. When creating new instance + * first parameter will be null. * */ public class ClassBasedModuleFactory implements ModuleFactory { @@ -36,14 +36,15 @@ public class ClassBasedModuleFactory implements ModuleFactory { private final Class configBeanClass; /** + * Module factory constructor. + * * @param implementationName + * name of the implementation * @param configBeanClass - * class that will be instantiated when createModule is called. - * This class must implement Module interface and all exported - * interfaces. + * class that will be instantiated when createModule is called. This + * class must implement Module interface and all exported interfaces. */ - public ClassBasedModuleFactory(String implementationName, - Class configBeanClass) { + public ClassBasedModuleFactory(final String implementationName, final Class configBeanClass) { this.implementationName = implementationName; this.configBeanClass = configBeanClass; } @@ -54,41 +55,42 @@ public class ClassBasedModuleFactory implements ModuleFactory { } @Override - public Module createModule(String instanceName, - DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext) - throws Exception { + public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, + final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception { Preconditions.checkNotNull(old); return constructModule(instanceName, dependencyResolver, old); } - private Module constructModule(String instanceName, DependencyResolver dependencyResolver, DynamicMBeanWithInstance old) throws InstantiationException, IllegalAccessException, InvocationTargetException { + @Override + public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, + final BundleContext bundleContext) { + try { + return constructModule(instanceName, dependencyResolver, null); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + private Module constructModule(final String instanceName, final DependencyResolver dependencyResolver, + final DynamicMBeanWithInstance old) + throws InstantiationException, IllegalAccessException, InvocationTargetException { Preconditions.checkNotNull(dependencyResolver); ModuleIdentifier moduleIdentifier = new ModuleIdentifier(implementationName, instanceName); Constructor declaredConstructor; try { - declaredConstructor = configBeanClass.getDeclaredConstructor(DynamicMBeanWithInstance.class, ModuleIdentifier.class); - } catch (NoSuchMethodException e) { + declaredConstructor = configBeanClass.getDeclaredConstructor(DynamicMBeanWithInstance.class, + ModuleIdentifier.class); + } catch (final NoSuchMethodException e) { throw new IllegalStateException( - "Did not find constructor with parameters (DynamicMBeanWithInstance) in " - + configBeanClass, e); + "Did not find constructor with parameters (DynamicMBeanWithInstance) in " + configBeanClass, e); } Preconditions.checkState(declaredConstructor != null); return declaredConstructor.newInstance(old, moduleIdentifier); } - @Override - public Module createModule(String instanceName, - DependencyResolver dependencyResolver, BundleContext bundleContext) { - try { - return constructModule(instanceName, dependencyResolver, null); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - @Override public boolean isModuleImplementingServiceInterface( - Class serviceInterface) { + final Class serviceInterface) { Class[] classes = configBeanClass.getInterfaces(); List> ifc = Arrays.asList(classes); if (ifc.contains(serviceInterface)) { @@ -104,8 +106,9 @@ public class ClassBasedModuleFactory implements ModuleFactory { } @Override - public Set getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) { - return new HashSet(); + public Set getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, + final BundleContext bundleContext) { + return new HashSet<>(); } @Override