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;fp=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdynamicmbean%2FAttributeHolder.java;h=0000000000000000000000000000000000000000;hp=ff607d32e5f340319b050020998c23ded9e7c9d6;hb=ac6f2699cd0c1e340cc32e8f0d0ca94c8e9c0cc0;hpb=f43b01b81319959b1907e3e04537f5169e7f33d8 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 deleted file mode 100644 index ff607d32e5..0000000000 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -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 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; - -@Immutable -class AttributeHolder { - - private final String name; - private final String description; - private final Object object; - private final boolean writable; - - @Nullable - private final RequireInterface requireInterfaceAnnotation; - private final String attributeType; - - protected 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); - } - - AttributeHolder(final String name, final Object object, final String returnType, final boolean writable, - @Nullable final RequireInterface requireInterfaceAnnotation, final String description) { - if (name == null) { - throw new NullPointerException(); - } - this.name = name; - if (object == null) { - throw new NullPointerException(); - } - this.object = object; - this.writable = writable; - this.requireInterfaceAnnotation = requireInterfaceAnnotation; - this.attributeType = returnType; - this.description = description; - } - - public MBeanAttributeInfo toMBeanAttributeInfo() { - return new MBeanAttributeInfo(name, attributeType, description, true, true, false); - } - - /** - * Anotation. - * - * @return annotation if setter sets ObjectName or ObjectName[], and is - * annotated. Return null otherwise. - */ - RequireInterface getRequireInterfaceOrNull() { - return requireInterfaceAnnotation; - } - - public String getName() { - return name; - } - - public Object getObject() { - return object; - } - - public String getAttributeType() { - return attributeType; - } - - public boolean isWritable() { - return writable; - } - - public String getDescription() { - return description; - } - - /** - * Find @Description annotations in method class and all its exported - * interfaces. - * - * @param setter setter method - * @param jmxInterfaces JMX interfaces - * @return empty string if no annotation is found, or list of descriptions - * separated by newline - */ - static String findDescription(final Method setter, final Set> jmxInterfaces) { - List descriptions = AnnotationsHelper.findMethodAnnotationInSuperClassesAndIfcs(setter, - Description.class, jmxInterfaces); - return AnnotationsHelper.aggregateDescriptions(descriptions); - } - - /** - * Find @RequireInterface annotation by searching method class and all exported - * interfaces. - * - * @param setter setter method - * @param inspectedInterfaces interfaces - * @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, - final Set> inspectedInterfaces) { - - // only allow setX(ObjectName y) or setX(ObjectName[] y) or - // setX(List y) to continue - - if (setter.getParameterTypes().length > 1 - || !PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0])) { - return null; - } - - List foundRequireInterfaces = AnnotationsHelper - .findMethodAnnotationInSuperClassesAndIfcs(setter, RequireInterface.class, inspectedInterfaces); - // make sure the list if not empty contains always annotation with same - // value - Set> foundValues = new HashSet<>(); - for (RequireInterface ri : foundRequireInterfaces) { - foundValues.add(ri.value()); - } - if (foundValues.isEmpty()) { - return null; - } else if (foundValues.size() > 1) { - throw new IllegalStateException( - "Error finding @RequireInterface. " + "More than one value specified as required interface " - + foundValues + " of " + setter + " of " + setter.getDeclaringClass()); - } else { - return foundRequireInterfaces.get(0); - } - } -}