Example usage for javax.management.modelmbean ModelMBeanAttributeInfo isWritable

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

Introduction

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

Prototype

public boolean isWritable() 

Source Link

Document

Whether new values can be written to the attribute.

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.
 *///from  w  ww .j a v a 2  s.  c  o 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());
    }
}