2
|
1 |
/*
|
|
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. 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. 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 |
|
|
30 |
import javax.management.MBeanInfo;
|
|
31 |
import javax.management.MBeanServer;
|
|
32 |
import javax.management.NotCompliantMBeanException;
|
|
33 |
import javax.management.ObjectName;
|
687
|
34 |
import javax.management.openmbean.MXBeanMappingFactory;
|
2
|
35 |
|
|
36 |
/**
|
|
37 |
* Base class for Standard MBeans.
|
|
38 |
*
|
|
39 |
* @since 1.6
|
|
40 |
*/
|
|
41 |
public class StandardMBeanSupport extends MBeanSupport<Method> {
|
|
42 |
|
|
43 |
/**
|
|
44 |
<p>Construct a Standard MBean that wraps the given resource using the
|
|
45 |
given Standard MBean interface.</p>
|
|
46 |
|
|
47 |
@param resource the underlying resource for the new MBean.
|
|
48 |
|
|
49 |
@param mbeanInterface the interface to be used to determine
|
|
50 |
the MBean's management interface.
|
|
51 |
|
|
52 |
@param <T> a type parameter that allows the compiler to check
|
|
53 |
that {@code resource} implements {@code mbeanInterface},
|
|
54 |
provided that {@code mbeanInterface} is a class constant like
|
|
55 |
{@code SomeMBean.class}.
|
|
56 |
|
|
57 |
@throws IllegalArgumentException if {@code resource} is null or
|
|
58 |
if it does not implement the class {@code mbeanInterface} or if
|
|
59 |
that class is not a valid Standard MBean interface.
|
|
60 |
*/
|
|
61 |
public <T> StandardMBeanSupport(T resource, Class<T> mbeanInterface)
|
|
62 |
throws NotCompliantMBeanException {
|
687
|
63 |
super(resource, mbeanInterface, (MXBeanMappingFactory) null);
|
2
|
64 |
}
|
|
65 |
|
|
66 |
@Override
|
687
|
67 |
MBeanIntrospector<Method> getMBeanIntrospector(MXBeanMappingFactory ignored) {
|
2
|
68 |
return StandardMBeanIntrospector.getInstance();
|
|
69 |
}
|
|
70 |
|
|
71 |
@Override
|
|
72 |
Object getCookie() {
|
|
73 |
return null;
|
|
74 |
}
|
|
75 |
|
|
76 |
@Override
|
|
77 |
public void register(MBeanServer mbs, ObjectName name) {}
|
|
78 |
|
|
79 |
@Override
|
|
80 |
public void unregister() {}
|
|
81 |
|
|
82 |
/* Standard MBeans that are NotificationBroadcasters can return a different
|
|
83 |
* MBeanNotificationInfo[] every time getMBeanInfo() is called, so we have
|
|
84 |
* to reconstruct this MBeanInfo if necessary.
|
|
85 |
*/
|
|
86 |
@Override
|
|
87 |
public MBeanInfo getMBeanInfo() {
|
|
88 |
MBeanInfo mbi = super.getMBeanInfo();
|
|
89 |
Class<?> resourceClass = getResource().getClass();
|
|
90 |
if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass))
|
|
91 |
return mbi;
|
|
92 |
return new MBeanInfo(mbi.getClassName(), mbi.getDescription(),
|
|
93 |
mbi.getAttributes(), mbi.getConstructors(),
|
|
94 |
mbi.getOperations(),
|
|
95 |
MBeanIntrospector.findNotifications(getResource()),
|
|
96 |
mbi.getDescriptor());
|
|
97 |
}
|
|
98 |
}
|