package javax.management.openmbean;
import java.io.Serializable;
import java.util.Arrays;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
public class OpenMBeanInfoSupport
extends MBeanInfo
implements OpenMBeanInfo, Serializable
{
private static final long serialVersionUID = 4349395935420511492L;
private transient int cachedHashCode;
private transient String cachedToString;
private static MBeanAttributeInfo[] convertArray(OpenMBeanAttributeInfo[] array)
{
if (array == null)
return null;
MBeanAttributeInfo[] result = new MBeanAttributeInfo[array.length];
System.arraycopy(array, 0, result, 0, array.length);
return result;
}
private static MBeanConstructorInfo[] convertArray(OpenMBeanConstructorInfo[] array)
{
if (array == null)
return null;
MBeanConstructorInfo[] result = new MBeanConstructorInfo[array.length];
System.arraycopy(array, 0, result, 0, array.length);
return result;
}
private static MBeanOperationInfo[] convertArray(OpenMBeanOperationInfo[] array)
{
if (array == null)
return null;
MBeanOperationInfo[] result = new MBeanOperationInfo[array.length];
System.arraycopy(array, 0, result, 0, array.length);
return result;
}
public OpenMBeanInfoSupport(String className, String description,
OpenMBeanAttributeInfo[] attributes,
OpenMBeanConstructorInfo[] constructors,
OpenMBeanOperationInfo[] operations,
MBeanNotificationInfo[] notifications)
{
super(className, description, convertArray(attributes), convertArray(constructors),
convertArray(operations), notifications);
}
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null || !(obj instanceof OpenMBeanInfoSupport))
return false;
OpenMBeanInfo other = (OpenMBeanInfo) obj;
if (getClassName().equals(other.getClassName()) == false)
return false;
if (compareArray(getAttributes(), other.getAttributes()) == false)
return false;
if (compareArray(getConstructors(), other.getConstructors()) == false)
return false;
if (compareArray(getNotifications(), other.getNotifications()) == false)
return false;
if (compareArray(getOperations(), other.getOperations()) == false)
return false;
return true;
}
public int hashCode()
{
if (cachedHashCode != 0)
return cachedHashCode;
cachedHashCode = getClassName().hashCode();
MBeanAttributeInfo[] attrs = getAttributes();
for (int i = 0; i < attrs.length; i++)
cachedHashCode += attrs[i].hashCode();
MBeanConstructorInfo[] ctors = getConstructors();
for (int i = 0; i < ctors.length; i++)
cachedHashCode += ctors[i].hashCode();
MBeanNotificationInfo[] notify = getNotifications();
for (int i = 0; i < notify.length; i++)
cachedHashCode += notify[i].hashCode();
MBeanOperationInfo[] ops = getOperations();
for (int i = 0; i < ops.length; i++)
cachedHashCode += ops[i].hashCode();
return cachedHashCode;
}
public String toString()
{
if (cachedToString != null)
return cachedToString;
StringBuffer buffer = new StringBuffer(getClass().getName());
buffer.append(": className=");
buffer.append(getClassName());
buffer.append(", attributes=");
buffer.append(Arrays.asList(getAttributes()));
buffer.append(", constructors=");
buffer.append(Arrays.asList(getConstructors()));
buffer.append(", notifications=");
buffer.append(Arrays.asList(getNotifications()));
buffer.append(", operations=");
buffer.append(Arrays.asList(getOperations()));
cachedToString = buffer.toString();
return cachedToString;
}
private boolean compareArray(Object[] one, Object[] two)
{
if (one.length != two.length)
return false;
if (Arrays.asList(one).containsAll(Arrays.asList(two)) == false)
return false;
return true;
}
}