Example usage for javax.management.modelmbean ModelMBeanAttributeInfo getType

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

Introduction

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

Prototype

public String getType() 

Source Link

Document

Returns the class name of 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 w  w.  j a va2s. c om
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());
    }
}