Class DescriptorSupport
- All Implemented Interfaces:
Serializable, Cloneable, Descriptor
A descriptor consists of a collection of fields. Each field is in fieldname=fieldvalue format. Field names are not case sensitive, case will be preserved on field values.
All field names and values are not predefined. New fields can be defined and added by any program. Some fields have been predefined for consistency of implementation and support by the ModelMBeanInfo, ModelMBeanAttributeInfo, ModelMBeanConstructorInfo, ModelMBeanNotificationInfo, ModelMBeanOperationInfo and ModelMBean classes.
The serialVersionUID of this class is -6292969195866300415L.
- Since:
- 1.5
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDescriptor default constructor.DescriptorSupport(int initNumFields) Descriptor constructor.DescriptorSupport(String... fields) Constructor taking fields in the fieldName=fieldValue format.DescriptorSupport(String[] fieldNames, Object[] fieldValues) Constructor taking field names and field values.DescriptorSupport(DescriptorSupport inDescr) Descriptor constructor taking a Descriptor as parameter. -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a new Descriptor which is a duplicate of the Descriptor.booleanCompares this descriptor to the given object.String[]Returns all the field names in the descriptor.String[]Returns all of the fields contained in this descriptor as a string array.getFieldValue(String fieldName) Returns the value for a specific field name, or null if no value is present for that name.Object[]getFieldValues(String... fieldNames) Returns all the field values in the descriptor as an array of Objects.inthashCode()Returns the hash code value for this descriptor.booleanisValid()Returns true if all of the fields have legal values given their names.voidremoveField(String fieldName) Removes a field from the descriptor.voidSets the value for a specific field name.voidSets all fields in the field names array to the new value with the same index in the field values array.toString()Returns a human readable string representing the descriptor.Methods declared in class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionbooleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
DescriptorSupport
public DescriptorSupport()Descriptor default constructor. Default initial descriptor size is 20. It will grow as needed.
Note that the created empty descriptor is not a valid descriptor (the methodisValidreturnsfalse) -
DescriptorSupport
Descriptor constructor. Takes as parameter the initial capacity of the Map that stores the descriptor fields. Capacity will grow as needed.
Note that the created empty descriptor is not a valid descriptor (the methodisValidreturnsfalse).- Parameters:
initNumFields- The initial capacity of the Map that stores the descriptor fields.- Throws:
RuntimeOperationsException- for illegal value for initNumFields (<= 0)MBeanException- Wraps a distributed communication Exception.
-
DescriptorSupport
Descriptor constructor taking a Descriptor as parameter. Creates a new descriptor initialized to the values of the descriptor passed in parameter.- Parameters:
inDescr- the descriptor to be used to initialize the constructed descriptor. If it is null or contains no descriptor fields, an empty Descriptor will be created.
-
DescriptorSupport
public DescriptorSupport(String[] fieldNames, Object[] fieldValues) throws RuntimeOperationsException Constructor taking field names and field values. Neither array can be null.- Parameters:
fieldNames- String array of field names. No elements of this array can be null.fieldValues- Object array of the corresponding field values. Elements of the array can be null. ThefieldValuemust be valid for thefieldName(as defined in methodisValid)Note: array sizes of parameters should match. If both arrays are empty, then an empty descriptor is created.
- Throws:
RuntimeOperationsException- for illegal value for field Names or field Values. The array lengths must be equal. If the descriptor construction fails for any reason, this exception will be thrown.
-
DescriptorSupport
Constructor taking fields in the fieldName=fieldValue format.- Parameters:
fields- String array with each element containing a field name and value. If this array is null or empty, then the default constructor will be executed. Null strings or empty strings will be ignored.All field values should be Strings. If the field values are not Strings, the programmer will have to reset or convert these fields correctly.
Note: Each string should be of the form fieldName=fieldValue. The field name ends at the first
=character; for example if the String isa=b=cthen the field name isaand its value isb=c.- Throws:
RuntimeOperationsException- for illegal value for field Names or field Values. The field must contain an "=". "=fieldValue", "fieldName", and "fieldValue" are illegal. FieldName cannot be null. "fieldName=" will cause the value to be null. If the descriptor construction fails for any reason, this exception will be thrown.
-
-
Method Details
-
getFieldValue
Description copied from interface:DescriptorReturns the value for a specific field name, or null if no value is present for that name.- Specified by:
getFieldValuein interfaceDescriptor- Parameters:
fieldName- the field name.- Returns:
- the corresponding value, or null if the field is not present.
- Throws:
RuntimeOperationsException- if the field name is illegal.
-
setField
Description copied from interface:DescriptorSets the value for a specific field name. This will modify an existing field or add a new field.
The field value will be validated before it is set. If it is not valid, then an exception will be thrown. The meaning of validity is dependent on the descriptor implementation.
- Specified by:
setFieldin interfaceDescriptor- Parameters:
fieldName- The field name to be set. Cannot be null or empty.fieldValue- The field value to be set for the field name. Can be null if that is a valid value for the field.- Throws:
RuntimeOperationsException- if the field name or field value is illegal (wrapped exception isIllegalArgumentException); or if the descriptor is immutable (wrapped exception isUnsupportedOperationException).
-
getFields
Description copied from interface:DescriptorReturns all of the fields contained in this descriptor as a string array.- Specified by:
getFieldsin interfaceDescriptor- Returns:
- String array of fields in the format fieldName=fieldValue
If the value of a field is not a String, then the toString() method will be called on it and the returned value, enclosed in parentheses, used as the value for the field in the returned array. If the value of a field is null, then the value of the field in the returned array will be empty. If the descriptor is empty, you will get an empty array. - See Also:
-
getFieldNames
Description copied from interface:DescriptorReturns all the field names in the descriptor.- Specified by:
getFieldNamesin interfaceDescriptor- Returns:
- String array of field names. If the descriptor is empty, you will get an empty array.
-
getFieldValues
Description copied from interface:DescriptorReturns all the field values in the descriptor as an array of Objects. The returned values are in the same order as thefieldNamesString array parameter.- Specified by:
getFieldValuesin interfaceDescriptor- Parameters:
fieldNames- String array of the names of the fields that the values should be returned for. If the array is empty then an empty array will be returned. If the array is null then all values will be returned, as if the parameter were the array returned byDescriptor.getFieldNames(). If a field name in the array does not exist, including the case where it is null or the empty string, then null is returned for the matching array element being returned.- Returns:
- Object array of field values. If the list of
fieldNamesis empty, you will get an empty array.
-
setFields
Description copied from interface:DescriptorSets all fields in the field names array to the new value with the same index in the field values array. Array sizes must match.
The field value will be validated before it is set. If it is not valid, then an exception will be thrown. If the arrays are empty, then no change will take effect.
- Specified by:
setFieldsin interfaceDescriptor- Parameters:
fieldNames- String array of field names. The array and array elements cannot be null.fieldValues- Object array of the corresponding field values. The array cannot be null. Elements of the array can be null.- Throws:
RuntimeOperationsException- if the change fails for any reason. Wrapped exception isIllegalArgumentExceptioniffieldNamesorfieldValuesis null, or if the arrays are of different lengths, or if there is an illegal value in one of them. Wrapped exception isUnsupportedOperationExceptionif the descriptor is immutable, and the call would change its contents.- See Also:
-
clone
Returns a new Descriptor which is a duplicate of the Descriptor.- Specified by:
clonein interfaceDescriptor- Overrides:
clonein classObject- Returns:
- A descriptor which is equal to this descriptor.
- Throws:
RuntimeOperationsException- for illegal value for field Names or field Values. If the descriptor construction fails for any reason, this exception will be thrown.- See Also:
-
removeField
Description copied from interface:DescriptorRemoves a field from the descriptor.- Specified by:
removeFieldin interfaceDescriptor- Parameters:
fieldName- String name of the field to be removed. If the field name is illegal or the field is not found, no exception is thrown.
-
equals
Description copied from interface:DescriptorCompares this descriptor to the given object. The objects are equal if the given object is also a Descriptor, and if the two Descriptors have the same field names (possibly differing in case) and the same associated values. The respective values for a field in the two Descriptors are equal if the following conditions hold:
- If one value is null then the other must be too.
- If one value is a primitive array then the other must be a primitive array of the same type with the same elements.
- If one value is an object array then the other must be too and
Arrays.deepEquals(Object[],Object[])must return true. - Otherwise
Object.equals(Object)must return true.
- Specified by:
equalsin interfaceDescriptor- Overrides:
equalsin classObject- Parameters:
o- the object to compare with.- Returns:
trueif the objects are the same;falseotherwise.- See Also:
-
hashCode
public int hashCode()Description copied from interface:DescriptorReturns the hash code value for this descriptor. The hash code is computed as the sum of the hash codes for each field in the descriptor. The hash code of a field with name
nand valuevisn.toLowerCase().hashCode() ^ h. Herehis the hash code ofv, computed as follows:- If
vis null thenhis 0. - If
vis a primitive array thenhis computed using the appropriate overloading ofjava.util.Arrays.hashCode. - If
vis an object array thenhis computed usingArrays.deepHashCode(Object[]). - Otherwise
hisv.hashCode().
- Specified by:
hashCodein interfaceDescriptor- Overrides:
hashCodein classObject- Returns:
- A hash code value for this object.
- See Also:
- If
-
isValid
Returns true if all of the fields have legal values given their names.This implementation does not support interoperating with a directory or lookup service. Thus, conforming to the specification, no checking is done on the "export" field.
Otherwise this implementation returns false if:
- name and descriptorType fieldNames are not defined, or null, or empty, or not String
- class, role, getMethod, setMethod fieldNames, if defined, are null or not String
- persistPeriod, currencyTimeLimit, lastUpdatedTimeStamp, lastReturnedTimeStamp if defined, are null, or not a Numeric String or not a Numeric Value >= -1
- log fieldName, if defined, is null, or not a Boolean or not a String with value "t", "f", "true", "false". These String values must not be case sensitive.
- visibility fieldName, if defined, is null, or not a Numeric String or a not Numeric Value >= 1 and <= 4
- severity fieldName, if defined, is null, or not a Numeric
String or not a Numeric Value >= 0 and <= 6
- persistPolicy fieldName, if defined, is null, or not one of
the following strings:
"OnUpdate", "OnTimer", "NoMoreOftenThan", "OnUnregister", "Always", "Never". These String values must not be case sensitive.
- Specified by:
isValidin interfaceDescriptor- Returns:
- true if the values are legal.
- Throws:
RuntimeOperationsException- If the validity checking fails for any reason, this exception will be thrown.
-
toString
Returns a human readable string representing the descriptor. The string will be in the format of "fieldName=fieldValue,fieldName2=fieldValue2,..."
If there are no fields in the descriptor, then an empty String is returned.
If a fieldValue is an object then the toString() method is called on it and its returned value is used as the value for the field enclosed in parenthesis.- Overrides:
toStringin classObject- Returns:
- a string representation of the object
- Throws:
RuntimeOperationsException- for illegal value for field Names or field Values. If the descriptor string fails for any reason, this exception will be thrown.
-