View Javadoc

1   package org.apache.commons.modeler.mbeans;
2   
3   import java.util.HashMap;
4   
5   import javax.management.Attribute;
6   import javax.management.AttributeNotFoundException;
7   import javax.management.MBeanException;
8   import javax.management.ReflectionException;
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 atts=new HashMap();
21  
22      SimpleRemoteConnector jkmx;
23  
24      public MBeanProxy(SimpleRemoteConnector jkmx, String code) throws Exception {
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 name, String 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 getAttribute(String name)
40          throws AttributeNotFoundException, MBeanException,
41              ReflectionException
42      {
43          // If we're stale - refresh values
44          jkmx.refresh();
45          return atts.get(name);
46      }
47  
48      public void setAttribute(Attribute attribute)
49          throws AttributeNotFoundException, MBeanException,
50          ReflectionException
51      {
52          try {
53              jkmx.setAttribute(oname, attribute);
54          } catch( Exception ex ) {
55              throw new MBeanException(ex);
56          }
57      }
58  
59      public Object invoke(String name, Object params[], String signature[])
60          throws MBeanException, ReflectionException
61      {
62          try {
63              jkmx.invoke(oname, name, params, signature);
64          } catch( Exception ex ) {
65              throw new MBeanException(ex);
66          }
67          return null;
68      }
69  }