Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.management/share/classes/javax/management/Descriptor.java
41155 views
1
/*
2
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
/*
26
* @author IBM Corp.
27
*
28
* Copyright IBM Corp. 1999-2000. All rights reserved.
29
*/
30
31
package javax.management;
32
33
import java.io.Serializable;
34
35
// Javadoc imports:
36
import java.lang.management.MemoryUsage;
37
import java.util.Arrays;
38
import java.util.Locale;
39
import java.util.ResourceBundle;
40
import javax.management.openmbean.CompositeData;
41
import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
42
import javax.management.openmbean.OpenMBeanOperationInfoSupport;
43
import javax.management.openmbean.OpenMBeanParameterInfoSupport;
44
import javax.management.openmbean.OpenType;
45
46
/**
47
* <p>Additional metadata for a JMX element. A {@code Descriptor}
48
* is associated with a {@link MBeanInfo}, {@link MBeanAttributeInfo}, etc.
49
* It consists of a collection of fields. A field is a name and an
50
* associated value.</p>
51
*
52
* <p>Field names are not case-sensitive. The names {@code descriptorType},
53
* {@code descriptortype}, and {@code DESCRIPTORTYPE} are all equivalent.
54
* However, the case that was used when the field was first set is preserved
55
* in the result of the {@link #getFields} and {@link #getFieldNames}
56
* methods.</p>
57
*
58
* <p>Not all field names and values are predefined.
59
* New fields can be defined and added by any program.</p>
60
*
61
* <p>A descriptor can be mutable or immutable.
62
* An immutable descriptor, once created, never changes.
63
* The <code>Descriptor</code> methods that could modify the contents
64
* of the descriptor will throw an exception
65
* for an immutable descriptor. Immutable descriptors are usually
66
* instances of {@link ImmutableDescriptor} or a subclass. Mutable
67
* descriptors are usually instances of
68
* {@link javax.management.modelmbean.DescriptorSupport} or a subclass.
69
*
70
* <p>Certain fields are used by the JMX implementation. This means
71
* either that the presence of the field may change the behavior of
72
* the JMX API or that the field may be set in descriptors returned by
73
* the JMX API. These fields appear in <i>italics</i> in the table
74
* below, and each one has a corresponding constant in the {@link JMX}
75
* class. For example, the field {@code defaultValue} is represented
76
* by the constant {@link JMX#DEFAULT_VALUE_FIELD}.</p>
77
*
78
* <p>Certain other fields have conventional meanings described in the
79
* table below but they are not required to be understood or set by
80
* the JMX implementation.</p>
81
*
82
* <p>Field names defined by the JMX specification in this and all
83
* future versions will never contain a period (.). Users can safely
84
* create their own fields by including a period in the name and be
85
* sure that these names will not collide with any future version of
86
* the JMX API. It is recommended to follow the Java package naming
87
* convention to avoid collisions between field names from different
88
* origins. For example, a field created by {@code example.com} might
89
* have the name {@code com.example.interestLevel}.</p>
90
*
91
* <p>Note that the values in the {@code defaultValue}, {@code
92
* legalValues}, {@code maxValue}, and {@code minValue} fields should
93
* be consistent with the type returned by the {@code getType()}
94
* method for the associated {@code MBeanAttributeInfo} or {@code
95
* MBeanParameterInfo}. For MXBeans, this means that they should be
96
* of the mapped Java type, called <em>opendata</em>(J) in the <a
97
* href="MXBean.html#mapping-rules">MXBean type mapping rules</a>.</p>
98
*
99
* <table class="striped">
100
* <caption style="display:none">Descriptor Fields</caption>
101
* <thead>
102
* <tr><th scope="col">Name</th>
103
* <th scope="col">Type</th>
104
* <th scope="col">Used in</th>
105
* <th scope="col">Meaning</th></tr>
106
* </thead>
107
*
108
* <tbody style="text-align:left">
109
* <tr id="defaultValue"><th scope="row"><i>defaultValue</i><td>Object</td>
110
* <td>MBeanAttributeInfo<br>MBeanParameterInfo</td>
111
*
112
* <td>Default value for an attribute or parameter. See
113
* {@link javax.management.openmbean}.</td>
114
*
115
* <tr><th scope="row">deprecated</th><td>String</td><td>Any</td>
116
*
117
* <td>An indication that this element of the information model is no
118
* longer recommended for use. A set of MBeans defined by an
119
* application is collectively called an <em>information model</em>.
120
* The convention is for the value of this field to contain a string
121
* that is the version of the model in which the element was first
122
* deprecated, followed by a space, followed by an explanation of the
123
* deprecation, for example {@code "1.3 Replaced by the Capacity
124
* attribute"}.</td>
125
*
126
* <tr><th scope="row" id="descriptionResourceBundleBaseName">descriptionResource<br>
127
* BundleBaseName</th><td>String</td><td>Any</td>
128
*
129
* <td>The base name for the {@link ResourceBundle} in which the key given in
130
* the {@code descriptionResourceKey} field can be found, for example
131
* {@code "com.example.myapp.MBeanResources"}. The meaning of this
132
* field is defined by this specification but the field is not set or
133
* used by the JMX API itself.</td>
134
*
135
* <tr><th scope="row" id="descriptionResourceKey">descriptionResourceKey</th>
136
* <td>String</td><td>Any</td>
137
*
138
* <td>A resource key for the description of this element. In
139
* conjunction with the {@code descriptionResourceBundleBaseName},
140
* this can be used to find a localized version of the description.
141
* The meaning of this field is defined by this specification but the
142
* field is not set or used by the JMX API itself.</td>
143
*
144
* <tr><th scope="row">enabled</th><td>String</td>
145
* <td>MBeanAttributeInfo<br>MBeanNotificationInfo<br>MBeanOperationInfo</td>
146
*
147
* <td>The string {@code "true"} or {@code "false"} according as this
148
* item is enabled. When an attribute or operation is not enabled, it
149
* exists but cannot currently be accessed. A user interface might
150
* present it as a greyed-out item. For example, an attribute might
151
* only be meaningful after the {@code start()} method of an MBean has
152
* been called, and is otherwise disabled. Likewise, a notification
153
* might be disabled if it cannot currently be emitted but could be in
154
* other circumstances.</td>
155
*
156
* <tr id="exceptions"><th scope="row">exceptions<td>String[]</td>
157
* <td>MBeanAttributeInfo, MBeanConstructorInfo, MBeanOperationInfo</td>
158
*
159
* <td>The class names of the exceptions that can be thrown when invoking a
160
* constructor or operation, or getting an attribute. The meaning of this field
161
* is defined by this specification but the field is not set or used by the
162
* JMX API itself. Exceptions thrown when
163
* setting an attribute are specified by the field
164
* <a href="#setExceptions">{@code setExceptions}</a>.
165
*
166
* <tr id="immutableInfo"><th scope="row"><i>immutableInfo</i><td>String</td>
167
* <td>MBeanInfo</td>
168
*
169
* <td>The string {@code "true"} or {@code "false"} according as this
170
* MBean's MBeanInfo is <em>immutable</em>. When this field is true,
171
* the MBeanInfo for the given MBean is guaranteed not to change over
172
* the lifetime of the MBean. Hence, a client can read it once and
173
* cache the read value. When this field is false or absent, there is
174
* no such guarantee, although that does not mean that the MBeanInfo
175
* will necessarily change. See also the <a
176
* href="MBeanInfo.html#info-changed">{@code "jmx.mbean.info.changed"}</a>
177
* notification.</td>
178
*
179
* <tr id="infoTimeout"><th scope="row">infoTimeout</th><td>String<br>Long</td><td>MBeanInfo</td>
180
*
181
* <td>The time in milli-seconds that the MBeanInfo can reasonably be
182
* expected to be unchanged. The value can be a {@code Long} or a
183
* decimal string. This provides a hint from a DynamicMBean or any
184
* MBean that does not define {@code immutableInfo} as {@code true}
185
* that the MBeanInfo is not likely to change within this period and
186
* therefore can be cached. When this field is missing or has the
187
* value zero, it is not recommended to cache the MBeanInfo unless it
188
* has the {@code immutableInfo} set to {@code true} or it has <a
189
* href="MBeanInfo.html#info-changed">{@code "jmx.mbean.info.changed"}</a> in
190
* its {@link MBeanNotificationInfo} array.</td></tr>
191
*
192
* <tr id="interfaceClassName"><th scope="row"><i>interfaceClassName</i></th>
193
* <td>String</td><td>MBeanInfo</td>
194
*
195
* <td>The Java interface name for a Standard MBean or MXBean, as
196
* returned by {@link Class#getName()}. A Standard MBean or MXBean
197
* registered directly in the MBean Server or created using the {@link
198
* StandardMBean} class will have this field in its MBeanInfo
199
* Descriptor.</td>
200
*
201
* <tr id="legalValues"><th scope="row"><i>legalValues</i></th>
202
* <td>{@literal Set<?>}</td><td>MBeanAttributeInfo<br>MBeanParameterInfo</td>
203
*
204
* <td>Legal values for an attribute or parameter. See
205
* {@link javax.management.openmbean}.</td>
206
*
207
* <tr id="locale"><th scope="row">locale</th>
208
* <td>String</td><td>Any</td>
209
*
210
* <td>The {@linkplain Locale locale} of the description in this
211
* {@code MBeanInfo}, {@code MBeanAttributeInfo}, etc, as returned
212
* by {@link Locale#toString()}.</td>
213
*
214
* <tr id="maxValue"><th scope="row"><i>maxValue</i><td>Object</td>
215
* <td>MBeanAttributeInfo<br>MBeanParameterInfo</td>
216
*
217
* <td>Maximum legal value for an attribute or parameter. See
218
* {@link javax.management.openmbean}.</td>
219
*
220
* <tr id="metricType"><th scope="row">metricType</th><td>String</td>
221
* <td>MBeanAttributeInfo<br>MBeanOperationInfo</td>
222
*
223
* <td>The type of a metric, one of the strings "counter" or "gauge".
224
* A metric is a measurement exported by an MBean, usually an
225
* attribute but sometimes the result of an operation. A metric that
226
* is a <em>counter</em> has a value that never decreases except by
227
* being reset to a starting value. Counter metrics are almost always
228
* non-negative integers. An example might be the number of requests
229
* received. A metric that is a <em>gauge</em> has a numeric value
230
* that can increase or decrease. Examples might be the number of
231
* open connections or a cache hit rate or a temperature reading.
232
*
233
* <tr id="minValue"><th scope="row"><i>minValue</i><td>Object</td>
234
* <td>MBeanAttributeInfo<br>MBeanParameterInfo</td>
235
*
236
* <td>Minimum legal value for an attribute or parameter. See
237
* {@link javax.management.openmbean}.</td>
238
*
239
* <tr id="mxbean"><th scope="row"><i>mxbean</i><td>String</td>
240
* <td>MBeanInfo</td>
241
*
242
* <td>The string {@code "true"} or {@code "false"} according as this
243
* MBean is an {@link MXBean}. A Standard MBean or MXBean registered
244
* directly with the MBean Server or created using the {@link
245
* StandardMBean} class will have this field in its MBeanInfo
246
* Descriptor.</td>
247
*
248
* <tr id="openType"><th scope="row"><i>openType</i><td>{@link OpenType}</td>
249
* <td>MBeanAttributeInfo<br>MBeanOperationInfo<br>MBeanParameterInfo</td>
250
*
251
* <td><p>The Open Type of this element. In the case of {@code
252
* MBeanAttributeInfo} and {@code MBeanParameterInfo}, this is the
253
* Open Type of the attribute or parameter. In the case of {@code
254
* MBeanOperationInfo}, it is the Open Type of the return value. This
255
* field is set in the Descriptor for all instances of {@link
256
* OpenMBeanAttributeInfoSupport}, {@link
257
* OpenMBeanOperationInfoSupport}, and {@link
258
* OpenMBeanParameterInfoSupport}. It is also set for attributes,
259
* operations, and parameters of MXBeans.</p>
260
*
261
* <p>This field can be set for an {@code MBeanNotificationInfo}, in
262
* which case it indicates the Open Type that the {@link
263
* Notification#getUserData() user data} will have.</td>
264
*
265
* <tr id="originalType"><th scope="row"><i>originalType</i><td>String</td>
266
* <td>MBeanAttributeInfo<br>MBeanOperationInfo<br>MBeanParameterInfo</td>
267
*
268
* <td><p>The original Java type of this element as it appeared in the
269
* {@link MXBean} interface method that produced this {@code
270
* MBeanAttributeInfo} (etc). For example, a method<br> <code>public
271
* </code> {@link MemoryUsage}<code> getHeapMemoryUsage();</code><br>
272
* in an MXBean interface defines an attribute called {@code
273
* HeapMemoryUsage} of type {@link CompositeData}. The {@code
274
* originalType} field in the Descriptor for this attribute will have
275
* the value {@code "java.lang.management.MemoryUsage"}.
276
*
277
* <p>The format of this string is described in the section <a
278
* href="MXBean.html#type-names">Type Names</a> of the MXBean
279
* specification.</p>
280
*
281
* <tr id="setExceptions"><th scope="row"><i>setExceptions</i><td>String[]</td>
282
* <td>MBeanAttributeInfo</td>
283
*
284
* <td>The class names of the exceptions that can be thrown when setting
285
* an attribute. The meaning of this field
286
* is defined by this specification but the field is not set or used by the
287
* JMX API itself. Exceptions thrown when getting an attribute are specified
288
* by the field <a href="#exceptions">{@code exceptions}</a>.
289
*
290
* <tr><th scope="row">severity</th><td>String<br>Integer</td>
291
* <td>MBeanNotificationInfo</td>
292
*
293
* <td>The severity of this notification. It can be 0 to mean
294
* unknown severity or a value from 1 to 6 representing decreasing
295
* levels of severity. It can be represented as a decimal string or
296
* an {@code Integer}.</td>
297
*
298
* <tr><th scope="row">since</th><td>String</td><td>Any</td>
299
*
300
* <td>The version of the information model in which this element
301
* was introduced. A set of MBeans defined by an application is
302
* collectively called an <em>information model</em>. The
303
* application may also define versions of this model, and use the
304
* {@code "since"} field to record the version in which an element
305
* first appeared.</td>
306
*
307
* <tr><th scope="row">units</th><td>String</td>
308
* <td>MBeanAttributeInfo<br>MBeanParameterInfo<br>MBeanOperationInfo</td>
309
*
310
* <td>The units in which an attribute, parameter, or operation return
311
* value is measured, for example {@code "bytes"} or {@code
312
* "seconds"}.</td>
313
*
314
* </tbody>
315
* </table>
316
*
317
* <p>Some additional fields are defined by Model MBeans. See the
318
* information for <a href="modelmbean/ModelMBeanInfo.html#descriptor"><!--
319
* -->{@code ModelMBeanInfo}</a>,
320
* <a href="modelmbean/ModelMBeanAttributeInfo.html#descriptor"><!--
321
* -->{@code ModelMBeanAttributeInfo}</a>,
322
* <a href="modelmbean/ModelMBeanConstructorInfo.html#descriptor"><!--
323
* -->{@code ModelMBeanConstructorInfo}</a>,
324
* <a href="modelmbean/ModelMBeanNotificationInfo.html#descriptor"><!--
325
* -->{@code ModelMBeanNotificationInfo}</a>, and
326
* <a href="modelmbean/ModelMBeanOperationInfo.html#descriptor"><!--
327
* -->{@code ModelMBeanOperationInfo}</a>, as
328
* well as the chapter "Model MBeans" of the <a
329
* href="http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html">JMX
330
* Specification</a>. The following table summarizes these fields. Note
331
* that when the Type in this table is Number, a String that is the decimal
332
* representation of a Long can also be used.</p>
333
*
334
* <p>Nothing prevents the use of these fields in MBeans that are not Model
335
* MBeans. The <a href="#displayName">displayName</a>, <a href="#severity"><!--
336
* -->severity</a>, and <a href="#visibility">visibility</a> fields are of
337
* interest outside Model MBeans, for example. But only Model MBeans have
338
* a predefined behavior for these fields.</p>
339
*
340
* <table class="striped">
341
* <caption style="display:none">ModelMBean Fields</caption>
342
*
343
* <thead>
344
* <tr><th scope="col">Name</th>
345
* <th scope="col">Type</th>
346
* <th scope="col">Used in</th>
347
* <th scope="col">Meaning</th></tr>
348
* </thead>
349
*
350
* <tbody style="text-align:left">
351
* <tr><th scope="row">class</th><td>String</td><td>ModelMBeanOperationInfo</td>
352
* <td>Class where method is defined (fully qualified).</td></tr>
353
*
354
* <tr><th scope="row">currencyTimeLimit</th><td>Number</td>
355
* <td>ModelMBeanInfo<br>ModelMBeanAttributeInfo<br>ModelMBeanOperationInfo</td>
356
* <td>How long cached value is valid: &lt;0 never, =0 always,
357
* &gt;0 seconds.</td></tr>
358
*
359
* <tr><th scope="row">default</th><td>Object</td><td>ModelMBeanAttributeInfo</td>
360
* <td>Default value for attribute.</td></tr>
361
*
362
* <tr><th scope="row">descriptorType</th><td>String</td><td>Any</td>
363
* <td>Type of descriptor, "mbean", "attribute", "constructor", "operation",
364
* or "notification".</td></tr>
365
*
366
* <tr id="displayName"><th scope="row">displayName</th><td>String</td><td>Any</td>
367
* <td>Human readable name of this item.</td></tr>
368
*
369
* <tr><th scope="row">export</th><td>String</td><td>ModelMBeanInfo</td>
370
* <td>Name to be used to export/expose this MBean so that it is
371
* findable by other JMX Agents.</td></tr>
372
*
373
* <tr><th scope="row">getMethod</th><td>String</td><td>ModelMBeanAttributeInfo</td>
374
* <td>Name of operation descriptor for get method.</td></tr>
375
*
376
* <tr><th scope="row">lastUpdatedTimeStamp</th><td>Number</td>
377
* <td>ModelMBeanAttributeInfo<br>ModelMBeanOperationInfo</td>
378
* <td>When <a href="#value-field">value</a> was set.</td></tr>
379
*
380
* <tr><th scope="row">log</th><td>String</td><td>ModelMBeanInfo<br>ModelMBeanNotificationInfo</td>
381
* <td>t or T: log all notifications, f or F: log no notifications.</td></tr>
382
*
383
* <tr><th scope="row">logFile</th><td>String</td><td>ModelMBeanInfo<br>ModelMBeanNotificationInfo</td>
384
* <td>Fully qualified filename to log events to.</td></tr>
385
*
386
* <tr><th scope="row">messageID</th><td>String</td><td>ModelMBeanNotificationInfo</td>
387
* <td>Unique key for message text (to allow translation, analysis).</td></tr>
388
*
389
* <tr><th scope="row">messageText</th><td>String</td><td>ModelMBeanNotificationInfo</td>
390
* <td>Text of notification.</td></tr>
391
*
392
* <tr><th scope="row">name</th><td>String</td><td>Any</td>
393
* <td>Name of this item.</td></tr>
394
*
395
* <tr><th scope="row">persistFile</th><td>String</td><td>ModelMBeanInfo</td>
396
* <td>File name into which the MBean should be persisted.</td></tr>
397
*
398
* <tr><th scope="row">persistLocation</th><td>String</td><td>ModelMBeanInfo</td>
399
* <td>The fully qualified directory name where the MBean should be
400
* persisted (if appropriate).</td></tr>
401
*
402
* <tr><th scope="row">persistPeriod</th><td>Number</td>
403
* <td>ModelMBeanInfo<br>ModelMBeanAttributeInfo</td>
404
* <td>Frequency of persist cycle in seconds. Used when persistPolicy is
405
* "OnTimer" or "NoMoreOftenThan".</td></tr>
406
*
407
* <tr><th scope="row">persistPolicy</th><td>String</td>
408
* <td>ModelMBeanInfo<br>ModelMBeanAttributeInfo</td>
409
* <td>One of: OnUpdate|OnTimer|NoMoreOftenThan|OnUnregister|Always|Never.
410
* See the section "MBean Descriptor Fields" in the JMX specification
411
* document.</td></tr>
412
*
413
* <tr><th scope="row">presentationString</th><td>String</td><td>Any</td>
414
* <td>XML formatted string to allow presentation of data.</td></tr>
415
*
416
* <tr><th scope="row">protocolMap</th><td>Descriptor</td><td>ModelMBeanAttributeInfo</td>
417
* <td>See the section "Protocol Map Support" in the JMX specification
418
* document. Mappings must be appropriate for the attribute and entries
419
* can be updated or augmented at runtime.</td></tr>
420
*
421
* <tr><th scope="row">role</th><td>String</td>
422
* <td>ModelMBeanConstructorInfo<br>ModelMBeanOperationInfo</td>
423
* <td>One of "constructor", "operation", "getter", or "setter".</td></tr>
424
*
425
* <tr><th scope="row">setMethod</th><td>String</td><td>ModelMBeanAttributeInfo</td>
426
* <td>Name of operation descriptor for set method.</td></tr>
427
*
428
* <tr id="severity"><th scope="row">severity</th><td>Number</td>
429
* <td>ModelMBeanNotificationInfo</td>
430
* <td>0-6 where 0: unknown; 1: non-recoverable;
431
* 2: critical, failure; 3: major, severe;
432
* 4: minor, marginal, error; 5: warning;
433
* 6: normal, cleared, informative</td></tr>
434
*
435
* <tr><th scope="row">targetObject</th><td>Object</td><td>ModelMBeanOperationInfo</td>
436
* <td>Object on which to execute this method.</td></tr>
437
*
438
* <tr><th scope="row">targetType</th><td>String</td><td>ModelMBeanOperationInfo</td>
439
* <td>type of object reference for targetObject. Can be:
440
* ObjectReference | Handle | EJBHandle | IOR | RMIReference.</td></tr>
441
*
442
* <tr id="value-field"><th scope="row">value</th><td>Object</td>
443
* <td>ModelMBeanAttributeInfo<br>ModelMBeanOperationInfo</td>
444
* <td>Current (cached) value for attribute or operation.</td></tr>
445
*
446
* <tr id="visibility"><th scope="row">visibility</th><td>Number</td><td>Any</td>
447
* <td>1-4 where 1: always visible, 4: rarely visible.</td></tr>
448
*
449
* </tbody>
450
* </table>
451
*
452
* @since 1.5
453
*/
454
public interface Descriptor extends Serializable, Cloneable
455
{
456
457
/**
458
* Returns the value for a specific field name, or null if no value
459
* is present for that name.
460
*
461
* @param fieldName the field name.
462
*
463
* @return the corresponding value, or null if the field is not present.
464
*
465
* @exception RuntimeOperationsException if the field name is illegal.
466
*/
467
public Object getFieldValue(String fieldName)
468
throws RuntimeOperationsException;
469
470
/**
471
* <p>Sets the value for a specific field name. This will
472
* modify an existing field or add a new field.</p>
473
*
474
* <p>The field value will be validated before it is set.
475
* If it is not valid, then an exception will be thrown.
476
* The meaning of validity is dependent on the descriptor
477
* implementation.</p>
478
*
479
* @param fieldName The field name to be set. Cannot be null or empty.
480
* @param fieldValue The field value to be set for the field
481
* name. Can be null if that is a valid value for the field.
482
*
483
* @exception RuntimeOperationsException if the field name or field value
484
* is illegal (wrapped exception is {@link IllegalArgumentException}); or
485
* if the descriptor is immutable (wrapped exception is
486
* {@link UnsupportedOperationException}).
487
*/
488
public void setField(String fieldName, Object fieldValue)
489
throws RuntimeOperationsException;
490
491
492
/**
493
* Returns all of the fields contained in this descriptor as a string array.
494
*
495
* @return String array of fields in the format <i>fieldName=fieldValue</i>
496
* <br>If the value of a field is not a String, then the toString() method
497
* will be called on it and the returned value, enclosed in parentheses,
498
* used as the value for the field in the returned array. If the value
499
* of a field is null, then the value of the field in the returned array
500
* will be empty. If the descriptor is empty, you will get
501
* an empty array.
502
*
503
* @see #setFields
504
*/
505
public String[] getFields();
506
507
508
/**
509
* Returns all the field names in the descriptor.
510
*
511
* @return String array of field names. If the descriptor is empty,
512
* you will get an empty array.
513
*/
514
public String[] getFieldNames();
515
516
/**
517
* Returns all the field values in the descriptor as an array of Objects. The
518
* returned values are in the same order as the {@code fieldNames} String array parameter.
519
*
520
* @param fieldNames String array of the names of the fields that
521
* the values should be returned for. If the array is empty then
522
* an empty array will be returned. If the array is null then all
523
* values will be returned, as if the parameter were the array
524
* returned by {@link #getFieldNames()}. If a field name in the
525
* array does not exist, including the case where it is null or
526
* the empty string, then null is returned for the matching array
527
* element being returned.
528
*
529
* @return Object array of field values. If the list of {@code fieldNames}
530
* is empty, you will get an empty array.
531
*/
532
public Object[] getFieldValues(String... fieldNames);
533
534
/**
535
* Removes a field from the descriptor.
536
*
537
* @param fieldName String name of the field to be removed.
538
* If the field name is illegal or the field is not found,
539
* no exception is thrown.
540
*
541
* @exception RuntimeOperationsException if a field of the given name
542
* exists and the descriptor is immutable. The wrapped exception will
543
* be an {@link UnsupportedOperationException}.
544
*/
545
public void removeField(String fieldName);
546
547
/**
548
* <p>Sets all fields in the field names array to the new value with
549
* the same index in the field values array. Array sizes must match.</p>
550
*
551
* <p>The field value will be validated before it is set.
552
* If it is not valid, then an exception will be thrown.
553
* If the arrays are empty, then no change will take effect.</p>
554
*
555
* @param fieldNames String array of field names. The array and array
556
* elements cannot be null.
557
* @param fieldValues Object array of the corresponding field values.
558
* The array cannot be null. Elements of the array can be null.
559
*
560
* @throws RuntimeOperationsException if the change fails for any reason.
561
* Wrapped exception is {@link IllegalArgumentException} if
562
* {@code fieldNames} or {@code fieldValues} is null, or if
563
* the arrays are of different lengths, or if there is an
564
* illegal value in one of them.
565
* Wrapped exception is {@link UnsupportedOperationException}
566
* if the descriptor is immutable, and the call would change
567
* its contents.
568
*
569
* @see #getFields
570
*/
571
public void setFields(String[] fieldNames, Object[] fieldValues)
572
throws RuntimeOperationsException;
573
574
575
/**
576
* <p>Returns a descriptor which is equal to this descriptor.
577
* Changes to the returned descriptor will have no effect on this
578
* descriptor, and vice versa. If this descriptor is immutable,
579
* it may fulfill this condition by returning itself.</p>
580
* @exception RuntimeOperationsException for illegal value for field names
581
* or field values.
582
* If the descriptor construction fails for any reason, this exception will
583
* be thrown.
584
* @return A descriptor which is equal to this descriptor.
585
*/
586
public Object clone() throws RuntimeOperationsException;
587
588
589
/**
590
* Returns true if all of the fields have legal values given their
591
* names.
592
*
593
* @return true if the values are legal.
594
*
595
* @exception RuntimeOperationsException If the validity checking fails for
596
* any reason, this exception will be thrown.
597
* The method returns false if the descriptor is not valid, but throws
598
* this exception if the attempt to determine validity fails.
599
*/
600
public boolean isValid() throws RuntimeOperationsException;
601
602
/**
603
* <p>Compares this descriptor to the given object. The objects are equal if
604
* the given object is also a Descriptor, and if the two Descriptors have
605
* the same field names (possibly differing in case) and the same
606
* associated values. The respective values for a field in the two
607
* Descriptors are equal if the following conditions hold:</p>
608
*
609
* <ul>
610
* <li>If one value is null then the other must be too.</li>
611
* <li>If one value is a primitive array then the other must be a primitive
612
* array of the same type with the same elements.</li>
613
* <li>If one value is an object array then the other must be too and
614
* {@link Arrays#deepEquals(Object[],Object[])} must return true.</li>
615
* <li>Otherwise {@link Object#equals(Object)} must return true.</li>
616
* </ul>
617
*
618
* @param obj the object to compare with.
619
*
620
* @return {@code true} if the objects are the same; {@code false}
621
* otherwise.
622
*
623
* @since 1.6
624
*/
625
public boolean equals(Object obj);
626
627
/**
628
* <p>Returns the hash code value for this descriptor. The hash
629
* code is computed as the sum of the hash codes for each field in
630
* the descriptor. The hash code of a field with name {@code n}
631
* and value {@code v} is {@code n.toLowerCase().hashCode() ^ h}.
632
* Here {@code h} is the hash code of {@code v}, computed as
633
* follows:</p>
634
*
635
* <ul>
636
* <li>If {@code v} is null then {@code h} is 0.</li>
637
* <li>If {@code v} is a primitive array then {@code h} is computed using
638
* the appropriate overloading of {@code java.util.Arrays.hashCode}.</li>
639
* <li>If {@code v} is an object array then {@code h} is computed using
640
* {@link Arrays#deepHashCode(Object[])}.</li>
641
* <li>Otherwise {@code h} is {@code v.hashCode()}.</li>
642
* </ul>
643
*
644
* @return A hash code value for this object.
645
*
646
* @since 1.6
647
*/
648
public int hashCode();
649
}
650
651