Example usage for javax.management InvalidAttributeValueException InvalidAttributeValueException

List of usage examples for javax.management InvalidAttributeValueException InvalidAttributeValueException

Introduction

In this page you can find the example usage for javax.management InvalidAttributeValueException InvalidAttributeValueException.

Prototype

public InvalidAttributeValueException() 

Source Link

Document

Default constructor.

Usage

From source file:org.echocat.jemoni.jmx.support.CacheDynamicMBean.java

@Override
public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    final String attributeName = attribute.getName();
    final Object value = attribute.getValue();
    if ("maximumLifetime".equals(attributeName)) {
        if (value != null && !(value instanceof String)) {
            throw new InvalidAttributeValueException();
        }//ww w  .j  av  a 2s .  com
        cast(LimitedCache.class).setMaximumLifetime(
                value != null && !value.toString().trim().isEmpty() ? new Duration(value.toString()) : null);
    } else if ("capacity".equals(attributeName)) {
        if (value != null && !(value instanceof Number)) {
            throw new InvalidAttributeValueException();
        }
        cast(LimitedCache.class).setCapacity(value != null ? ((Number) value).longValue() : null);
    } else if ("producingType".equals(attributeName)) {
        if (value != null && !(value instanceof String)) {
            throw new InvalidAttributeValueException();
        }
        final ProducingType producingType;
        if (value == null || value.toString().trim().isEmpty()) {
            producingType = ProducingType.DEFAULT;
        } else {
            try {
                producingType = ProducingType.valueOf(value.toString().trim());
            } catch (IllegalArgumentException ignored) {
                throw new InvalidAttributeValueException("Illegal value: " + value + ". Possible values: "
                        + StringUtils.join(ProducingType.values(), ", "));
            }
        }
        cast(ProducingTypeEnabledCache.class).setProducingType(producingType);
    } else {
        throw new AttributeNotFoundException();
    }
}