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(String message) 

Source Link

Document

Constructor that allows a specific error message to be specified.

Usage

From source file:org.cleverbus.core.throttling.JmxThrottlingConfiguration.java

@Override
public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Assert.notNull(attribute, "attribute must not be null");

    // attr name: systemName . serviceName
    String attrName = attribute.getName();

    String[] nameParts = StringUtils.split(attrName, ThrottleScope.THROTTLE_SEPARATOR);

    if (nameParts.length != 2) {
        throw new AttributeNotFoundException(
                "attribute name is not in expected format: 'systemName . serviceName'");
    }/*from www .ja  va2 s  .  c  o  m*/

    // attr value: limit / interval
    String attrValue = (String) attribute.getValue();

    String[] valueParts = StringUtils.split(attrValue, ThrottleProps.PROP_VALUE_SEPARATOR);

    if (valueParts.length != 2) {
        throw new InvalidAttributeValueException(
                "attribute value is not in expected format: 'limit / interval'");
    }

    configuration.addProperty(nameParts[0], nameParts[1], Integer.valueOf(valueParts[1]),
            Integer.valueOf(valueParts[0]));
}

From source file:com.ecyrd.management.SimpleMBean.java

public void setAttribute(Attribute attr)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Method m;/*from w  w  w  .j  a va  2s.  com*/

    String mname = "set" + StringUtils.capitalize(attr.getName());
    m = findGetterSetter(getClass(), mname, attr.getValue().getClass());

    if (m == null)
        throw new AttributeNotFoundException(attr.getName());

    Object[] args = { attr.getValue() };

    try {
        m.invoke(this, args);
    } catch (IllegalArgumentException e) {
        throw new InvalidAttributeValueException("Faulty argument: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e, "Cannot access attribute " + e.getMessage());
    } catch (InvocationTargetException e) {
        throw new ReflectionException(e, "Cannot invoke attribute " + e.getMessage());
    }
}

From source file:com.cyberway.issue.crawler.settings.ComplexType.java

/** Set the value of a specific attribute of the ComplexType.
 *
 * This method is an extension to the Dynamic MBean specification so that
 * it is possible to set the value for a CrawlerSettings object other than
 * the settings object representing the order.
 *
 * @param settings the settings object for which this attributes value is valid
 * @param attribute The identification of the attribute to be set and the
 *                  value it is to be set to.
 * @throws AttributeNotFoundException is thrown if there is no attribute
 *         with this name./*from w w w . j  a v a2  s. co  m*/
 * @throws InvalidAttributeValueException is thrown if the attribute is of
 *         wrong type and cannot be converted to the right type.
 * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
 */
public synchronized final void setAttribute(CrawlerSettings settings, Attribute attribute)
        throws InvalidAttributeValueException, AttributeNotFoundException {

    if (settings == null) {
        settings = globalSettings();
    }

    DataContainer data = getOrCreateDataContainer(settings);
    Object value = attribute.getValue();

    ModuleAttributeInfo attrInfo = (ModuleAttributeInfo) getAttributeInfo(settings.getParent(),
            attribute.getName());

    ModuleAttributeInfo localAttrInfo = (ModuleAttributeInfo) data.getAttributeInfo(attribute.getName());

    // Check if attribute exists
    if (attrInfo == null && localAttrInfo == null) {
        throw new AttributeNotFoundException(attribute.getName());
    }

    // Check if we are overriding and if that is allowed for this attribute
    if (localAttrInfo == null) {
        if (!attrInfo.isOverrideable()) {
            throw new InvalidAttributeValueException("Attribute not overrideable: " + attribute.getName());
        }
        localAttrInfo = new ModuleAttributeInfo(attrInfo);
    }

    // Check if value is of correct type. If not, see if it is
    // a string and try to turn it into right type
    Class typeClass = getDefinition(attribute.getName()).getLegalValueType();
    if (!(typeClass.isInstance(value)) && value instanceof String) {
        try {
            value = SettingsHandler.StringToType((String) value,
                    SettingsHandler.getTypeName(typeClass.getName()));
        } catch (ClassCastException e) {
            throw new InvalidAttributeValueException(
                    "Unable to decode string '" + value + "' into type '" + typeClass.getName() + "'");
        }
    }

    // Check if the attribute value is legal
    FailedCheck error = checkValue(settings, attribute.getName(), value);
    if (error != null) {
        if (error.getLevel() == Level.SEVERE) {
            throw new InvalidAttributeValueException(error.getMessage());
        } else if (error.getLevel() == Level.WARNING) {
            if (!getSettingsHandler().fireValueErrorHandlers(error)) {
                throw new InvalidAttributeValueException(error.getMessage());
            }
        } else {
            getSettingsHandler().fireValueErrorHandlers(error);
        }
    }

    // Everything ok, set it
    localAttrInfo.setType(value);
    Object oldValue = data.put(attribute.getName(), localAttrInfo, value);

    // If the attribute is a complex type other than the old value,
    // make sure that all sub attributes are correctly set
    if (value instanceof ComplexType && value != oldValue) {
        ComplexType complex = (ComplexType) value;
        replaceComplexType(settings, complex);
    }
}

From source file:com.cyberway.issue.crawler.Heritrix.java

public String addCrawlJobBasedOn(String jobUidOrProfile, String name, String description, String seeds) {
    try {/*from  www .  jav a  2 s  .c  o  m*/
        CrawlJob cj = getJobHandler().getJob(jobUidOrProfile);
        if (cj == null) {
            throw new InvalidAttributeValueException(
                    jobUidOrProfile + " is not a job UID or profile name (Job UIDs are "
                            + " usually the 14 digit date portion of job name).");
        }
        CrawlJob job = addCrawlJobBasedOn(cj.getSettingsHandler().getOrderFile(), name, description, seeds);
        return job.getUID();
    } catch (Exception e) {
        e.printStackTrace();
        return "Exception on " + jobUidOrProfile + ": " + e.getMessage();
    }
}