MBeanAttributeInfopublic class MBeanAttributeInfo extends MBeanFeatureInfo implements CloneableDescribes an MBean attribute exposed for management. Instances of
this class are immutable. Subclasses may be mutable but this is
not recommended. |
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.
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.
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.
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.String | attributeType(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.Object | clone()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 boolean | equals(java.lang.Object o)Compare this MBeanAttributeInfo to another.
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.String | getType()Returns the class name of the attribute.
return attributeType;
| public int | hashCode()
return getName().hashCode() ^ getType().hashCode();
| private static boolean | isIs(java.lang.reflect.Method getter)
return (getter != null &&
getter.getName().startsWith("is") &&
(getter.getReturnType().equals(Boolean.TYPE) ||
getter.getReturnType().equals(Boolean.class)));
| public boolean | isIs()Indicates if this attribute has an "is" getter.
return is;
| public boolean | isReadable()Whether the value of the attribute can be read.
return isRead;
| public boolean | isWritable()Whether new values can be written to the attribute.
return isWrite;
| public java.lang.String | toString()
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() +
"]";
|
|