OpenMBeanInfoSupportpublic class OpenMBeanInfoSupport extends MBeanInfo implements OpenMBeanInfoThe {@code OpenMBeanInfoSupport} class describes the management
information of an open MBean: it is a subclass of {@link
javax.management.MBeanInfo}, and it implements the {@link
OpenMBeanInfo} interface. Note that an open MBean is
recognized as such if its {@code getMBeanInfo()} method returns an
instance of a class which implements the OpenMBeanInfo interface,
typically {@code OpenMBeanInfoSupport}. |
Fields Summary |
---|
static final long | serialVersionUID | private transient Integer | myHashCode | private transient String | myToString |
Constructors Summary |
---|
public OpenMBeanInfoSupport(String className, String description, OpenMBeanAttributeInfo[] openAttributes, OpenMBeanConstructorInfo[] openConstructors, OpenMBeanOperationInfo[] openOperations, MBeanNotificationInfo[] notifications)Constructs an {@code OpenMBeanInfoSupport} instance, which
describes a class of open MBeans with the specified {@code
className}, {@code description}, {@code openAttributes}, {@code
openConstructors} , {@code openOperations} and {@code
notifications}.
The {@code openAttributes}, {@code openConstructors},
{@code openOperations} and {@code notifications}
array parameters are internally copied, so that subsequent changes
to the arrays referenced by these parameters have no effect on this
instance.
this(className, description,
openAttributes, openConstructors, openOperations, notifications,
(Descriptor) null);
| public OpenMBeanInfoSupport(String className, String description, OpenMBeanAttributeInfo[] openAttributes, OpenMBeanConstructorInfo[] openConstructors, OpenMBeanOperationInfo[] openOperations, MBeanNotificationInfo[] notifications, Descriptor descriptor)Constructs an {@code OpenMBeanInfoSupport} instance, which
describes a class of open MBeans with the specified {@code
className}, {@code description}, {@code openAttributes}, {@code
openConstructors} , {@code openOperations}, {@code
notifications}, and {@code descriptor}.
The {@code openAttributes}, {@code openConstructors}, {@code
openOperations} and {@code notifications} array parameters are
internally copied, so that subsequent changes to the arrays
referenced by these parameters have no effect on this
instance.
super(className,
description,
attributeArray(openAttributes),
constructorArray(openConstructors),
operationArray(openOperations),
(notifications == null) ? null : notifications.clone(),
descriptor);
|
Methods Summary |
---|
private static int | arraySetHash(T[] a)
return new HashSet<T>(Arrays.asList(a)).hashCode();
| private static javax.management.MBeanAttributeInfo[] | attributeArray(javax.management.openmbean.OpenMBeanAttributeInfo[] src)
if (src == null)
return null;
MBeanAttributeInfo[] dst = new MBeanAttributeInfo[src.length];
System.arraycopy(src, 0, dst, 0, src.length);
// may throw an ArrayStoreException
return dst;
| private static javax.management.MBeanConstructorInfo[] | constructorArray(javax.management.openmbean.OpenMBeanConstructorInfo[] src)
if (src == null)
return null;
MBeanConstructorInfo[] dst = new MBeanConstructorInfo[src.length];
System.arraycopy(src, 0, dst, 0, src.length);
// may throw an ArrayStoreException
return dst;
| public boolean | equals(java.lang.Object obj)Compares the specified {@code obj} parameter with this
{@code OpenMBeanInfoSupport} instance for equality.
Returns {@code true} if and only if all of the following
statements are true:
- {@code obj} is non null,
- {@code obj} also implements the {@code OpenMBeanInfo}
interface,
- their class names are equal
- their infos on attributes, constructors, operations and
notifications are equal
This ensures that this {@code equals} method works properly for
{@code obj} parameters which are different implementations of
the {@code OpenMBeanInfo} interface.
// if obj is null, return false
//
if (obj == null) {
return false;
}
// if obj is not a OpenMBeanInfo, return false
//
OpenMBeanInfo other;
try {
other = (OpenMBeanInfo) obj;
} catch (ClassCastException e) {
return false;
}
// Now, really test for equality between this OpenMBeanInfo
// implementation and the other:
//
// their MBean className should be equal
if ( ! this.getClassName().equals(other.getClassName()) )
return false;
// their infos on attributes should be equal (order not
// significant => equality between sets, not arrays or lists)
if (!sameArrayContents(this.getAttributes(), other.getAttributes()))
return false;
// their infos on constructors should be equal (order not
// significant => equality between sets, not arrays or lists)
if (!sameArrayContents(this.getConstructors(), other.getConstructors()))
return false;
// their infos on operations should be equal (order not
// significant => equality between sets, not arrays or lists)
if (!sameArrayContents(this.getOperations(), other.getOperations()))
return false;
// their infos on notifications should be equal (order not
// significant => equality between sets, not arrays or lists)
if (!sameArrayContents(this.getNotifications(), other.getNotifications()))
return false;
// All tests for equality were successful
//
return true;
| public int | hashCode()Returns the hash code value for this {@code
OpenMBeanInfoSupport} instance.
The hash code of an {@code OpenMBeanInfoSupport} instance is
the sum of the hash codes of all elements of information used
in {@code equals} comparisons (ie: its class name, and its
infos on attributes, constructors, operations and
notifications, where the hashCode of each of these arrays is
calculated by a call to {@code new
java.util.HashSet(java.util.Arrays.asList(this.getSignature)).hashCode()}).
This ensures that {@code t1.equals(t2)} implies that {@code
t1.hashCode()==t2.hashCode()} for any two {@code
OpenMBeanInfoSupport} instances {@code t1} and {@code t2}, as
required by the general contract of the method {@link
Object#hashCode() Object.hashCode()}.
However, note that another instance of a class implementing
the {@code OpenMBeanInfo} interface may be equal to this {@code
OpenMBeanInfoSupport} instance as defined by {@link
#equals(java.lang.Object)}, but may have a different hash code
if it is calculated differently.
As {@code OpenMBeanInfoSupport} instances are immutable, the
hash code for this instance is calculated once, on the first
call to {@code hashCode}, and then the same value is returned
for subsequent calls.
// Calculate the hash code value if it has not yet been done
// (ie 1st call to hashCode())
//
if (myHashCode == null) {
int value = 0;
value += this.getClassName().hashCode();
value += arraySetHash(this.getAttributes());
value += arraySetHash(this.getConstructors());
value += arraySetHash(this.getOperations());
value += arraySetHash(this.getNotifications());
myHashCode = new Integer(value);
}
// return always the same hash code for this instance (immutable)
//
return myHashCode.intValue();
| private static javax.management.MBeanOperationInfo[] | operationArray(javax.management.openmbean.OpenMBeanOperationInfo[] src)
if (src == null)
return null;
MBeanOperationInfo[] dst = new MBeanOperationInfo[src.length];
System.arraycopy(src, 0, dst, 0, src.length);
return dst;
| private static boolean | sameArrayContents(T[] a1, T[] a2)
return (new HashSet<T>(Arrays.asList(a1))
.equals(new HashSet<T>(Arrays.asList(a2))));
| public java.lang.String | toString()Returns a string representation of this {@code
OpenMBeanInfoSupport} instance.
The string representation consists of the name of this class
(ie {@code javax.management.openmbean.OpenMBeanInfoSupport}),
the MBean class name, the string representation of infos on
attributes, constructors, operations and notifications of the
described MBean and the string representation of the descriptor.
As {@code OpenMBeanInfoSupport} instances are immutable, the
string representation for this instance is calculated once, on
the first call to {@code toString}, and then the same value is
returned for subsequent calls.
// Calculate the string value if it has not yet been done (ie
// 1st call to toString())
//
if (myToString == null) {
myToString = new StringBuffer()
.append(this.getClass().getName())
.append("(mbean_class_name=")
.append(this.getClassName())
.append(",attributes=")
.append(Arrays.asList(this.getAttributes()).toString())
.append(",constructors=")
.append(Arrays.asList(this.getConstructors()).toString())
.append(",operations=")
.append(Arrays.asList(this.getOperations()).toString())
.append(",notifications=")
.append(Arrays.asList(this.getNotifications()).toString())
.append(",descriptor=")
.append(this.getDescriptor())
.append(")")
.toString();
}
// return always the same string representation for this
// instance (immutable)
//
return myToString;
|
|