KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jmx > access > MBeanProxyFactoryBean


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jmx.access;
18
19 import org.springframework.aop.framework.ProxyFactory;
20 import org.springframework.beans.factory.BeanClassLoaderAware;
21 import org.springframework.beans.factory.FactoryBean;
22 import org.springframework.beans.factory.InitializingBean;
23 import org.springframework.jmx.MBeanServerNotFoundException;
24 import org.springframework.util.ClassUtils;
25
26 /**
27  * Creates a proxy to a managed resource running either locally or remotely.
28  * The "proxyInterface" property defines the interface that the generated
29  * proxy is supposed to implement. This interface should define methods and
30  * properties that correspond to operations and attributes in the management
31  * interface of the resource you wish to proxy.
32  *
33  * <p>There is no need for the managed resource to implement the proxy interface,
34  * although you may find it convenient to do. It is not required that every
35  * operation and attribute in the management interface is matched by a
36  * corresponding property or method in the proxy interface.
37  *
38  * <p>Attempting to invoke or access any method or property on the proxy
39  * interface that does not correspond to the management interface will lead
40  * to an <code>InvalidInvocationException</code>.
41  *
42  * <p>Requires JMX 1.2's <code>MBeanServerConnection</code> feature.
43  * As a consequence, this class will not work on JMX 1.0.
44  *
45  * @author Rob Harrop
46  * @author Juergen Hoeller
47  * @since 1.2
48  * @see MBeanClientInterceptor
49  * @see InvalidInvocationException
50  */

51 public class MBeanProxyFactoryBean extends MBeanClientInterceptor
52         implements FactoryBean, BeanClassLoaderAware, InitializingBean {
53
54     private Class JavaDoc proxyInterface;
55
56     private ClassLoader JavaDoc beanClassLoader = ClassUtils.getDefaultClassLoader();
57
58     private Object JavaDoc mbeanProxy;
59
60
61     /**
62      * Set the interface that the generated proxy will implement.
63      * <p>This will usually be a management interface that matches the target MBean,
64      * exposing bean property setters and getters for MBean attributes and
65      * conventional Java methods for MBean operations.
66      * @see #setObjectName
67      */

68     public void setProxyInterface(Class JavaDoc managementInterface) {
69         this.proxyInterface = managementInterface;
70     }
71
72     public void setBeanClassLoader(ClassLoader JavaDoc classLoader) {
73         this.beanClassLoader = classLoader;
74     }
75
76     /**
77      * Checks that the <code>proxyInterface</code> has been specified and then
78      * generates the proxy for the target MBean.
79      */

80     public void afterPropertiesSet() throws MBeanServerNotFoundException, MBeanInfoRetrievalException {
81         super.afterPropertiesSet();
82
83         if (this.proxyInterface == null) {
84             throw new IllegalArgumentException JavaDoc("Property 'proxyInterface' is required");
85         }
86         this.mbeanProxy = new ProxyFactory(this.proxyInterface, this).getProxy(this.beanClassLoader);
87     }
88
89
90     public Object JavaDoc getObject() {
91         return this.mbeanProxy;
92     }
93
94     public Class JavaDoc getObjectType() {
95         return this.proxyInterface;
96     }
97
98     public boolean isSingleton() {
99         return true;
100     }
101
102 }
103
Popular Tags