OpenMBeanConstructorInfoSupport.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* OpenMBeanConstructorInfoSupport.java -- Open typed info about an constructor.
  2. Copyright (C) 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.management.openmbean;
  32. import java.util.Arrays;
  33. import javax.management.MBeanConstructorInfo;
  34. import javax.management.MBeanParameterInfo;
  35. /**
  36. * Describes a constructor for an open management bean.
  37. *
  38. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  39. * @since 1.5
  40. */
  41. public class OpenMBeanConstructorInfoSupport
  42. extends MBeanConstructorInfo
  43. implements OpenMBeanConstructorInfo
  44. {
  45. /**
  46. * Compatible with JDK 1.5
  47. */
  48. private static final long serialVersionUID = -4400441579007477003L;
  49. /**
  50. * The hash code of this instance.
  51. */
  52. private transient Integer hashCode;
  53. /**
  54. * The <code>toString()</code> result of this instance.
  55. */
  56. private transient String string;
  57. /**
  58. * Constructs a @link{OpenMBeanConstructorInfo} with the specified
  59. * name, description and parameter information. A <code>null</code>
  60. * value for the parameter information is the same as passing in
  61. * an empty array. Neither the name nor the description may be
  62. * null or equal to the empty string. A copy of the parameter array
  63. * is taken, so later changes have no effect.
  64. *
  65. * @param name the name of the constructor.
  66. * @param desc a description of the constructor.
  67. * @param sig the signature of the constructor, as a series
  68. * of {@link MBeanParameterInfo} objects, one for
  69. * each parameter.
  70. * @throws IllegalArgumentException if the name or description is
  71. * either <code>null</code>
  72. * or the empty string.
  73. * @throws ArrayStoreException if the members of the signature array
  74. * are not assignable to
  75. * {@link javax.management.MBeanParameterInfo}
  76. */
  77. public OpenMBeanConstructorInfoSupport(String name, String desc,
  78. OpenMBeanParameterInfo[] sig)
  79. {
  80. super(name, desc, (MBeanParameterInfo[]) sig);
  81. if (name == null)
  82. throw new IllegalArgumentException("The name may not be null.");
  83. if (desc == null)
  84. throw new IllegalArgumentException("The description may not be null.");
  85. if (name.length() == 0)
  86. throw new IllegalArgumentException("The name may not be the empty string.");
  87. if (desc.length() == 0)
  88. throw new IllegalArgumentException("The description may not be the " +
  89. "empty string.");
  90. }
  91. /**
  92. * Compares this attribute with the supplied object. This returns
  93. * true iff the object is an instance of {@link OpenMBeanConstructorInfo}
  94. * with an equal name and signature.
  95. *
  96. * @param obj the object to compare.
  97. * @return true if the object is a {@link OpenMBeanParameterInfo}
  98. * instance,
  99. * <code>name.equals(object.getName())</code>,
  100. * and <code>signature.equals(object.getSignature())</code>.
  101. */
  102. public boolean equals(Object obj)
  103. {
  104. if (!(obj instanceof OpenMBeanConstructorInfo))
  105. return false;
  106. OpenMBeanConstructorInfo o = (OpenMBeanConstructorInfo) obj;
  107. return getName().equals(o.getName()) &&
  108. getSignature().equals(o.getSignature());
  109. }
  110. /**
  111. * <p>
  112. * Returns the hashcode of the constructor information as the sum of
  113. * the hashcodes of the name and signature (calculated by
  114. * <code>java.util.Arrays.asList(signature).hashCode()</code>).
  115. * </p>
  116. * <p>
  117. * As instances of this class are immutable, the return value
  118. * is computed just once for each instance and reused
  119. * throughout its life.
  120. * </p>
  121. *
  122. * @return the hashcode of the constructor information.
  123. */
  124. public int hashCode()
  125. {
  126. if (hashCode == null)
  127. hashCode = Integer.valueOf(getName().hashCode() +
  128. Arrays.asList(getSignature()).hashCode());
  129. return hashCode.intValue();
  130. }
  131. /**
  132. * <p>
  133. * Returns a textual representation of this instance. This
  134. * is constructed using the class name
  135. * (<code>javax.management.openmbean.OpenMBeanConstructorInfo</code>)
  136. * along with the name and signature.
  137. * </p>
  138. * <p>
  139. * As instances of this class are immutable, the return value
  140. * is computed just once for each instance and reused
  141. * throughout its life.
  142. * </p>
  143. *
  144. * @return a @link{java.lang.String} instance representing
  145. * the instance in textual form.
  146. */
  147. public String toString()
  148. {
  149. if (string == null)
  150. string = getClass().getName()
  151. + "[name=" + getName()
  152. + ",signature=" + Arrays.toString(getSignature())
  153. + "]";
  154. return string;
  155. }
  156. }