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. package javax.management.openmbean;
  8. // java import
  9. //
  10. import java.io.Serializable;
  11. import java.util.Set;
  12. import java.util.HashSet;
  13. import java.util.Collections;
  14. import java.lang.Comparable; // to be substituted for jdk1.1.x
  15. // jmx import
  16. //
  17. import javax.management.MBeanAttributeInfo;
  18. /**
  19. * Describes an attribute of an open MBean.
  20. *
  21. * @version 3.28 03/12/19
  22. * @author Sun Microsystems, Inc.
  23. *
  24. * @since 1.5
  25. * @since.unbundled JMX 1.1
  26. */
  27. public class OpenMBeanAttributeInfoSupport
  28. extends MBeanAttributeInfo
  29. implements OpenMBeanAttributeInfo, Serializable {
  30. /* Serial version */
  31. static final long serialVersionUID = -4867215622149721849L;
  32. /**
  33. * @serial The open mbean attribute's <i>open type</i>
  34. */
  35. private OpenType openType;
  36. /**
  37. * @serial The open mbean attribute's default value
  38. */
  39. private Object defaultValue = null;
  40. /**
  41. * @serial The open mbean attribute's legal values. This {@link Set} is unmodifiable
  42. */
  43. private Set legalValues = null; // to be constructed unmodifiable
  44. /**
  45. * @serial The open mbean attribute's min value
  46. */
  47. private Comparable minValue = null;
  48. /**
  49. * @serial The open mbean attribute's max value
  50. */
  51. private Comparable maxValue = null;
  52. private transient Integer myHashCode = null; // As this instance is immutable, these two values
  53. private transient String myToString = null; // need only be calculated once.
  54. /**
  55. * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute of an open MBean
  56. * with the specified <var>name</var>, <var>openType</var> and <var>description</var>,
  57. * and the specified read/write access properties.
  58. *
  59. * @param name cannot be a null or empty string.
  60. *
  61. * @param description cannot be a null or empty string.
  62. *
  63. * @param openType cannot be null.
  64. *
  65. * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
  66. *
  67. * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
  68. *
  69. * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
  70. *
  71. * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
  72. * or <var>openType</var> is null.
  73. */
  74. public OpenMBeanAttributeInfoSupport(String name,
  75. String description,
  76. OpenType openType,
  77. boolean isReadable,
  78. boolean isWritable,
  79. boolean isIs) {
  80. // Construct parent's state
  81. //
  82. super(name, ( (openType==null) ? null : openType.getClassName() ), description, isReadable, isWritable, isIs);
  83. // check parameters that should not be null or empty (unfortunately it is not done in superclass :-( ! )
  84. //
  85. if ( (name == null) || (name.trim().equals("")) ) {
  86. throw new IllegalArgumentException("Argument name cannot be null or empty.");
  87. }
  88. if (openType == null) {
  89. throw new IllegalArgumentException("Argument openType cannot be null.");
  90. }
  91. if ( (description == null) || (description.trim().equals("")) ) {
  92. throw new IllegalArgumentException("Argument description cannot be null or empty.");
  93. }
  94. // Initialize this instance's specific state
  95. //
  96. this.openType = openType;
  97. }
  98. /**
  99. * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute of an open MBean
  100. * with the specified <var>name</var>, <var>openType</var>, <var>description</var> and <var>defaultValue</var>,
  101. * and the specified read/write access properties.
  102. *
  103. * @param name cannot be a null or empty string.
  104. *
  105. * @param description cannot be a null or empty string.
  106. *
  107. * @param openType cannot be null.
  108. *
  109. * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
  110. *
  111. * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
  112. *
  113. * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
  114. *
  115. * @param defaultValue must be a valid value for the <var>openType</var> specified for this attribute;
  116. * default value not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>
  117. * can be null, in which case it means that no default value is set.
  118. *
  119. * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
  120. * or <var>openType</var> is null.
  121. *
  122. * @throws OpenDataException if <var>defaultValue</var> is not a valid value for the specified <var>openType</var>,
  123. * or <var>defaultValue</var> is non null and
  124. * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>.
  125. */
  126. public OpenMBeanAttributeInfoSupport(String name,
  127. String description,
  128. OpenType openType,
  129. boolean isReadable,
  130. boolean isWritable,
  131. boolean isIs,
  132. Object defaultValue) throws OpenDataException {
  133. // First check and construct the part regarding name, openType and description
  134. //
  135. this(name, description, openType, isReadable, isWritable, isIs);
  136. // Check and initialize defaultValue
  137. //
  138. if (defaultValue != null) {
  139. // Default value not supported for ArrayType and TabularType
  140. if ( (openType.isArray()) || (openType instanceof TabularType) ) {
  141. throw new OpenDataException("Default value not supported for ArrayType and TabularType.");
  142. }
  143. // Check defaultValue's class
  144. if ( ! openType.isValue(defaultValue) ) {
  145. throw new OpenDataException("Argument defaultValue's class [\""+ defaultValue.getClass().getName() +
  146. "\"] does not match the one defined in openType[\""+ openType.getClassName() +"\"].");
  147. }
  148. // Then initializes defaultValue:
  149. // no need to clone it: apart from arrays and TabularData, basic data types are immutable
  150. this.defaultValue = defaultValue;
  151. }
  152. }
  153. /**
  154. * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute of an open MBean
  155. * with the specified <var>name</var>, <var>openType</var>, <var>description</var>,
  156. * <var>defaultValue</var> and <var>legalValues</var>,
  157. * and the specified read/write access properties.
  158. *
  159. * The contents of <var>legalValues</var> are internally dumped into an unmodifiable <tt>Set</tt>,
  160. * so subsequent modifications of the array referenced by <var>legalValues</var> have no impact on
  161. * this <tt>OpenMBeanAttributeInfoSupport</tt> instance.
  162. *
  163. * @param name cannot be a null or empty string.
  164. *
  165. * @param description cannot be a null or empty string.
  166. *
  167. * @param openType cannot be null.
  168. *
  169. * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
  170. *
  171. * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
  172. *
  173. * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
  174. *
  175. * @param defaultValue must be a valid value for the <var>openType</var> specified for this attribute;
  176. * default value not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>
  177. * can be null, in which case it means that no default value is set.
  178. *
  179. * @param legalValues each contained value must be valid for the <var>openType</var> specified for this attribute;
  180. * legal values not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>
  181. * can be null or empty.
  182. *
  183. * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
  184. * or <var>openType</var> is null.
  185. *
  186. * @throws OpenDataException if <var>defaultValue</var> is not a valid value for the specified <var>openType</var>,
  187. * or one value in <var>legalValues</var> is not valid for the specified <var>openType</var>,
  188. * or <var>defaultValue</var> is non null and
  189. * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>,
  190. * or <var>legalValues</var> is non null and non empty and
  191. * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>,
  192. * or <var>legalValues</var> is non null and non empty and
  193. * <var>defaultValue</var> is not contained in <var>legalValues</var>.
  194. */
  195. public OpenMBeanAttributeInfoSupport(String name,
  196. String description,
  197. OpenType openType,
  198. boolean isReadable,
  199. boolean isWritable,
  200. boolean isIs,
  201. Object defaultValue,
  202. Object[] legalValues) throws OpenDataException {
  203. // First check and construct the part regarding name, openType, description and defaultValue
  204. //
  205. this(name, description, openType, isReadable, isWritable, isIs, defaultValue);
  206. // Check and initialize legalValues
  207. //
  208. if ( (legalValues != null) && (legalValues.length > 0) ){
  209. // legalValues not supported for TabularType and arrays
  210. if ( (openType instanceof TabularType) || (openType.isArray()) ) {
  211. throw new OpenDataException("Legal values not supported for TabularType and arrays");
  212. }
  213. // Check legalValues are valid with openType
  214. for (int i = 0; i < legalValues.length; i++ ) {
  215. if ( ! openType.isValue(legalValues[i]) ) {
  216. throw new OpenDataException("Element legalValues["+ i +"]="+ legalValues[i] +
  217. " is not a valid value for the specified openType ["+ openType.toString() +"].");
  218. }
  219. }
  220. // dump the legalValues array content into a Set: ensures uniqueness of elements
  221. // (and we could not keep the array reference as array content could be modified by the caller)
  222. Set tmpSet = new HashSet(legalValues.length+1, 1);
  223. for (int i = 0; i < legalValues.length; i++ ) {
  224. tmpSet.add(legalValues[i]);
  225. }
  226. // initializes legalValues as an unmodifiable Set
  227. this.legalValues = Collections.unmodifiableSet(tmpSet);
  228. }
  229. // Check that defaultValue is a legal value
  230. //
  231. if ( (this.hasDefaultValue()) && (this.hasLegalValues()) ) {
  232. if ( ! this.legalValues.contains(defaultValue) ) {
  233. throw new OpenDataException("defaultValue is not contained in legalValues");
  234. }
  235. }
  236. }
  237. /**
  238. * Constructs an <tt>OpenMBeanAttributeInfoSupport</tt> instance, which describes the attribute
  239. * used in one or more operations or constructors of a class of open MBeans,
  240. * with the specified <var>name</var>, <var>openType</var>, <var>description</var>,
  241. * <var>defaultValue</var>, <var>minValue</var> and <var>maxValue</var>.
  242. *
  243. * It is possible to specify minimal and maximal values only for an open type
  244. * whose values are <tt>Comparable</tt>.
  245. *
  246. * @param name cannot be a null or empty string.
  247. *
  248. * @param description cannot be a null or empty string.
  249. *
  250. * @param openType cannot be null.
  251. *
  252. * @param isReadable <tt>true</tt> if the attribute has a getter exposed for management.
  253. *
  254. * @param isWritable <tt>true</tt> if the attribute has a setter exposed for management.
  255. *
  256. * @param isIs <tt>true</tt> if the attribute's getter is of the form <tt>is<i>XXX</i></tt>.
  257. *
  258. * @param defaultValue must be a valid value for the <var>openType</var> specified for this attribute;
  259. * default value not supported for <tt>ArrayType</tt> and <tt>TabularType</tt>
  260. * can be null, in which case it means that no default value is set.
  261. *
  262. * @param minValue must be valid for the <var>openType</var> specified for this attribute;
  263. * can be null, in which case it means that no minimal value is set.
  264. *
  265. * @param maxValue must be valid for the <var>openType</var> specified for this attribute;
  266. * can be null, in which case it means that no maximal value is set.
  267. *
  268. * @throws IllegalArgumentException if <var>name</var> or <var>description</var> are null or empty string,
  269. * or <var>openType</var> is null.
  270. *
  271. * @throws OpenDataException if <var>defaultValue</var>, <var>minValue</var> or <var>maxValue</var>
  272. * is not a valid value for the specified <var>openType</var>,
  273. * or <var>defaultValue</var> is non null and
  274. * <var>openType</var> is an <tt>ArrayType</tt> or a <tt>TabularType</tt>,
  275. * or both <var>minValue</var> and <var>maxValue</var> are non-null and
  276. * <tt>minValue.compareTo(maxValue) > 0</tt> is <tt>true</tt>,
  277. * or both <var>defaultValue</var> and <var>minValue</var> are non-null and
  278. * <tt>minValue.compareTo(defaultValue) > 0</tt> is <tt>true</tt>,
  279. * or both <var>defaultValue</var> and <var>maxValue</var> are non-null and
  280. * <tt>defaultValue.compareTo(maxValue) > 0</tt> is <tt>true</tt>.
  281. */
  282. public OpenMBeanAttributeInfoSupport(String name,
  283. String description,
  284. OpenType openType,
  285. boolean isReadable,
  286. boolean isWritable,
  287. boolean isIs,
  288. Object defaultValue,
  289. Comparable minValue,
  290. Comparable maxValue) throws OpenDataException {
  291. // First check and construct the part regarding name, openType, description and defaultValue
  292. //
  293. this(name, description, openType, isReadable, isWritable, isIs, defaultValue);
  294. // Check and initialize minValue
  295. //(note: no need to worry about Composite, Tabular and arrays as they are not Comparable)
  296. //
  297. if (minValue != null) {
  298. if ( ! openType.isValue(minValue) ) {
  299. throw new OpenDataException("Argument minValue's class [\""+ minValue.getClass().getName() +
  300. "\"] does not match openType's definition [\""+ openType.getClassName() +"\"].");
  301. }
  302. // then initializes minValue
  303. this.minValue = minValue;
  304. }
  305. // Check and initialize maxValue
  306. //(note: no need to worry about Composite, Tabular and arrays as they are not Comparable)
  307. //
  308. if (maxValue != null) {
  309. if ( ! openType.isValue(maxValue) ) {
  310. throw new OpenDataException("Argument maxValue's class [\""+ maxValue.getClass().getName() +
  311. "\"] does not match openType's definition [\""+ openType.getClassName() +"\"].");
  312. }
  313. // then initializes maxValue
  314. this.maxValue = maxValue;
  315. }
  316. // Check that, if both specified, minValue <= maxValue
  317. //
  318. if (hasMinValue() && hasMaxValue()) {
  319. if (minValue.compareTo(maxValue) > 0) {
  320. throw new OpenDataException("minValue cannot be greater than maxValue.");
  321. }
  322. }
  323. // Check that minValue <= defaultValue <= maxValue
  324. //
  325. if ( (this.hasDefaultValue()) && (this.hasMinValue()) ) {
  326. if (minValue.compareTo((Comparable)defaultValue) > 0) {
  327. throw new OpenDataException("minValue cannot be greater than defaultValue.");
  328. }
  329. }
  330. if ( (this.hasDefaultValue()) && (this.hasMaxValue()) ) {
  331. if (((Comparable)defaultValue).compareTo(maxValue) > 0) {
  332. throw new OpenDataException("defaultValue cannot be greater than maxValue.");
  333. }
  334. }
  335. }
  336. /**
  337. * Returns the open type for the values of the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance.
  338. */
  339. public OpenType getOpenType() {
  340. return openType;
  341. }
  342. /**
  343. * Returns the default value for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
  344. * if specified, or <tt>null</tt> otherwise.
  345. */
  346. public Object getDefaultValue() {
  347. // Special case for ArrayType and TabularType
  348. // [JF] TODO: clone it so that it cannot be altered,
  349. // [JF] TODO: if we decide to support defaultValue as an array itself.
  350. // [JF] As of today (oct 2000) it is not supported so defaultValue is null for arrays. Nothing to do.
  351. return defaultValue;
  352. }
  353. /**
  354. * Returns an unmodifiable Set of legal values for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
  355. * if specified, or <tt>null</tt> otherwise.
  356. */
  357. public Set getLegalValues() {
  358. // Special case for ArrayType and TabularType
  359. // [JF] TODO: clone values so that they cannot be altered,
  360. // [JF] TODO: if we decide to support LegalValues as an array itself.
  361. // [JF] As of today (oct 2000) it is not supported so legalValues is null for arrays. Nothing to do.
  362. // Returns our legalValues Set (set was constructed unmodifiable)
  363. return (legalValues);
  364. }
  365. /**
  366. * Returns the minimal value for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
  367. * if specified, or <tt>null</tt> otherwise.
  368. */
  369. public Comparable getMinValue() {
  370. // Note: only comparable values have a minValue, so that's not the case of arrays and tabulars (always null).
  371. return minValue;
  372. }
  373. /**
  374. * Returns the maximal value for the attribute described by this <tt>OpenMBeanAttributeInfoSupport</tt> instance,
  375. * if specified, or <tt>null</tt> otherwise.
  376. */
  377. public Comparable getMaxValue() {
  378. // Note: only comparable values have a maxValue, so that's not the case of arrays and tabulars (always null).
  379. return maxValue;
  380. }
  381. /**
  382. * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null default value
  383. * for the described attribute, <tt>false</tt> otherwise.
  384. */
  385. public boolean hasDefaultValue() {
  386. return (defaultValue != null);
  387. }
  388. /**
  389. * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null set of legal values
  390. * for the described attribute, <tt>false</tt> otherwise.
  391. */
  392. public boolean hasLegalValues() {
  393. return (legalValues != null);
  394. }
  395. /**
  396. * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null minimal value
  397. * for the described attribute, <tt>false</tt> otherwise.
  398. */
  399. public boolean hasMinValue() {
  400. return (minValue != null);
  401. }
  402. /**
  403. * Returns <tt>true</tt> if this <tt>OpenMBeanAttributeInfoSupport</tt> instance specifies a non-null maximal value
  404. * for the described attribute, <tt>false</tt> otherwise.
  405. */
  406. public boolean hasMaxValue() {
  407. return (maxValue != null);
  408. }
  409. /**
  410. * Tests whether <var>obj</var> is a valid value for the attribute
  411. * described by this <code>OpenMBeanAttributeInfoSupport</code>
  412. * instance.
  413. *
  414. * @param obj the object to be tested.
  415. *
  416. * @return <code>true</code> if <var>obj</var> is a valid value for for the parameter described by
  417. * this <code>OpenMBeanAttributeInfoSupport</code> instance, <code>false</code> otherwise.
  418. */
  419. public boolean isValue(Object obj) {
  420. boolean result;
  421. if ( hasDefaultValue() && obj == null ) {
  422. result = true;
  423. }
  424. else if ( ! openType.isValue(obj) ) {
  425. result = false;
  426. }
  427. else if ( hasLegalValues() && ! legalValues.contains(obj) ) {
  428. result = false;
  429. }
  430. else if ( hasMinValue() && (minValue.compareTo(obj)>0) ) {
  431. result = false;
  432. }
  433. else if ( hasMaxValue() && (maxValue.compareTo(obj)<0) ) {
  434. result = false;
  435. }
  436. else {
  437. result = true;
  438. }
  439. return result;
  440. }
  441. /* *** Commodity methods from java.lang.Object *** */
  442. /**
  443. * Compares the specified <var>obj</var> parameter with this <code>OpenMBeanAttributeInfoSupport</code> instance for equality.
  444. * <p>
  445. * Returns <tt>true</tt> if and only if all of the following statements are true:
  446. * <ul>
  447. * <li><var>obj</var> is non null,</li>
  448. * <li><var>obj</var> also implements the <code>OpenMBeanAttributeInfo</code> interface,</li>
  449. * <li>their names are equal</li>
  450. * <li>their open types are equal</li>
  451. * <li>their access properties (isReadable, isWritable and isIs) are equal</li>
  452. * <li>their default, min, max and legal values are equal.</li>
  453. * </ul>
  454. * This ensures that this <tt>equals</tt> method works properly for <var>obj</var> parameters which are
  455. * different implementations of the <code>OpenMBeanAttributeInfo</code> interface.
  456. * <br> 
  457. * @param obj the object to be compared for equality with this <code>OpenMBeanAttributeInfoSupport</code> instance;
  458. *
  459. * @return <code>true</code> if the specified object is equal to this <code>OpenMBeanAttributeInfoSupport</code> instance.
  460. */
  461. public boolean equals(Object obj) {
  462. // if obj is null, return false
  463. //
  464. if (obj == null) {
  465. return false;
  466. }
  467. // if obj is not a OpenMBeanAttributeInfo, return false
  468. //
  469. OpenMBeanAttributeInfo other;
  470. try {
  471. other = (OpenMBeanAttributeInfo) obj;
  472. } catch (ClassCastException e) {
  473. return false;
  474. }
  475. // Now, really test for equality between this OpenMBeanAttributeInfo implementation and the other:
  476. //
  477. // their Name should be equal
  478. if ( ! this.getName().equals(other.getName()) ) {
  479. return false;
  480. }
  481. // their OpenType should be equal
  482. if ( ! this.getOpenType().equals(other.getOpenType()) ) {
  483. return false;
  484. }
  485. // their access properties (isReadable, isWritable and isIs) are equal</li>
  486. if ( (this.isReadable() != other.isReadable()) ||
  487. (this.isWritable() != other.isWritable()) ||
  488. (this.isIs() != other.isIs()) ) {
  489. return false;
  490. }
  491. // their DefaultValue should be equal
  492. if (this.hasDefaultValue()) {
  493. if ( ! this.defaultValue.equals(other.getDefaultValue()) ) {
  494. return false;
  495. }
  496. } else {
  497. if (other.hasDefaultValue()) {
  498. return false;
  499. }
  500. }
  501. // their MinValue should be equal
  502. if (this.hasMinValue()) {
  503. if ( ! this.minValue.equals(other.getMinValue()) ) {
  504. return false;
  505. }
  506. } else {
  507. if (other.hasMinValue()) {
  508. return false;
  509. }
  510. }
  511. // their MaxValue should be equal
  512. if (this.hasMaxValue()) {
  513. if ( ! this.maxValue.equals(other.getMaxValue()) ) {
  514. return false;
  515. }
  516. } else {
  517. if (other.hasMaxValue()) {
  518. return false;
  519. }
  520. }
  521. // their LegalValues should be equal
  522. if (this.hasLegalValues()) {
  523. if ( ! this.legalValues.equals(other.getLegalValues()) ) {
  524. return false;
  525. }
  526. } else {
  527. if (other.hasLegalValues()) {
  528. return false;
  529. }
  530. }
  531. // All tests for equality were successfull
  532. //
  533. return true;
  534. }
  535. /**
  536. * Returns the hash code value for this <code>OpenMBeanAttributeInfoSupport</code> instance.
  537. * <p>
  538. * The hash code of an <code>OpenMBeanAttributeInfoSupport</code> instance is the sum of the hash codes
  539. * of all elements of information used in <code>equals</code> comparisons
  540. * (ie: its name, its <i>open type</i>, and its default, min, max and legal values).
  541. * <p>
  542. * This ensures that <code> t1.equals(t2) </code> implies that <code> t1.hashCode()==t2.hashCode() </code>
  543. * for any two <code>OpenMBeanAttributeInfoSupport</code> instances <code>t1</code> and <code>t2</code>,
  544. * as required by the general contract of the method
  545. * {@link Object#hashCode() Object.hashCode()}.
  546. * <p>
  547. * However, note that another instance of a class implementing the <code>OpenMBeanAttributeInfo</code> interface
  548. * may be equal to this <code>OpenMBeanAttributeInfoSupport</code> instance as defined by {@link #equals(java.lang.Object)},
  549. * but may have a different hash code if it is calculated differently.
  550. * <p>
  551. * As <code>OpenMBeanAttributeInfoSupport</code> instances are immutable, the hash code for this instance is calculated once,
  552. * on the first call to <code>hashCode</code>, and then the same value is returned for subsequent calls.
  553. *
  554. * @return the hash code value for this <code>OpenMBeanAttributeInfoSupport</code> instance
  555. */
  556. public int hashCode() {
  557. // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
  558. //
  559. if (myHashCode == null) {
  560. int value = 0;
  561. value += this.getName().hashCode();
  562. value += this.openType.hashCode();
  563. if (this.hasDefaultValue()) {
  564. value += this.defaultValue.hashCode();
  565. }
  566. if (this.hasMinValue()) {
  567. value += this.minValue.hashCode();
  568. }
  569. if (this.hasMaxValue()) {
  570. value += this.maxValue.hashCode();
  571. }
  572. if (this.hasLegalValues()) {
  573. value += this.legalValues.hashCode();
  574. }
  575. myHashCode = new Integer(value);
  576. }
  577. // return always the same hash code for this instance (immutable)
  578. //
  579. return myHashCode.intValue();
  580. }
  581. /**
  582. * Returns a string representation of this <code>OpenMBeanAttributeInfoSupport</code> instance.
  583. * <p>
  584. * The string representation consists of the name of this class (ie <code>javax.management.openmbean.OpenMBeanAttributeInfoSupport</code>),
  585. * the string representation of the name and open type of the described parameter,
  586. * and the string representation of its default, min, max and legal values.
  587. * <p>
  588. * As <code>OpenMBeanAttributeInfoSupport</code> instances are immutable, the string representation for this instance is calculated once,
  589. * on the first call to <code>toString</code>, and then the same value is returned for subsequent calls.
  590. *
  591. * @return a string representation of this <code>OpenMBeanAttributeInfoSupport</code> instance
  592. */
  593. public String toString() {
  594. // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
  595. //
  596. if (myToString == null) {
  597. myToString = new StringBuffer()
  598. .append(this.getClass().getName())
  599. .append("(name=")
  600. .append(this.getName())
  601. .append(",openType=")
  602. .append(this.openType.toString())
  603. .append(",default=")
  604. .append(String.valueOf(this.defaultValue))
  605. .append(",min=")
  606. .append(String.valueOf(this.minValue))
  607. .append(",max=")
  608. .append(String.valueOf(this.maxValue))
  609. .append(",legals=")
  610. .append(String.valueOf(this.legalValues))
  611. .append(")")
  612. .toString();
  613. }
  614. // return always the same string representation for this instance (immutable)
  615. //
  616. return myToString;
  617. }
  618. }