OpenMBeanOperationInfoSupport.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* OpenMBeanOperationInfoSupport.java -- Open typed info about an operation.
  2. Copyright (C) 2006, 2007 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.MBeanOperationInfo;
  34. import javax.management.MBeanParameterInfo;
  35. /**
  36. * Describes a operation for an open management bean.
  37. *
  38. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  39. * @since 1.5
  40. */
  41. public class OpenMBeanOperationInfoSupport
  42. extends MBeanOperationInfo
  43. implements OpenMBeanOperationInfo
  44. {
  45. /**
  46. * Compatible with JDK 1.5
  47. */
  48. private static final long serialVersionUID = 4996859732565369366L;
  49. /**
  50. * The open type representing the return value.
  51. */
  52. private OpenType<?> returnOpenType;
  53. /**
  54. * The hash code of this instance.
  55. */
  56. private transient Integer hashCode;
  57. /**
  58. * The <code>toString()</code> result of this instance.
  59. */
  60. private transient String string;
  61. /**
  62. * Constructs a @link{OpenMBeanOperationInfo} with the specified name,
  63. * description, parameter information, open return type and impact. A
  64. * <code>null</code> value for the parameter information is the same
  65. * as passing in an empty array. A copy of the parameter array is
  66. * taken, so later changes have no effect. The name and the
  67. * description may not be equal to the empty string, and neither
  68. * the name, description nor the open return type may be
  69. * <code>null</code>. The value of <code>impact</code> must be
  70. * one of the four valid values
  71. * ({@link javax.management.MBeanOperationInfo#INFO},
  72. * {@link javax.management.MBeanOperationInfo#ACTION},
  73. * {@link javax.management.MBeanOperationInfo#ACTION_INFO} and
  74. * {@link javax.management.MBeanOperationInfo#UNKNOWN}).
  75. *
  76. *
  77. * @param name the name of the constructor.
  78. * @param desc a description of the attribute.
  79. * @param sig the signature of the method, as a series
  80. * of {@link MBeanParameterInfo} objects, one for
  81. * each parameter.
  82. * @param type the open return type of the method.
  83. * @param impact the impact of performing the operation.
  84. * @throws IllegalArgumentException if the name, description or
  85. * open return type is <code>null</code>,
  86. * the name or description are equal to
  87. * the empty string, or the impact factor
  88. * is not one of the values enumerated
  89. * above.
  90. * @throws ArrayStoreException if the members of the signature array
  91. * are not assignable to
  92. * {@link javax.management.MBeanParameterInfo}
  93. */
  94. public OpenMBeanOperationInfoSupport(String name, String desc,
  95. OpenMBeanParameterInfo[] sig,
  96. OpenType<?> type, int impact)
  97. {
  98. super(name, desc, (MBeanParameterInfo[]) sig,
  99. type == null ? null : type.getClassName(), impact);
  100. if (name == null)
  101. throw new IllegalArgumentException("The name may not be null.");
  102. if (desc == null)
  103. throw new IllegalArgumentException("The description may not be null.");
  104. if (type == null)
  105. throw new IllegalArgumentException("The type may not be null.");
  106. if (name.length() == 0)
  107. throw new IllegalArgumentException("The name may not be the empty string.");
  108. if (desc.length() == 0)
  109. throw new IllegalArgumentException("The description may not be the " +
  110. "empty string.");
  111. if (impact != ACTION && impact != INFO &&
  112. impact != ACTION_INFO && impact != UNKNOWN)
  113. throw new IllegalArgumentException("The impact factor is an invalid value.");
  114. returnOpenType = type;
  115. }
  116. /**
  117. * Compares this attribute with the supplied object. This returns
  118. * true iff the object is an instance of {@link OpenMBeanOperationInfo}
  119. * with an equal name, signature, open return type and impact.
  120. *
  121. * @param obj the object to compare.
  122. * @return true if the object is a {@link OpenMBeanParameterInfo}
  123. * instance,
  124. * <code>name.equals(object.getName())</code>,
  125. * <code>signature.equals(object.getSignature())</code>,
  126. * <code>returnOpenType.equals(object.getReturnOpenType())</code>,
  127. * and <code>impact == object.getImpact()</code>.
  128. */
  129. public boolean equals(Object obj)
  130. {
  131. if (!(obj instanceof OpenMBeanOperationInfo))
  132. return false;
  133. OpenMBeanOperationInfo o = (OpenMBeanOperationInfo) obj;
  134. return getName().equals(o.getName()) &&
  135. getSignature().equals(o.getSignature()) &&
  136. returnOpenType.equals(o.getReturnOpenType()) &&
  137. getImpact() == o.getImpact();
  138. }
  139. /**
  140. * Returns the open type instance which represents the type of the
  141. * return value.
  142. *
  143. * @return the open type of the return value.
  144. */
  145. public OpenType<?> getReturnOpenType()
  146. {
  147. return returnOpenType;
  148. }
  149. /**
  150. * <p>
  151. * Returns the hashcode of the operation information as the sum of
  152. * the hashcodes of the name, open return type, impact and signature
  153. * (calculated by
  154. * <code>java.util.Arrays.asList(signature).hashCode()</code>).
  155. * </p>
  156. * <p>
  157. * As instances of this class are immutable, the return value
  158. * is computed just once for each instance and reused
  159. * throughout its life.
  160. * </p>
  161. *
  162. * @return the hashcode of the operation information.
  163. */
  164. public int hashCode()
  165. {
  166. if (hashCode == null)
  167. hashCode = Integer.valueOf(getName().hashCode() +
  168. returnOpenType.hashCode() +
  169. Integer.valueOf(getImpact()).hashCode() +
  170. Arrays.asList(getSignature()).hashCode());
  171. return hashCode.intValue();
  172. }
  173. /**
  174. * <p>
  175. * Returns a textual representation of this instance. This
  176. * is constructed using the class name
  177. * (<code>javax.management.openmbean.OpenMBeanOperationInfo</code>)
  178. * along with the name, signature, open return type and impact.
  179. * </p>
  180. * <p>
  181. * As instances of this class are immutable, the return value
  182. * is computed just once for each instance and reused
  183. * throughout its life.
  184. * </p>
  185. *
  186. * @return a @link{java.lang.String} instance representing
  187. * the instance in textual form.
  188. */
  189. public String toString()
  190. {
  191. if (string == null)
  192. {
  193. String impactString;
  194. switch (getImpact())
  195. {
  196. case INFO:
  197. impactString = "INFO";
  198. break;
  199. case ACTION:
  200. impactString = "ACTION";
  201. break;
  202. case ACTION_INFO:
  203. impactString = "ACTION_INFO";
  204. break;
  205. case UNKNOWN:
  206. impactString = "UNKNOWN";
  207. break;
  208. default:
  209. impactString = "ERRONEOUS VALUE";
  210. }
  211. string = getClass().getName()
  212. + "[name=" + getName()
  213. + ",signature=" + Arrays.toString(getSignature())
  214. + ",returnOpenType=" + returnOpenType
  215. + ",impact=" + impactString
  216. + "]";
  217. }
  218. return string;
  219. }
  220. }