KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > MBeanNotificationInfo


1 /*
2  * @(#)MBeanNotificationInfo.java 1.32 04/02/10
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management;
9
10 import java.util.Arrays JavaDoc;
11
12 /**
13  * <p>The <CODE>MBeanNotificationInfo</CODE> class is used to describe the
14  * characteristics of the different notification instances
15  * emitted by an MBean, for a given Java class of notification.
16  * If an MBean emits notifications that can be instances of different Java classes,
17  * then the metadata for that MBean should provide an <CODE>MBeanNotificationInfo</CODE>
18  * object for each of these notification Java classes.</p>
19  *
20  * <p>Instances of this class are immutable. Subclasses may be
21  * mutable but this is not recommended.</p>
22  *
23  * <p>This class extends <CODE>javax.management.MBeanFeatureInfo</CODE>
24  * and thus provides <CODE>name</CODE> and <CODE>description</CODE> fields.
25  * The <CODE>name</CODE> field should be the fully qualified Java class name of
26  * the notification objects described by this class.</p>
27  *
28  * <p>The <CODE>getNotifTypes</CODE> method returns an array of
29  * strings containing the notification types that the MBean may
30  * emit. The notification type is a dot-notation string which
31  * describes what the emitted notification is about, not the Java
32  * class of the notification. A single generic notification class can
33  * be used to send notifications of several types. All of these types
34  * are returned in the string array result of the
35  * <CODE>getNotifTypes</CODE> method.
36  *
37  * @since 1.5
38  */

39 public class MBeanNotificationInfo extends MBeanFeatureInfo JavaDoc implements Cloneable JavaDoc, java.io.Serializable JavaDoc {
40   
41     /* Serial version */
42     static final long serialVersionUID = -3888371564530107064L;
43
44     private static final String JavaDoc[] NO_TYPES = new String JavaDoc[0];
45
46     static final MBeanNotificationInfo JavaDoc[] NO_NOTIFICATIONS =
47     new MBeanNotificationInfo JavaDoc[0];
48
49     /**
50      * @serial The different types of the notification.
51      */

52     private final String JavaDoc[] types;
53     
54     /** @see MBeanInfo#immutable */
55     private final transient boolean immutable;
56
57     /**
58      * Constructs an <CODE>MBeanNotificationInfo</CODE> object.
59      *
60      * @param notifTypes The array of strings (in dot notation)
61      * containing the notification types that the MBean may emit.
62      * This may be null with the same effect as a zero-length array.
63      * @param name The fully qualified Java class name of the
64      * described notifications.
65      * @param description A human readable description of the data.
66      */

67     public MBeanNotificationInfo(String JavaDoc[] notifTypes,
68                  String JavaDoc name,
69                  String JavaDoc description)
70         throws IllegalArgumentException JavaDoc {
71     super(name, description);
72     
73
74     /* We do not validate the notifTypes, since the spec just says
75        they are dot-separated, not that they must look like Java
76        classes. E.g. the spec doesn't forbid "sun.prob.25" as a
77        notifType, though it doesn't explicitly allow it
78        either. */

79
80     if (notifTypes == null)
81         notifTypes = NO_TYPES;
82     this.types = notifTypes;
83     this.immutable =
84         MBeanInfo.isImmutableClass(this.getClass(),
85                        MBeanNotificationInfo JavaDoc.class);
86     }
87
88
89     /**
90      * Returns a shallow clone of this instance.
91      * The clone is obtained by simply calling <tt>super.clone()</tt>,
92      * thus calling the default native shallow cloning mechanism
93      * implemented by <tt>Object.clone()</tt>.
94      * No deeper cloning of any internal field is made.
95      */

96      public Object JavaDoc clone () {
97      try {
98          return super.clone() ;
99      } catch (CloneNotSupportedException JavaDoc e) {
100          // should not happen as this class is cloneable
101
return null;
102      }
103      }
104
105     
106     /**
107      * Returns the array of strings (in dot notation) containing the
108      * notification types that the MBean may emit.
109      *
110      * @return the array of strings. Changing the returned array has no
111      * effect on this MBeanNotificationInfo.
112      */

113     public String JavaDoc[] getNotifTypes() {
114     if (types.length == 0)
115             return NO_TYPES;
116         else
117             return (String JavaDoc[]) types.clone();
118     }
119
120     private String JavaDoc[] fastGetNotifTypes() {
121     if (immutable)
122         return types;
123     else
124         return getNotifTypes();
125     }
126
127     /**
128      * Compare this MBeanAttributeInfo to another.
129      *
130      * @param o the object to compare to.
131      *
132      * @return true iff <code>o</code> is an MBeanNotificationInfo
133      * such that its {@link #getName()}, {@link #getDescription()},
134      * and {@link #getNotifTypes()} values are equal (not necessarily
135      * identical) to those of this MBeanNotificationInfo. Two
136      * notification type arrays are equal if their corresponding
137      * elements are equal. They are not equal if they have the same
138      * elements but in a different order.
139      */

140     public boolean equals(Object JavaDoc o) {
141     if (o == this)
142         return true;
143     if (!(o instanceof MBeanNotificationInfo JavaDoc))
144         return false;
145     MBeanNotificationInfo JavaDoc p = (MBeanNotificationInfo JavaDoc) o;
146     return (p.getName().equals(getName()) &&
147         p.getDescription().equals(getDescription()) &&
148         Arrays.equals(p.fastGetNotifTypes(), fastGetNotifTypes()));
149     }
150
151     public int hashCode() {
152     int hash = getName().hashCode();
153     for (int i = 0; i < types.length; i++)
154         hash ^= types[i].hashCode();
155     return hash;
156     }
157 }
158
Popular Tags