MBeanFeatureInfo.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* MBeanFeatureInfo.java -- Information about a bean feature.
  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.io.IOException;
  33. import java.io.ObjectOutputStream;
  34. import java.io.Serializable;
  35. /**
  36. * A general superclass for the description of features
  37. * of management beans. This allows the user to access
  38. * the feature dynamically, without knowing the details
  39. * beforehand. The information is immutable as standard.
  40. * Of course, subclasses may change this, but this
  41. * behaviour is not recommended.
  42. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  43. * @since 1.5
  44. */
  45. public class MBeanFeatureInfo
  46. implements Serializable
  47. {
  48. /**
  49. * Compatible with JDK 1.5
  50. */
  51. private static final long serialVersionUID = 3952882688968447265L;
  52. /**
  53. * A description of the feature in human-readable form.
  54. * Subclasses should access this via the {@link #getDescription()}
  55. * function rather than using the value directly.
  56. *
  57. * @serial a description of the feature.
  58. */
  59. protected String description;
  60. /**
  61. * The name of the feature. Subclasses should access this
  62. * via the {@link #getName()} function rather than using the
  63. * value directly.
  64. *
  65. * @serial the name of the feature.
  66. */
  67. protected String name;
  68. /**
  69. * The <code>toString()</code> result of this instance.
  70. */
  71. transient String string;
  72. /**
  73. * Constructs a new {@link MBeanFeatureInfo} with the specified
  74. * name and description.
  75. *
  76. * @param name the name of the management bean feature.
  77. * @param description the description of the feature.
  78. */
  79. public MBeanFeatureInfo(String name, String description)
  80. {
  81. this.name = name;
  82. this.description = description;
  83. }
  84. /**
  85. * Compares this feature with the supplied object. This
  86. * returns true iff the object is an instance of
  87. * {@link MBeanFeatureInfo} and {@link Object#equals()}
  88. * returns true for a comparison of both the name and
  89. * description of this feature with that of the specified
  90. * object.
  91. *
  92. * @param obj the object to compare.
  93. * @return true if the object is a {@link MBeanFeatureInfo}
  94. * instance,
  95. * <code>name.equals(object.getName())</code> and
  96. * <code>description.equals(object.getDescription</code>.
  97. */
  98. public boolean equals(Object obj)
  99. {
  100. if (obj instanceof MBeanFeatureInfo)
  101. {
  102. MBeanFeatureInfo o = (MBeanFeatureInfo) obj;
  103. return ((name == null ?
  104. o.getName() == null :
  105. name.equals(o.getName())) &&
  106. (description == null ?
  107. o.getDescription() == null :
  108. description.equals(o.getDescription())));
  109. }
  110. else
  111. return false;
  112. }
  113. /**
  114. * Returns a description of this feature.
  115. *
  116. * @return a human-readable description.
  117. */
  118. public String getDescription()
  119. {
  120. return description;
  121. }
  122. /**
  123. * Returns the name of this feature.
  124. *
  125. * @return the name of the feature.
  126. */
  127. public String getName()
  128. {
  129. return name;
  130. }
  131. /**
  132. * Returns the hashcode of the feature as
  133. * the sum of the hashcodes of its name
  134. * and description.
  135. *
  136. * @return the hashcode of this feature.
  137. */
  138. public int hashCode()
  139. {
  140. return (name == null ? -1 : name.hashCode())
  141. + (description == null ? -1 : description.hashCode());
  142. }
  143. /**
  144. * <p>
  145. * Returns a textual representation of this instance. This
  146. * is constructed using the class name
  147. * (<code>javax.management.MBeanFeatureInfo</code>) and
  148. * the name and description of the feature.
  149. * </p>
  150. * <p>
  151. * As instances of this class are immutable, the return value
  152. * is computed just once for each instance and reused
  153. * throughout its life.
  154. * </p>
  155. *
  156. * @return a @link{java.lang.String} instance representing
  157. * the instance in textual form.
  158. */
  159. public String toString()
  160. {
  161. if (string == null)
  162. string = getClass().getName()
  163. + "[name=" + name
  164. + ",desc=" + description
  165. + "]";
  166. return string;
  167. }
  168. /**
  169. * Serialize the {@link MBeanFeatureInfo}.
  170. *
  171. * @param out the output stream to write to.
  172. * @throws IOException if an I/O error occurs.
  173. */
  174. private void writeObject(ObjectOutputStream out)
  175. throws IOException
  176. {
  177. out.defaultWriteObject();
  178. /* FIXME: Handle extra 1.6 descriptor stuff */
  179. }
  180. }