1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.modeler.mbeans;
18
19 import java.util.HashMap;
20
21 import javax.management.Attribute;
22 import javax.management.AttributeNotFoundException;
23 import javax.management.MBeanException;
24 import javax.management.ReflectionException;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.commons.modeler.BaseModelMBean;
29
30 /*** Use the same metadata, except that we replace the attribute
31 * get/set methods.
32 */
33 class MBeanProxy extends BaseModelMBean {
34 private static Log log = LogFactory.getLog(MBeanProxy.class);
35
36 HashMap atts=new HashMap();
37
38 SimpleRemoteConnector jkmx;
39
40 public MBeanProxy(SimpleRemoteConnector jkmx, String code) throws Exception {
41 this.jkmx=jkmx;
42 initModelInfo(code);
43 }
44
45 /*** Called by the connector - will update the value when a chunk of
46 * data is received
47 */
48 protected void update( String name, String val ) {
49 if( log.isTraceEnabled() )
50 log.trace( "Updating " + oname + " " + name + " " + val);
51
52 atts.put( name, val);
53 }
54
55 public Object getAttribute(String name)
56 throws AttributeNotFoundException, MBeanException,
57 ReflectionException
58 {
59
60 jkmx.refresh();
61 return atts.get(name);
62 }
63
64 public void setAttribute(Attribute attribute)
65 throws AttributeNotFoundException, MBeanException,
66 ReflectionException
67 {
68 try {
69 jkmx.setAttribute(oname, attribute);
70 } catch( Exception ex ) {
71 throw new MBeanException(ex);
72 }
73 }
74
75 public Object invoke(String name, Object params[], String signature[])
76 throws MBeanException, ReflectionException
77 {
78 try {
79 jkmx.invoke(oname, name, params, signature);
80 } catch( Exception ex ) {
81 throw new MBeanException(ex);
82 }
83 return null;
84 }
85 }