1/* 2 * Copyright (c) 2005, 2008, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package com.sun.jmx.mbeanserver; 27 28import java.lang.reflect.Method; 29 30import javax.management.MBeanInfo; 31import javax.management.MBeanServer; 32import javax.management.NotCompliantMBeanException; 33import javax.management.ObjectName; 34 35/** 36 * Base class for Standard MBeans. 37 * 38 * @since 1.6 39 */ 40public class StandardMBeanSupport extends MBeanSupport<Method> { 41 42 /** 43 * <p>Construct a Standard MBean that wraps the given resource using the 44 * given Standard MBean interface.</p> 45 * 46 * @param resource the underlying resource for the new MBean. 47 * @param mbeanInterfaceType the class or interface to be used to determine 48 * the MBean's management interface. An interface if this is a 49 * classic Standard MBean; a class if this is a {@code @ManagedResource}. 50 * @param <T> a type parameter that allows the compiler to check 51 * that {@code resource} implements {@code mbeanInterfaceType}, 52 * provided that {@code mbeanInterfaceType} is a class constant like 53 * {@code SomeMBean.class}. 54 * @throws IllegalArgumentException if {@code resource} is null or 55 * if it does not implement the class {@code mbeanInterfaceType} or if 56 * that class is not a valid Standard MBean interface. 57 */ 58 public <T> StandardMBeanSupport(T resource, Class<T> mbeanInterfaceType) 59 throws NotCompliantMBeanException { 60 super(resource, mbeanInterfaceType); 61 } 62 63 @Override 64 MBeanIntrospector<Method> getMBeanIntrospector() { 65 return StandardMBeanIntrospector.getInstance(); 66 } 67 68 @Override 69 Object getCookie() { 70 return null; 71 } 72 73 @Override 74 public void register(MBeanServer mbs, ObjectName name) {} 75 76 @Override 77 public void unregister() {} 78 79 /* Standard MBeans that are NotificationBroadcasters can return a different 80 * MBeanNotificationInfo[] every time getMBeanInfo() is called, so we have 81 * to reconstruct this MBeanInfo if necessary. 82 */ 83 @Override 84 public MBeanInfo getMBeanInfo() { 85 MBeanInfo mbi = super.getMBeanInfo(); 86 Class<?> resourceClass = getResource().getClass(); 87 if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass)) 88 return mbi; 89 return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), 90 mbi.getAttributes(), mbi.getConstructors(), 91 mbi.getOperations(), 92 MBeanIntrospector.findNotifications(getResource()), 93 mbi.getDescriptor()); 94 } 95} 96