1 /* MBeanInfo.java -- Information about a management bean.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.management;
40 import java.io.Serializable;
42 import java.util.Arrays;
46 * Describes the interface of a management bean. This allows
47 * the user to access the bean dynamically, without knowing
48 * the details of any of its attributes, operations,
49 * constructors or notifications beforehand. The information
50 * is immutable as standard. Of course, subclasses may change
51 * this, but this behaviour is not recommended.
54 * The contents of this class, for standard management beans,
55 * are dynamically compiled using reflection.
56 * {@link #getClassName()} and {@link #getConstructors()}
57 * return the name of the class and its constructors, respectively.
58 * This is much the same as could be obtained by reflection on the
59 * bean. {@link #getAttributes()} and {@link #getOperations()},
60 * however, do something more in splitting the methods of the
61 * class into two sets. Those of the form, <code>getXXX</code>,
62 * <code>setXXX</code> and <code>isXXX</code> are taken to be
63 * the accessors and mutators of a series of attributes, with
64 * <code>XXX</code> being the attribute name. These are returned
65 * by {@link getAttributes()} and the {@link Attribute} class can
66 * be used to manipulate them. The remaining methods are classified
67 * as operations and returned by {@link getOperations()}.
70 * Beans can also broadcast notifications. If the bean provides this
71 * facility, by implementing the {@link NotificationBroadcaster}
72 * interface, then an array of {@link MBeanNotificationInfo} objects
73 * may be obtained from {@link #getNotifications()}, which describe
74 * the notifications emitted.
77 * Model management beans and open management beans also supply an
78 * instance of this class, as part of implementing the
79 * {@link DynamicMBean#getMBeanInfo()} method of {@link DynamicMBean}.
82 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
85 public class MBeanInfo
86 implements Cloneable, Serializable
90 * Compatible with JDK 1.5
92 private static final long serialVersionUID = -6451021435135161911L;
95 * A description of the bean.
97 * @serial The bean's description.
99 private String description;
102 * The class name of the management bean.
104 * @serial The bean's class name.
106 private String className;
109 * Descriptions of the attributes provided by the bean.
111 private MBeanAttributeInfo[] attributes;
114 * Descriptions of the operations provided by the bean.
116 private MBeanOperationInfo[] operations;
119 * Descriptions of the bean's constructors.
121 private MBeanConstructorInfo[] constructors;
124 * Descriptions of the notifications emitted by the bean.
126 * @serial The bean's notifications.
128 private MBeanNotificationInfo[] notifications;
131 * The <code>toString()</code> result of this instance.
133 private transient String string;
136 * Constructs a new {@link MBeanInfo} using the supplied
137 * class name and description with the given attributes,
138 * operations, constructors and notifications. The class
139 * name does not have to actually specify a valid class that
140 * can be loaded by the MBean server or class loader; it merely
141 * has to be a syntactically correct class name. Any of the
142 * arrays may be <code>null</code>; this will be treated as if
143 * an empty array was supplied. A copy of the arrays is
144 * taken, so later changes have no effect.
146 * @param name the name of the class this instance describes.
147 * @param desc a description of the bean.
148 * @param attribs the attribute descriptions for the bean,
149 * or <code>null</code>.
150 * @param cons the constructor descriptions for the bean,
151 * or <code>null</code>.
152 * @param ops the operation descriptions for the bean,
153 * or <code>null</code>.
154 * @param notifs the notification descriptions for the bean,
155 * or <code>null</code>.
157 public MBeanInfo(String name, String desc, MBeanAttributeInfo[] attribs,
158 MBeanConstructorInfo[] cons, MBeanOperationInfo[] ops,
159 MBeanNotificationInfo[] notifs)
164 attributes = new MBeanAttributeInfo[0];
167 attributes = new MBeanAttributeInfo[attribs.length];
168 System.arraycopy(attribs, 0, attributes, 0, attribs.length);
171 constructors = new MBeanConstructorInfo[0];
174 constructors = new MBeanConstructorInfo[cons.length];
175 System.arraycopy(cons, 0, constructors, 0, cons.length);
178 operations = new MBeanOperationInfo[0];
181 operations = new MBeanOperationInfo[ops.length];
182 System.arraycopy(ops, 0, operations, 0, ops.length);
185 notifications = new MBeanNotificationInfo[0];
188 notifications = new MBeanNotificationInfo[notifs.length];
189 System.arraycopy(notifs, 0, notifications, 0, notifs.length);
194 * Returns a shallow clone of the information. This is
195 * simply a new copy of each string and a clone
196 * of each array, which still references the same objects,
197 * as obtained by the {@link Object} implementation of
198 * {@link Object#clone()}. As the fields can not be
199 * changed, this method is only really of interest to
200 * subclasses which may add new mutable fields or make
201 * the existing ones mutable.
203 * @return a shallow clone of this {@link MBeanInfo}.
205 public Object clone()
207 MBeanInfo clone = null;
210 clone = (MBeanInfo) super.clone();
212 catch (CloneNotSupportedException e)
214 /* This won't happen as we implement Cloneable */
220 * Compares this feature with the supplied object. This returns
221 * true iff the object is an instance of {@link MBeanInfo} and
222 * {@link Object#equals()} returns true for a comparison of the
223 * class name and description, and the arrays each contain the same
224 * elements in the same order (but one may be longer than the
227 * @param obj the object to compare.
228 * @return true if the object is a {@link MBeanInfo}
230 * <code>className.equals(object.getClassName())</code>,
231 * <code>description.equals(object.getDescription())</code>
232 * and the corresponding elements of the arrays are
235 public boolean equals(Object obj)
237 if (!(obj instanceof MBeanInfo))
239 if (!(super.equals(obj)))
241 MBeanInfo o = (MBeanInfo) obj;
242 MBeanAttributeInfo[] attr = o.getAttributes();
243 for (int a = 0; a < attributes.length; ++a)
245 if (a == attr.length)
247 if (!(attributes[a].equals(attr[a])))
250 MBeanConstructorInfo[] cons = o.getConstructors();
251 for (int a = 0; a < constructors.length; ++a)
253 if (a == cons.length)
255 if (!(constructors[a].equals(cons[a])))
258 MBeanOperationInfo[] ops = o.getOperations();
259 for (int a = 0; a < operations.length; ++a)
263 if (!(operations[a].equals(ops[a])))
266 MBeanNotificationInfo[] notifs = o.getNotifications();
267 for (int a = 0; a < notifications.length; ++a)
269 if (a == notifs.length)
271 if (!(notifications[a].equals(notifs[a])))
274 return (className.equals(o.getClassName()) &&
275 description.equals(o.getDescription()));
279 * Returns descriptions of each of the attributes provided
280 * by this management bean. The returned value is a shallow
281 * copy of the attribute array maintained by this instance.
282 * Hence, changing the elements of the returned array will not
283 * affect the attribute array, and the elements (instances
284 * of the {@link MBeanAttributeInfo} class) are immutable.
286 * @return an array of {@link MBeanAttributeInfo} objects,
287 * representing the attributes emitted by this
290 public MBeanAttributeInfo[] getAttributes()
292 return (MBeanAttributeInfo[]) attributes.clone();
296 * Returns the class name of the management bean.
298 * @return the bean's class name.
300 public String getClassName()
306 * Returns descriptions of each of the constructors provided
307 * by this management bean. The returned value is a shallow
308 * copy of the constructor array maintained by this instance.
309 * Hence, changing the elements of the returned array will not
310 * affect the constructor array, and the elements (instances
311 * of the {@link MBeanConstructorInfo} class) are immutable.
313 * @return an array of {@link MBeanConstructorInfo} objects,
314 * representing the constructors emitted by this
317 public MBeanConstructorInfo[] getConstructors()
319 return (MBeanConstructorInfo[]) constructors.clone();
323 * Returns a description of the management bean.
325 * @return the bean's description.
327 public String getDescription()
333 * Returns descriptions of each of the notifications emitted
334 * by this management bean. The returned value is a shallow
335 * copy of the notification array maintained by this instance.
336 * Hence, changing the elements of the returned array will not
337 * affect the notification array, and the elements (instances
338 * of the {@link MBeanNotificationInfo} class) are immutable.
340 * @return an array of {@link MBeanNotificationInfo} objects,
341 * representing the notifications emitted by this
344 public MBeanNotificationInfo[] getNotifications()
346 return (MBeanNotificationInfo[]) notifications.clone();
350 * Returns descriptions of each of the operations provided
351 * by this management bean. The returned value is a shallow
352 * copy of the operation array maintained by this instance.
353 * Hence, changing the elements of the returned array will not
354 * affect the operation array, and the elements (instances
355 * of the {@link MBeanOperationInfo} class) are immutable.
357 * @return an array of {@link MBeanOperationInfo} objects,
358 * representing the operations emitted by this
361 public MBeanOperationInfo[] getOperations()
363 return (MBeanOperationInfo[]) operations.clone();
367 * Returns the hashcode of the information as the sum of the
368 * hashcode of the classname, description and each array.
370 * @return the hashcode of the information.
372 public int hashCode()
374 return className.hashCode() + description.hashCode()
375 + Arrays.hashCode(attributes) + Arrays.hashCode(constructors)
376 + Arrays.hashCode(operations) + Arrays.hashCode(notifications);
381 * Returns a textual representation of this instance. This
382 * is constructed using the class name
383 * (<code>javax.management.MBeanInfo</code>),
384 * the name and description of the bean and the contents
385 * of the four arrays.
388 * As instances of this class are immutable, the return value
389 * is computed just once for each instance and reused
390 * throughout its life.
393 * @return a @link{java.lang.String} instance representing
394 * the instance in textual form.
396 public String toString()
399 string = getClass().getName()
400 + "[name=" + className
401 + ",desc=" + description
402 + ",attributes=" + Arrays.toString(attributes)
403 + ",constructors=" + Arrays.toString(constructors)
404 + ",operations=" + Arrays.toString(operations)
405 + ",notifications=" + Arrays.toString(notifications)