KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > openmbean > OpenMBeanAttributeInfoSupport


1 /*
2  * @(#)OpenMBeanAttributeInfoSupport.java 3.28 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8
9 package javax.management.openmbean;
10
11
12 // java import
13
//
14
import java.io.Serializable JavaDoc;
15 import java.util.Set JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Collections JavaDoc;
18 import java.lang.Comparable JavaDoc; // to be substituted for jdk1.1.x
19

20
21 // jmx import
22
//
23
import javax.management.MBeanAttributeInfo JavaDoc;
24
25
26 /**
27  * Describes an attribute of an open MBean.
28  *
29  * @version 3.28 03/12/19
30  * @author Sun Microsystems, Inc.
31  *
32  * @since 1.5
33  * @since.unbundled JMX 1.1
34  */

35 public class OpenMBeanAttributeInfoSupport
36     extends MBeanAttributeInfo JavaDoc
37     implements OpenMBeanAttributeInfo JavaDoc, Serializable JavaDoc {
38     
39     
40     /* Serial version */
41     static final long serialVersionUID = -4867215622149721849L;
42
43     /**
44      * @serial The open mbean attribute's <i>open type</i>
45      */

46     private OpenType JavaDoc openType;
47
48     /**
49      * @serial The open mbean attribute's default value
50      */

51     private Object JavaDoc defaultValue = null;
52
53     /**
54      * @serial The open mbean attribute's legal values. This {@link Set} is unmodifiable
55      */

56     private Set JavaDoc legalValues = null; // to be constructed unmodifiable
57

58     /**
59      * @serial The open mbean attribute's min value
60      */

61     private Comparable JavaDoc minValue = null;
62
63     /**
64      * @serial The open mbean attribute's max value
65      */

66     private Comparable JavaDoc maxValue = null;
67
68
69     private transient Integer JavaDoc myHashCode = null; // As this instance is immutable, these two values
70
private transient String JavaDoc myToString = null; // need only be calculated once.
71

72
73     /**
74      * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute of an open MBean
75      * with the specified <var>name</var>, <var>openType</var> and <var>description</var>,
76      * and the specified read/write access properties.
77      *
78      * @param name cannot be a null or empty string.
79      *
80      * @param description cannot be a null or empty string.
81      *
82      * @param openType cannot be null.
83      *
84      * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
85      *
86      * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
87      *
88      * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
89      *
90      * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
91      * or <var>openType</var> is null.
92      */

93     public OpenMBeanAttributeInfoSupport(String JavaDoc name,
94                      String JavaDoc description,
95                      OpenType JavaDoc openType,
96                      boolean isReadable,
97                      boolean isWritable,
98                      boolean isIs) {
99
100     // Construct parent's state
101
//
102
super(name, ( (openType==null) ? null : openType.getClassName() ), description, isReadable, isWritable, isIs);
103
104     // check parameters that should not be null or empty (unfortunately it is not done in superclass :-( ! )
105
//
106
if ( (name == null) || (name.trim().equals("")) ) {
107         throw new IllegalArgumentException JavaDoc("Argument name cannot be null or empty.");
108     }
109     if (openType == null) {
110         throw new IllegalArgumentException JavaDoc("Argument openType cannot be null.");
111     }
112     if ( (description == null) || (description.trim().equals("")) ) {
113         throw new IllegalArgumentException JavaDoc("Argument description cannot be null or empty.");
114     }
115
116     // Initialize this instance's specific state
117
//
118
this.openType = openType;
119     }
120
121     /**
122      * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute of an open MBean
123      * with the specified <var>name</var>, <var>openType</var>, <var>description</var> and <var>defaultValue</var>,
124      * and the specified read/write access properties.
125      *
126      * @param name cannot be a null or empty string.
127      *
128      * @param description cannot be a null or empty string.
129      *
130      * @param openType cannot be null.
131      *
132      * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
133      *
134      * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
135      *
136      * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
137      *
138      * @param defaultValue must be a valid value for the <var>openType</var> specified for this attribute;
139      * default value not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>;
140      * can be null, in which case it means that no default value is set.
141      *
142      * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
143      * or <var>openType</var> is null.
144      *
145      * @throws OpenDataException if <var>defaultValue</var> is not a valid value for the specified <var>openType</var>,
146      * or <var>defaultValue</var> is non null and
147      * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>.
148      */

149     public OpenMBeanAttributeInfoSupport(String JavaDoc name,
150                      String JavaDoc description,
151                      OpenType JavaDoc openType,
152                      boolean isReadable,
153                      boolean isWritable,
154                      boolean isIs,
155                      Object JavaDoc defaultValue) throws OpenDataException JavaDoc {
156
157     // First check and construct the part regarding name, openType and description
158
//
159
this(name, description, openType, isReadable, isWritable, isIs);
160
161     // Check and initialize defaultValue
162
//
163
if (defaultValue != null) {
164         // Default value not supported for ArrayType and TabularType
165
if ( (openType.isArray()) || (openType instanceof TabularType JavaDoc) ) {
166         throw new OpenDataException JavaDoc("Default value not supported for ArrayType and TabularType.");
167         }
168         // Check defaultValue's class
169
if ( ! openType.isValue(defaultValue) ) {
170         throw new OpenDataException JavaDoc("Argument defaultValue's class [\""+ defaultValue.getClass().getName() +
171                         "\"] does not match the one defined in openType[\""+ openType.getClassName() +"\"].");
172         }
173         // Then initializes defaultValue:
174
// no need to clone it: apart from arrays and TabularData, basic data types are immutable
175
this.defaultValue = defaultValue;
176     }
177     }
178
179
180     /**
181      * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute of an open MBean
182      * with the specified <var>name</var>, <var>openType</var>, <var>description</var>,
183      * <var>defaultValue</var> and <var>legalValues</var>,
184      * and the specified read/write access properties.
185      *
186      * The contents of <var>legalValues</var> are internally dumped into an unmodifiable <tt>Set</tt>,
187      * so subsequent modifications of the array referenced by <var>legalValues</var> have no impact on
188      * this <tt>OpenMBeanAttributeInfoSupport</tt> instance.
189      *
190      * @param name cannot be a null or empty string.
191      *
192      * @param description cannot be a null or empty string.
193      *
194      * @param openType cannot be null.
195      *
196      * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
197      *
198      * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
199      *
200      * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
201      *
202      * @param defaultValue must be a valid value for the <var>openType</var> specified for this attribute;
203      * default value not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>;
204      * can be null, in which case it means that no default value is set.
205      *
206      * @param legalValues each contained value must be valid for the <var>openType</var> specified for this attribute;
207      * legal values not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>;
208      * can be null or empty.
209      *
210      * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
211      * or <var>openType</var> is null.
212      *
213      * @throws OpenDataException if <var>defaultValue</var> is not a valid value for the specified <var>openType</var>,
214      * or one value in <var>legalValues</var> is not valid for the specified <var>openType</var>,
215      * or <var>defaultValue</var> is non null and
216      * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>,
217      * or <var>legalValues</var> is non null and non empty and
218      * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>,
219      * or <var>legalValues</var> is non null and non empty and
220      * <var>defaultValue</var> is not contained in <var>legalValues</var>.
221      */

222     public OpenMBeanAttributeInfoSupport(String JavaDoc name,
223                      String JavaDoc description,
224                      OpenType JavaDoc openType,
225                      boolean isReadable,
226                      boolean isWritable,
227                      boolean isIs,
228                      Object JavaDoc defaultValue,
229                      Object JavaDoc[] legalValues) throws OpenDataException JavaDoc {
230
231     // First check and construct the part regarding name, openType, description and defaultValue
232
//
233
this(name, description, openType, isReadable, isWritable, isIs, defaultValue);
234
235     // Check and initialize legalValues
236
//
237
if ( (legalValues != null) && (legalValues.length > 0) ){
238         // legalValues not supported for TabularType and arrays
239
if ( (openType instanceof TabularType JavaDoc) || (openType.isArray()) ) {
240         throw new OpenDataException JavaDoc("Legal values not supported for TabularType and arrays");
241         }
242         // Check legalValues are valid with openType
243
for (int i = 0; i < legalValues.length; i++ ) {
244         if ( ! openType.isValue(legalValues[i]) ) {
245             throw new OpenDataException JavaDoc("Element legalValues["+ i +"]="+ legalValues[i] +
246                         " is not a valid value for the specified openType ["+ openType.toString() +"].");
247         }
248         }
249         // dump the legalValues array content into a Set: ensures uniqueness of elements
250
// (and we could not keep the array reference as array content could be modified by the caller)
251
Set JavaDoc tmpSet = new HashSet JavaDoc(legalValues.length+1, 1);
252         for (int i = 0; i < legalValues.length; i++ ) {
253         tmpSet.add(legalValues[i]);
254         }
255         // initializes legalValues as an unmodifiable Set
256
this.legalValues = Collections.unmodifiableSet(tmpSet);
257     }
258
259     // Check that defaultValue is a legal value
260
//
261
if ( (this.hasDefaultValue()) && (this.hasLegalValues()) ) {
262         if ( ! this.legalValues.contains(defaultValue) ) {
263         throw new OpenDataException JavaDoc("defaultValue is not contained in legalValues");
264         }
265     }
266     }
267
268
269     /**
270      * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute
271      * used in one or more operations or constructors of a class of open MBeans,
272      * with the specified <var>name</var>, <var>openType</var>, <var>description</var>,
273      * <var>defaultValue</var>, <var>minValue</var> and <var>maxValue</var>.
274      *
275      * It is possible to specify minimal and maximal values only for an open type
276      * whose values are <tt>Comparable</tt>.
277      *
278      * @param name cannot be a null or empty string.
279      *
280      * @param description cannot be a null or empty string.
281      *
282      * @param openType cannot be null.
283      *
284      * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
285      *
286      * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
287      *
288      * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
289      *
290      * @param defaultValue must be a valid value for the <var>openType</var> specified for this attribute;
291      * default value not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>;
292      * can be null, in which case it means that no default value is set.
293      *
294      * @param minValue must be valid for the <var>openType</var> specified for this attribute;
295      * can be null, in which case it means that no minimal value is set.
296      *
297      * @param maxValue must be valid for the <var>openType</var> specified for this attribute;
298      * can be null, in which case it means that no maximal value is set.
299      *
300      * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
301      * or <var>openType</var> is null.
302      *
303      * @throws OpenDataException if <var>defaultValue</var>, <var>minValue</var> or <var>maxValue</var>
304      * is not a valid value for the specified <var>openType</var>,
305      * or <var>defaultValue</var> is non null and
306      * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>,
307      * or both <var>minValue</var> and <var>maxValue</var> are non-null and
308      * <tt>minValue.compareTo(maxValue) > 0</tt> is <tt>true</tt>,
309      * or both <var>defaultValue</var> and <var>minValue</var> are non-null and
310      * <tt>minValue.compareTo(defaultValue) > 0</tt> is <tt>true</tt>,
311      * or both <var>defaultValue</var> and <var>maxValue</var> are non-null and
312      * <tt>defaultValue.compareTo(maxValue) > 0</tt> is <tt>true</tt>.
313      */

314     public OpenMBeanAttributeInfoSupport(String JavaDoc name,
315                      String JavaDoc description,
316                      OpenType JavaDoc openType,
317                      boolean isReadable,
318                      boolean isWritable,
319                      boolean isIs,
320                      Object JavaDoc defaultValue,
321                      Comparable JavaDoc minValue,
322                      Comparable JavaDoc maxValue) throws OpenDataException JavaDoc {
323
324     // First check and construct the part regarding name, openType, description and defaultValue
325
//
326
this(name, description, openType, isReadable, isWritable, isIs, defaultValue);
327
328     // Check and initialize minValue
329
//(note: no need to worry about Composite, Tabular and arrays as they are not Comparable)
330
//
331
if (minValue != null) {
332         if ( ! openType.isValue(minValue) ) {
333         throw new OpenDataException JavaDoc("Argument minValue's class [\""+ minValue.getClass().getName() +
334                         "\"] does not match openType's definition [\""+ openType.getClassName() +"\"].");
335         }
336         // then initializes minValue
337
this.minValue = minValue;
338     }
339
340     // Check and initialize maxValue
341
//(note: no need to worry about Composite, Tabular and arrays as they are not Comparable)
342
//
343
if (maxValue != null) {
344         if ( ! openType.isValue(maxValue) ) {
345         throw new OpenDataException JavaDoc("Argument maxValue's class [\""+ maxValue.getClass().getName() +
346                         "\"] does not match openType's definition [\""+ openType.getClassName() +"\"].");
347         }
348         // then initializes maxValue
349
this.maxValue = maxValue;
350     }
351
352     // Check that, if both specified, minValue <= maxValue
353
//
354
if (hasMinValue() && hasMaxValue()) {
355         if (minValue.compareTo(maxValue) > 0) {
356         throw new OpenDataException JavaDoc("minValue cannot be greater than maxValue.");
357         }
358     }
359
360     // Check that minValue <= defaultValue <= maxValue
361
//
362
if ( (this.hasDefaultValue()) && (this.hasMinValue()) ) {
363         if (minValue.compareTo((Comparable JavaDoc)defaultValue) > 0) {
364         throw new OpenDataException JavaDoc("minValue cannot be greater than defaultValue.");
365         }
366     }
367     if ( (this.hasDefaultValue()) && (this.hasMaxValue()) ) {
368         if (((Comparable JavaDoc)defaultValue).compareTo(maxValue) > 0) {
369         throw new OpenDataException JavaDoc("defaultValue cannot be greater than maxValue.");
370         }
371     }
372     }
373
374     /**
375      * Returns the open type for the values of the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance.
376      */

377     public OpenType JavaDoc getOpenType() {
378     return openType;
379     }
380
381     /**
382      * Returns the default value for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
383      * if specified, or <tt>null</tt> otherwise.
384      */

385     public Object JavaDoc getDefaultValue() {
386
387     // Special case for ArrayType and TabularType
388
// [JF] TODO: clone it so that it cannot be altered,
389
// [JF] TODO: if we decide to support defaultValue as an array itself.
390
// [JF] As of today (oct 2000) it is not supported so defaultValue is null for arrays. Nothing to do.
391

392     return defaultValue;
393     }
394
395     /**
396      * Returns an unmodifiable Set of legal values for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
397      * if specified, or <tt>null</tt> otherwise.
398      */

399     public Set JavaDoc getLegalValues() {
400
401     // Special case for ArrayType and TabularType
402
// [JF] TODO: clone values so that they cannot be altered,
403
// [JF] TODO: if we decide to support LegalValues as an array itself.
404
// [JF] As of today (oct 2000) it is not supported so legalValues is null for arrays. Nothing to do.
405

406     // Returns our legalValues Set (set was constructed unmodifiable)
407
return (legalValues);
408     }
409
410     /**
411      * Returns the minimal value for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
412      * if specified, or <tt>null</tt> otherwise.
413      */

414     public Comparable JavaDoc getMinValue() {
415
416     // Note: only comparable values have a minValue, so that's not the case of arrays and tabulars (always null).
417

418     return minValue;
419     }
420
421     /**
422      * Returns the maximal value for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
423      * if specified, or <tt>null</tt> otherwise.
424      */

425     public Comparable JavaDoc getMaxValue() {
426
427     // Note: only comparable values have a maxValue, so that's not the case of arrays and tabulars (always null).
428

429     return maxValue;
430     }
431
432     /**
433      * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null default value
434      * for the described attribute, <tt>false</tt> otherwise.
435      */

436     public boolean hasDefaultValue() {
437
438     return (defaultValue != null);
439     }
440
441     /**
442      * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null set of legal values
443      * for the described attribute, <tt>false</tt> otherwise.
444      */

445     public boolean hasLegalValues() {
446
447     return (legalValues != null);
448     }
449
450     /**
451      * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null minimal value
452      * for the described attribute, <tt>false</tt> otherwise.
453      */

454     public boolean hasMinValue() {
455
456     return (minValue != null);
457     }
458
459     /**
460      * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null maximal value
461      * for the described attribute, <tt>false</tt> otherwise.
462      */

463     public boolean hasMaxValue() {
464
465     return (maxValue != null);
466     }
467
468
469     /**
470      * Tests whether <var>obj</var> is a valid value for the attribute
471      * described by this <code>OpenMBeanAttributeInfoSupport</code>
472      * instance.
473      *
474      * @param obj the object to be tested.
475      *
476      * @return <code>true</code> if <var>obj</var> is a valid value for for the parameter described by
477      * this <code>OpenMBeanAttributeInfoSupport</code> instance, <code>false</code> otherwise.
478      */

479     public boolean isValue(Object JavaDoc obj) {
480
481     boolean result;
482
483     if ( hasDefaultValue() && obj == null ) {
484         result = true;
485     }
486     else if ( ! openType.isValue(obj) ) {
487         result = false;
488     }
489     else if ( hasLegalValues() && ! legalValues.contains(obj) ) {
490         result = false;
491     }
492     else if ( hasMinValue() && (minValue.compareTo(obj)>0) ) {
493         result = false;
494     }
495     else if ( hasMaxValue() && (maxValue.compareTo(obj)<0) ) {
496         result = false;
497     }
498     else {
499         result = true;
500     }
501
502     return result;
503     }
504
505     /* *** Commodity methods from java.lang.Object *** */
506
507
508     /**
509      * Compares the specified <var>obj</var> parameter with this <code>OpenMBeanAttributeInfoSupport</code> instance for equality.
510      * <p>
511      * Returns <tt>true</tt> if and only if all of the following statements are true:
512      * <ul>
513      * <li><var>obj</var> is non null,</li>
514      * <li><var>obj</var> also implements the <code>OpenMBeanAttributeInfo</code> interface,</li>
515      * <li>their names are equal</li>
516      * <li>their open types are equal</li>
517      * <li>their access properties (isReadable, isWritable and isIs) are equal</li>
518      * <li>their default, min, max and legal values are equal.</li>
519      * </ul>
520      * This ensures that this <tt>equals</tt> method works properly for <var>obj</var> parameters which are
521      * different implementations of the <code>OpenMBeanAttributeInfo</code> interface.
522      * <br>&nbsp;
523      * @param obj the object to be compared for equality with this <code>OpenMBeanAttributeInfoSupport</code> instance;
524      *
525      * @return <code>true</code> if the specified object is equal to this <code>OpenMBeanAttributeInfoSupport</code> instance.
526      */

527     public boolean equals(Object JavaDoc obj) {
528
529     // if obj is null, return false
530
//
531
if (obj == null) {
532         return false;
533     }
534
535     // if obj is not a OpenMBeanAttributeInfo, return false
536
//
537
OpenMBeanAttributeInfo JavaDoc other;
538     try {
539         other = (OpenMBeanAttributeInfo JavaDoc) obj;
540     } catch (ClassCastException JavaDoc e) {
541         return false;
542     }
543
544     // Now, really test for equality between this OpenMBeanAttributeInfo implementation and the other:
545
//
546

547     // their Name should be equal
548
if ( ! this.getName().equals(other.getName()) ) {
549         return false;
550     }
551
552     // their OpenType should be equal
553
if ( ! this.getOpenType().equals(other.getOpenType()) ) {
554         return false;
555     }
556
557     // their access properties (isReadable, isWritable and isIs) are equal</li>
558
if ( (this.isReadable() != other.isReadable()) ||
559          (this.isWritable() != other.isWritable()) ||
560          (this.isIs() != other.isIs()) ) {
561         return false;
562     }
563     
564
565     // their DefaultValue should be equal
566
if (this.hasDefaultValue()) {
567         if ( ! this.defaultValue.equals(other.getDefaultValue()) ) {
568         return false;
569         }
570     } else {
571         if (other.hasDefaultValue()) {
572         return false;
573         }
574     }
575        
576     // their MinValue should be equal
577
if (this.hasMinValue()) {
578         if ( ! this.minValue.equals(other.getMinValue()) ) {
579         return false;
580         }
581     } else {
582         if (other.hasMinValue()) {
583         return false;
584         }
585     }
586        
587     // their MaxValue should be equal
588
if (this.hasMaxValue()) {
589         if ( ! this.maxValue.equals(other.getMaxValue()) ) {
590         return false;
591         }
592     } else {
593         if (other.hasMaxValue()) {
594         return false;
595         }
596     }
597        
598     // their LegalValues should be equal
599
if (this.hasLegalValues()) {
600         if ( ! this.legalValues.equals(other.getLegalValues()) ) {
601         return false;
602         }
603     } else {
604         if (other.hasLegalValues()) {
605         return false;
606         }
607     }
608        
609     // All tests for equality were successfull
610
//
611
return true;
612     }
613
614     /**
615      * Returns the hash code value for this <code>OpenMBeanAttributeInfoSupport</code> instance.
616      * <p>
617      * The hash code of an <code>OpenMBeanAttributeInfoSupport</code> instance is the sum of the hash codes
618      * of all elements of information used in <code>equals</code> comparisons
619      * (ie: its name, its <i>open type</i>, and its default, min, max and legal values).
620      * <p>
621      * This ensures that <code> t1.equals(t2) </code> implies that <code> t1.hashCode()==t2.hashCode() </code>
622      * for any two <code>OpenMBeanAttributeInfoSupport</code> instances <code>t1</code> and <code>t2</code>,
623      * as required by the general contract of the method
624      * {@link Object#hashCode() Object.hashCode()}.
625      * <p>
626      * However, note that another instance of a class implementing the <code>OpenMBeanAttributeInfo</code> interface
627      * may be equal to this <code>OpenMBeanAttributeInfoSupport</code> instance as defined by {@link #equals(java.lang.Object)},
628      * but may have a different hash code if it is calculated differently.
629      * <p>
630      * As <code>OpenMBeanAttributeInfoSupport</code> instances are immutable, the hash code for this instance is calculated once,
631      * on the first call to <code>hashCode</code>, and then the same value is returned for subsequent calls.
632      *
633      * @return the hash code value for this <code>OpenMBeanAttributeInfoSupport</code> instance
634      */

635     public int hashCode() {
636
637     // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
638
//
639
if (myHashCode == null) {
640         int value = 0;
641         value += this.getName().hashCode();
642         value += this.openType.hashCode();
643         if (this.hasDefaultValue()) {
644         value += this.defaultValue.hashCode();
645         }
646         if (this.hasMinValue()) {
647         value += this.minValue.hashCode();
648         }
649         if (this.hasMaxValue()) {
650         value += this.maxValue.hashCode();
651         }
652         if (this.hasLegalValues()) {
653         value += this.legalValues.hashCode();
654         }
655         myHashCode = new Integer JavaDoc(value);
656     }
657     
658     // return always the same hash code for this instance (immutable)
659
//
660
return myHashCode.intValue();
661     }
662
663     /**
664      * Returns a string representation of this <code>OpenMBeanAttributeInfoSupport</code> instance.
665      * <p>
666      * The string representation consists of the name of this class (ie <code>javax.management.openmbean.OpenMBeanAttributeInfoSupport</code>),
667      * the string representation of the name and open type of the described parameter,
668      * and the string representation of its default, min, max and legal values.
669      * <p>
670      * As <code>OpenMBeanAttributeInfoSupport</code> instances are immutable, the string representation for this instance is calculated once,
671      * on the first call to <code>toString</code>, and then the same value is returned for subsequent calls.
672      *
673      * @return a string representation of this <code>OpenMBeanAttributeInfoSupport</code> instance
674      */

675     public String JavaDoc toString() {
676
677     // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
678
//
679
if (myToString == null) {
680         myToString = new StringBuffer JavaDoc()
681         .append(this.getClass().getName())
682         .append("(name=")
683         .append(this.getName())
684         .append(",openType=")
685         .append(this.openType.toString())
686         .append(",default=")
687         .append(String.valueOf(this.defaultValue))
688         .append(",min=")
689         .append(String.valueOf(this.minValue))
690         .append(",max=")
691         .append(String.valueOf(this.maxValue))
692         .append(",legals=")
693         .append(String.valueOf(this.legalValues))
694         .append(")")
695         .toString();
696     }
697
698     // return always the same string representation for this instance (immutable)
699
//
700
return myToString;
701     }
702
703 }
704
Popular Tags