public class DescriptorSupport extends Object implements 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
.
Constructor | Description |
---|---|
DescriptorSupport() |
Descriptor default constructor.
|
DescriptorSupport(DescriptorSupport inDescr) |
Descriptor constructor taking a Descriptor as parameter.
|
DescriptorSupport(int initNumFields) |
Descriptor constructor.
|
DescriptorSupport(String... fields) |
Constructor taking fields in the fieldName=fieldValue
format.
|
DescriptorSupport(String inStr) |
Descriptor constructor taking an XML String.
|
DescriptorSupport(String[] fieldNames,
Object[] fieldValues) |
Constructor taking field names and field values.
|
Modifier and Type | Method | Description |
---|---|---|
Object |
clone() |
Returns a new Descriptor which is a duplicate of the Descriptor.
|
boolean |
equals(Object o) |
Compares this descriptor to the given object.
|
String[] |
getFieldNames() |
Returns all the field names in the descriptor.
|
String[] |
getFields() |
Returns all of the fields contained in this descriptor as a string array.
|
Object |
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.
|
int |
hashCode() |
Returns the hash code value for this descriptor.
|
boolean |
isValid() |
Returns true if all of the fields have legal values given their
names.
|
void |
removeField(String fieldName) |
Removes a field from the descriptor.
|
void |
setField(String fieldName,
Object fieldValue) |
Sets the value for a specific field name.
|
void |
setFields(String[] fieldNames,
Object[] fieldValues) |
Sets all fields in the field names array to the new value with
the same index in the field values array.
|
String |
toString() |
Returns a human readable string representing the
descriptor.
|
String |
toXMLString() |
Returns an XML String representing the descriptor.
|
public DescriptorSupport()
isValid
returns false
)public DescriptorSupport(int initNumFields) throws MBeanException, RuntimeOperationsException
isValid
returns false
).initNumFields
- The initial capacity of the Map that
stores the descriptor fields.RuntimeOperationsException
- for illegal value for
initNumFields (<= 0)MBeanException
- Wraps a distributed communication Exception.public DescriptorSupport(DescriptorSupport inDescr)
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.public DescriptorSupport(String inStr) throws MBeanException, RuntimeOperationsException, XMLParseException
Descriptor constructor taking an XML String.
The format of the XML string is not defined, but an
implementation must ensure that the string returned by
toXMLString()
on an existing
descriptor can be used to instantiate an equivalent
descriptor using this constructor.
In this implementation, all field values will be created as Strings. If the field values are not Strings, the programmer will have to reset or convert these fields correctly.
inStr
- An XML-formatted string used to populate this
Descriptor. The format is not defined, but any
implementation must ensure that the string returned by
method toXMLString
on an existing
descriptor can be used to instantiate an equivalent
descriptor when instantiated using this constructor.RuntimeOperationsException
- If the String inStr
passed in parameter is nullXMLParseException
- XML parsing problem while parsing
the input StringMBeanException
- Wraps a distributed communication Exception.public DescriptorSupport(String[] fieldNames, Object[] fieldValues) throws RuntimeOperationsException
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. The
fieldValue
must be valid for the
fieldName
(as defined in method isValid
)
Note: array sizes of parameters should match. If both arrays are empty, then an empty descriptor is created.
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.public DescriptorSupport(String... fields)
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
is a=b=c
then the field name is a
and its value
is b=c
.
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.public Object getFieldValue(String fieldName) throws RuntimeOperationsException
Descriptor
getFieldValue
in interface Descriptor
fieldName
- the field name.RuntimeOperationsException
- if the field name is illegal.public void setField(String fieldName, Object fieldValue) throws RuntimeOperationsException
Descriptor
Sets 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.
setField
in interface Descriptor
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.RuntimeOperationsException
- if the field name or field value
is illegal (wrapped exception is IllegalArgumentException
); or
if the descriptor is immutable (wrapped exception is
UnsupportedOperationException
).public String[] getFields()
Descriptor
getFields
in interface Descriptor
Descriptor.setFields(java.lang.String[], java.lang.Object[])
public String[] getFieldNames()