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