Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/mxbean/MXBeanTest.java
38841 views
1
/*
2
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6175517 6278707 6318827 6305746 6392303 6600709 8010285
27
* @summary General MXBean test.
28
* @author Eamonn McManus
29
* @author Jaroslav Bachorik
30
* @run clean MXBeanTest MerlinMXBean TigerMXBean
31
* @run build MXBeanTest MerlinMXBean TigerMXBean
32
* @run main MXBeanTest
33
*/
34
35
import java.lang.reflect.Array;
36
import java.lang.reflect.Field;
37
import java.lang.reflect.InvocationHandler;
38
import java.lang.reflect.Method;
39
import java.lang.reflect.Proxy;
40
import java.util.Arrays;
41
import java.util.Collection;
42
import java.util.HashMap;
43
import java.util.Iterator;
44
import java.util.Map;
45
import java.util.SortedMap;
46
import javax.management.JMX;
47
import javax.management.MBeanAttributeInfo;
48
import javax.management.MBeanInfo;
49
import javax.management.MBeanOperationInfo;
50
import javax.management.MBeanParameterInfo;
51
import javax.management.MBeanServer;
52
import javax.management.MBeanServerConnection;
53
import javax.management.MBeanServerFactory;
54
import javax.management.MBeanServerInvocationHandler;
55
import javax.management.NotCompliantMBeanException;
56
import javax.management.ObjectName;
57
import javax.management.StandardMBean;
58
import javax.management.openmbean.ArrayType;
59
import javax.management.openmbean.CompositeData;
60
import javax.management.openmbean.CompositeDataInvocationHandler;
61
import javax.management.openmbean.OpenType;
62
import javax.management.openmbean.SimpleType;
63
import javax.management.openmbean.TabularData;
64
import javax.management.openmbean.TabularType;
65
import javax.management.remote.JMXConnector;
66
import javax.management.remote.JMXConnectorFactory;
67
import javax.management.remote.JMXConnectorServer;
68
import javax.management.remote.JMXConnectorServerFactory;
69
import javax.management.remote.JMXServiceURL;
70
71
public class MXBeanTest {
72
public static void main(String[] args) throws Exception {
73
testInterface(MerlinMXBean.class, false);
74
testInterface(TigerMXBean.class, false);
75
testInterface(MerlinMXBean.class, true);
76
testInterface(TigerMXBean.class, true);
77
testExplicitMXBean();
78
testSubclassMXBean();
79
testIndirectMXBean();
80
testNonCompliantMXBean("Private", new Private());
81
testNonCompliantMXBean("NonCompliant", new NonCompliant());
82
83
if (failures == 0)
84
System.out.println("Test passed");
85
else
86
throw new Exception("TEST FAILURES: " + failures);
87
}
88
89
private static int failures = 0;
90
91
private static interface PrivateMXBean {
92
public int[] getInts();
93
}
94
95
public static class Private implements PrivateMXBean {
96
public int[] getInts() {
97
return new int[]{1,2,3};
98
}
99
}
100
101
public static interface NonCompliantMXBean {
102
public boolean getInt();
103
public boolean isInt();
104
public void setInt(int a);
105
public void setInt(long b);
106
}
107
108
public static class NonCompliant implements NonCompliantMXBean {
109
public boolean getInt() {
110
return false;
111
}
112
113
public boolean isInt() {
114
return true;
115
}
116
117
public void setInt(int a) {
118
}
119
120
public void setInt(long b) {
121
}
122
}
123
124
public static interface ExplicitMXBean {
125
public int[] getInts();
126
}
127
public static class Explicit implements ExplicitMXBean {
128
public int[] getInts() {
129
return new int[] {1, 2, 3};
130
}
131
}
132
public static class Subclass
133
extends StandardMBean
134
implements ExplicitMXBean {
135
public Subclass() {
136
super(ExplicitMXBean.class, true);
137
}
138
139
public int[] getInts() {
140
return new int[] {1, 2, 3};
141
}
142
}
143
public static interface IndirectInterface extends ExplicitMXBean {}
144
public static class Indirect implements IndirectInterface {
145
public int[] getInts() {
146
return new int[] {1, 2, 3};
147
}
148
}
149
150
private static void testNonCompliantMXBean(String type, Object bean) throws Exception {
151
System.out.println(type + " MXBean test...");
152
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
153
ObjectName on = new ObjectName("test:type=" + type);
154
try {
155
mbs.registerMBean(bean, on);
156
failure(bean.getClass().getInterfaces()[0].getName() + " is not a compliant "
157
+ "MXBean interface");
158
} catch (NotCompliantMBeanException e) {
159
success("Non-compliant MXBean not registered");
160
}
161
}
162
163
private static void testExplicitMXBean() throws Exception {
164
System.out.println("Explicit MXBean test...");
165
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
166
ObjectName on = new ObjectName("test:type=Explicit");
167
Explicit explicit = new Explicit();
168
mbs.registerMBean(explicit, on);
169
testMXBean(mbs, on);
170
}
171
172
private static void testSubclassMXBean() throws Exception {
173
System.out.println("Subclass MXBean test...");
174
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
175
ObjectName on = new ObjectName("test:type=Subclass");
176
Subclass subclass = new Subclass();
177
mbs.registerMBean(subclass, on);
178
testMXBean(mbs, on);
179
}
180
181
private static void testIndirectMXBean() throws Exception {
182
System.out.println("Indirect MXBean test...");
183
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
184
ObjectName on = new ObjectName("test:type=Indirect");
185
Indirect indirect = new Indirect();
186
mbs.registerMBean(indirect, on);
187
testMXBean(mbs, on);
188
}
189
190
private static void testMXBean(MBeanServer mbs, ObjectName on)
191
throws Exception {
192
MBeanInfo mbi = mbs.getMBeanInfo(on);
193
MBeanAttributeInfo[] attrs = mbi.getAttributes();
194
int nattrs = attrs.length;
195
if (mbi.getAttributes().length != 1)
196
failure("wrong number of attributes: " + attrs);
197
else {
198
MBeanAttributeInfo mbai = attrs[0];
199
if (mbai.getName().equals("Ints")
200
&& mbai.isReadable() && !mbai.isWritable()
201
&& mbai.getDescriptor().getFieldValue("openType")
202
.equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
203
&& attrs[0].getType().equals("[I"))
204
success("MBeanAttributeInfo");
205
else
206
failure("MBeanAttributeInfo: " + mbai);
207
}
208
209
int[] ints = (int[]) mbs.getAttribute(on, "Ints");
210
if (equal(ints, new int[] {1, 2, 3}, null))
211
success("getAttribute");
212
else
213
failure("getAttribute: " + Arrays.toString(ints));
214
215
ExplicitMXBean proxy =
216
JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
217
int[] pints = proxy.getInts();
218
if (equal(pints, new int[] {1, 2, 3}, null))
219
success("getAttribute through proxy");
220
else
221
failure("getAttribute through proxy: " + Arrays.toString(pints));
222
}
223
224
private static class NamedMXBeans extends HashMap<ObjectName, Object> {
225
private static final long serialVersionUID = 0;
226
227
NamedMXBeans(MBeanServerConnection mbsc) {
228
this.mbsc = mbsc;
229
}
230
231
MBeanServerConnection getMBeanServerConnection() {
232
return mbsc;
233
}
234
235
private final MBeanServerConnection mbsc;
236
}
237
238
/* This is the core of the test. Given the MXBean interface c, we
239
make an MXBean object that implements that interface by
240
constructing a dynamic proxy. If the interface defines an
241
attribute Foo (with getFoo and setFoo methods), then it must
242
also contain a field (constant) Foo of the same type, and a
243
field (constant) FooType that is an OpenType. The field Foo is
244
a reference value for this case. We check that the attribute
245
does indeed have the given OpenType. The dynamically-created
246
MXBean will return the reference value from the getFoo()
247
method, and we check that that value survives the mapping to
248
open values and back when the attribute is accessed through an
249
MXBean proxy. The MXBean will also check in its setFoo method
250
that the value being set is equal to the reference value, which
251
tests that the mapping and unmapping also works in the other
252
direction. The interface should define an operation opFoo with
253
two parameters and a return value all of the same type as the
254
attribute. The MXBean will check that the two parameters are
255
equal to the reference value, and will return that value. The
256
test checks that calling the operation through an MXBean proxy
257
returns the reference value, again after mapping to and back
258
from open values.
259
260
If any field (constant) in the MXBean interface has a name that
261
ends with ObjectName, say FooObjectName, then its value must be
262
a String containing an ObjectName value. There must be a field
263
(constant) called Foo that is a valid MXBean, and that MXBean
264
will be registered in the MBean Server with the given name before
265
the test starts. This enables us to test that inter-MXBean
266
references are correctly converted to ObjectNames and back.
267
*/
268
private static <T> void testInterface(Class<T> c, boolean nullTest)
269
throws Exception {
270
271
System.out.println("Testing " + c.getName() +
272
(nullTest ? " for null values" : "") + "...");
273
274
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
275
276
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
277
JMXConnectorServer cs =
278
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
279
cs.start();
280
JMXServiceURL addr = cs.getAddress();
281
JMXConnector cc = JMXConnectorFactory.connect(addr);
282
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
283
284
NamedMXBeans namedMXBeans = new NamedMXBeans(mbsc);
285
InvocationHandler ih =
286
nullTest ? new MXBeanNullImplInvocationHandler(c, namedMXBeans) :
287
new MXBeanImplInvocationHandler(c, namedMXBeans);
288
T impl = c.cast(Proxy.newProxyInstance(c.getClassLoader(),
289
new Class[] {c},
290
ih));
291
ObjectName on = new ObjectName("test:type=" + c.getName());
292
mbs.registerMBean(impl, on);
293
294
System.out.println("Register any MXBeans...");
295
296
Field[] fields = c.getFields();
297
for (Field field : fields) {
298
String n = field.getName();
299
if (n.endsWith("ObjectName")) {
300
String objectNameString = (String) field.get(null);
301
String base = n.substring(0, n.length() - 10);
302
Field f = c.getField(base);
303
Object mxbean = f.get(null);
304
ObjectName objectName =
305
ObjectName.getInstance(objectNameString);
306
mbs.registerMBean(mxbean, objectName);
307
namedMXBeans.put(objectName, mxbean);
308
}
309
}
310
311
try {
312
testInterface(c, mbsc, on, namedMXBeans, nullTest);
313
} finally {
314
try {
315
cc.close();
316
} finally {
317
cs.stop();
318
}
319
}
320
}
321
322
private static <T> void testInterface(Class<T> c,
323
MBeanServerConnection mbsc,
324
ObjectName on,
325
NamedMXBeans namedMXBeans,
326
boolean nullTest)
327
throws Exception {
328
329
System.out.println("Type check...");
330
331
MBeanInfo mbi = mbsc.getMBeanInfo(on);
332
MBeanAttributeInfo[] mbais = mbi.getAttributes();
333
for (int i = 0; i < mbais.length; i++) {
334
MBeanAttributeInfo mbai = mbais[i];
335
String name = mbai.getName();
336
Field typeField = c.getField(name + "Type");
337
OpenType typeValue = (OpenType) typeField.get(null);
338
OpenType openType =
339
(OpenType) mbai.getDescriptor().getFieldValue("openType");
340
if (typeValue.equals(openType))
341
success("attribute " + name);
342
else {
343
final String msg =
344
"Wrong type attribute " + name + ": " +
345
openType + " should be " + typeValue;
346
failure(msg);
347
}
348
}
349
350
MBeanOperationInfo[] mbois = mbi.getOperations();
351
for (int i = 0; i < mbois.length; i++) {
352
MBeanOperationInfo mboi = mbois[i];
353
String oname = mboi.getName();
354
if (!oname.startsWith("op"))
355
throw new Error();
356
OpenType retType =
357
(OpenType) mboi.getDescriptor().getFieldValue("openType");
358
MBeanParameterInfo[] params = mboi.getSignature();
359
MBeanParameterInfo p1i = params[0];
360
MBeanParameterInfo p2i = params[1];
361
OpenType p1Type =
362
(OpenType) p1i.getDescriptor().getFieldValue("openType");
363
OpenType p2Type =
364
(OpenType) p2i.getDescriptor().getFieldValue("openType");
365
if (!retType.equals(p1Type) || !p1Type.equals(p2Type)) {
366
final String msg =
367
"Parameter and return open types should all be same " +
368
"but are not: " + retType + " " + oname + "(" + p1Type +
369
", " + p2Type + ")";
370
failure(msg);
371
continue;
372
}
373
String name = oname.substring(2);
374
Field typeField = c.getField(name + "Type");
375
OpenType typeValue = (OpenType) typeField.get(null);
376
if (typeValue.equals(retType))
377
success("operation " + oname);
378
else {
379
final String msg =
380
"Wrong type operation " + oname + ": " +
381
retType + " should be " + typeValue;
382
failure(msg);
383
}
384
}
385
386
387
System.out.println("Mapping check...");
388
389
Object proxy =
390
JMX.newMXBeanProxy(mbsc, on, c);
391
392
Method[] methods = c.getMethods();
393
for (int i = 0; i < methods.length; i++) {
394
final Method method = methods[i];
395
if (method.getDeclaringClass() != c)
396
continue; // skip hashCode() etc inherited from Object
397
final String mname = method.getName();
398
final int what = getType(method);
399
final String name = getName(method);
400
final Field refField = c.getField(name);
401
if (nullTest && refField.getType().isPrimitive())
402
continue;
403
final Field openTypeField = c.getField(name + "Type");
404
final OpenType openType = (OpenType) openTypeField.get(null);
405
final Object refValue = nullTest ? null : refField.get(null);
406
Object setValue = refValue;
407
try {
408
Field onField = c.getField(name + "ObjectName");
409
String refName = (String) onField.get(null);
410
ObjectName refObjName = ObjectName.getInstance(refName);
411
Class<?> mxbeanInterface = refField.getType();
412
setValue = nullTest ? null :
413
JMX.newMXBeanProxy(mbsc, refObjName, mxbeanInterface);
414
} catch (Exception e) {
415
// no xObjectName field, setValue == refValue
416
}
417
boolean ok = true;
418
try {
419
switch (what) {
420
case GET:
421
final Object gotOpen = mbsc.getAttribute(on, name);
422
if (nullTest) {
423
if (gotOpen != null) {
424
failure(mname + " got non-null value " +
425
gotOpen);
426
ok = false;
427
}
428
} else if (!openType.isValue(gotOpen)) {
429
if (gotOpen instanceof TabularData) {
430
// detail the mismatch
431
TabularData gotTabular = (TabularData) gotOpen;
432
compareTabularType((TabularType) openType,
433
gotTabular.getTabularType());
434
}
435
failure(mname + " got open data " + gotOpen +
436
" not valid for open type " + openType);
437
ok = false;
438
}
439
final Object got = method.invoke(proxy, (Object[]) null);
440
if (!equal(refValue, got, namedMXBeans)) {
441
failure(mname + " got " + string(got) +
442
", should be " + string(refValue));
443
ok = false;
444
}
445
break;
446
447
case SET:
448
method.invoke(proxy, new Object[] {setValue});
449
break;
450
451
case OP:
452
final Object opped =
453
method.invoke(proxy, new Object[] {setValue, setValue});
454
if (!equal(refValue, opped, namedMXBeans)) {
455
failure(
456
mname + " got " + string(opped) +
457
", should be " + string(refValue)
458
);
459
ok = false;
460
}
461
break;
462
463
default:
464
throw new Error();
465
}
466
467
if (ok)
468
success(mname);
469
470
} catch (Exception e) {
471
failure(mname, e);
472
}
473
}
474
}
475
476
477
private static void success(String what) {
478
System.out.println("OK: " + what);
479
}
480
481
private static void failure(String what) {
482
System.out.println("FAILED: " + what);
483
failures++;
484
}
485
486
private static void failure(String what, Exception e) {
487
System.out.println("FAILED WITH EXCEPTION: " + what);
488
e.printStackTrace(System.out);
489
failures++;
490
}
491
492
private static class MXBeanImplInvocationHandler
493
implements InvocationHandler {
494
MXBeanImplInvocationHandler(Class intf, NamedMXBeans namedMXBeans) {
495
this.intf = intf;
496
this.namedMXBeans = namedMXBeans;
497
}
498
499
public Object invoke(Object proxy, Method method, Object[] args)
500
throws Throwable {
501
final String mname = method.getName();
502
final int what = getType(method);
503
final String name = getName(method);
504
final Field refField = intf.getField(name);
505
final Object refValue = getRefValue(refField);
506
507
switch (what) {
508
case GET:
509
assert args == null;
510
return refValue;
511
512
case SET:
513
assert args.length == 1;
514
Object setValue = args[0];
515
if (!equal(refValue, setValue, namedMXBeans)) {
516
final String msg =
517
mname + "(" + string(setValue) +
518
") does not match ref: " + string(refValue);
519
throw new IllegalArgumentException(msg);
520
}
521
return null;
522
523
case OP:
524
assert args.length == 2;
525
Object arg1 = args[0];
526
Object arg2 = args[1];
527
if (!equal(arg1, arg2, namedMXBeans)) {
528
final String msg =
529
mname + "(" + string(arg1) + ", " + string(arg2) +
530
"): args not equal";
531
throw new IllegalArgumentException(msg);
532
}
533
if (!equal(refValue, arg1, namedMXBeans)) {
534
final String msg =
535
mname + "(" + string(arg1) + ", " + string(arg2) +
536
"): args do not match ref: " + string(refValue);
537
throw new IllegalArgumentException(msg);
538
}
539
return refValue;
540
default:
541
throw new Error();
542
}
543
}
544
545
Object getRefValue(Field refField) throws Exception {
546
return refField.get(null);
547
}
548
549
private final Class intf;
550
private final NamedMXBeans namedMXBeans;
551
}
552
553
private static class MXBeanNullImplInvocationHandler
554
extends MXBeanImplInvocationHandler {
555
MXBeanNullImplInvocationHandler(Class intf, NamedMXBeans namedMXBeans) {
556
super(intf, namedMXBeans);
557
}
558
559
@Override
560
Object getRefValue(Field refField) throws Exception {
561
Class<?> type = refField.getType();
562
if (type.isPrimitive())
563
return super.getRefValue(refField);
564
else
565
return null;
566
}
567
}
568
569
570
private static final String[] prefixes = {
571
"get", "set", "op",
572
};
573
private static final int GET = 0, SET = 1, OP = 2;
574
575
private static String getName(Method m) {
576
return getName(m.getName());
577
}
578
579
private static String getName(String n) {
580
for (int i = 0; i < prefixes.length; i++) {
581
if (n.startsWith(prefixes[i]))
582
return n.substring(prefixes[i].length());
583
}
584
throw new Error();
585
}
586
587
private static int getType(Method m) {
588
return getType(m.getName());
589
}
590
591
private static int getType(String n) {
592
for (int i = 0; i < prefixes.length; i++) {
593
if (n.startsWith(prefixes[i]))
594
return i;
595
}
596
throw new Error();
597
}
598
599
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) {
600
if (o1 == o2)
601
return true;
602
if (o1 == null || o2 == null)
603
return false;
604
if (o1.getClass().isArray()) {
605
if (!o2.getClass().isArray())
606
return false;
607
return deepEqual(o1, o2, namedMXBeans);
608
}
609
if (o1 instanceof Map) {
610
if (!(o2 instanceof Map))
611
return false;
612
return equalMap((Map) o1, (Map) o2, namedMXBeans);
613
}
614
if (o1 instanceof CompositeData && o2 instanceof CompositeData) {
615
return compositeDataEqual((CompositeData) o1, (CompositeData) o2,
616
namedMXBeans);
617
}
618
if (Proxy.isProxyClass(o1.getClass())) {
619
if (Proxy.isProxyClass(o2.getClass()))
620
return proxyEqual(o1, o2, namedMXBeans);
621
InvocationHandler ih = Proxy.getInvocationHandler(o1);
622
// if (ih instanceof MXBeanInvocationHandler) {
623
// return proxyEqualsObject((MXBeanInvocationHandler) ih,
624
// o2, namedMXBeans);
625
if (ih instanceof MBeanServerInvocationHandler) {
626
return true;
627
} else if (ih instanceof CompositeDataInvocationHandler) {
628
return o2.equals(o1);
629
// We assume the other object has a reasonable equals method
630
}
631
} else if (Proxy.isProxyClass(o2.getClass()))
632
return equal(o2, o1, namedMXBeans);
633
return o1.equals(o2);
634
}
635
636
// We'd use Arrays.deepEquals except we want the test to work on 1.4
637
// Note this code assumes no selfreferential arrays
638
// (as does Arrays.deepEquals)
639
private static boolean deepEqual(Object a1, Object a2,
640
NamedMXBeans namedMXBeans) {
641
int len = Array.getLength(a1);
642
if (len != Array.getLength(a2))
643
return false;
644
for (int i = 0; i < len; i++) {
645
Object e1 = Array.get(a1, i);
646
Object e2 = Array.get(a2, i);
647
if (!equal(e1, e2, namedMXBeans))
648
return false;
649
}
650
return true;
651
}
652
653
private static boolean equalMap(Map<?,?> m1, Map<?,?> m2,
654
NamedMXBeans namedMXBeans) {
655
if (m1.size() != m2.size())
656
return false;
657
if ((m1 instanceof SortedMap) != (m2 instanceof SortedMap))
658
return false;
659
for (Object k1 : m1.keySet()) {
660
if (!m2.containsKey(k1))
661
return false;
662
if (!equal(m1.get(k1), m2.get(k1), namedMXBeans))
663
return false;
664
}
665
return true;
666
}
667
668
// This is needed to work around a bug (5095277)
669
// in CompositeDataSupport.equals
670
private static boolean compositeDataEqual(CompositeData cd1,
671
CompositeData cd2,
672
NamedMXBeans namedMXBeans) {
673
if (cd1 == cd2)
674
return true;
675
if (!cd1.getCompositeType().equals(cd2.getCompositeType()))
676
return false;
677
Collection v1 = cd1.values();
678
Collection v2 = cd2.values();
679
if (v1.size() != v2.size())
680
return false; // should not happen
681
for (Iterator i1 = v1.iterator(), i2 = v2.iterator();
682
i1.hasNext(); ) {
683
if (!equal(i1.next(), i2.next(), namedMXBeans))
684
return false;
685
}
686
return true;
687
}
688
689
// Also needed for 5095277
690
private static boolean proxyEqual(Object proxy1, Object proxy2,
691
NamedMXBeans namedMXBeans) {
692
if (proxy1.getClass() != proxy2.getClass())
693
return proxy1.equals(proxy2);
694
InvocationHandler ih1 = Proxy.getInvocationHandler(proxy1);
695
InvocationHandler ih2 = Proxy.getInvocationHandler(proxy2);
696
if (!(ih1 instanceof CompositeDataInvocationHandler)
697
|| !(ih2 instanceof CompositeDataInvocationHandler))
698
return proxy1.equals(proxy2);
699
CompositeData cd1 =
700
((CompositeDataInvocationHandler) ih1).getCompositeData();
701
CompositeData cd2 =
702
((CompositeDataInvocationHandler) ih2).getCompositeData();
703
return compositeDataEqual(cd1, cd2, namedMXBeans);
704
}
705
706
// private static boolean proxyEqualsObject(MXBeanInvocationHandler ih,
707
// Object o,
708
// NamedMXBeans namedMXBeans) {
709
// if (namedMXBeans.getMBeanServerConnection() !=
710
// ih.getMBeanServerConnection())
711
// return false;
712
//
713
// ObjectName on = ih.getObjectName();
714
// Object named = namedMXBeans.get(on);
715
// if (named == null)
716
// return false;
717
// return (o == named && ih.getMXBeanInterface().isInstance(named));
718
// }
719
720
/* I wanted to call this method toString(Object), but oddly enough
721
this meant that I couldn't call it from the inner class
722
MXBeanImplInvocationHandler, because the inherited Object.toString()
723
prevented that. */
724
static String string(Object o) {
725
if (o == null)
726
return "null";
727
if (o instanceof String)
728
return '"' + (String) o + '"';
729
if (o instanceof Collection)
730
return deepToString((Collection) o);
731
if (o.getClass().isArray())
732
return deepToString(o);
733
return o.toString();
734
}
735
736
private static String deepToString(Object o) {
737
StringBuffer buf = new StringBuffer();
738
buf.append("[");
739
int len = Array.getLength(o);
740
for (int i = 0; i < len; i++) {
741
if (i > 0)
742
buf.append(", ");
743
Object e = Array.get(o, i);
744
buf.append(string(e));
745
}
746
buf.append("]");
747
return buf.toString();
748
}
749
750
private static String deepToString(Collection c) {
751
return deepToString(c.toArray());
752
}
753
754
private static void compareTabularType(TabularType t1, TabularType t2) {
755
if (t1.equals(t2)) {
756
System.out.println("same tabular type");
757
return;
758
}
759
if (t1.getClassName().equals(t2.getClassName()))
760
System.out.println("same class name");
761
if (t1.getDescription().equals(t2.getDescription()))
762
System.out.println("same description");
763
else {
764
System.out.println("t1 description: " + t1.getDescription());
765
System.out.println("t2 description: " + t2.getDescription());
766
}
767
if (t1.getIndexNames().equals(t2.getIndexNames()))
768
System.out.println("same index names");
769
if (t1.getRowType().equals(t2.getRowType()))
770
System.out.println("same row type");
771
}
772
}
773
774