1 22 package org.jboss.mx.modelmbean; 23 24 import javax.management.Attribute ; 25 import javax.management.AttributeList ; 26 import javax.management.AttributeNotFoundException ; 27 import javax.management.DynamicMBean ; 28 import javax.management.InvalidAttributeValueException ; 29 import javax.management.MBeanException ; 30 import javax.management.ReflectionException ; 31 import javax.management.RuntimeMBeanException ; 32 import javax.management.RuntimeOperationsException ; 33 import javax.management.ServiceNotFoundException ; 34 import javax.management.modelmbean.RequiredModelMBean ; 35 36 import org.jboss.mx.server.RawDynamicInvoker; 37 38 44 public class RequiredModelMBeanInvoker extends RawDynamicInvoker 45 { 46 RequiredModelMBean mbean; 47 48 public RequiredModelMBeanInvoker(DynamicMBean resource) 49 { 50 super(resource); 51 mbean = (RequiredModelMBean ) resource; 52 } 53 54 public Object getAttribute(String name) throws AttributeNotFoundException , MBeanException , ReflectionException 55 { 56 try 57 { 58 return super.getAttribute(name); 59 } 60 catch (ReflectionException e) 61 { 62 Exception ex = e.getTargetException(); 64 if ((ex instanceof ClassNotFoundException ) == false && 65 (ex instanceof NoSuchMethodException ) == false) 66 { 67 log.debug("Rewrapping reflection exception: ", e); 68 throw new MBeanException (new ServiceNotFoundException (ex.getMessage()), e.getMessage()); 69 } 70 else 71 throw e; 72 } 73 } 74 75 public void setAttribute(Attribute attribute) 76 throws AttributeNotFoundException , InvalidAttributeValueException , MBeanException , ReflectionException 77 { 78 if (attribute == null) 80 throw new RuntimeOperationsException (new IllegalArgumentException ("Null attribute")); 81 try 82 { 83 super.setAttribute(attribute); 84 } 85 catch (ReflectionException e) 86 { 87 Exception ex = e.getTargetException(); 89 if ((ex instanceof ClassNotFoundException ) == false && 90 (ex instanceof NoSuchMethodException ) == false) 91 { 92 log.debug("Rewrapping reflection exception: ", e); 93 throw new MBeanException (new ServiceNotFoundException (ex.getMessage()), e.getMessage()); 94 } 95 else 96 throw e; 97 } 98 } 99 100 public AttributeList getAttributes(String [] attributes) 101 { 102 if (attributes == null) 103 throw new RuntimeOperationsException (new IllegalArgumentException ("Null attributes")); 104 return super.getAttributes(attributes); 105 } 106 107 public AttributeList setAttributes(AttributeList attributes) 108 { 109 if (attributes == null) 110 throw new RuntimeOperationsException (new IllegalArgumentException ("Null attributes")); 111 return super.setAttributes(attributes); 112 } 113 114 public Object invoke(String name, Object [] args, String [] signature) throws 115 MBeanException , ReflectionException 116 { 117 Object value; 118 119 if (name == null) 120 throw new RuntimeOperationsException (new IllegalArgumentException ("Null operation")); 121 else if( name.equals("getNotificationInfo") ) 122 value = mbean.getNotificationInfo(); 123 else 124 { 125 try 126 { 127 value = super.invoke(name, args, signature); 128 } 129 catch (RuntimeMBeanException e) 130 { 131 throw new MBeanException (e.getTargetException(), e.getMessage()); 134 } 135 catch (ReflectionException e) 136 { 137 Exception ex = e.getTargetException(); 139 if ((ex instanceof ClassNotFoundException ) == false && 140 (ex instanceof NoSuchMethodException ) == false) 141 { 142 log.debug("Rewrapping reflection exception: ", e); 143 throw new MBeanException (new ServiceNotFoundException (ex.getMessage()), e.getMessage()); 144 } 145 else 146 throw e; 147 } 148 } 149 return value; 150 } 151 } 152 | Popular Tags |