FileDocCategorySizeDatePackage
MBeanAttributeInfo.javaAPI DocJava SE 6 API10895Tue Jun 10 00:26:12 BST 2008javax.management

MBeanAttributeInfo

public class MBeanAttributeInfo extends MBeanFeatureInfo implements Cloneable
Describes an MBean attribute exposed for management. Instances of this class are immutable. Subclasses may be mutable but this is not recommended.
since
1.5

Fields Summary
private static final long
serialVersionUID
static final MBeanAttributeInfo[]
NO_ATTRIBUTES
private final String
attributeType
private final boolean
isWrite
private final boolean
isRead
private final boolean
is
Constructors Summary
public MBeanAttributeInfo(String name, String type, String description, boolean isReadable, boolean isWritable, boolean isIs)
Constructs an MBeanAttributeInfo object.

param
name The name of the attribute.
param
type The type or class name of the attribute.
param
description A human readable description of the attribute.
param
isReadable True if the attribute has a getter method, false otherwise.
param
isWritable True if the attribute has a setter method, false otherwise.
param
isIs True if this attribute has an "is" getter, false otherwise.
throws
IllegalArgumentException if {@code isIs} is true but {@code isReadable} is not, or if {@code isIs} is true and {@code type} is not {@code boolean} or {@code java.lang.Boolean}. (New code should always use {@code boolean} rather than {@code java.lang.Boolean}.)



                                                                                                                  
      
			       
			       
			       
			       
			        
        this(name, type, description, isReadable, isWritable, isIs,
             (Descriptor) null);
    
public MBeanAttributeInfo(String name, String type, String description, boolean isReadable, boolean isWritable, boolean isIs, Descriptor descriptor)
Constructs an MBeanAttributeInfo object.

param
name The name of the attribute.
param
type The type or class name of the attribute.
param
description A human readable description of the attribute.
param
isReadable True if the attribute has a getter method, false otherwise.
param
isWritable True if the attribute has a setter method, false otherwise.
param
isIs True if this attribute has an "is" getter, false otherwise.
param
descriptor The descriptor for the attribute. This may be null which is equivalent to an empty descriptor.
throws
IllegalArgumentException if {@code isIs} is true but {@code isReadable} is not, or if {@code isIs} is true and {@code type} is not {@code boolean} or {@code java.lang.Boolean}. (New code should always use {@code boolean} rather than {@code java.lang.Boolean}.)
since
1.6

        super(name, description, descriptor);

	this.attributeType = type;
	this.isRead = isReadable;
	this.isWrite = isWritable;
	if (isIs && !isReadable) {
	    throw new IllegalArgumentException("Cannot have an \"is\" getter " +
                                               "for a non-readable attribute");
	}
	if (isIs && !type.equals("java.lang.Boolean") &&
                !type.equals("boolean")) {
	    throw new IllegalArgumentException("Cannot have an \"is\" getter " +
                                               "for a non-boolean attribute");
	}
	this.is = isIs;
    
public MBeanAttributeInfo(String name, String description, Method getter, Method setter)

This constructor takes the name of a simple attribute, and Method objects for reading and writing the attribute. The {@link Descriptor} of the constructed object will include fields contributed by any annotations on the {@code Method} objects that contain the {@link DescriptorKey} meta-annotation.

param
name The programmatic name of the attribute.
param
description A human readable description of the attribute.
param
getter The method used for reading the attribute value. May be null if the property is write-only.
param
setter The method used for writing the attribute value. May be null if the attribute is read-only.
exception
IntrospectionException There is a consistency problem in the definition of this attribute.

        this(name,
	     attributeType(getter, setter),
	     description,
	     (getter != null),
	     (setter != null),
	     isIs(getter),
             ImmutableDescriptor.union(Introspector.descriptorForElement(getter),
                                   Introspector.descriptorForElement(setter)));
    
Methods Summary
private static java.lang.StringattributeType(java.lang.reflect.Method getter, java.lang.reflect.Method setter)
Finds the type of the attribute.

	Class type = null;

	if (getter != null) {
	    if (getter.getParameterTypes().length != 0) {
		throw new IntrospectionException("bad getter arg count");
	    }
	    type = getter.getReturnType();
	    if (type == Void.TYPE) {
		throw new IntrospectionException("getter " + getter.getName() +
						 " returns void");
	    }
	}

	if (setter != null) {
	    Class params[] = setter.getParameterTypes();
	    if (params.length != 1) {
		throw new IntrospectionException("bad setter arg count");
	    }
	    if (type == null)
		type = params[0];
	    else if (type != params[0]) {
		throw new IntrospectionException("type mismatch between " +
						 "getter and setter");
	    }
	}

	if (type == null) {
	    throw new IntrospectionException("getter and setter cannot " +
					     "both be null");
	}

	return type.getName();
    
public java.lang.Objectclone()

Returns a shallow clone of this instance. The clone is obtained by simply calling super.clone(), thus calling the default native shallow cloning mechanism implemented by Object.clone(). No deeper cloning of any internal field is made.

Since this class is immutable, cloning is chiefly of interest to subclasses.

	 try {
	     return super.clone() ;
	 } catch (CloneNotSupportedException e) {
	     // should not happen as this class is cloneable
	     return null;
	 }
     
public booleanequals(java.lang.Object o)
Compare this MBeanAttributeInfo to another.

param
o the object to compare to.
return
true if and only if o is an MBeanAttributeInfo such that its {@link #getName()}, {@link #getType()}, {@link #getDescription()}, {@link #isReadable()}, {@link #isWritable()}, and {@link #isIs()} values are equal (not necessarily identical) to those of this MBeanAttributeInfo.

	if (o == this)
	    return true;
	if (!(o instanceof MBeanAttributeInfo))
	    return false;
	MBeanAttributeInfo p = (MBeanAttributeInfo) o;
	return (p.getName().equals(getName()) &&
		p.getType().equals(getType()) &&
		p.getDescription().equals(getDescription()) &&
                p.getDescriptor().equals(getDescriptor()) &&
		p.isReadable() == isReadable() &&
		p.isWritable() == isWritable() &&
		p.isIs() == isIs());
    
public java.lang.StringgetType()
Returns the class name of the attribute.

return
the class name.

	return attributeType;
    
public inthashCode()

	return getName().hashCode() ^ getType().hashCode();
    
private static booleanisIs(java.lang.reflect.Method getter)

	return (getter != null &&
		getter.getName().startsWith("is") &&
		(getter.getReturnType().equals(Boolean.TYPE) ||
                 getter.getReturnType().equals(Boolean.class)));
    
public booleanisIs()
Indicates if this attribute has an "is" getter.

return
true if this attribute has an "is" getter.

	return is;
    
public booleanisReadable()
Whether the value of the attribute can be read.

return
True if the attribute can be read, false otherwise.

	return isRead;
    
public booleanisWritable()
Whether new values can be written to the attribute.

return
True if the attribute can be written to, false otherwise.

	return isWrite;
    
public java.lang.StringtoString()

        String access;
        if (isReadable()) {
            if (isWritable())
                access = "read/write";
            else
                access = "read-only";
        } else if (isWritable())
            access = "write-only";
        else
            access = "no-access";
        
        return
            getClass().getName() + "[" +
            "description=" + getDescription() + ", " +
            "name=" + getName() + ", " +
            "type=" + getType() + ", " +
            access + ", " +
            (isIs() ? "isIs, " : "") +
            "descriptor=" + getDescriptor() +
            "]";