Example usage for javax.management.modelmbean ModelMBeanAttributeInfo isReadable

List of usage examples for javax.management.modelmbean ModelMBeanAttributeInfo isReadable

Introduction

In this page you can find the example usage for javax.management.modelmbean ModelMBeanAttributeInfo isReadable.

Prototype

public boolean isReadable() 

Source Link

Document

Whether the value of the attribute can be read.

Usage

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

/** Define an attribute.
 * Explicit definition of an attribute. Reflection is used to
 * locate the actual getter and setter methods.
 * @param attrInfo ModelMBeanAttributeInfo.
 *//*  ww w.  j  a  v a 2s  . co  m*/
public synchronized void defineAttribute(ModelMBeanAttributeInfo attrInfo) {
    if (_object == null)
        throw new IllegalStateException("No Object");

    _dirty = true;

    String name = attrInfo.getName();
    String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
    Class oClass = _object.getClass();

    try {
        Class type = TypeUtil.fromName(attrInfo.getType());
        if (type == null)
            type = Thread.currentThread().getContextClassLoader().loadClass(attrInfo.getType());

        Method getter = null;
        Method setter = null;

        if (attrInfo.isReadable())
            getter = oClass.getMethod((attrInfo.isIs() ? "is" : "get") + uName, (java.lang.Class[]) null);

        if (attrInfo.isWritable())
            setter = oClass.getMethod("set" + uName, new Class[] { type });

        _getter.put(name, getter);
        _setter.put(name, setter);
        _attributes.add(attrInfo);
    } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new IllegalArgumentException(e.toString());
    }
}