X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdynamicmbean%2FAttributeHolder.java;h=14be2545047a87af8b1e514d0b81632cd3d71c06;hp=109ab10ac2a086e590ab1023bfa2ffd1442e8ad8;hb=0a16f37f1baa4a2616e9b7289a445649b4f3132d;hpb=9fb64948564e252018f9b1e13e7cea2c92f991aa diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java index 109ab10ac2..14be254504 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java @@ -7,18 +7,17 @@ */ package org.opendaylight.controller.config.manager.impl.dynamicmbean; -import java.lang.reflect.Method; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import org.opendaylight.controller.config.api.annotations.Description; +import org.opendaylight.controller.config.api.annotations.RequireInterface; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import javax.management.MBeanAttributeInfo; import javax.management.ObjectName; - -import org.opendaylight.controller.config.api.annotations.Description; -import org.opendaylight.controller.config.api.annotations.RequireInterface; +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.List; +import java.util.Set; @Immutable class AttributeHolder { @@ -32,10 +31,18 @@ class AttributeHolder { private final RequireInterface requireInterfaceAnnotation; private final String attributeType; + public static final Set> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>(); + + static { + PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(ObjectName.class); + PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(ObjectName[].class); + PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(List.class); + } + public AttributeHolder(String name, Object object, String returnType, - boolean writable, - @Nullable RequireInterface requireInterfaceAnnotation, - String description) { + boolean writable, + @Nullable RequireInterface requireInterfaceAnnotation, + String description) { if (name == null) { throw new NullPointerException(); } @@ -58,7 +65,7 @@ class AttributeHolder { /** * @return annotation if setter sets ObjectName or ObjectName[], and is - * annotated. Return null otherwise. + * annotated. Return null otherwise. */ RequireInterface getRequireInterfaceOrNull() { return requireInterfaceAnnotation; @@ -91,7 +98,7 @@ class AttributeHolder { * @param setter * @param jmxInterfaces * @return empty string if no annotation is found, or list of descriptions - * separated by newline + * separated by newline */ static String findDescription(Method setter, Set> jmxInterfaces) { List descriptions = AnnotationsHelper @@ -105,19 +112,19 @@ class AttributeHolder { * * @param setter * @param inspectedInterfaces - * @throws IllegalStateException - * if more than one value is specified by found annotations - * @throws IllegalArgumentException - * if set of exported interfaces contains non interface type * @return null if no annotation is found, otherwise return the annotation + * @throws IllegalStateException if more than one value is specified by found annotations + * @throws IllegalArgumentException if set of exported interfaces contains non interface type */ static RequireInterface findRequireInterfaceAnnotation(final Method setter, - Set> inspectedInterfaces) { + Set> inspectedInterfaces) { + + // only allow setX(ObjectName y) or setX(ObjectName[] y) or setX(List y) to continue - // only allow setX(ObjectName y) or setX(ObjectName[] y) to continue - if (setter.getParameterTypes().length != 1 - || (setter.getParameterTypes()[0].equals(ObjectName.class) == false && setter - .getParameterTypes()[0].equals(ObjectName[].class) == false)) { + if (setter.getParameterTypes().length > 1) { + return null; + } + if (PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0]) == false) { return null; } @@ -129,7 +136,7 @@ class AttributeHolder { for (RequireInterface ri : foundRequireInterfaces) { foundValues.add(ri.value()); } - if (foundValues.size() == 0) { + if (foundValues.isEmpty()) { return null; } else if (foundValues.size() > 1) { throw new IllegalStateException("Error finding @RequireInterface. "