API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.management.openmbean. OpenMBeanInfoSupport View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

/*
 * @(#)OpenMBeanInfoSupport.java	3.29 06/03/15
 * 
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */


package javax.management.openmbean;


// java import
//
import java.util.Arrays;
import java.util.HashSet;
import javax.management.Descriptor;
import javax.management.MBeanInfo;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanNotificationInfo;



/**
 * The {@code OpenMBeanInfoSupport} class describes the management
 * information of an <i>open MBean</i>: it is a subclass of {@link
 * javax.management.MBeanInfo}, and it implements the {@link
 * OpenMBeanInfo} interface.  Note that an <i>open MBean</i> is
 * recognized as such if its {@code getMBeanInfo()} method returns an
 * instance of a class which implements the OpenMBeanInfo interface,
 * typically {@code OpenMBeanInfoSupport}.
 *
 * @version     3.29  06/03/15
 * @author      Sun Microsystems, Inc.
 *
 * @since 1.5
 * @since.unbundled JMX 1.1
 */
public class OpenMBeanInfoSupport extends MBeanInfo
    implements OpenMBeanInfo {

    /* Serial version */
    static final long serialVersionUID = 4349395935420511492L;

    // As this instance is immutable, these two values
    // need only be calculated once.
    private transient Integer myHashCode = null;
    private transient String  myToString = null;


    /**
     * <p>Constructs an {@code OpenMBeanInfoSupport} instance, which
     * describes a class of open MBeans with the specified {@code
     * className}, {@code description}, {@code openAttributes}, {@code
     * openConstructors} , {@code openOperations} and {@code
     * notifications}.</p>
     *
     * <p>The {@code openAttributes}, {@code openConstructors},  
     * {@code openOperations} and {@code notifications}
     * array parameters are internally copied, so that subsequent changes 
     * to the arrays referenced by these parameters have no effect on this
     * instance.</p>
     *
     * @param className The fully qualified Java class name of the
     * open MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
     * instance.
     *
     * @param description A human readable description of the open
     * MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
     * instance.
     *
     * @param openAttributes The list of exposed attributes of the
     * described open MBean; Must be an array of instances of a
     * subclass of {@code MBeanAttributeInfo}, typically {@code
     * OpenMBeanAttributeInfoSupport}.
     *
     * @param openConstructors The list of exposed public constructors
     * of the described open MBean; Must be an array of instances of a
     * subclass of {@code MBeanConstructorInfo}, typically {@code
     * OpenMBeanConstructorInfoSupport}.
     *
     * @param openOperations The list of exposed operations of the
     * described open MBean.  Must be an array of instances of a
     * subclass of {@code MBeanOperationInfo}, typically {@code
     * OpenMBeanOperationInfoSupport}.
     *
     * @param notifications The list of notifications emitted by the
     * described open MBean.
     *
     * @throws ArrayStoreException If {@code openAttributes}, {@code
     * openConstructors} or {@code openOperations} is not an array of
     * instances of a subclass of {@code MBeanAttributeInfo}, {@code
     * MBeanConstructorInfo} or {@code MBeanOperationInfo}
     * respectively.
     */
    public OpenMBeanInfoSupport(String className, 
				String description,
				OpenMBeanAttributeInfo[] openAttributes, 
				OpenMBeanConstructorInfo[] openConstructors,
				OpenMBeanOperationInfo[] openOperations, 
				MBeanNotificationInfo[] notifications) {
	this(className, description,
	     openAttributes, openConstructors, openOperations, notifications,
	     (Descriptor) null);
    }
	
    /**
     * <p>Constructs an {@code OpenMBeanInfoSupport} instance, which
     * describes a class of open MBeans with the specified {@code
     * className}, {@code description}, {@code openAttributes}, {@code
     * openConstructors} , {@code openOperations}, {@code
     * notifications}, and {@code descriptor}.</p>
     *
     * <p>The {@code openAttributes}, {@code openConstructors}, {@code
     * openOperations} and {@code notifications} array parameters are
     * internally copied, so that subsequent changes to the arrays
     * referenced by these parameters have no effect on this
     * instance.</p>
     *
     * @param className The fully qualified Java class name of the
     * open MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
     * instance.
     *
     * @param description A human readable description of the open
     * MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
     * instance.
     *
     * @param openAttributes The list of exposed attributes of the
     * described open MBean; Must be an array of instances of a
     * subclass of {@code MBeanAttributeInfo}, typically {@code
     * OpenMBeanAttributeInfoSupport}.
     *
     * @param openConstructors The list of exposed public constructors
     * of the described open MBean; Must be an array of instances of a
     * subclass of {@code MBeanConstructorInfo}, typically {@code
     * OpenMBeanConstructorInfoSupport}.
     *
     * @param openOperations The list of exposed operations of the
     * described open MBean.  Must be an array of instances of a
     * subclass of {@code MBeanOperationInfo}, typically {@code
     * OpenMBeanOperationInfoSupport}.
     *
     * @param notifications The list of notifications emitted by the
     * described open MBean.
     *
     * @param descriptor The descriptor for the MBean.  This may be null
     * which is equivalent to an empty descriptor.
     *
     * @throws ArrayStoreException If {@code openAttributes}, {@code
     * openConstructors} or {@code openOperations} is not an array of
     * instances of a subclass of {@code MBeanAttributeInfo}, {@code
     * MBeanConstructorInfo} or {@code MBeanOperationInfo}
     * respectively.
     *
     * @since 1.6
     */
    public OpenMBeanInfoSupport(String className, 
				String description,
				OpenMBeanAttributeInfo[] openAttributes, 
				OpenMBeanConstructorInfo[] openConstructors,
				OpenMBeanOperationInfo[] openOperations, 
				MBeanNotificationInfo[] notifications,
				Descriptor descriptor) {
	super(className, 
	      description, 
	      attributeArray(openAttributes),
	      constructorArray(openConstructors),
	      operationArray(openOperations),
	      (notifications == null) ? null : notifications.clone(),
	      descriptor);
    }


    private static MBeanAttributeInfo[]
	    attributeArray(OpenMBeanAttributeInfo[] src) {
	if (src == null)
	    return null;
	MBeanAttributeInfo[] dst = new MBeanAttributeInfo[src.length];
	System.arraycopy(src, 0, dst, 0, src.length);
	// may throw an ArrayStoreException
	return dst;
    }

    private static MBeanConstructorInfo[]
	    constructorArray(OpenMBeanConstructorInfo[] src) {
	if (src == null)
	    return null;
	MBeanConstructorInfo[] dst = new MBeanConstructorInfo[src.length];
	System.arraycopy(src, 0, dst, 0, src.length);
	// may throw an ArrayStoreException
	return dst;
    }

    private static MBeanOperationInfo[]
	    operationArray(OpenMBeanOperationInfo[] src) {
	if (src == null)
	    return null;
	MBeanOperationInfo[] dst = new MBeanOperationInfo[src.length];
	System.arraycopy(src, 0, dst, 0, src.length);
	return dst;
    }



    /* ***  Commodity methods from java.lang.Object  *** */


    /**
     * <p>Compares the specified {@code obj} parameter with this
     * {@code OpenMBeanInfoSupport} instance for equality.</p>
     *
     * <p>Returns {@code true} if and only if all of the following
     * statements are true:
     *
     * <ul>
     * <li>{@code obj} is non null,</li>
     * <li>{@code obj} also implements the {@code OpenMBeanInfo}
     * interface,</li>
     * <li>their class names are equal</li>
     * <li>their infos on attributes, constructors, operations and
     * notifications are equal</li>
     * </ul>
     *
     * This ensures that this {@code equals} method works properly for
     * {@code obj} parameters which are different implementations of
     * the {@code OpenMBeanInfo} interface.
     *
     * @param obj the object to be compared for equality with this
     * {@code OpenMBeanInfoSupport} instance;
     * 
     * @return {@code true} if the specified object is equal to this
     * {@code OpenMBeanInfoSupport} instance.
     */
    public boolean equals(Object obj) { 

	// if obj is null, return false
	//
	if (obj == null) {
	    return false;
	}

	// if obj is not a OpenMBeanInfo, return false
	//
	OpenMBeanInfo other;
	try {
	    other = (OpenMBeanInfo) obj;
	} catch (ClassCastException e) {
	    return false;
	}

	// Now, really test for equality between this OpenMBeanInfo
	// implementation and the other:
	//
	
	// their MBean className should be equal
	if ( ! this.getClassName().equals(other.getClassName()) )
	    return false;

	// their infos on attributes should be equal (order not
	// significant => equality between sets, not arrays or lists)
	if (!sameArrayContents(this.getAttributes(), other.getAttributes()))
	    return false;
       
	// their infos on constructors should be equal (order not
	// significant => equality between sets, not arrays or lists)
	if (!sameArrayContents(this.getConstructors(), other.getConstructors()))
	    return false;
       
	// their infos on operations should be equal (order not
	// significant => equality between sets, not arrays or lists)
	if (!sameArrayContents(this.getOperations(), other.getOperations()))

	    return false;
       
	// their infos on notifications should be equal (order not
	// significant => equality between sets, not arrays or lists)
	if (!sameArrayContents(this.getNotifications(), other.getNotifications()))
	    return false;
       
	// All tests for equality were successful
	//
	return true;
    }

    private static <T> boolean sameArrayContents(T[] a1, T[] a2) {
	return (new HashSet<T>(Arrays.asList(a1))
		.equals(new HashSet<T>(Arrays.asList(a2))));
    }

    /**
     * <p>Returns the hash code value for this {@code
     * OpenMBeanInfoSupport} instance.</p>
     *
     * <p>The hash code of an {@code OpenMBeanInfoSupport} instance is
     * the sum of the hash codes of all elements of information used
     * in {@code equals} comparisons (ie: its class name, and its
     * infos on attributes, constructors, operations and
     * notifications, where the hashCode of each of these arrays is
     * calculated by a call to {@code new
     * java.util.HashSet(java.util.Arrays.asList(this.getSignature)).hashCode()}).</p>
     *
     * <p>This ensures that {@code t1.equals(t2)} implies that {@code
     * t1.hashCode()==t2.hashCode()} for any two {@code
     * OpenMBeanInfoSupport} instances {@code t1} and {@code t2}, as
     * required by the general contract of the method {@link
     * Object#hashCode() Object.hashCode()}.</p>
     *
     * <p>However, note that another instance of a class implementing
     * the {@code OpenMBeanInfo} interface may be equal to this {@code
     * OpenMBeanInfoSupport} instance as defined by {@link
     * #equals(java.lang.Object)}, but may have a different hash code
     * if it is calculated differently.</p>
     *
     * <p>As {@code OpenMBeanInfoSupport} instances are immutable, the
     * hash code for this instance is calculated once, on the first
     * call to {@code hashCode}, and then the same value is returned
     * for subsequent calls.</p>
     *
     * @return the hash code value for this {@code
     * OpenMBeanInfoSupport} instance
     */
    public int hashCode() {

	// Calculate the hash code value if it has not yet been done
	// (ie 1st call to hashCode())
	//
	if (myHashCode == null) {
	    int value = 0;
	    value += this.getClassName().hashCode();
	    value += arraySetHash(this.getAttributes());
	    value += arraySetHash(this.getConstructors());
	    value += arraySetHash(this.getOperations());
	    value += arraySetHash(this.getNotifications());
	    myHashCode = new Integer(value);
	}
	
	// return always the same hash code for this instance (immutable)
	//
	return myHashCode.intValue();
    }

    private static <T> int arraySetHash(T[] a) {
	return new HashSet<T>(Arrays.asList(a)).hashCode();
    }



    /**
     * <p>Returns a string representation of this {@code
     * OpenMBeanInfoSupport} instance.</p>
     *
     * <p>The string representation consists of the name of this class
     * (ie {@code javax.management.openmbean.OpenMBeanInfoSupport}),
     * the MBean class name, the string representation of infos on
     * attributes, constructors, operations and notifications of the
     * described MBean and the string representation of the descriptor.</p>
     *
     * <p>As {@code OpenMBeanInfoSupport} instances are immutable, the
     * string representation for this instance is calculated once, on
     * the first call to {@code toString}, and then the same value is
     * returned for subsequent calls.</p>
     * 
     * @return a string representation of this {@code
     * OpenMBeanInfoSupport} instance
     */
    public String toString() { 

	// Calculate the string value if it has not yet been done (ie
	// 1st call to toString())
	//
	if (myToString == null) {
	    myToString = new StringBuffer()
		.append(this.getClass().getName())
		.append("(mbean_class_name=")
		.append(this.getClassName())
		.append(",attributes=")
		.append(Arrays.asList(this.getAttributes()).toString())
		.append(",constructors=")
		.append(Arrays.asList(this.getConstructors()).toString())
		.append(",operations=")
		.append(Arrays.asList(this.getOperations()).toString())
		.append(",notifications=")
		.append(Arrays.asList(this.getNotifications()).toString())
		.append(",descriptor=")
		.append(this.getDescriptor())
		.append(")")
		.toString();
	}

	// return always the same string representation for this
	// instance (immutable)
	//
	return myToString;
    }

}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar