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