287
|
1 |
/*
|
715
|
2 |
* Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
|
287
|
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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.jmx.mbeanserver;
|
|
27 |
|
|
28 |
import java.lang.reflect.Method;
|
|
29 |
import java.util.ArrayList;
|
|
30 |
import java.util.List;
|
|
31 |
import javax.management.NotCompliantMBeanException;
|
|
32 |
import javax.management.Notification;
|
687
|
33 |
import javax.management.openmbean.MXBeanMappingFactory;
|
287
|
34 |
|
|
35 |
/**
|
|
36 |
* <p>A variant of {@code StandardMBeanSupport} where the only
|
|
37 |
* methods included are public getters. This is used by
|
|
38 |
* {@code QueryNotificationFilter} to pretend that a Notification is
|
|
39 |
* an MBean so it can have a query evaluated on it. Standard queries
|
|
40 |
* never set attributes or invoke methods but custom queries could and
|
|
41 |
* we don't want to allow that. Also we don't want to fail if a
|
|
42 |
* Notification happens to have inconsistent types in a pair of getX and
|
|
43 |
* setX methods, and we want to include the Object.getClass() method.
|
|
44 |
*/
|
|
45 |
public class NotificationMBeanSupport extends StandardMBeanSupport {
|
|
46 |
public <T extends Notification> NotificationMBeanSupport(T n)
|
|
47 |
throws NotCompliantMBeanException {
|
|
48 |
super(n, Util.<Class<T>>cast(n.getClass()));
|
|
49 |
}
|
|
50 |
|
|
51 |
@Override
|
687
|
52 |
MBeanIntrospector<Method> getMBeanIntrospector(MXBeanMappingFactory ignored) {
|
287
|
53 |
return introspector;
|
|
54 |
}
|
|
55 |
|
|
56 |
private static class Introspector extends StandardMBeanIntrospector {
|
|
57 |
@Override
|
|
58 |
void checkCompliance(Class<?> mbeanType) {}
|
|
59 |
|
|
60 |
@Override
|
|
61 |
List<Method> getMethods(final Class<?> mbeanType)
|
|
62 |
throws Exception {
|
|
63 |
List<Method> methods = new ArrayList<Method>();
|
|
64 |
for (Method m : mbeanType.getMethods()) {
|
|
65 |
String name = m.getName();
|
|
66 |
Class<?> ret = m.getReturnType();
|
|
67 |
if (m.getParameterTypes().length == 0) {
|
|
68 |
if ((name.startsWith("is") && name.length() > 2 &&
|
|
69 |
ret == boolean.class) ||
|
|
70 |
(name.startsWith("get") && name.length() > 3 &&
|
|
71 |
ret != void.class)) {
|
|
72 |
methods.add(m);
|
|
73 |
}
|
|
74 |
}
|
|
75 |
}
|
|
76 |
return methods;
|
|
77 |
}
|
|
78 |
|
|
79 |
}
|
|
80 |
private static final MBeanIntrospector<Method> introspector =
|
|
81 |
new Introspector();
|
|
82 |
}
|