1 23 24 109 110 package com.sun.enterprise.admin.runtime; 111 112 import java.text.CharacterIterator ; 113 import java.text.StringCharacterIterator ; 114 import java.lang.reflect.Method ; 115 import java.util.Iterator ; 116 import java.util.ArrayList ; 117 import java.util.logging.Level ; 118 import java.util.logging.Logger ; 119 120 import javax.management.*; 122 import javax.management.Descriptor ; 123 import javax.management.modelmbean.ModelMBeanInfo ; 124 import javax.management.modelmbean.ModelMBeanOperationInfo ; 125 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 126 127 129 import com.sun.enterprise.admin.MBeanHelper; 130 import com.sun.enterprise.admin.meta.MBeanMetaConstants; 131 132 134 public class ManagedJsr77MdlBean { 135 136 DynamicMBean m_mbean = null; 137 Object m_baseJsr77Bean = null; 138 139 public ManagedJsr77MdlBean(DynamicMBean mbean, Object cb) 140 { 141 m_baseJsr77Bean = cb; 142 m_mbean = mbean; 143 } 144 151 public Object getAttribute(ModelMBeanAttributeInfo attrInfo, String attrName) throws MBeanException,AttributeNotFoundException { 152 Descriptor descr = attrInfo.getDescriptor(); 153 String getter = (String )descr.getFieldValue(MBeanMetaConstants.GETTER_FIELD_NAME); 154 if(getter==null) 155 throw new MBeanException(new MBeanRuntimeException("ManagedJsr77MdlBean:getAttribute:No getter found in descriptor")); 156 try 157 { 158 Method method = m_baseJsr77Bean.getClass().getMethod(getter); 159 return method.invoke(m_baseJsr77Bean); 160 } 161 catch (Exception e) 162 { 163 throw MBeanHelper.extractAndWrapTargetException(e, 165 "Exception invoking getter method in runtime bean " + getter); 166 } 167 } 168 174 public void setAttribute(ModelMBeanAttributeInfo attrInfo, Attribute attr) throws MBeanException,AttributeNotFoundException { 175 Descriptor descr = attrInfo.getDescriptor(); 176 String setter = (String )descr.getFieldValue(MBeanMetaConstants.SETTER_FIELD_NAME); 177 if(setter==null) 178 throw new MBeanException(new MBeanRuntimeException("ManagedJsr77MdlBean:getAttribute:No setter found in descriptor")); 179 try 180 { 181 Method method = m_baseJsr77Bean.getClass().getMethod(setter, new Class []{getClassForName(attrInfo.getType())}); 182 method.invoke(m_baseJsr77Bean, new Object []{attr.getValue()}); 183 } 184 catch (Exception e) 185 { 186 throw MBeanHelper.extractAndWrapTargetException(e, 189 "Exception invoking setter method in runtime bean " + setter); 190 } 191 } 192 193 public Object invokeOperation(ModelMBeanOperationInfo opInfo, Object params[], String signature[]) throws MBeanException, ReflectionException 194 { 195 String name = opInfo.getName(); 196 try 197 { 198 Object ret = MBeanHelper.invokeOperationInBean(opInfo, this, params); 199 if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT) 200 { 201 return ret; 202 } 203 } 204 catch (Exception e) 205 { 206 throw MBeanHelper.extractAndWrapTargetException(e, 208 "Exception invoking method in runtime bean " + name); 209 } 210 211 try 212 { 213 return MBeanHelper.invokeOperationInBean(opInfo, m_baseJsr77Bean, params); 214 } 216 catch (Exception e) 217 { 218 throw MBeanHelper.extractAndWrapTargetException(e, 220 "Exception invoking method in runtime bean " + name); 221 } 222 } 223 private Class getClassForName(String type) throws ClassNotFoundException 224 { 225 if(type.equals("int")) 226 return Integer.TYPE; 227 if(type.equals("long")) 228 return Long.TYPE; 229 if(type.equals("boolean")) 230 return Boolean.TYPE; 231 return Class.forName(type); 232 } 233 } 234 235 | Popular Tags |