OpenMBeanParameterInfoSupportpublic class OpenMBeanParameterInfoSupport extends MBeanParameterInfo implements OpenMBeanParameterInfo, SerializableDescribes a parameter used in one or more operations or constructors of an open MBean. |
Fields Summary |
---|
static final long | serialVersionUID | private OpenType | openType | private Object | defaultValue | private Set | legalValues | private Comparable | minValue | private Comparable | maxValue | private transient Integer | myHashCode | private transient String | myToString |
Constructors Summary |
---|
public OpenMBeanParameterInfoSupport(String name, String description, 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 and description. // need only be calculated once.
// Construct parent's state
//
super(name, ( (openType==null) ? null : openType.getClassName() ), description);
// check parameters that should not be null or empty (unfortunately it is not done in superclass :-( ! )
//
if ( (name == null) || (name.trim().equals("")) ) {
throw new IllegalArgumentException("Argument name cannot be null or empty.");
}
if ( (description == null) || (description.trim().equals("")) ) {
throw new IllegalArgumentException("Argument description cannot be null or empty.");
}
if (openType == null) {
throw new IllegalArgumentException("Argument openType cannot be null.");
}
// Initialize this instance's specific state
//
this.openType = openType;
| public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType, Object defaultValue)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.
// First check and construct the part regarding name, openType and description
//
this(name, description, openType);
// Check and initialize defaultValue
//
if (defaultValue != null) {
// Default value not supported for ArrayType and TabularType
if ( (openType.isArray()) || (openType instanceof TabularType) ) {
throw new OpenDataException("Default value not supported for ArrayType and TabularType.");
}
// Check defaultValue's class
if ( ! openType.isValue(defaultValue) ) {
throw new OpenDataException("Argument defaultValue's class [\""+ defaultValue.getClass().getName() +
"\"] does not match the one defined in openType[\""+ openType.getClassName() +"\"].");
}
// Then initializes defaultValue:
// no need to clone it: apart from arrays and TabularData, basic data types are immutable
this.defaultValue = defaultValue;
}
| public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType, Object defaultValue, Object[] legalValues)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.
// First check and construct the part regarding name, openType, description and defaultValue
//
this(name, description, openType, defaultValue);
// Check and initialize legalValues
//
if ( (legalValues != null) && (legalValues.length > 0) ) {
// legalValues not supported for TabularType and arrays
if ( (openType instanceof TabularType) || (openType.isArray()) ) {
throw new OpenDataException("Legal values not supported for TabularType and arrays");
}
// Check legalValues are valid with openType
for (int i = 0; i < legalValues.length; i++ ) {
if ( ! openType.isValue(legalValues[i]) ) {
throw new OpenDataException("Element legalValues["+ i +"]="+ legalValues[i] +
" is not a valid value for the specified openType ["+ openType.toString() +"].");
}
}
// dump the legalValues array content into a Set: ensures uniqueness of elements
// (and we could not keep the array reference as array content could be modified by the caller)
Set tmpSet = new HashSet(legalValues.length+1, 1);
for (int i = 0; i < legalValues.length; i++ ) {
tmpSet.add(legalValues[i]);
}
// initializes legalValues as an unmodifiable Set
this.legalValues = Collections.unmodifiableSet(tmpSet);
}
// Check that defaultValue is a legal value
//
if ( (this.hasDefaultValue()) && (this.hasLegalValues()) ) {
if ( ! this.legalValues.contains(defaultValue) ) {
throw new OpenDataException("defaultValue is not contained in legalValues");
}
}
| public OpenMBeanParameterInfoSupport(String name, String description, OpenType openType, Object defaultValue, Comparable minValue, Comparable maxValue)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.
// First check and construct the part regarding name, openType, description and defaultValue
//
this(name, description, openType, defaultValue);
// Check and initialize minValue
//(note: no need to worry about Composite, Tabular and arrays as they are not Comparable)
//
if (minValue != null) {
if ( ! openType.isValue(minValue) ) {
throw new OpenDataException("Argument minValue's class [\""+ minValue.getClass().getName() +
"\"] does not match openType's definition [\""+ openType.getClassName() +"\"].");
}
// then initializes minValue
this.minValue = minValue;
}
// Check and initialize maxValue
//(note: no need to worry about Composite, Tabular and arrays as they are not Comparable)
//
if (maxValue != null) {
if ( ! openType.isValue(maxValue) ) {
throw new OpenDataException("Argument maxValue's class [\""+ maxValue.getClass().getName() +
"\"] does not match openType's definition [\""+ openType.getClassName() +"\"].");
}
// then initializes maxValue
this.maxValue = maxValue;
}
// Check that, if both specified, minValue <= maxValue
//
if (hasMinValue() && hasMaxValue()) {
if (minValue.compareTo(maxValue) > 0) {
throw new OpenDataException("minValue cannot be greater than maxValue.");
}
}
// Check that minValue <= defaultValue <= maxValue
//
if ( (this.hasDefaultValue()) && (this.hasMinValue()) ) {
if (minValue.compareTo((Comparable)defaultValue) > 0) {
throw new OpenDataException("minValue cannot be greater than defaultValue.");
}
}
if ( (this.hasDefaultValue()) && (this.hasMaxValue()) ) {
if (((Comparable)defaultValue).compareTo(maxValue) > 0) {
throw new OpenDataException("defaultValue cannot be greater than maxValue.");
}
}
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Compares the specified obj parameter with this OpenMBeanParameterInfoSupport instance for equality.
Returns true if and only if all of the following statements are true:
- obj is non null,
- obj also implements the
OpenMBeanParameterInfo interface,
- their names are equal
- their open types are equal
- their default, min, max and legal values are equal.
This ensures that this equals method works properly for obj parameters which are
different implementations of the OpenMBeanParameterInfo interface.
// if obj is null, return false
//
if (obj == null) {
return false;
}
// if obj is not a OpenMBeanParameterInfo, return false
//
OpenMBeanParameterInfo other;
try {
other = (OpenMBeanParameterInfo) obj;
} catch (ClassCastException e) {
return false;
}
// Now, really test for equality between this OpenMBeanParameterInfo implementation and the other:
//
// their Name should be equal
if ( ! this.getName().equals(other.getName()) ) {
return false;
}
// their OpenType should be equal
if ( ! this.getOpenType().equals(other.getOpenType()) ) {
return false;
}
// their DefaultValue should be equal
if (this.hasDefaultValue()) {
if ( ! this.defaultValue.equals(other.getDefaultValue()) ) {
return false;
}
} else {
if (other.hasDefaultValue()) {
return false;
}
}
// their MinValue should be equal
if (this.hasMinValue()) {
if ( ! this.minValue.equals(other.getMinValue()) ) {
return false;
}
} else {
if (other.hasMinValue()) {
return false;
}
}
// their MaxValue should be equal
if (this.hasMaxValue()) {
if ( ! this.maxValue.equals(other.getMaxValue()) ) {
return false;
}
} else {
if (other.hasMaxValue()) {
return false;
}
}
// their LegalValues should be equal
if (this.hasLegalValues()) {
if ( ! this.legalValues.equals(other.getLegalValues()) ) {
return false;
}
} else {
if (other.hasLegalValues()) {
return false;
}
}
// All tests for equality were successfull
//
return true;
| public java.lang.Object | getDefaultValue()Returns the default value for the parameter described by this OpenMBeanParameterInfoSupport instance,
if specified, or null otherwise.
// Special case for ArrayType and TabularType
// [JF] TODO: clone it so that it cannot be altered,
// [JF] TODO: if we decide to support defaultValue as an array itself.
// [JF] As of today (oct 2000) it is not supported so defaultValue is null for arrays. Nothing to do.
return defaultValue;
| public java.util.Set | getLegalValues()Returns an unmodifiable Set of legal values for the parameter described by this OpenMBeanParameterInfoSupport instance,
if specified, or null otherwise.
// Special case for ArrayType and TabularType
// [JF] TODO: clone values so that they cannot be altered,
// [JF] TODO: if we decide to support LegalValues as an array itself.
// [JF] As of today (oct 2000) it is not supported so legalValues is null for arrays. Nothing to do.
// Returns our legalValues Set (set was constructed unmodifiable)
return (legalValues);
| public java.lang.Comparable | getMaxValue()Returns the maximal value for the parameter described by this OpenMBeanParameterInfoSupport instance,
if specified, or null otherwise.
// Note: only comparable values have a maxValue, so that's not the case of arrays and tabulars (always null).
return maxValue;
| public java.lang.Comparable | getMinValue()Returns the minimal value for the parameter described by this OpenMBeanParameterInfoSupport instance,
if specified, or null otherwise.
// Note: only comparable values have a minValue, so that's not the case of arrays and tabulars (always null).
return minValue;
| public javax.management.openmbean.OpenType | getOpenType()Returns the open type for the values of the parameter described by this OpenMBeanParameterInfoSupport instance.
return openType;
| public boolean | hasDefaultValue()Returns true if this OpenMBeanParameterInfoSupport instance specifies a non-null default value
for the described parameter, false otherwise.
return (defaultValue != null);
| public boolean | hasLegalValues()Returns true if this OpenMBeanParameterInfoSupport instance specifies a non-null set of legal values
for the described parameter, false otherwise.
return (legalValues != null);
| public boolean | hasMaxValue()Returns true if this OpenMBeanParameterInfoSupport instance specifies a non-null maximal value
for the described parameter, false otherwise.
return (maxValue != null);
| public boolean | hasMinValue()Returns true if this OpenMBeanParameterInfoSupport instance specifies a non-null minimal value
for the described parameter, false otherwise.
return (minValue != null);
| public int | hashCode()Returns the hash code value for this OpenMBeanParameterInfoSupport instance.
The hash code of an OpenMBeanParameterInfoSupport instance is the sum of the hash codes
of all elements of information used in equals comparisons
(ie: its name, its open type, and its default, min, max and legal values).
This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode()
for any two OpenMBeanParameterInfoSupport instances t1 and 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 OpenMBeanParameterInfo interface
may be equal to this OpenMBeanParameterInfoSupport instance as defined by {@link #equals(java.lang.Object)},
but may have a different hash code if it is calculated differently.
As OpenMBeanParameterInfoSupport instances are immutable, the hash code for this instance is calculated once,
on the first call to 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.getName().hashCode();
value += this.openType.hashCode();
if (this.hasDefaultValue()) {
value += this.defaultValue.hashCode();
}
if (this.hasMinValue()) {
value += this.minValue.hashCode();
}
if (this.hasMaxValue()) {
value += this.maxValue.hashCode();
}
if (this.hasLegalValues()) {
value += this.legalValues.hashCode();
}
myHashCode = new Integer(value);
}
// return always the same hash code for this instance (immutable)
//
return myHashCode.intValue();
| public boolean | isValue(java.lang.Object obj)Tests whether obj is a valid value for the parameter
described by this OpenMBeanParameterInfo instance.
boolean result;
if ( hasDefaultValue() && obj == null ) {
result = true;
}
else if ( ! openType.isValue(obj) ) {
result = false;
}
else if ( hasLegalValues() && ! legalValues.contains(obj) ) {
result = false;
}
else if ( hasMinValue() && (minValue.compareTo(obj)>0) ) {
result = false;
}
else if ( hasMaxValue() && (maxValue.compareTo(obj)<0) ) {
result = false;
}
else {
result = true;
}
return result;
| public java.lang.String | toString()Returns a string representation of this OpenMBeanParameterInfoSupport instance.
The string representation consists of the name of this class (ie javax.management.openmbean.OpenMBeanParameterInfoSupport ),
the string representation of the name and open type of the described parameter,
and the string representation of its default, min, max and legal values.
As OpenMBeanParameterInfoSupport instances are immutable, the string representation for this instance is calculated once,
on the first call to toString , 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 (myToString == null) {
myToString = new StringBuffer()
.append(this.getClass().getName())
.append("(name=")
.append(this.getName())
.append(",openType=")
.append(this.openType.toString())
.append(",default=")
.append(String.valueOf(this.defaultValue))
.append(",min=")
.append(String.valueOf(this.minValue))
.append(",max=")
.append(String.valueOf(this.maxValue))
.append(",legals=")
.append(String.valueOf(this.legalValues))
.append(")")
.toString();
}
// return always the same string representation for this instance (immutable)
//
return myToString;
|
|