mx4j/src/core/javax/management/openmbean OpenMBeanAttributeInfoSupport.java,1.12,1.13 OpenMBeanConstructorInfoSupport.java,1.4,1.5 OpenMBeanInfoSupport.java,1.8,1.9 OpenMBeanOperationInfoSupport.java,1.9,1.10 OpenMBeanParameterInfoSupport.java,1.7,1.8
Simone Bordet <[email protected]> Tue, 05 Oct 2004 09:46:23 +0000
| Newsgroups | gmane.comp.java.mx4j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7692/src/core/javax/management/openmbean Modified Files: OpenMBeanAttributeInfoSupport.java OpenMBeanConstructorInfoSupport.java OpenMBeanInfoSupport.java OpenMBeanOperationInfoSupport.java OpenMBeanParameterInfoSupport.java Log Message: Fix for bug #1033138: hashCode() and equals() were not spec-compliant. Also taken the chance to clean up openmbean code. Index: OpenMBeanConstructorInfoSupport.java =================================================================== RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean/OpenMBeanConstructorInfoSupport.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OpenMBeanConstructorInfoSupport.java 4 Sep 2004 15:44:05 -0000 1.4 --- OpenMBeanConstructorInfoSupport.java 5 Oct 2004 09:46:21 -0000 1.5 *************** *** 15,26 **** /** - * * @author <a href="mailto:[email protected]">Bronwen Cassidy</a> * @version $Revision$ */ - - /** - * Describes a constructor of an openMBean - */ public class OpenMBeanConstructorInfoSupport extends MBeanConstructorInfo implements OpenMBeanConstructorInfo, Serializable { --- 15,21 ---- *************** *** 30,60 **** private transient int m_hashcode = 0; - /** - * <p>Constructs an OpenMBeanConstructorInfoSupport instance, which describes the constructor of a class of open MBeans with the specified name, description and signature</p> - * <p>The signature array parameter is internally copied, so that subsequent changes to the array referenced by signature have no effect on this instance</p> - * - * @param name - cannot be a null or empty string - * @param description - cannot be a null or empty string - * @param signature - can be null or empty if there are no parameters to describe - * @throws IllegalArgumentException - if name or description are null or empty string - * @throws ArrayStoreException - If signature is not an array of instances of a subclass of MBeanParameterInfo - */ public OpenMBeanConstructorInfoSupport(String name, String description, OpenMBeanParameterInfo[] signature) { ! super(name, ! description, ! signature == null ! ? null ! : (MBeanParameterInfo[])Arrays.asList(signature).toArray(new MBeanParameterInfo[0])); ! if (name == null || name.trim().equals("")) throw new IllegalArgumentException("name parameter cannot be null or an empty string"); ! if (description == null || description.trim().equals("")) throw new IllegalArgumentException("description parameter cannot be null or an empty string"); } - /** - * Tests if the object given in the parameter is equal to this instance - * - * @param obj the object to test for equality - * @return true if equals false otherwise - */ public boolean equals(Object obj) { --- 25,35 ---- private transient int m_hashcode = 0; public OpenMBeanConstructorInfoSupport(String name, String description, OpenMBeanParameterInfo[] signature) { ! super(name, description, signature == null ? null : (MBeanParameterInfo[])Arrays.asList(signature).toArray(new MBeanParameterInfo[0])); ! if (name == null || name.trim().length() == 0) throw new IllegalArgumentException("name parameter cannot be null or an empty string"); ! if (description == null || description.trim().length() == 0) throw new IllegalArgumentException("description parameter cannot be null or an empty string"); } public boolean equals(Object obj) { *************** *** 64,70 **** } - /** - * @return the calculated hashCode for this instance. The same values tested for in equals are used to calculate the hashCode - */ public int hashCode() { --- 39,42 ---- *************** *** 78,100 **** } - /** - * @return the human readable representation of this instance - */ public String toString() { return (getClass().getName() + " ( name = " + getName() + " signature = " + Arrays.asList(getSignature()).toString() + " )"); } - - - /** - * fullfills the constructor contract that the signature array parameter is internally copied, so that subsequent changes to the array referenced by signature have no effect on this instance - * the ArrayStoreException is thrown by the System.arraycopy method if an element in the <code>src</code> - * array could not be stored into the <code>dest</code> array because of a type mismatch. - */ - private static MBeanParameterInfo[] copyParameterInfo(OpenMBeanParameterInfo[] signature) throws ArrayStoreException - { - MBeanParameterInfo[] parameterInfo = new MBeanParameterInfo[signature.length]; - System.arraycopy(signature, 0, parameterInfo, 0, signature.length); - return parameterInfo; - } } --- 50,56 ---- Index: OpenMBeanInfoSupport.java =================================================================== RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean/OpenMBeanInfoSupport.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** OpenMBeanInfoSupport.java 4 Sep 2004 15:44:05 -0000 1.8 --- OpenMBeanInfoSupport.java 5 Oct 2004 09:46:21 -0000 1.9 *************** *** 29,91 **** private transient int hashCode = 0; ! /** ! * Creates an OpenMBeanInfoSupport. ! * ! * @param className The fully qualified class name of the OpenMBean ! * @param description The description ! */ ! public OpenMBeanInfoSupport(String className, String description, ! OpenMBeanAttributeInfo[] openAttributes, ! OpenMBeanConstructorInfo[] openConstructors, ! OpenMBeanOperationInfo[] openOperations, ! MBeanNotificationInfo[] notifications) { ! //we cant pass this directly because ! //OpenMBean*Info and friends isn't a direct subclass ! //of their MBean*Info counterpart but the *Support ! //We need to do an ! //arraycopy for this to work and the implementation should ! //be a subclass of thir MBean*Support counterpart ! super(className, description, ! createMBeanAttributes(openAttributes), ! createMBeanConstructors(openConstructors), ! createMBeanOperations(openOperations), ! notifications); ! } - - /** - * Check the given obj for equality - */ public boolean equals(Object obj) { if (obj == null) return false; if (obj == this) return true; ! try ! { ! OpenMBeanInfo other = (OpenMBeanInfo)obj; ! if ((getClassName() == null && other.getClassName() == null) || ! (getClassName() != null && getClassName().equals(other.getClassName()))) ! { ! if (!Arrays.equals(getConstructors(), other.getConstructors())) return false; ! if (!Arrays.equals(getAttributes(), other.getAttributes())) return false; ! if (!Arrays.equals(getOperations(), other.getOperations())) return false; ! if (!Arrays.equals(getNotifications(), other.getNotifications())) return false; ! return true; ! } ! } ! catch (ClassCastException ignored) ! { ! } ! return false; } - /** - * Returns the hashCode of this OpenMBeanInfoSupport - * - * @return int The hashCode - */ public int hashCode() { --- 29,61 ---- private transient int hashCode = 0; ! public OpenMBeanInfoSupport(String className, String description, OpenMBeanAttributeInfo[] openAttributes, OpenMBeanConstructorInfo[] openConstructors, OpenMBeanOperationInfo[] openOperations, MBeanNotificationInfo[] notifications) { ! // We cant pass this directly because OpenMBean*Info ! // and friends isn't a direct subclass of their MBean*Info ! // counterpart but the *Support. We need to do an arraycopy ! // for this to work and the implementation should be a ! // subclass of thir MBean*Support counterpart ! super(className, description, createMBeanAttributes(openAttributes), createMBeanConstructors(openConstructors), createMBeanOperations(openOperations), notifications); } public boolean equals(Object obj) { if (obj == null) return false; if (obj == this) return true; + if (!(obj instanceof OpenMBeanInfo)) return false; ! OpenMBeanInfo other = (OpenMBeanInfo)obj; ! String thisClassName = getClassName(); ! String otherClassName = other.getClassName(); ! if (thisClassName != null ? !thisClassName.equals(otherClassName) : otherClassName != null) return false; ! ! if (!Arrays.equals(getConstructors(), other.getConstructors())) return false; ! if (!Arrays.equals(getAttributes(), other.getAttributes())) return false; ! if (!Arrays.equals(getOperations(), other.getOperations())) return false; ! if (!Arrays.equals(getNotifications(), other.getNotifications())) return false; ! ! return true; } public int hashCode() { *************** *** 102,106 **** } - /** * Helper Method for OpenMBeanAttributeInfo[] to MBeanAttributeInfo[] --- 72,75 ---- *************** *** 109,117 **** { if (attributes == null) return null; ! MBeanAttributeInfo[] attrInfo = ! new MBeanAttributeInfo[attributes.length]; ! System.arraycopy(attributes, 0, attrInfo, 0, attrInfo.length); - return attrInfo; } --- 78,83 ---- { if (attributes == null) return null; ! MBeanAttributeInfo[] attrInfo = new MBeanAttributeInfo[attributes.length]; System.arraycopy(attributes, 0, attrInfo, 0, attrInfo.length); return attrInfo; } *************** *** 122,133 **** private static MBeanConstructorInfo[] createMBeanConstructors(OpenMBeanConstructorInfo[] constructors) throws ArrayStoreException { - if (constructors == null) return null; ! ! MBeanConstructorInfo[] constInfo = ! new MBeanConstructorInfo[constructors.length]; ! System.arraycopy(constructors, 0, constInfo, 0, constInfo.length); - return constInfo; } --- 88,94 ---- private static MBeanConstructorInfo[] createMBeanConstructors(OpenMBeanConstructorInfo[] constructors) throws ArrayStoreException { if (constructors == null) return null; ! MBeanConstructorInfo[] constInfo = new MBeanConstructorInfo[constructors.length]; System.arraycopy(constructors, 0, constInfo, 0, constInfo.length); return constInfo; } *************** *** 138,152 **** private static MBeanOperationInfo[] createMBeanOperations(OpenMBeanOperationInfo[] operations) throws ArrayStoreException { - if (operations == null) return null; ! ! MBeanOperationInfo[] operInfo = ! new MBeanOperationInfo[operations.length]; ! System.arraycopy(operations, 0, operInfo, 0, operInfo.length); - return operInfo; } - - } --- 99,106 ---- private static MBeanOperationInfo[] createMBeanOperations(OpenMBeanOperationInfo[] operations) throws ArrayStoreException { if (operations == null) return null; ! MBeanOperationInfo[] operInfo = new MBeanOperationInfo[operations.length]; System.arraycopy(operations, 0, operInfo, 0, operInfo.length); return operInfo; } } Index: OpenMBeanParameterInfoSupport.java =================================================================== RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean/OpenMBeanParameterInfoSupport.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** OpenMBeanParameterInfoSupport.java 4 Sep 2004 15:44:05 -0000 1.7 --- OpenMBeanParameterInfoSupport.java 5 Oct 2004 09:46:21 -0000 1.8 *************** *** 12,16 **** import java.util.Collections; import java.util.HashSet; - import java.util.Iterator; import java.util.Set; import javax.management.MBeanParameterInfo; --- 12,15 ---- *************** *** 20,27 **** * @version $Revision$ */ - - /** - * Describes a parameter used in one or more operations or constructors of an open MBean - */ public class OpenMBeanParameterInfoSupport extends MBeanParameterInfo implements OpenMBeanParameterInfo, Serializable { --- 19,22 ---- *************** *** 36,71 **** private transient int m_hashcode = 0; - /** - * No validation done for null values is done here. - * Constructs an OpenMBeanParameterInfoSupport instance, which describes the parameter used in one or more operations or constructors of a class of open MBeans, - * with the specified name, openType and description. - * - * @param name - cannot be a null or empty string - * @param description - cannot be a null or empty string. - * @param openType - cannot be null - * @throws IllegalArgumentException - if name or description are null or empty string, or openType is null. - */ public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType) { super(name, openType == null ? "" : openType.getClassName(), description); ! if (name == null || name.trim().equals("")) throw new IllegalArgumentException("name parameter cannot be null or an empty string."); ! if (description == null || description.trim().equals("")) throw new IllegalArgumentException("description parameter cannot be null or an empty string."); if (openType == null) throw new IllegalArgumentException("OpenType parameter cannot be null."); this.openType = openType; } - /** - * Constructs an OpenMBeanParameterInfoSupport instance, which describes the parameter used in one or more operations or constructors of a class of open MBeans, with the specified name, - * openType, description and defaultValue. - * - * @param name - cannot be a null or empty string. - * @param description - cannot be a null or empty string. - * @param openType - cannot be null. - * @param defaultValue - must be a valid value for the openType specified for this parameter; - * default value not supported for ArrayType and TabularType; - * can be null, in which case it means that no default value is set. - * @throws IllegalArgumentException - if name or description are null or empty string, or openType is null - * @throws OpenDataException - if defaultValue is not a valid value for the specified openType, or defaultValue is non null and openType is an ArrayType or a TabularType. - */ public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType, Object defaultValue) throws OpenDataException { --- 31,43 ---- private transient int m_hashcode = 0; public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType) { super(name, openType == null ? "" : openType.getClassName(), description); ! if (name == null || name.trim().length() == 0) throw new IllegalArgumentException("name parameter cannot be null or an empty string."); ! if (description == null || description.trim().length() == 0) throw new IllegalArgumentException("description parameter cannot be null or an empty string."); if (openType == null) throw new IllegalArgumentException("OpenType parameter cannot be null."); this.openType = openType; } public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType, Object defaultValue) throws OpenDataException { *************** *** 79,100 **** } - /** - * Constructs an OpenMBeanParameterInfoSupport instance, which describes the parameter used in one or more operations or constructors of a class of open MBeans, with the specified name, - * openType, description, defaultValue and legalValues. The contents of legalValues are internally dumped into an unmodifiable Set, so subsequent modifications of the array referenced - * by legalValues have no impact on this OpenMBeanParameterInfoSupport instance - * - * @param name - cannot be a null or empty string. - * @param description - cannot be a null or empty string. - * @param openType - cannot be null. - * @param defaultValue - must be a valid value for the openType specified for this parameter; - * default value not supported for ArrayType and TabularType; - * can be null, in which case it means that no default value is set. - * @param legalValues - each contained value must be valid for the openType specified for this parameter; legal values not supported for ArrayType and TabularType; can be null or empty - * @throws IllegalArgumentException - if name or description are null or empty string, or openType is null. - * @throws OpenDataException - if defaultValue is not a valid value for the specified openType, or one value in legalValues is not valid for the specified openType, - * or defaultValue is non null and openType is an ArrayType or a TabularType, - * or legalValues is non null and non empty and openType is an ArrayType or a TabularType, - * or legalValues is non null and non empty and defaultValue is not contained in legalValues. - */ public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType, Object defaultValue, Object[] legalValues) throws OpenDataException { --- 51,54 ---- *************** *** 113,135 **** } - /** - * Constructs an OpenMBeanParameterInfoSupport instance, which describes the parameter used in one or more operations or constructors of a class of open MBeans, - * with the specified name, openType, description, defaultValue, minValue and maxValue. It is possible to specify minimal and maximal values only for an open type whose values are Comparable - * - * @param name - cannot be a null or empty string. - * @param description - cannot be a null or empty string - * @param openType - cannot be null. - * @param defaultValue - must be a valid value for the openType specified for this parameter; - * default value not supported for ArrayType and TabularType; - * can be null, in which case it means that no default value is set. - * @param minValue - must be valid for the openType specified for this parameter; can be null, in which case it means that no minimal value is set. - * @param maxValue - must be valid for the openType specified for this parameter; can be null, in which case it means that no maximal value is set. - * @throws IllegalArgumentException - if name or description are null or empty string, or openType is null. - * @throws OpenDataException - if defaultValue, minValue or maxValue is not a valid value for the specified openType, - * or defaultValue is non null and openType is an ArrayType or a TabularType, - * or both minValue and maxValue are non-null and minValue.compareTo(maxValue) > 0 is true, - * or both defaultValue and minValue are non-null and minValue.compareTo(defaultValue) > 0 is true, - * or both defaultValue and maxValue are non-null and defaultValue.compareTo(maxValue) > 0 is true. - */ public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType, Object defaultValue, Comparable minValue, Comparable maxValue) throws OpenDataException { --- 67,70 ---- *************** *** 147,156 **** } if (hasMinValue() && hasMaxValue() && minValue.compareTo(maxValue) > 0) throw new OpenDataException("minValue cannot be greater than maxValue."); ! if (hasDefaultValue() && hasMinValue() && minValue.compareTo((Comparable)defaultValue) > 0) throw new OpenDataException("minValue cannot be greater than defaultValue."); if (hasDefaultValue() && hasMaxValue() && ((Comparable)defaultValue).compareTo(maxValue) > 0) throw new OpenDataException("defaultValue cannot be greater than maxValue."); } /** ! * assigns the validated Object[] into the set legal values as the constructor states this is unmodifiable will create an unmodifiable set */ private void assignLegalValues(Object[] legalValues) --- 82,92 ---- } if (hasMinValue() && hasMaxValue() && minValue.compareTo(maxValue) > 0) throw new OpenDataException("minValue cannot be greater than maxValue."); ! if (hasDefaultValue() && hasMinValue() && minValue.compareTo(defaultValue) > 0) throw new OpenDataException("minValue cannot be greater than defaultValue."); if (hasDefaultValue() && hasMaxValue() && ((Comparable)defaultValue).compareTo(maxValue) > 0) throw new OpenDataException("defaultValue cannot be greater than maxValue."); } /** ! * Assigns the validated Object[] into the set legal values as the constructor states ! * this is unmodifiable will create an unmodifiable set */ private void assignLegalValues(Object[] legalValues) *************** *** 164,170 **** } - /** - * @return the open type for the values of the parameter described by this OpenMBeanParameterInfoSupport instance. - */ public OpenType getOpenType() { --- 100,103 ---- *************** *** 172,178 **** } - /** - * @return the default value for the parameter described by this OpenMBeanParameterInfoSupport instance, if specified, or null otherwise. - */ public Object getDefaultValue() { --- 105,108 ---- *************** *** 180,186 **** } - /** - * @return an unmodifiable Set of legal values for the parameter described by this OpenMBeanParameterInfoSupport instance, if specified, or null otherwise - */ public Set getLegalValues() { --- 110,113 ---- *************** *** 188,194 **** } - /** - * @return the minimal value for the parameter described by this OpenMBeanParameterInfoSupport instance, if specified, or null otherwise. - */ public Comparable getMinValue() { --- 115,118 ---- *************** *** 196,202 **** } - /** - * @return the maximal value for the parameter described by this OpenMBeanParameterInfoSupport instance, if specified, or null otherwise. - */ public Comparable getMaxValue() { --- 120,123 ---- *************** *** 204,210 **** } - /** - * @return true if defaultValue is specified (i.e not null) false otherwise - */ public boolean hasDefaultValue() { --- 125,128 ---- *************** *** 212,218 **** } - /** - * @return true if legalValues is specified, false if legalValues is null - */ public boolean hasLegalValues() { --- 130,133 ---- *************** *** 220,226 **** } - /** - * @return true if minValue is specified, false if minValue is null - */ public boolean hasMinValue() { --- 135,138 ---- *************** *** 228,234 **** } - /** - * @return true if maxValue is specified, false if maxValue is null - */ public boolean hasMaxValue() { --- 140,143 ---- *************** *** 236,251 **** } - /** - * Tests wether obj is a valid value for the parameter described by this OpenMBeanParameterInfo instance - * - * @param obj - the Object to test if is a valid value - * @return true if obj is a valid value false otherwise. - * A valid value is determined by - * <ul> - * <li>if <tt>openType.isValue(obj)</tt> returns true</li> - * <li>if legalValues is present and <tt>legalValues.contains(obj)</tt> returns true</li> - * <li>if minValue and maxValue compare to obj with minValue being less than obj and maxValue being greater than obj</li> - * </ul> - */ public boolean isValue(Object obj) { --- 145,148 ---- *************** *** 260,304 **** } - /** - * Compares the specified obj parameter with this OpenMBeanParameterInfoSupport instance for equality. - * - * @return true if and only if all of the following statements are true: - * <ul> - * <li>obj is non null</li> - * <li>obj also implements the OpenMBeanParameterInfo interface</li> - * <li>their names are equal</li> - * <li>their open types are equal</li> - * <li>their default, min, max and legal values are equal and if present in this instance msut be present in obj</li> - * </ul> - */ public boolean equals(Object obj) { ! if (!(obj instanceof OpenMBeanParameterInfo)) ! return false; OpenMBeanParameterInfo paramObj = (OpenMBeanParameterInfo)obj; ! if (!getName().equals(paramObj.getName()) || !getOpenType().equals(paramObj.getOpenType())) ! return false; ! if (hasDefaultValue() && (!getDefaultValue().equals(paramObj.getDefaultValue()))) ! return false; ! if (!hasDefaultValue() && paramObj.hasDefaultValue()) ! return false; ! if (hasMinValue() && !(getMinValue().equals(paramObj.getMinValue()))) ! return false; ! if (!hasMinValue() && paramObj.hasMinValue()) ! return false; ! if (hasMaxValue() && !(getMaxValue().equals(paramObj.getMaxValue()))) ! return false; ! if (!hasMaxValue() && paramObj.hasMaxValue()) ! return false; ! if (hasLegalValues() && !(getLegalValues().equals(paramObj.getLegalValues()))) ! return false; ! if (!hasLegalValues() && paramObj.hasLegalValues()) ! return false; return true; --- 157,182 ---- } public boolean equals(Object obj) { ! if (obj == this) return true; ! if (obj == null) return false; ! if (!(obj instanceof OpenMBeanParameterInfo)) return false; OpenMBeanParameterInfo paramObj = (OpenMBeanParameterInfo)obj; ! if (!getName().equals(paramObj.getName())) return false; ! if (!getOpenType().equals(paramObj.getOpenType())) return false; ! if (hasDefaultValue() && (!getDefaultValue().equals(paramObj.getDefaultValue()))) return false; ! if (!hasDefaultValue() && paramObj.hasDefaultValue()) return false; ! if (hasMinValue() && !(getMinValue().equals(paramObj.getMinValue()))) return false; ! if (!hasMinValue() && paramObj.hasMinValue()) return false; ! if (hasMaxValue() && !(getMaxValue().equals(paramObj.getMaxValue()))) return false; ! if (!hasMaxValue() && paramObj.hasMaxValue()) return false; ! if (hasLegalValues() && !(getLegalValues().equals(paramObj.getLegalValues()))) return false; ! if (!hasLegalValues() && paramObj.hasLegalValues()) return false; return true; *************** *** 309,313 **** if (m_hashcode == 0) { ! m_hashcode = hashCode(this); } return m_hashcode; --- 187,197 ---- if (m_hashcode == 0) { ! int result = getName().hashCode(); ! result += getOpenType().hashCode(); ! result += (hasDefaultValue() == false) ? 0 : getDefaultValue().hashCode(); ! result += (hasLegalValues() == false) ? 0 : getLegalValues().hashCode(); ! result += (hasMinValue() == false) ? 0 : getMinValue().hashCode(); ! result += (hasMaxValue() == false) ? 0 : getMaxValue().hashCode(); ! m_hashcode = result; } return m_hashcode; *************** *** 332,357 **** return buf.toString(); } - - private int hashCode(OpenMBeanParameterInfo info) - { - int result = info.getName().hashCode(); - result += info.getOpenType().hashCode(); - result += (info.hasDefaultValue() == false) ? 0 : info.getDefaultValue().hashCode(); - result += (info.hasLegalValues() == false) ? 0 : hashCode(info.getLegalValues()); - result += (info.hasMinValue() == false) ? 0 : info.getMinValue().hashCode(); - result += (info.hasMaxValue() == false) ? 0 : info.getMaxValue().hashCode(); - return result; - } - - private int hashCode(Set legalvalues) - { - int result = 0; - Iterator i = legalvalues.iterator(); - while (i.hasNext()) - { - Object v = i.next(); - result += v.hashCode(); - } - return result; - } } --- 216,218 ---- Index: OpenMBeanOperationInfoSupport.java =================================================================== RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean/OpenMBeanOperationInfoSupport.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** OpenMBeanOperationInfoSupport.java 4 Sep 2004 15:44:05 -0000 1.9 --- OpenMBeanOperationInfoSupport.java 5 Oct 2004 09:46:21 -0000 1.10 *************** *** 14,21 **** import javax.management.MBeanParameterInfo; - /** - * Describes an operation of an <code>OpenMBean</code> - * * @author <a href="mailto:[email protected]">Bronwen Cassidy</a> * @author <a href="mailto:[email protected]">Warren Mira</a> --- 14,18 ---- *************** *** 31,74 **** private transient String toStringName = null; ! /** ! * Creates an instance of <code>OpenMBeanOperationInfoSupport</code> ! * ! * @param name The name of this operation ! * @param description The description ! * @param signature The parameter[s] of this operation ! * @param returnOpenType The return type ! * @param impact The impact of the operation ! * @throws ArrayStoreException If signature is not of type {@link MBeanParameterInfo } ! * @see OpenMBeanOperationInfo#getImpact ! */ ! public OpenMBeanOperationInfoSupport(String name, ! String description, ! OpenMBeanParameterInfo[] signature, ! OpenType returntype, ! int impact) { ! super(name, ! description, ! (signature == null) ! ? (MBeanParameterInfo[])Arrays.asList(new OpenMBeanParameterInfo[0]).toArray(new MBeanParameterInfo[0]) ! : (MBeanParameterInfo[])Arrays.asList(signature).toArray(new MBeanParameterInfo[0]), ! returntype == null ? "" : returntype.getClassName(), ! impact); ! // super class constructors don't do the necessary validation ! if (name == null || name.length() == 0) ! { ! throw new IllegalArgumentException("name cannot be null or empty"); ! } ! if (description == null || description.length() == 0) ! { ! throw new IllegalArgumentException("descripiton cannot be null or empty"); ! } ! if (returntype == null) ! { ! throw new IllegalArgumentException("return open type cannont be null"); ! } if (impact != MBeanOperationInfo.ACTION --- 28,41 ---- private transient String toStringName = null; ! public OpenMBeanOperationInfoSupport(String name, String description, OpenMBeanParameterInfo[] signature, OpenType returntype, int impact) { ! super(name, description, (signature == null) ? (MBeanParameterInfo[])Arrays.asList(new OpenMBeanParameterInfo[0]).toArray(new MBeanParameterInfo[0]) : (MBeanParameterInfo[])Arrays.asList(signature).toArray(new MBeanParameterInfo[0]), returntype == null ? "" : returntype.getClassName(), impact); ! // Superclass constructors don't do the necessary validation ! if (name == null || name.length() == 0) throw new IllegalArgumentException("name cannot be null or empty"); ! if (description == null || description.length() == 0) throw new IllegalArgumentException("descripiton cannot be null or empty"); ! if (returntype == null) throw new IllegalArgumentException("return open type cannont be null"); if (impact != MBeanOperationInfo.ACTION *************** *** 80,85 **** } ! if (signature != null ! && signature.getClass().isInstance(MBeanParameterInfo[].class)) { throw new ArrayStoreException("signature elements can't be assigned to MBeanParameterInfo"); --- 47,51 ---- } ! if (signature != null && signature.getClass().isInstance(MBeanParameterInfo[].class)) { throw new ArrayStoreException("signature elements can't be assigned to MBeanParameterInfo"); *************** *** 89,98 **** } - - /** - * Returns the returntype as an <code>OpenType</code> - * - * @return OpenType The OpenType instance - */ public OpenType getReturnOpenType() { --- 55,58 ---- *************** *** 100,171 **** } - /** - * Test the specified object for equality. - * <p/> - * <p/> - * This method will return true if and only if the following - * conditions are true: - * </p> - * <p/> - * <ul> - * <li>obj is not null</li> - * <li>obj also implements OpenMBeanOperationInfo</li> - * <li>their names are equal</li> - * <li>their signatures are equal</li> - * <li>their return opentypes are equal</li> - * <li>their impacts are equal</li> - * </ul> - * <p/> - * </p> - * - * @param obj The object being compared to - * @return boolean - */ public boolean equals(Object obj) { if (obj == null) return false; if (obj == this) return true; ! //better if we wont allow throwing exception ! if (obj instanceof OpenMBeanOperationInfo) ! { ! OpenMBeanOperationInfo other = (OpenMBeanOperationInfo)obj; ! if ((getName() == null && other.getName() == null) || ! (getName() != null && getName().equals(other.getName()))) ! { ! if (other.getImpact() != getImpact()) return false; ! if (getReturnOpenType() == null) ! { ! if (other.getReturnOpenType() != null) return false; ! } ! else ! { ! if (!getReturnOpenType().equals(other.getReturnOpenType())) return false; ! } ! if (!Arrays.equals(getSignature(), other.getSignature())) return false; ! return true; ! } ! } ! return false; } - /** - * Returns the hashcode of this <code>OpenMBeanOperationInfo</code> - * - * @return int The hashcode - */ public int hashCode() { - - if (hashCode == 0) { int result = getName().hashCode(); ! result += returnOpenType.hashCode(); result += getImpact(); result += java.util.Arrays.asList(getSignature()).hashCode(); --- 60,92 ---- } public boolean equals(Object obj) { if (obj == null) return false; if (obj == this) return true; + if (!(obj instanceof OpenMBeanOperationInfo)) return false; ! OpenMBeanOperationInfo other = (OpenMBeanOperationInfo)obj; + String thisName = getName(); + String otherName = other.getName(); + if (thisName != null ? !thisName.equals(otherName) : otherName != null) return false; ! if (other.getImpact() != getImpact()) return false; ! OpenType thisReturn = getReturnOpenType(); ! OpenType otherReturn = other.getReturnOpenType(); ! if (thisReturn != null ? !thisReturn.equals(otherReturn) : otherReturn != null) return false; ! if (!Arrays.equals(getSignature(), other.getSignature())) return false; + return true; } public int hashCode() { if (hashCode == 0) { int result = getName().hashCode(); ! result += getReturnOpenType().hashCode(); result += getImpact(); result += java.util.Arrays.asList(getSignature()).hashCode(); *************** *** 175,184 **** } - - /** - * Returns a String representation of this OpenMBeanOperationInfoSupport - * - * @return String The string representation - */ public String toString() { --- 96,99 ---- *************** *** 199,221 **** toStringName = sb.toString(); } - return toStringName; - } - //private - - private static MBeanParameterInfo[] createParameterInfo(OpenMBeanParameterInfo[] signature) - { - - if (signature == null) return null; - - MBeanParameterInfo[] paramInfo = - new MBeanParameterInfo[signature.length]; - - System.arraycopy(signature, 0, paramInfo, 0, paramInfo.length); - - return paramInfo; - - - } //end } --- 114,118 ---- Index: OpenMBeanAttributeInfoSupport.java =================================================================== RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** OpenMBeanAttributeInfoSupport.java 4 Sep 2004 15:44:04 -0000 1.12 --- OpenMBeanAttributeInfoSupport.java 5 Oct 2004 09:46:21 -0000 1.13 *************** *** 12,16 **** import java.util.Collections; import java.util.HashSet; - import java.util.Iterator; import java.util.Set; import javax.management.MBeanAttributeInfo; --- 12,15 ---- *************** *** 31,51 **** private Comparable maxValue = null; - private transient int hashCode = 0; private transient String toStringName = null; - /** - * Constructs an OpenMBeanAttributeInfoSupport which is an <code>OpenMBean</code> - * with the specified name,<code>OpenType</code>, description and - * and the specified read/write access properties. - * - * @param name The name of the attribute. Cant be a null. - * @param description The description of the attribute. Cant be null. - * @param openType The <code>OpenType</code> representation - * @param isReadable <code>true</code> if the attribute has a getter exposed. - * @param isWritable <code>true</code> if the attribute has a setter exposed - * @param isIs true if the attribute's getter is of the form isXXX. - * @throws IllegalArgumentException If name or description are null or empty string, or openType is null - */ public OpenMBeanAttributeInfoSupport(String name, String description, OpenType openType, boolean isReadable, boolean isWritable, boolean isIs) { --- 30,36 ---- *************** *** 53,156 **** if (openType == null) throw new IllegalArgumentException("OpenType can't be null"); ! if (name == null || name.length() == 0 || name.trim().equals("")) throw new IllegalArgumentException("name can't be null or empty"); ! if (description == null || description.length() == 0 || description.trim().equals("")) throw new IllegalArgumentException("description can't be null or empty"); this.openType = openType; - } - - /** - * Constructs an OpenMBeanAttributeInfoSupport which is an <code>OpenMBean</code> - * with the specified name,<code>OpenType</code>, description and - * and the specified read/write access properties and the default value. - * - * @param name The name of the attribute. Cant be a null. - * @param description The description of the attribute. Cant be null. - * @param openType The <code>OpenType</code> representation - * @param isReadable <code>true</code> if the attribute has a getter exposed. - * @param isWritable <code>true</code> if the attribute has a setter exposed - * @param isIs true if the attribute's getter is of the form isXXX. - * @param defaultValue The default value of the attribute. Must be a - * valid value for the <code>OpenType</code> specified. - * <code>null</code> if no default value is set. - * <code>ArrayType</code> and <code>TabularType</code> are - * not supported for a default value. - * @throws IllegalArgumentException If name or description are null - * or empty string, or openType is null - * @throws OpenDataException If defaultValue is not of valid type; and - * default value not supported for ArrayType and TabularType - * (should be null) - */ public OpenMBeanAttributeInfoSupport(String name, String description, OpenType openType, boolean isReadable, boolean isWritable, boolean isIs, Object defaultValue) throws OpenDataException { this(name, description, openType, isReadable, isWritable, isIs); ! //then should be a proper value ! if (openType instanceof ArrayType || ! openType instanceof TabularType) { if (defaultValue != null) ! throw new OpenDataException("defaultValue is not " + ! "supported for ArrayType and TabularType. Should be null"); } if (defaultValue != null && !openType.isValue(defaultValue)) ! throw new OpenDataException("defaultValue is not " + ! "a valid value for the given OpenType"); this.defaultValue = defaultValue; } - /** - * Constructs an OpenMBeanAttributeInfoSupport which is an <code>OpenMBean</code> - * with the specified name,<code>OpenType</code>, description and - * and the specified read/write access properties and the default value. - * - * @param name The name of the attribute. Cant be a null. - * @param description The description of the attribute. Cant be null. - * @param openType The <code>OpenType</code> representation - * @param isReadable <code>true</code> if the attribute has a getter exposed. - * @param isWritable <code>true</code> if the attribute has a setter exposed - * @param isIs true if the attribute's getter is of the form isXXX. - * @param defaultValue The default value of the attribute. Must be a valid - * value for the <code>OpenType</code> specified. - * <code>null</code> if no default value is set. - * <code>ArrayType</code> and <code>TabularType</code> are - * not supported for a default value. - * @param legalValues each value must be a valid - * value for the <code>OpenType</code> specified. - * <code>null</code> if no default value is set. - * <code>ArrayTypr</code> and <code>TabularType</code> are - * not supported for a legal value (should be null). - * @throws IllegalArgumentException If name or description are null or - * empty string, or openType is null - * @throws OpenDataException If defaultValue is not of valid type; and - * default value not supported for ArrayType and TabularType - * (should be null) - */ public OpenMBeanAttributeInfoSupport(String name, String description, OpenType openType, boolean isReadable, boolean isWritable, boolean isIs, Object defaultValue, Object[] legalValues) throws OpenDataException { ! this(name, ! description, ! openType, ! isReadable, ! isWritable, ! isIs, ! defaultValue); if (openType instanceof ArrayType || openType instanceof TabularType) { if (legalValues != null && legalValues.length > 0) ! throw new OpenDataException("legalValues isn't allowed " ! + "for ArrayType and TabularType. Should be null or empty " ! + "array"); ! } else if (legalValues != null && legalValues.length > 0) { ! Set tmpSet = new HashSet(legalValues.length, 1.0f); for (int i = 0; i < legalValues.length; i++) --- 38,77 ---- if (openType == null) throw new IllegalArgumentException("OpenType can't be null"); ! if (name == null || name.length() == 0 || name.trim().length() == 0) throw new IllegalArgumentException("name can't be null or empty"); ! if (description == null || description.length() == 0 || description.trim().length() == 0) throw new IllegalArgumentException("description can't be null or empty"); this.openType = openType; } public OpenMBeanAttributeInfoSupport(String name, String description, OpenType openType, boolean isReadable, boolean isWritable, boolean isIs, Object defaultValue) throws OpenDataException { this(name, description, openType, isReadable, isWritable, isIs); ! if (openType instanceof ArrayType || openType instanceof TabularType) { if (defaultValue != null) ! throw new OpenDataException("defaultValue is not supported for ArrayType and TabularType. Should be null"); } if (defaultValue != null && !openType.isValue(defaultValue)) ! throw new OpenDataException("defaultValue is not a valid value for the given OpenType"); this.defaultValue = defaultValue; } public OpenMBeanAttributeInfoSupport(String name, String description, OpenType openType, boolean isReadable, boolean isWritable, boolean isIs, Object defaultValue, Object[] legalValues) throws OpenDataException { ! this(name, description, openType, isReadable, isWritable, isIs, defaultValue); if (openType instanceof ArrayType || openType instanceof TabularType) { if (legalValues != null && legalValues.length > 0) ! throw new OpenDataException("legalValues isn't allowed for ArrayType and TabularType. Should be null or empty array"); } else if (legalValues != null && legalValues.length > 0) { ! Set tmpSet = new HashSet(legalValues.length); for (int i = 0; i < legalValues.length; i++) *************** *** 163,169 **** else { ! throw new OpenDataException("An Entry in the set " ! + "of legalValues is not a valid value for the given " ! + "opentype"); } } --- 84,88 ---- else { ! throw new OpenDataException("An Entry in the set of legalValues is not a valid value for the given opentype"); } } *************** *** 178,215 **** } - /** - * Constructs an OpenMBeanAttributeInfoSupport which is an <code>OpenMBean</code> - * with the specified name,<code>OpenType</code>, description and - * and the specified read/write access properties,default value and legal - * values as an array - * - * @param name The name of the attribute. Cant be a null. - * @param description The description of the attribute. Cant be null. - * @param openType The <code>OpenType</code> representation - * @param isReadable <code>true</code> if the attribute has a getter exposed. - * @param isWritable <code>true</code> if the attribute has a setter exposed - * @param isIs true if the attribute's getter is of the form isXXX. - * @param defaultValue The default value of the attribute. - * Must be a valid value for the <code>OpenType</code> - * specified. <code>null</code> if no default - * @param minValue must be a valid <code>OpenType</code> specified for - * this attribute. Can be null, which means no minimal value - * for the attribute. - * @param maxValue must be a valid <code>OpenType</code> specified for - * this attribute. Can be null, which means no miximal value - * for the attribute. - * @throws IllegalArgumentException If name or description - * are null or empty string, or openType is null - * @throws OpenDataException If defaultValue is not of valid type; - * and default value not supported for ArrayType - * and Tabular (should be null). If minValue and maxValue is - * not a valid value for specified <code>OpenType</code>. - * If minValue and maxValue are non-null and - * <code>OpenType</code> and minValue.compareTo(maxValue) > 0 - * is true, or both defaultValue and minValue are non-null - * and minValue.compareTo(defaultValue) >0 is true, - * or both defaultValue and maxValue are non-null and - * defaultValue.compareTo(maxValue) >0 is true - */ public OpenMBeanAttributeInfoSupport(String name, String description, OpenType openType, boolean isReadable, boolean isWritable, boolean isIs, Object defaultValue, Comparable minValue, Comparable maxValue) throws OpenDataException { --- 97,100 ---- *************** *** 218,227 **** if (minValue != null) if (!openType.isValue(minValue)) ! throw new OpenDataException("minValue is not a valid " + ! "value for the specified openType"); if (maxValue != null) if (!openType.isValue(maxValue)) ! throw new OpenDataException("maxValue is not a valid " + ! "value for the specified openType"); if (minValue != null && maxValue != null) --- 103,111 ---- if (minValue != null) if (!openType.isValue(minValue)) ! throw new OpenDataException("minValue is not a valid value for the specified openType"); ! if (maxValue != null) if (!openType.isValue(maxValue)) ! throw new OpenDataException("maxValue is not a valid value for the specified openType"); if (minValue != null && maxValue != null) *************** *** 230,248 **** "invalid: minValue is greater than maxValue"); if (defaultValue != null && minValue != null) ! if (minValue.compareTo((Comparable)defaultValue) > 0) throw new OpenDataException("defaultvalue and/or minValue is invalid: minValue is greater than defaultValue"); if (defaultValue != null && maxValue != null) if (((Comparable)defaultValue).compareTo(maxValue) > 0) throw new OpenDataException("defaultvalue and/or maxValue is invalid: defaultValue is greater than maxValue"); - this.minValue = minValue; this.maxValue = maxValue; - } - /** - * Returns the <code>OpenType</code> of this attribute - */ public OpenType getOpenType() { --- 114,128 ---- "invalid: minValue is greater than maxValue"); if (defaultValue != null && minValue != null) ! if (minValue.compareTo(defaultValue) > 0) throw new OpenDataException("defaultvalue and/or minValue is invalid: minValue is greater than defaultValue"); + if (defaultValue != null && maxValue != null) if (((Comparable)defaultValue).compareTo(maxValue) > 0) throw new OpenDataException("defaultvalue and/or maxValue is invalid: defaultValue is greater than maxValue"); this.minValue = minValue; this.maxValue = maxValue; } public OpenType getOpenType() { *************** *** 250,256 **** } - /** - * Returns the default value, if specified, null otherwise - */ public Object getDefaultValue() { --- 130,133 ---- *************** *** 258,264 **** } - /** - * Returns the legalValues as a <code>Set</code> - */ public Set getLegalValues() { --- 135,138 ---- *************** *** 266,273 **** } - - /** - * Returns the minValue - */ public Comparable getMinValue() { --- 140,143 ---- *************** *** 275,281 **** } - /** - * Returns the maxValue - */ public Comparable getMaxValue() { --- 145,148 ---- *************** *** 283,289 **** } - /** - * <code>true</code> if has defaultValue, false otherwise - */ public boolean hasDefaultValue() { --- 150,153 ---- *************** *** 292,298 **** } - /** - * <code>true</code> if has a legalValues allowed, false otherwise. - */ public boolean hasLegalValues() { --- 156,159 ---- *************** *** 300,306 **** } - /** - * <code>true</code> if has a minValue, false otherwise. - */ public boolean hasMinValue() { --- 161,164 ---- *************** *** 308,314 **** } - /** - * <code>true</code> if has a maxValue, false otherwise. - */ public boolean hasMaxValue() { --- 166,169 ---- *************** *** 316,326 **** } - - /** - * Test wether obj is a valid value for this attribute - * - * @param obj The object being tested - * @return true If a valid value - */ public boolean isValue(Object obj) { --- 171,174 ---- *************** *** 329,396 **** if (openType.isValue(obj)) return true; } ! else //defaultValue is null { - //if obj is null- true if (obj == null) return true; } return false; - } - /** - * Compares the give <code>Object</code> for equality with this instance. - * <p/> - * <p/> - * The operation returns true if and only if the following statements - * are all true: - * <ul> - * <li>obj is not null</li> - * <li>obj also implements OpenMBeanAttributeInfo</li> - * <li>their names are equals</li> - * <li>their open types are equal</li> - * <li>access properties (isReadable, isWritable, isIs) are equal</li> - * <li>default,min,max and legal values are equal</li> - * </ul> - * - * @return boolean true if the above conditions are met - */ public boolean equals(Object obj) { if (obj == this) return true; ! //obj should not be null if (obj == null) return false; ! //obj should implement OpenMBeanAttributeInfo if (!(obj instanceof OpenMBeanAttributeInfo)) return false; - //this wouldn't fail OpenMBeanAttributeInfo other = (OpenMBeanAttributeInfo)obj; - - //name should be equal if (!getName().equals(other.getName())) return false; - - //opentype should be equal if (!getOpenType().equals(other.getOpenType())) return false; - //access properties should be equal - if (!(isReadable() == other.isReadable())) return false; - if (!(isWritable() == other.isWritable())) return false; - if (!(isIs() == other.isIs())) return false; - - //default, min, max and legalvalues are equal if (hasDefaultValue()) { if (!getDefaultValue().equals(other.getDefaultValue())) return false; } ! else //no defaultvalue { - //other should also not have default value if (other.hasDefaultValue()) return false; } - //min if (hasMinValue()) { ! if (!minValue.equals(other.getMinValue())) return false; } else --- 177,215 ---- if (openType.isValue(obj)) return true; } ! else { if (obj == null) return true; } return false; } public boolean equals(Object obj) { if (obj == this) return true; ! // obj should not be null if (obj == null) return false; ! // obj should implement OpenMBeanAttributeInfo if (!(obj instanceof OpenMBeanAttributeInfo)) return false; OpenMBeanAttributeInfo other = (OpenMBeanAttributeInfo)obj; if (!getName().equals(other.getName())) return false; if (!getOpenType().equals(other.getOpenType())) return false; + if (isReadable() != other.isReadable()) return false; + if (isWritable() != other.isWritable()) return false; + if (isIs() != other.isIs()) return false; if (hasDefaultValue()) { if (!getDefaultValue().equals(other.getDefaultValue())) return false; } ! else { if (other.hasDefaultValue()) return false; } if (hasMinValue()) { ! if (!getMinValue().equals(other.getMinValue())) return false; } else *************** *** 399,406 **** } - //max if (hasMaxValue()) { ! if (!maxValue.equals(other.getMaxValue())) return false; } else --- 218,224 ---- } if (hasMaxValue()) { ! if (!getMaxValue().equals(other.getMaxValue())) return false; } else *************** *** 409,416 **** } - //legalValues if (hasLegalValues()) { ! if (!legalValues.equals(other.getLegalValues())) return false; } else --- 227,233 ---- } if (hasLegalValues()) { ! if (!getLegalValues().equals(other.getLegalValues())) return false; } else *************** *** 420,451 **** return true; - - } - - /** - * Computes the hashCode of this <code>OpenMBeanAttributeInfo</code> - * - * @return int The hashCode value - */ public int hashCode() { if (hashCode == 0) { ! hashCode = hashCode(this); } return hashCode; - } - /** - * Returns a string representation of this <code>OpenMBeanAttributeInfo</code> instance. - * - * @return String The representation as string - */ public String toString() { - if (toStringName == null) { --- 237,259 ---- return true; } public int hashCode() { if (hashCode == 0) { ! int result = getName().hashCode(); ! result += getOpenType().hashCode(); ! result += (hasDefaultValue() == false) ? 0 : getDefaultValue().hashCode(); ! result += (hasLegalValues() == false) ? 0 : getLegalValues().hashCode(); ! result += (hasMinValue() == false) ? 0 : getMinValue().hashCode(); ! result += (hasMaxValue() == false) ? 0 : getMaxValue().hashCode(); ! hashCode = result; } return hashCode; } public String toString() { if (toStringName == null) { *************** *** 464,496 **** sb.append(hasLegalValues() ? getLegalValues().toString() : "null"); sb.append(")"); - toStringName = sb.toString(); } - return toStringName; - - } - - private int hashCode(OpenMBeanAttributeInfoSupport info) - { - int result = info.getName().hashCode(); - result += info.getOpenType().hashCode(); - result += (info.hasDefaultValue() == false) ? 0 : info.getDefaultValue().hashCode(); - result += (info.hasLegalValues() == false) ? 0 : hashCode(info.getLegalValues()); - result += (info.hasMinValue() == false) ? 0 : info.getMinValue().hashCode(); - result += (info.hasMaxValue() == false) ? 0 : info.getMaxValue().hashCode(); - return result; - } - - private int hashCode(Set legalvalues) - { - int result = 0; - Iterator i = legalvalues.iterator(); - while (i.hasNext()) - { - Object v = i.next(); - result += v.hashCode(); - } - return result; } } --- 272,278 ---- ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl