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