1 23 24 126 127 package com.sun.enterprise.admin.runtime; 128 129 import java.lang.reflect.InvocationTargetException ; 130 import java.util.Iterator ; 131 import java.util.Hashtable ; 132 import java.util.ArrayList ; 133 134 import javax.management.ObjectName ; 135 136 138 import javax.management.modelmbean.DescriptorSupport ; 139 import javax.management.Descriptor ; 142 import javax.management.modelmbean.ModelMBeanInfo ; 143 import javax.management.modelmbean.ModelMBeanOperationInfo ; 144 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 145 import javax.management.*; 146 147 import com.sun.org.apache.commons.modeler.BaseModelMBean; 148 import com.sun.enterprise.admin.BaseAdminMBean; 150 import com.sun.enterprise.admin.MBeanHelper; 151 152 import com.sun.enterprise.admin.config.ManagedConfigBean; 153 import com.sun.enterprise.admin.config.ConfigMBeanHelper; 154 import com.sun.enterprise.admin.config.MBeanConfigException; 155 156 import com.sun.enterprise.config.ConfigException; 158 import com.sun.enterprise.config.serverbeans.ServerTags; 160 import com.sun.enterprise.config.ConfigContext; 161 import com.sun.enterprise.config.ConfigFactory; 162 import com.sun.enterprise.config.ConfigBean; 163 import com.sun.enterprise.config.ConfigBeansFactory; 164 import com.sun.enterprise.config.serverbeans.ElementProperty; 165 166 import com.sun.enterprise.admin.meta.naming.MBeanNamingInfo; 168 import com.sun.enterprise.admin.meta.MBeanMetaConstants; 169 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 170 import com.sun.enterprise.admin.meta.MBeanRegistry; 171 172 174 180 181 public class BaseRuntimeMBean extends BaseAdminMBean implements MBeanRegistration 182 { 183 184 private ManagedConfigBean mcb = null; 186 private ManagedJsr77MdlBean mrb = null; 187 protected MBeanRegistry m_registry = null; 188 189 190 200 public BaseRuntimeMBean() { 201 202 super(); 203 m_registry = MBeanRegistryFactory.getRuntimeMBeanRegistry(); 204 } 205 206 207 225 public void setManagedResource(Object resource, String type) 226 throws InstanceNotFoundException, 227 MBeanException, RuntimeOperationsException { 228 229 if (resource == null) 230 throw new RuntimeOperationsException 231 (new IllegalArgumentException ("Managed resource is null"), 232 "Managed resource is null"); 233 234 if (MBeanMetaConstants.CONFIG_BEAN_REF.equalsIgnoreCase(type)) { 235 if(! (resource instanceof ConfigBean)) { 236 throw new RuntimeOperationsException 237 (new ClassCastException ("Managed resource is not a ConfigBean"), 238 "Managed resource is not a ConfigBean"); 239 } 240 this.mcb = new ManagedConfigBean(this, (ConfigBean) resource, m_registry); 241 242 } else { 243 if (MBeanMetaConstants.JSR77_MODEL_BEAN_REF.equalsIgnoreCase(type)) 244 { 245 251 this.mrb = new ManagedJsr77MdlBean(this, resource); 252 } else 253 { 254 super.setManagedResource(resource, type); 255 } 256 } 257 } 258 259 260 261 262 263 265 266 278 public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException 279 { 280 ModelMBeanAttributeInfo attrInfo = (ModelMBeanAttributeInfo )MBeanHelper.findMatchingAttributeInfo((MBeanInfo )info, name); 281 if(attrInfo==null) 282 throw new AttributeNotFoundException(); 283 try 286 { 287 return super.getAttribute(name); 288 } catch (Exception e) {} 289 290 if(mrb!=null) 292 { 293 try { 294 return mrb.getAttribute(attrInfo, name); 295 } catch (Exception e) {} 296 } 297 298 if(mcb!=null) 300 { 301 try { 302 return mcb.getAttribute(attrInfo, name); 303 } catch (Exception e) {} 304 } 305 throw new AttributeNotFoundException(); } 307 308 public AttributeList getAttributes(String [] attributeNames) 309 { 310 AttributeList list = new AttributeList(); 311 if(attributeNames!=null) 312 for(int i=0; i<attributeNames.length; i++) 313 { 314 try { 315 Object value = getAttribute(attributeNames[i]); 316 list.add(new Attribute(attributeNames[i], value)); 317 } catch (Exception e) {} 318 } 319 return list; 320 } 321 322 335 public void setAttribute(Attribute attribute) 336 throws AttributeNotFoundException, MBeanException, 337 ReflectionException 338 { 339 ModelMBeanAttributeInfo attrInfo = (ModelMBeanAttributeInfo )MBeanHelper.findMatchingAttributeInfo((MBeanInfo )info, attribute.getName()); 340 if(attrInfo==null) 341 throw new AttributeNotFoundException(); 342 344 try 346 { 347 super.setAttribute(attribute); 348 return; 349 } catch (Exception e) {} 350 351 if(mrb!=null) 353 { 354 try { 355 mrb.setAttribute(attrInfo, attribute); 356 return; 357 } catch (Exception e) {} 358 } 359 360 if(mcb!=null) 362 { 363 try { 364 mcb.setAttribute(attrInfo, attribute); 365 return; 366 } catch (Exception e) {} 367 } 368 369 } 370 371 376 public AttributeList setAttributes(AttributeList list) 377 { 378 if(list==null || list.size()<=0) 379 return null; 380 AttributeList listRes = new AttributeList(); 381 for(int i=0; i<list.size(); i++) 382 { 383 try { 384 Attribute attr = (Attribute)list.get(i); 385 setAttribute(attr); 386 listRes.add(attr); 387 } catch (Exception e) {} 388 } 389 return listRes; 390 } 391 392 393 412 public Object invoke(String name, Object params[], String signature[]) 413 throws MBeanException, ReflectionException { 414 ModelMBeanOperationInfo opInfo = (ModelMBeanOperationInfo )MBeanHelper.findMatchingOperationInfo((MBeanInfo )info, name, signature); 415 if (opInfo == null) 416 { 417 String msg = _localStrings.getString( "admin.server.core.mbean.config.base.operation_is_not_found", mbeanType, name); 418 throw new MBeanException 419 (new ServiceNotFoundException(msg), msg); 420 } 421 422 Object ret; 424 try 425 { 426 ret = MBeanHelper.invokeOperationInBean(opInfo, this, params); 427 if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT) 428 return ret; 429 430 if(mrb!=null) 431 { 432 ret = mrb.invokeOperation(opInfo, params, signature); 433 if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT) 434 return ret; 435 } 436 437 if(mcb!=null) 438 { 439 ret = mcb.invokeOperation(opInfo, params, signature); 440 if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT) 441 return ret; 442 } 443 444 } 445 catch (MBeanException mbe) 446 { 447 throw mbe; 448 } 449 catch (Exception e) 450 { 451 String msg = _localStrings.getString( "admin.server.core.mbean.runtime.base.invoke_error", mbeanType, name); 452 throw MBeanHelper.extractAndWrapTargetException(e, msg); 453 } 454 455 return super.invoke(name, params, signature); 458 } 459 460 protected ObjectName createChildElementByType(String childElementName, Attribute[] attrs) throws Exception 462 { 463 return createChildElementByType(childElementName, attrs, true, false); 464 } 465 protected ObjectName createChildElementByType(String childElementName, Attribute[] attrs, boolean bSkipNullValued) throws Exception 466 { 467 return createChildElementByType(childElementName, attrs, bSkipNullValued, false); 468 } 469 protected ObjectName createChildElementByType(String childElementName, Attribute[] attrs, boolean bSkipNullValued, boolean bOnlyOne) throws Exception 470 { 471 AttributeList list = new AttributeList(); 472 for(int i=0; i<attrs.length; i++) 473 { 474 if(!bSkipNullValued || attrs[i].getValue()!=null) 475 list.add(attrs[i]); 476 } 477 ConfigBean bean = mcb.createChildByType(childElementName, list, null, bOnlyOne); 478 return ConfigMBeanHelper.getChildObjectName(m_registry, info, bean); 479 } 480 481 482 486 public ObjectName preRegister(MBeanServer server, 487 ObjectName name) 488 throws Exception 489 { 490 return name; 491 } 492 493 public void postRegister(Boolean registrationDone) { 494 } 495 496 public void preDeregister() throws Exception { 497 } 498 499 public void postDeregister() { 500 } 501 502 529 } 530 | Popular Tags |