Example usage for javax.management AttributeNotFoundException AttributeNotFoundException

List of usage examples for javax.management AttributeNotFoundException AttributeNotFoundException

Introduction

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

Prototype

public AttributeNotFoundException(String message) 

Source Link

Document

Constructor that allows a specific error message to be specified.

Usage

From source file:org.jolokia.converter.json.BeanExtractor.java

@SuppressWarnings("PMD.CompareObjectsWithEquals")
private Object extractJsonifiedPropertyValue(ObjectToJsonConverter pConverter, Object pValue, String pAttribute,
        Stack<String> pPathParts) throws AttributeNotFoundException {
    ValueFaultHandler faultHandler = pConverter.getValueFaultHandler();
    Object value = extractBeanPropertyValue(pValue, pAttribute, faultHandler);
    if (value == null) {
        if (!pPathParts.isEmpty()) {
            faultHandler.handleException(new AttributeNotFoundException(
                    "Cannot apply remaining path " + EscapeUtil.combineToPath(pPathParts) + " on value null"));
        }//  w  w w.ja v a 2 s  .  co m
        return null;
    } else if (value == pValue) {
        if (!pPathParts.isEmpty()) {
            faultHandler.handleException(new AttributeNotFoundException(
                    "Cannot apply remaining path " + EscapeUtil.combineToPath(pPathParts) + " on a cycle"));
        }
        // Break Cycle
        return "[this]";
    } else {
        // Call into the converted recursively for any object known.
        return pConverter.extractObject(value, pPathParts, true /* jsonify */);
    }
}

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 v  a 2 s .co m*/

    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

/** Get the active data container for this ComplexType for a specific
 * settings object./*w  w w. j  a va2s.  c  om*/
 *
 * If the key has not been overridden on the settings object for this
 * ComplexType, then it traverses up until it find a DataContainer with
 * the key for this ComplexType.
 *
 * This method should probably not be called from user code. It is a helper
 * method for the settings framework.
 *
 * @param context the settings object for which the {@link DataContainer}
 *                 is active.
 * @param key the key to look for.
 * @return the active DataContainer.
 * @throws AttributeNotFoundException
 */
protected DataContainer getDataContainerRecursive(Context context, String key)
        throws AttributeNotFoundException {
    Context c = new Context(context.settings, context.uri);
    DataContainer data = getDataContainerRecursive(c);
    while (data != null) {
        if (data.containsKey(key)) {
            return data;
        }
        c.settings = data.getSettings().getParent(c.uri);
        data = getDataContainerRecursive(c);
    }
    throw new AttributeNotFoundException(key);
}

From source file:org.jolokia.converter.json.BeanExtractor.java

private Object extractBeanPropertyValue(Object pValue, String pAttribute, ValueFaultHandler pFaultHandler)
        throws AttributeNotFoundException {
    Class clazz = pValue.getClass();

    Method method = null;//  ww  w .ja  v  a  2  s .  c o m

    String suffix = new StringBuilder(pAttribute.substring(0, 1).toUpperCase()).append(pAttribute.substring(1))
            .toString();
    for (String pref : GETTER_PREFIX) {
        try {
            String methodName = new StringBuilder(pref).append(suffix).toString();
            method = clazz.getMethod(methodName);
        } catch (NoSuchMethodException e) {
            // Try next one
            continue;
        }
        // We found a valid method
        break;
    }
    // Finally, try the attribute name directly
    if (method == null) {
        try {
            method = clazz.getMethod(new StringBuilder(pAttribute.substring(0, 1).toLowerCase())
                    .append(pAttribute.substring(1)).toString());
        } catch (NoSuchMethodException exp) {
            method = null;
        }
    }
    if (method == null) {
        return pFaultHandler.handleException(new AttributeNotFoundException(
                "No getter known for attribute " + pAttribute + " for class " + pValue.getClass().getName()));
    }
    try {
        method.setAccessible(true);
        return method.invoke(pValue);
    } catch (IllegalAccessException e) {
        return pFaultHandler.handleException(
                new IllegalStateException("Error while extracting " + pAttribute + " from " + pValue, e));
    } catch (InvocationTargetException e) {
        return pFaultHandler.handleException(
                new IllegalStateException("Error while extracting " + pAttribute + " from " + pValue, e));
    }
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

private CompositeData extractCompositeDataFromPath(TabularData pTd, Stack<String> pPathStack)
        throws AttributeNotFoundException {
    // We first try it as a key
    TabularType type = pTd.getTabularType();
    List<String> indexNames = type.getIndexNames();
    checkPathFitsIndexNames(pPathStack, indexNames);

    Object keys[] = new Object[indexNames.size()];
    CompositeType rowType = type.getRowType();
    List<String> pathPartsUsed = new ArrayList<String>();
    for (int i = 0; i < indexNames.size(); i++) {
        String path = pPathStack.pop();
        pathPartsUsed.add(path);//from   w  ww  .ja v  a  2 s  .  c  om
        keys[i] = getKey(rowType, indexNames.get(i), path);
    }
    if (pTd.containsKey(keys)) {
        return pTd.get(keys);
    } else {
        throw new AttributeNotFoundException("No entry with " + pathPartsUsed + " found");
    }
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

private void checkPathFitsIndexNames(Stack<String> pPathStack, List<String> pIndexNames)
        throws AttributeNotFoundException {
    if (pIndexNames.size() > pPathStack.size()) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < pIndexNames.size(); i++) {
            buf.append(pIndexNames.get(i));
            if (i < pIndexNames.size() - 1) {
                buf.append(",");
            }/*from   w  w  w.  jav a 2s  .  co  m*/
        }
        throw new AttributeNotFoundException(
                "No enough keys on path stack provided for accessing tabular data with index names "
                        + buf.toString());
    }
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

public Object getAttribute(String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (methods == null)
        init();// w w w  .ja  va2  s . c om
    Method m = (Method) getAttMap.get(attribute);
    if (m == null)
        throw new AttributeNotFoundException(attribute);

    try {
        if (log.isDebugEnabled())
            log.debug(real.getClass().getName() + " getAttribute " + attribute);
        return m.invoke(real, NO_ARGS_PARAM);
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        throw new MBeanException(ex);
    } catch (InvocationTargetException ex1) {
        ex1.printStackTrace();
        throw new MBeanException(ex1);
    }
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (methods == null)
        init();//from   w ww  . j a v  a 2 s  .c o  m
    // XXX Send notification !!!
    Method m = (Method) setAttMap.get(attribute.getName());
    if (m == null)
        throw new AttributeNotFoundException(attribute.getName());

    try {
        log.info(real.getClass().getName() + "setAttribute " + attribute.getName());
        m.invoke(real, new Object[] { attribute.getValue() });
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        throw new MBeanException(ex);
    } catch (InvocationTargetException ex1) {
        ex1.printStackTrace();
        throw new MBeanException(ex1);
    }
}

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

/**
 * Obtain the value of a specific attribute that is valid for a specific
 * CrawlerSettings object.<p>//  w  w w .  j a v a2  s  .c o  m
 * 
 * This method will first try to get a settings object from the supplied
 * context, then try to look up the attribute from this settings object. If
 * it is not found it will traverse the settings up to the order and as a
 * last resort deliver the default value.
 * 
 * @param context the object to get the settings from.
 * @param name the name of the attribute to be retrieved.
 * @return The value of the attribute retrieved.
 * @see CrawlerSettings
 * @throws AttributeNotFoundException
 */
public Object getAttribute(Object context, String name) throws AttributeNotFoundException {
    Context ctxt = getSettingsFromObject(context);

    // If settings is not set, return the default value
    if (ctxt.settings == null) {
        try {
            return ((Type) definitionMap.get(name)).getDefaultValue();
        } catch (NullPointerException e) {
            throw new AttributeNotFoundException("Could not find attribute: " + name);
        }
    }

    return getDataContainerRecursive(ctxt, name).get(name);
}

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./*w ww.  j  a va 2  s .  c om*/
 * @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);
    }
}