MBeanNotificationInfo.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* MBeanNotificationInfo.java -- Information about a bean's notification.
  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;
  32. import java.util.Arrays;
  33. /**
  34. * <p>
  35. * Describes the notifications emitted by a management bean.
  36. * An instance of this class is specific to notifications
  37. * involving a particular type of object. A new instance
  38. * should be created for each Java class used for notifications,
  39. * and the Java class name forms the name of the instance.
  40. * Each instance lists a number of notification types; these
  41. * are not types in the sense of different Java classes, but
  42. * instead form the names of notifications following the same
  43. * syntax as Java property and package names.
  44. * </p>
  45. * <p>
  46. * For instance, a management bean may emit two notifications
  47. * containing {@link java.lang.String} objects. Both would be described
  48. * using one instance of this class, with a member of the array
  49. * returned by {@link #getNotifTypes()} for each one. If another
  50. * notification containing a {@link java.util.Date} object were to
  51. * be added, this would require a new instance of this class.
  52. * </p>
  53. * <p>
  54. * The information in this class is immutable as standard.
  55. * Of course, subclasses may change this, but this
  56. * behaviour is not recommended.
  57. * </p>
  58. *
  59. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  60. * @since 1.5
  61. */
  62. public class MBeanNotificationInfo
  63. extends MBeanFeatureInfo
  64. implements Cloneable
  65. {
  66. /**
  67. * Compatible with JDK 1.5
  68. */
  69. private static final long serialVersionUID = -3888371564530107064L;
  70. /**
  71. * The types of notification described by this instance.
  72. *
  73. * @serial the types of notification.
  74. */
  75. private String[] types;
  76. /**
  77. * Constructs a new {@link MBeanNotificationInfo} with the
  78. * specified name, description and notification types. The
  79. * notification types array may be <code>null</code> or of
  80. * zero length, in order to indicate the absence of any types.
  81. *
  82. * @param types an array of {@link java.lang.String} objects,
  83. * containing the names of the notifications emitted
  84. * of this Java type. The names use the dot notation
  85. * familiar from Java property and package names.
  86. * @param name the name of the Java class the notifications described
  87. * by this object are instances of.
  88. * @param description a description of the data.
  89. * @throws IllegalArgumentException for some reason...
  90. */
  91. public MBeanNotificationInfo(String[] types, String name,
  92. String description)
  93. {
  94. super(name, description);
  95. this.types = types;
  96. }
  97. /**
  98. * Returns a clone of this instance. The clone is created
  99. * using just the method provided by {@link java.lang.Object}.
  100. * Thus, the clone is just a shallow clone as returned by
  101. * that method, and does not contain any deeper cloning based
  102. * on the subject of this class.
  103. *
  104. * @return a clone of this instance.
  105. * @see java.lang.Cloneable
  106. */
  107. public Object clone()
  108. {
  109. try
  110. {
  111. return super.clone();
  112. }
  113. catch (CloneNotSupportedException e)
  114. {
  115. /* This shouldn't happen; we implement Cloneable */
  116. throw new IllegalStateException("clone() called on " +
  117. "non-cloneable object.");
  118. }
  119. }
  120. /**
  121. * Compares this feature with the supplied object. This returns
  122. * true iff the object is an instance of {@link
  123. * MBeanNotificationInfo}, {@link Object#equals()} returns true for
  124. * a comparison of both the name and description of this
  125. * notification with that of the specified object, and the two
  126. * notification type arrays contain the same elements in the same
  127. * order (but one may be longer than the other).
  128. *
  129. * @param obj the object to compare.
  130. * @return true if the object is a {@link MBeanNotificationInfo}
  131. * instance,
  132. * <code>name.equals(object.getName())</code>,
  133. * <code>description.equals(object.getDescription())</code>
  134. * and the corresponding elements of the type arrays are
  135. * equal.
  136. */
  137. public boolean equals(Object obj)
  138. {
  139. if (obj instanceof MBeanNotificationInfo)
  140. {
  141. if (!(super.equals(obj)))
  142. return false;
  143. MBeanNotificationInfo o = (MBeanNotificationInfo) obj;
  144. String[] oTypes = o.getNotifTypes();
  145. for (int a = 0; a < types.length; ++a)
  146. {
  147. if (a == oTypes.length)
  148. return true;
  149. if (!(types[a].equals(oTypes[a])))
  150. return false;
  151. }
  152. return true;
  153. }
  154. else
  155. return false;
  156. }
  157. /**
  158. * Returns the notification types that the management bean may emit.
  159. * The notification types are strings using the dot notation
  160. * familiar from Java property and package names. Changing the
  161. * returned array does not affect the values retained by this
  162. * instance.
  163. *
  164. * @return the notification types.
  165. */
  166. public String[] getNotifTypes()
  167. {
  168. return types;
  169. }
  170. /**
  171. * Returns the hashcode of the notification information as the sum
  172. * of the hashcode of the superclass and the hashcode of the types
  173. * array.
  174. *
  175. * @return the hashcode of the notification information.
  176. */
  177. public int hashCode()
  178. {
  179. return super.hashCode() + Arrays.hashCode(types);
  180. }
  181. /**
  182. * <p>
  183. * Returns a textual representation of this instance. This
  184. * is constructed using the class name
  185. * (<code>javax.management.MBeanNotificationInfo</code>),
  186. * the name and description of the notification and the
  187. * contents of the array of types.
  188. * </p>
  189. * <p>
  190. * As instances of this class are immutable, the return value
  191. * is computed just once for each instance and reused
  192. * throughout its life.
  193. * </p>
  194. *
  195. * @return a @link{java.lang.String} instance representing
  196. * the instance in textual form.
  197. */
  198. public String toString()
  199. {
  200. if (string == null)
  201. {
  202. super.toString();
  203. string = string.substring(0, string.length() - 1)
  204. + ",types=" + Arrays.toString(types)
  205. + "]";
  206. }
  207. return string;
  208. }
  209. }