KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > modeler > mbeans > MBeanProxy


1 package org.apache.commons.modeler.mbeans;
2
3 import java.util.HashMap JavaDoc;
4
5 import javax.management.Attribute JavaDoc;
6 import javax.management.AttributeNotFoundException JavaDoc;
7 import javax.management.MBeanException JavaDoc;
8 import javax.management.ReflectionException JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.apache.commons.modeler.BaseModelMBean;
13
14 /** Use the same metadata, except that we replace the attribute
15  * get/set methods.
16  */

17 class MBeanProxy extends BaseModelMBean {
18     private static Log log = LogFactory.getLog(MBeanProxy.class);
19
20     HashMap JavaDoc atts=new HashMap JavaDoc();
21
22     SimpleRemoteConnector jkmx;
23
24     public MBeanProxy(SimpleRemoteConnector jkmx, String JavaDoc code) throws Exception JavaDoc {
25         this.jkmx=jkmx;
26         initModelInfo(code);
27     }
28
29     /** Called by the connector - will update the value when a chunk of
30      * data is received
31      */

32     protected void update( String JavaDoc name, String JavaDoc val ) {
33         if( log.isTraceEnabled() )
34             log.trace( "Updating " + oname + " " + name + " " + val);
35         // XXX Conversions !!!
36
atts.put( name, val);
37     }
38
39     public Object JavaDoc getAttribute(String JavaDoc name)
40         throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc,
41             ReflectionException JavaDoc
42     {
43         // If we're stale - refresh values
44
jkmx.refresh();
45         return atts.get(name);
46     }
47
48     public void setAttribute(Attribute JavaDoc attribute)
49         throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc,
50         ReflectionException JavaDoc
51     {
52         try {
53             jkmx.setAttribute(oname, attribute);
54         } catch( Exception JavaDoc ex ) {
55             throw new MBeanException JavaDoc(ex);
56         }
57     }
58
59     public Object JavaDoc invoke(String JavaDoc name, Object JavaDoc params[], String JavaDoc signature[])
60         throws MBeanException JavaDoc, ReflectionException JavaDoc
61     {
62         try {
63             jkmx.invoke(oname, name, params, signature);
64         } catch( Exception JavaDoc ex ) {
65             throw new MBeanException JavaDoc(ex);
66         }
67         return null;
68     }
69 }
70
Popular Tags