KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > mbeanserver > StandardMBeanSupport


1 /*
2  * @(#)StandardMBeanSupport.java 1.7 05/11/17
3  *
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 JavaDoc;
12 import java.lang.reflect.Constructor JavaDoc;
13 import java.lang.reflect.GenericArrayType JavaDoc;
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.lang.reflect.Method JavaDoc;
16 import java.lang.reflect.Type JavaDoc;
17 import java.util.Arrays JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23 import java.util.WeakHashMap JavaDoc;
24 import javax.management.Attribute JavaDoc;
25 import javax.management.AttributeList JavaDoc;
26 import javax.management.AttributeNotFoundException JavaDoc;
27 import javax.management.Descriptor JavaDoc;
28 import javax.management.DynamicMBean JavaDoc;
29 import javax.management.ImmutableDescriptor JavaDoc;
30 import javax.management.InstanceAlreadyExistsException JavaDoc;
31 import javax.management.IntrospectionException JavaDoc;
32 import javax.management.InvalidAttributeValueException JavaDoc;
33 import javax.management.JMX JavaDoc;
34 import javax.management.MBeanAttributeInfo JavaDoc;
35 import javax.management.MBeanConstructorInfo JavaDoc;
36 import javax.management.MBeanException JavaDoc;
37 import javax.management.MBeanInfo JavaDoc;
38 import javax.management.MBeanNotificationInfo JavaDoc;
39 import javax.management.MBeanOperationInfo JavaDoc;
40 import javax.management.MBeanParameterInfo JavaDoc;
41 import javax.management.MBeanRegistration JavaDoc;
42 import javax.management.MBeanServer JavaDoc;
43 import javax.management.NotCompliantMBeanException JavaDoc;
44 import javax.management.NotificationBroadcaster JavaDoc;
45 import javax.management.NotificationBroadcasterSupport JavaDoc;
46 import javax.management.ObjectName JavaDoc;
47 import javax.management.ReflectionException JavaDoc;
48 import javax.management.openmbean.OpenMBeanAttributeInfoSupport JavaDoc;
49 import javax.management.openmbean.OpenMBeanOperationInfoSupport JavaDoc;
50 import javax.management.openmbean.OpenMBeanParameterInfo JavaDoc;
51 import javax.management.openmbean.OpenMBeanParameterInfoSupport JavaDoc;
52 import javax.management.openmbean.OpenType JavaDoc;
53
54 /**
55  * Base class for Standard MBeans.
56  *
57  * @since 1.6
58  */

59 public class StandardMBeanSupport extends MBeanSupport<Method JavaDoc> {
60
61     /**
62        <p>Construct a Standard MBean that wraps the given resource using the
63        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 determine
68        the MBean's management interface.
69
70        @param <T> a type parameter that allows the compiler to check
71        that {@code resource} implements {@code mbeanInterface},
72        provided that {@code mbeanInterface} is a class constant like
73        {@code SomeMBean.class}.
74
75        @throws IllegalArgumentException if {@code resource} is null or
76        if it does not implement the class {@code mbeanInterface} or if
77        that class is not a valid Standard MBean interface.
78     */

79     public <T> StandardMBeanSupport(T resource, Class JavaDoc<T> mbeanInterface)
80             throws NotCompliantMBeanException JavaDoc {
81         super(resource, mbeanInterface);
82     }
83
84     @Override JavaDoc
85     MBeanIntrospector<Method JavaDoc> getMBeanIntrospector() {
86     return StandardMBeanIntrospector.getInstance();
87     }
88
89     @Override JavaDoc
90     Object JavaDoc getCookie() {
91     return null;
92     }
93     
94     @Override JavaDoc
95     public void register(MBeanServer JavaDoc mbs, ObjectName JavaDoc name) {}
96     
97     @Override JavaDoc
98     public void unregister() {}
99  
100     /* Standard MBeans that are NotificationBroadcasters can return a different
101      * MBeanNotificationInfo[] every time getMBeanInfo() is called, so we have
102      * to reconstruct this MBeanInfo if necessary.
103      */

104     @Override JavaDoc
105     public MBeanInfo JavaDoc getMBeanInfo() {
106         MBeanInfo JavaDoc mbi = super.getMBeanInfo();
107         Class JavaDoc<?> resourceClass = getResource().getClass();
108         if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass))
109             return mbi;
110         return new MBeanInfo JavaDoc(mbi.getClassName(), mbi.getDescription(),
111                 mbi.getAttributes(), mbi.getConstructors(),
112                 mbi.getOperations(),
113                 MBeanIntrospector.findNotifications(getResource()),
114                 mbi.getDescriptor());
115     }
116 }
117
Popular Tags