1 /*2 * @(#)StandardMBeanSupport.java 1.7 05/11/173 * 4 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.5 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.6 */7 8 package com.sun.jmx.mbeanserver;9 10 import static com.sun.jmx.mbeanserver.Util.*;11 import java.lang.annotation.Annotation ;12 import java.lang.reflect.Constructor ;13 import java.lang.reflect.GenericArrayType ;14 import java.lang.reflect.InvocationTargetException ;15 import java.lang.reflect.Method ;16 import java.lang.reflect.Type ;17 import java.util.Arrays ;18 import java.util.Collections ;19 import java.util.Iterator ;20 import java.util.List ;21 import java.util.Map ;22 import java.util.Set ;23 import java.util.WeakHashMap ;24 import javax.management.Attribute ;25 import javax.management.AttributeList ;26 import javax.management.AttributeNotFoundException ;27 import javax.management.Descriptor ;28 import javax.management.DynamicMBean ;29 import javax.management.ImmutableDescriptor ;30 import javax.management.InstanceAlreadyExistsException ;31 import javax.management.IntrospectionException ;32 import javax.management.InvalidAttributeValueException ;33 import javax.management.JMX ;34 import javax.management.MBeanAttributeInfo ;35 import javax.management.MBeanConstructorInfo ;36 import javax.management.MBeanException ;37 import javax.management.MBeanInfo ;38 import javax.management.MBeanNotificationInfo ;39 import javax.management.MBeanOperationInfo ;40 import javax.management.MBeanParameterInfo ;41 import javax.management.MBeanRegistration ;42 import javax.management.MBeanServer ;43 import javax.management.NotCompliantMBeanException ;44 import javax.management.NotificationBroadcaster ;45 import javax.management.NotificationBroadcasterSupport ;46 import javax.management.ObjectName ;47 import javax.management.ReflectionException ;48 import javax.management.openmbean.OpenMBeanAttributeInfoSupport ;49 import javax.management.openmbean.OpenMBeanOperationInfoSupport ;50 import javax.management.openmbean.OpenMBeanParameterInfo ;51 import javax.management.openmbean.OpenMBeanParameterInfoSupport ;52 import javax.management.openmbean.OpenType ;53 54 /**55 * Base class for Standard MBeans.56 *57 * @since 1.658 */59 public class StandardMBeanSupport extends MBeanSupport<Method > {60 61 /**62 <p>Construct a Standard MBean that wraps the given resource using the63 given Standard MBean interface.</p>64 65 @param resource the underlying resource for the new MBean.66 67 @param mbeanInterface the interface to be used to determine68 the MBean's management interface.69 70 @param <T> a type parameter that allows the compiler to check71 that {@code resource} implements {@code mbeanInterface},72 provided that {@code mbeanInterface} is a class constant like73 {@code SomeMBean.class}.74 75 @throws IllegalArgumentException if {@code resource} is null or76 if it does not implement the class {@code mbeanInterface} or if77 that class is not a valid Standard MBean interface.78 */79 public <T> StandardMBeanSupport(T resource, Class <T> mbeanInterface)80 throws NotCompliantMBeanException {81 super(resource, mbeanInterface);82 }83 84 @Override 85 MBeanIntrospector<Method > getMBeanIntrospector() {86 return StandardMBeanIntrospector.getInstance();87 }88 89 @Override 90 Object getCookie() {91 return null;92 }93 94 @Override 95 public void register(MBeanServer mbs, ObjectName name) {}96 97 @Override 98 public void unregister() {}99 100 /* Standard MBeans that are NotificationBroadcasters can return a different101 * MBeanNotificationInfo[] every time getMBeanInfo() is called, so we have102 * to reconstruct this MBeanInfo if necessary.103 */104 @Override 105 public MBeanInfo getMBeanInfo() {106 MBeanInfo mbi = super.getMBeanInfo();107 Class <?> resourceClass = getResource().getClass();108 if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass))109 return mbi;110 return new MBeanInfo (mbi.getClassName(), mbi.getDescription(),111 mbi.getAttributes(), mbi.getConstructors(),112 mbi.getOperations(),113 MBeanIntrospector.findNotifications(getResource()),114 mbi.getDescriptor());115 }116 }117