1 /*
2 * Copyright (C) The Spice Group. All rights reserved.
3 *
4 * This software is published under the terms of the Spice
5 * Software License version 1.1, a copy of which has been included
6 * with this distribution in the LICENSE.txt file.
7 */
8 package org.realityforge.metaclass.jmx;
9
10 import javax.management.modelmbean.RequiredModelMBean;
11 import javax.management.modelmbean.ModelMBeanInfo;
12 import javax.management.modelmbean.InvalidTargetObjectTypeException;
13 import javax.management.MBeanException;
14 import javax.management.RuntimeOperationsException;
15 import javax.management.ObjectName;
16 import javax.management.MBeanServer;
17 import javax.management.InstanceNotFoundException;
18 import javax.management.MBeanRegistration;
19 import javax.management.JMException;
20
21 /***
22 * A extension of RequiredModelMBean that propogates MBeanRegistration
23 * events to managed object.
24 *
25 * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
26 * @version $Revision: 1.4 $ $Date: 2003/10/14 01:27:28 $
27 */
28 public class WrapperModelMBean
29 extends RequiredModelMBean
30 implements MBeanRegistration
31 {
32 /***
33 * Constant for managed resource type.
34 */
35 private static final String OBJECT_REFERNECE_RESOURCE_TYPE = "ObjectReference";
36
37 /***
38 * The managed resource.
39 */
40 private Object m_resource;
41
42 /***
43 * Create the MBean.
44 *
45 * @param info the ModelMBeanInfo object.
46 * @param managedResource the managed resource
47 * @throws JMException if error creating MBean
48 * @throws InvalidTargetObjectTypeException if thrown from setManagedResource
49 */
50 public WrapperModelMBean( final ModelMBeanInfo info,
51 final Object managedResource )
52 throws JMException, InvalidTargetObjectTypeException
53 {
54 super( info );
55 setManagedResource( managedResource, OBJECT_REFERNECE_RESOURCE_TYPE );
56 }
57
58 /***
59 * @see MBeanRegistration#preRegister(MBeanServer, ObjectName)
60 */
61 public ObjectName preRegister( final MBeanServer server,
62 final ObjectName name )
63 throws Exception
64 {
65 final ObjectName objectName = super.preRegister( server, name );
66 if( m_resource instanceof MBeanRegistration )
67 {
68 return ( (MBeanRegistration)m_resource ).preRegister( server, name );
69 }
70 else
71 {
72 return objectName;
73 }
74 }
75
76 /***
77 * @see MBeanRegistration#postRegister(Boolean)
78 */
79 public void postRegister( final Boolean registrationDone )
80 {
81 super.postRegister( registrationDone );
82 if( m_resource instanceof MBeanRegistration )
83 {
84 ( (MBeanRegistration)m_resource ).postRegister( registrationDone );
85 }
86 }
87
88 /***
89 * @see MBeanRegistration#preDeregister()
90 */
91 public void preDeregister()
92 throws Exception
93 {
94 super.preDeregister();
95 if( m_resource instanceof MBeanRegistration )
96 {
97 ( (MBeanRegistration)m_resource ).preDeregister();
98 }
99 }
100
101 /***
102 * @see MBeanRegistration#postDeregister()
103 */
104 public void postDeregister()
105 {
106 super.postDeregister();
107 if( m_resource instanceof MBeanRegistration )
108 {
109 ( (MBeanRegistration)m_resource ).postDeregister();
110 }
111 }
112
113 /***
114 * Overloaded setManagedResource that caches the resource.
115 * @see RequiredModelMBean#setManagedResource(Object,String)
116 */
117 public void setManagedResource( final Object resource,
118 final String resourceType )
119 throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException
120 {
121 super.setManagedResource( resource, resourceType );
122 m_resource = resource;
123 }
124 }
This page was automatically generated by Maven