1 24 25 26 27 package javax.management.modelmbean; 28 29 import java.io.IOException ; 30 import java.io.ObjectInputStream ; 31 import java.io.ObjectOutputStream ; 32 import java.io.ObjectStreamField ; 33 import java.io.Serializable ; 34 import java.security.AccessController ; 35 import java.security.PrivilegedAction ; 36 37 import javax.management.Descriptor ; 38 import javax.management.DescriptorAccess ; 39 import javax.management.MBeanAttributeInfo ; 40 import javax.management.MBeanConstructorInfo ; 41 import javax.management.MBeanException ; 42 import javax.management.MBeanInfo ; 43 import javax.management.MBeanNotificationInfo ; 44 import javax.management.MBeanOperationInfo ; 45 import javax.management.RuntimeOperationsException ; 46 47 import com.sun.jmx.mbeanserver.GetPropertyAction; 48 import com.sun.jmx.trace.Trace; 49 50 72 public class ModelMBeanInfoSupport extends MBeanInfo 73 implements ModelMBeanInfo , java.io.Serializable 74 { 75 76 private static final long oldSerialVersionUID = -3944083498453227709L; 84 private static final long newSerialVersionUID = -1935722590756516193L; 87 private static final ObjectStreamField [] oldSerialPersistentFields = 90 { 91 new ObjectStreamField ("modelMBeanDescriptor", Descriptor .class), 92 new ObjectStreamField ("mmbAttributes", MBeanAttributeInfo [].class), 93 new ObjectStreamField ("mmbConstructors", MBeanConstructorInfo [].class), 94 new ObjectStreamField ("mmbNotifications", MBeanNotificationInfo [].class), 95 new ObjectStreamField ("mmbOperations", MBeanOperationInfo [].class), 96 new ObjectStreamField ("currClass", String .class) 97 }; 98 private static final ObjectStreamField [] newSerialPersistentFields = 101 { 102 new ObjectStreamField ("modelMBeanDescriptor", Descriptor .class), 103 new ObjectStreamField ("modelMBeanAttributes", MBeanAttributeInfo [].class), 104 new ObjectStreamField ("modelMBeanConstructors", MBeanConstructorInfo [].class), 105 new ObjectStreamField ("modelMBeanNotifications", MBeanNotificationInfo [].class), 106 new ObjectStreamField ("modelMBeanOperations", MBeanOperationInfo [].class) 107 }; 108 private static final long serialVersionUID; 111 122 private static final ObjectStreamField [] serialPersistentFields; 123 private static boolean compat = false; 124 static { 125 try { 126 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 127 String form = (String ) AccessController.doPrivileged(act); 128 compat = (form != null && form.equals("1.0")); 129 } catch (Exception e) { 130 } 132 if (compat) { 133 serialPersistentFields = oldSerialPersistentFields; 134 serialVersionUID = oldSerialVersionUID; 135 } else { 136 serialPersistentFields = newSerialPersistentFields; 137 serialVersionUID = newSerialVersionUID; 138 } 139 } 140 143 146 private Descriptor modelMBeanDescriptor = null; 147 148 155 156 160 private MBeanAttributeInfo [] modelMBeanAttributes; 161 162 166 private MBeanConstructorInfo [] modelMBeanConstructors; 167 168 172 private MBeanNotificationInfo [] modelMBeanNotifications; 173 174 178 private MBeanOperationInfo [] modelMBeanOperations; 179 180 private static final String ATTR = "attribute"; 181 private static final String OPER = "operation"; 182 private static final String NOTF = "notification"; 183 private static final String CONS = "constructor"; 184 private static final String MMB = "mbean"; 185 private static final String ALL = "all"; 186 private static final String currClass = "ModelMBeanInfoSupport"; 187 188 195 public ModelMBeanInfoSupport(ModelMBeanInfo mbi) 196 { 197 super(mbi.getClassName(), 198 mbi.getDescription(), 199 mbi.getAttributes(), 200 mbi.getConstructors(), 201 mbi.getOperations(), 202 mbi.getNotifications()); 203 204 modelMBeanAttributes = mbi.getAttributes(); 205 modelMBeanConstructors = mbi.getConstructors(); 206 modelMBeanOperations = mbi.getOperations(); 207 modelMBeanNotifications = mbi.getNotifications(); 208 209 try 210 { 211 Descriptor mbeandescriptor = mbi.getMBeanDescriptor(); 212 213 if ((mbeandescriptor != null) && isValidDescriptor(mbeandescriptor)) 214 { 215 if (tracing()) trace("ModelMBeanInfo(ModelMBeanInfo)","ModelMBeanDescriptor is valid, cloning Descriptor *" + mbeandescriptor.toString() + "*"); 216 modelMBeanDescriptor = (Descriptor ) mbeandescriptor.clone(); 217 addDefaultFields(); 218 } else 219 { 220 if (tracing()) trace("ModelMBeanInfo(ModelMBeanInfo)", 221 "ModelMBeanDescriptor in ModelMBeanInfo is null or invalid, setting to default value"); 222 modelMBeanDescriptor = createDefaultDescriptor(); 223 } 224 } catch (MBeanException mbe) 225 { 226 modelMBeanDescriptor = createDefaultDescriptor(); 227 if (tracing()) trace("ModelMBeanInfo(ModelMBeanInfo)","Could not get modelMBeanDescriptor, setting to default value"); 228 } 229 230 if (tracing()) 231 { 232 trace("ModelMBeanInfo(ModelMBeanInfo)","Executed"); 233 } 234 } 235 236 254 public ModelMBeanInfoSupport(String className, 255 String description, 256 ModelMBeanAttributeInfo [] attributes, 257 ModelMBeanConstructorInfo [] constructors, 258 ModelMBeanOperationInfo [] operations, 259 ModelMBeanNotificationInfo [] notifications) { 260 this(className, description, attributes, constructors, 261 operations, notifications, null); 262 } 263 264 294 295 public ModelMBeanInfoSupport(String className, 296 String description, 297 ModelMBeanAttributeInfo [] attributes, 298 ModelMBeanConstructorInfo [] constructors, 299 ModelMBeanOperationInfo [] operations, 300 ModelMBeanNotificationInfo [] notifications, 301 Descriptor mbeandescriptor) { 302 super(className, 303 description, 304 (attributes != null) ? attributes : NO_ATTRIBUTES, 305 (constructors != null) ? constructors : NO_CONSTRUCTORS, 306 (operations != null) ? operations : NO_OPERATIONS, 307 (notifications != null) ? notifications : NO_NOTIFICATIONS); 308 314 modelMBeanAttributes = attributes; 315 modelMBeanConstructors = constructors; 316 modelMBeanOperations = operations; 317 modelMBeanNotifications = notifications; 318 if (mbeandescriptor ==null) { 319 if (tracing()) 320 trace("ModelMBeanInfo(String,String,ModelMBeanAttributeInfo[],ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[],ModelMBeanNotificationInfo[],Descriptor)", 321 "MBeanDescriptor is null, setting default descriptor"); 322 323 modelMBeanDescriptor = createDefaultDescriptor(); 324 } else { 325 if (isValidDescriptor(mbeandescriptor)) { 326 modelMBeanDescriptor = (Descriptor ) mbeandescriptor.clone(); 327 addDefaultFields(); 328 } else { 329 throw new RuntimeOperationsException (new IllegalArgumentException ("Invalid descriptor passed in parameter")); 330 } 331 } 332 if (tracing()) 333 { 334 trace("ModelMBeanInfo(String,String,ModelMBeanAttributeInfo[],ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[],ModelMBeanNotificationInfo[],Descriptor)", 335 "Executed"); 336 } 337 } 338 339 private static final ModelMBeanAttributeInfo [] NO_ATTRIBUTES = 340 new ModelMBeanAttributeInfo [0]; 341 private static final ModelMBeanConstructorInfo [] NO_CONSTRUCTORS = 342 new ModelMBeanConstructorInfo [0]; 343 private static final ModelMBeanNotificationInfo [] NO_NOTIFICATIONS = 344 new ModelMBeanNotificationInfo [0]; 345 private static final ModelMBeanOperationInfo [] NO_OPERATIONS = 346 new ModelMBeanOperationInfo [0]; 347 348 350 public Object clone() { 351 return(new ModelMBeanInfoSupport (this)); 352 } 353 354 355 public Descriptor [] getDescriptors(String inDescriptorType) 356 throws MBeanException , RuntimeOperationsException { 357 if (tracing()) 358 { 359 trace("ModelMBeanInfoSupport.getDescriptors()","Entry"); 360 } 361 362 if ((inDescriptorType == null) || (inDescriptorType == "")) 363 { 364 inDescriptorType = "all"; 365 } 366 Descriptor [] retList; 368 369 if (inDescriptorType.equalsIgnoreCase(MMB)) 370 { 371 retList = new Descriptor [] {modelMBeanDescriptor}; 372 } else if (inDescriptorType.equalsIgnoreCase(ATTR)) 373 { 374 MBeanAttributeInfo [] attrList = modelMBeanAttributes; 375 int numAttrs = 0; 376 if (attrList != null) numAttrs = attrList.length; 377 378 retList = new Descriptor [numAttrs]; 379 for (int i=0; i < numAttrs; i++) 380 { 381 retList[i] = (((ModelMBeanAttributeInfo ) attrList[i]).getDescriptor()); 382 } 383 } else if (inDescriptorType.equalsIgnoreCase(OPER)) 384 { 385 MBeanOperationInfo [] operList = modelMBeanOperations; 386 int numOpers = 0; 387 if (operList != null) numOpers = operList.length; 388 389 retList = new Descriptor [numOpers]; 390 for (int i=0; i < numOpers; i++) 391 { 392 retList[i] = (((ModelMBeanOperationInfo ) operList[i]).getDescriptor()); 393 } 394 } else if (inDescriptorType.equalsIgnoreCase(CONS)) 395 { 396 MBeanConstructorInfo [] consList = modelMBeanConstructors; 397 int numCons = 0; 398 if (consList != null) numCons = consList.length; 399 400 retList = new Descriptor [numCons]; 401 for (int i=0; i < numCons; i++) 402 { 403 retList[i] = (((ModelMBeanConstructorInfo ) consList[i]).getDescriptor()); 404 } 405 } else if (inDescriptorType.equalsIgnoreCase(NOTF)) 406 { 407 MBeanNotificationInfo [] notifList = modelMBeanNotifications; 408 int numNotifs = 0; 409 if (notifList != null) numNotifs = notifList.length; 410 411 retList = new Descriptor [numNotifs]; 412 for (int i=0; i < numNotifs; i++) 413 { 414 retList[i] = (((ModelMBeanNotificationInfo ) notifList[i]).getDescriptor()); 415 } 416 } else if (inDescriptorType.equalsIgnoreCase(ALL)) 417 { 418 419 MBeanAttributeInfo [] attrList = modelMBeanAttributes; 420 int numAttrs = 0; 421 if (attrList != null) numAttrs = attrList.length; 422 423 MBeanOperationInfo [] operList = modelMBeanOperations; 424 int numOpers = 0; 425 if (operList != null) numOpers = operList.length; 426 427 MBeanConstructorInfo [] consList = modelMBeanConstructors; 428 int numCons = 0; 429 if (consList != null) numCons = consList.length; 430 431 MBeanNotificationInfo [] notifList = modelMBeanNotifications; 432 int numNotifs = 0; 433 if (notifList != null) numNotifs = notifList.length; 434 435 436 retList = new Descriptor [numAttrs + numCons + numOpers + numNotifs]; 437 int j=0; 438 for (int i=0; i < numAttrs; i++) 439 { 440 retList[j] = (((ModelMBeanAttributeInfo ) attrList[i]).getDescriptor()); 441 j++; 442 } 443 for (int i=0; i < numCons; i++) 444 { 445 retList[j] = (((ModelMBeanConstructorInfo )consList[i]).getDescriptor()); 446 j++; 447 } 448 for (int i=0; i < numOpers; i++) 449 { 450 retList[j] = (((ModelMBeanOperationInfo )operList[i]).getDescriptor()); 451 j++; 452 } 453 for (int i=0; i < numNotifs; i++) 454 { 455 retList[j] = (((ModelMBeanNotificationInfo )notifList[i]).getDescriptor()); 456 j++; 457 } 458 } else 459 { 460 throw new RuntimeOperationsException (new IllegalArgumentException ("Descriptor Type is invalid"), 461 ("Exception occurred trying to find the descriptors of the MBean")); 462 } 463 if (tracing()) 464 { 465 trace("ModelMBeanInfoSupport.getDescriptors()","Exit"); 466 } 467 468 return retList; 469 } 470 471 472 public void setDescriptors(Descriptor [] inDescriptors) 473 throws MBeanException , RuntimeOperationsException { 474 if (tracing()) 475 { 476 trace("ModelMBeanInfoSupport.setDescriptors(Descriptor[])","Entry"); 477 } 478 if (inDescriptors==null) 479 { throw new RuntimeOperationsException (new IllegalArgumentException ("Descriptor list is invalid"), 481 ("Exception occurred trying to set the descriptors of the MBeanInfo")); 482 } 483 if (inDescriptors.length == 0) 484 { return; 486 } 487 for (int j=0; j < inDescriptors.length; j++) 488 { 489 setDescriptor(inDescriptors[j],null); 490 } 491 if (tracing()) 492 { 493 trace("ModelMBeanInfoSupport.setDescriptors(Descriptor[])","Exit"); 494 } 495 496 } 497 498 499 512 513 public Descriptor getDescriptor(String inDescriptorName) 514 throws MBeanException , RuntimeOperationsException { 515 if (tracing()) 516 { 517 trace("ModelMBeanInfoSupport.getDescriptor(String)","Entry"); 518 } 519 return(getDescriptor(inDescriptorName, null)); 520 } 521 522 523 public Descriptor getDescriptor(String inDescriptorName, 524 String inDescriptorType) 525 throws MBeanException , RuntimeOperationsException { 526 if (inDescriptorName==null) { 527 throw new RuntimeOperationsException (new IllegalArgumentException ("Descriptor is invalid"), 529 ("Exception occurred trying to set the descriptors of the MBeanInfo")); 530 } 531 532 if (MMB.equalsIgnoreCase(inDescriptorType)) { 533 return (Descriptor ) modelMBeanDescriptor.clone(); 534 } 535 536 543 if (ATTR.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) { 544 ModelMBeanAttributeInfo attr = getAttribute(inDescriptorName); 545 if (attr != null) 546 return attr.getDescriptor(); 547 if (inDescriptorType != null) 548 return null; 549 } 550 if (OPER.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) { 551 ModelMBeanOperationInfo oper = getOperation(inDescriptorName); 552 if (oper != null) 553 return oper.getDescriptor(); 554 if (inDescriptorType != null) 555 return null; 556 } 557 if (CONS.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) { 558 ModelMBeanConstructorInfo oper = 559 getConstructor(inDescriptorName); 560 if (oper != null) 561 return oper.getDescriptor(); 562 if (inDescriptorType != null) 563 return null; 564 } 565 if (NOTF.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) { 566 ModelMBeanNotificationInfo notif = 567 getNotification(inDescriptorName); 568 if (notif != null) 569 return notif.getDescriptor(); 570 if (inDescriptorType != null) 571 return null; 572 } 573 if (inDescriptorType == null) 574 return null; 575 throw new RuntimeOperationsException (new IllegalArgumentException ("Descriptor Type is invalid"), 576 "Exception occurred trying to find the descriptors of the MBean"); 577 578 } 579 580 581 582 public void setDescriptor(Descriptor inDescriptor, 583 String inDescriptorType) 584 throws MBeanException , RuntimeOperationsException { 585 final String excMsg = 586 "Exception occurred trying to set the descriptors of the MBean"; 587 588 if (tracing()) { 589 trace("ModelMBeanInfoSupport.setDescriptor(Descriptor,String)", 590 "Entry"); 591 } 592 593 if (inDescriptor==null) { 594 RuntimeException iae = 595 new IllegalArgumentException ("Null Descriptor"); 596 throw new RuntimeOperationsException (iae, excMsg); 597 } 598 599 if ((inDescriptorType == null) || (inDescriptorType == "")) { 600 inDescriptorType = 601 (String ) inDescriptor.getFieldValue("descriptorType"); 602 603 if (inDescriptorType == null) { 604 RuntimeException iae = 605 new IllegalArgumentException ("Descriptor type is invalid"); 606 throw new RuntimeOperationsException (iae, excMsg); 607 } 608 } 609 610 String inDescriptorName = 611 (String ) inDescriptor.getFieldValue("name"); 612 if (inDescriptorName == null) { 613 RuntimeException iae = 614 new IllegalArgumentException ("Descriptor name is invalid"); 615 throw new RuntimeOperationsException (iae, excMsg); 616 } 617 boolean found = false; 618 if (inDescriptorType.equalsIgnoreCase(MMB)) { 619 setMBeanDescriptor(inDescriptor); 620 found = true; 621 } else if (inDescriptorType.equalsIgnoreCase(ATTR)) { 622 MBeanAttributeInfo [] attrList = modelMBeanAttributes; 623 int numAttrs = 0; 624 if (attrList != null) numAttrs = attrList.length; 625 626 for (int i=0; i < numAttrs; i++) { 627 if (inDescriptorName.equals(attrList[i].getName())) { 628 found = true; 629 ModelMBeanAttributeInfo mmbai = 630 (ModelMBeanAttributeInfo ) attrList[i]; 631 mmbai.setDescriptor(inDescriptor); 632 if (tracing()) { 633 trace("ModelMBeanInfoSupport.setDescriptor", 634 "setting descriptor to " + inDescriptor); 635 trace("ModelMBeanInfoSupport.setDescriptor", 636 "local: AttributeInfo descriptor is " + 637 mmbai.getDescriptor()); 638 trace("ModelMBeanInfoSupport.setDescriptor", 639 "modelMBeanInfo: AttributeInfo descriptor is " + 640 this.getDescriptor(inDescriptorName, 641 "attribute")); 642 } 643 } 644 } 645 } else if (inDescriptorType.equalsIgnoreCase(OPER)) { 646 MBeanOperationInfo [] operList = modelMBeanOperations; 647 int numOpers = 0; 648 if (operList != null) numOpers = operList.length; 649 650 for (int i=0; i < numOpers; i++) { 651 if (inDescriptorName.equals(operList[i].getName())) { 652 found = true; 653 ModelMBeanOperationInfo mmboi = 654 (ModelMBeanOperationInfo ) operList[i]; 655 mmboi.setDescriptor(inDescriptor); 656 } 657 } 658 } else if (inDescriptorType.equalsIgnoreCase(CONS)) { 659 MBeanConstructorInfo [] consList = modelMBeanConstructors; 660 int numCons = 0; 661 if (consList != null) numCons = consList.length; 662 663 for (int i=0; i < numCons; i++) { 664 if (inDescriptorName.equals(consList[i].getName())) { 665 found = true; 666 ModelMBeanConstructorInfo mmbci = 667 (ModelMBeanConstructorInfo ) consList[i]; 668 mmbci.setDescriptor(inDescriptor); 669 } 670 } 671 } else if (inDescriptorType.equalsIgnoreCase(NOTF)) { 672 MBeanNotificationInfo [] notifList = modelMBeanNotifications; 673 int numNotifs = 0; 674 if (notifList != null) numNotifs = notifList.length; 675 676 for (int i=0; i < numNotifs; i++) { 677 if (inDescriptorName.equals(notifList[i].getName())) { 678 found = true; 679 ModelMBeanNotificationInfo mmbni = 680 (ModelMBeanNotificationInfo ) notifList[i]; 681 mmbni.setDescriptor(inDescriptor); 682 } 683 } 684 } else { 685 RuntimeException iae = 686 new IllegalArgumentException ("Invalid descriptor type: " + 687 inDescriptorType); 688 throw new RuntimeOperationsException (iae, excMsg); 689 } 690 691 if (!found) { 692 RuntimeException iae = 693 new IllegalArgumentException ("Descriptor name is invalid: " + 694 "type=" + inDescriptorType + 695 "; name=" + inDescriptorName); 696 throw new RuntimeOperationsException (iae, excMsg); 697 } 698 if (tracing()) { 699 trace("ModelMBeanInfoSupport.setDescriptor(Descriptor,String)", 700 "Exit"); 701 } 702 703 } 704 705 706 public ModelMBeanAttributeInfo getAttribute(String inName) 707 throws MBeanException , RuntimeOperationsException { 708 ModelMBeanAttributeInfo retInfo = null; 709 if (tracing()) 710 { 711 trace("ModelMBeanInfoSupport.getAttributeInfo(String)","Entry"); 712 } 713 if (inName == null) 714 { 715 throw new RuntimeOperationsException (new IllegalArgumentException ("Attribute Name is null"), 716 ("Exception occurred trying to get the ModelMBeanAttributeInfo of the MBean")); 717 } 718 MBeanAttributeInfo [] attrList = modelMBeanAttributes; 719 int numAttrs = 0; 720 if (attrList != null) numAttrs = attrList.length; 721 722 for (int i=0; (i < numAttrs) && (retInfo == null); i++) 723 { 724 if (tracing()) 725 { 726 trace("ModelMBeanInfoSupport.getAttribute","this.getAttributes() MBeanAttributeInfo Array " + i + ":" + ((ModelMBeanAttributeInfo )attrList[i]).getDescriptor().toString()); 727 trace("ModelMBeanInfoSupport.getAttribute","this.modelMBeanAttributes MBeanAttributeInfo Array " + i + ":" + ((ModelMBeanAttributeInfo )modelMBeanAttributes[i]).getDescriptor().toString()); 728 } 729 if (inName.equals(attrList[i].getName())) 730 { 731 retInfo = ((ModelMBeanAttributeInfo )attrList[i].clone()); 732 } 733 } 734 if (tracing()) 735 { 736 trace("ModelMBeanInfoSupport.getAttribute()","Exit"); 737 } 738 739 return retInfo; 740 } 741 742 743 744 public ModelMBeanOperationInfo getOperation(String inName) 745 throws MBeanException , RuntimeOperationsException { 746 ModelMBeanOperationInfo retInfo = null; 747 if (tracing()) 748 { 749 trace("ModelMBeanInfoSupport.getOperation(String)","Entry"); 750 } 751 if (inName == null) 752 { 753 throw new RuntimeOperationsException (new IllegalArgumentException ("inName is null"), 754 ("Exception occurred trying to get the ModelMBeanOperationInfo of the MBean")); 755 } 756 MBeanOperationInfo [] operList = modelMBeanOperations; int numOpers = 0; 758 if (operList != null) numOpers = operList.length; 759 760 for (int i=0; (i < numOpers) && (retInfo == null); i++) 761 { 762 if (inName.equals(operList[i].getName())) 763 { 764 retInfo = ((ModelMBeanOperationInfo ) operList[i].clone()); 765 } 766 } 767 if (tracing()) 768 { 769 trace("ModelMBeanInfoSupport.getOperation(String)","Exit"); 770 } 771 772 return retInfo; 773 } 774 775 787 788 public ModelMBeanConstructorInfo getConstructor(String inName) 789 throws MBeanException , RuntimeOperationsException { 790 ModelMBeanConstructorInfo retInfo = null; 791 if (tracing()) 792 { 793 trace("ModelMBeanInfoSupport.getConstructor(String)","Entry"); 794 } 795 if (inName == null) 796 { 797 throw new RuntimeOperationsException (new IllegalArgumentException ("Constructor name is null"), 798 ("Exception occurred trying to get the ModelMBeanConstructorInfo of the MBean")); 799 } 800 MBeanConstructorInfo [] consList = modelMBeanConstructors; int numCons = 0; 802 if (consList != null) numCons = consList.length; 803 804 for (int i=0; (i < numCons) && (retInfo == null); i++) 805 { 806 if (inName.equals(consList[i].getName())) 807 { 808 retInfo = ((ModelMBeanConstructorInfo ) consList[i].clone()); 809 } 810 } 811 if (tracing()) 812 { 813 trace("ModelMBeanInfoSupport.getConstructor(String)","Exit"); 814 } 815 816 return retInfo; 817 } 818 819 820 public ModelMBeanNotificationInfo getNotification(String inName) 821 throws MBeanException , RuntimeOperationsException { 822 ModelMBeanNotificationInfo retInfo = null; 823 if (tracing()) 824 { 825 trace("ModelMBeanInfoSupport.getNotification(String)","Entry"); 826 } 827 if (inName == null) 828 { 829 throw new RuntimeOperationsException (new IllegalArgumentException ("Notification name is null"), 830 ("Exception occurred trying to get the ModelMBeanNotificationInfo of the MBean")); 831 } 832 MBeanNotificationInfo [] notifList = modelMBeanNotifications; int numNotifs = 0; 834 if (notifList != null) numNotifs = notifList.length; 835 836 for (int i=0; (i < numNotifs) && (retInfo == null); i++) 837 { 838 if (inName.equals(notifList[i].getName())) 839 { 840 retInfo = ((ModelMBeanNotificationInfo ) notifList[i].clone()); 841 } 842 } 843 if (tracing()) 844 { 845 trace("ModelMBeanInfoSupport.getNotification(String)","Exit"); 846 } 847 848 return retInfo; 849 } 850 851 852 public Descriptor getMBeanDescriptor() 853 throws MBeanException , RuntimeOperationsException { 854 if (tracing()) 855 { 856 trace("ModelMBeanInfoSupport.getMBeanDescriptor()","Executed"); 857 } 858 if (modelMBeanDescriptor == null) 859 { 860 return null; 861 } 862 if (tracing()) trace("ModelMBeanInfoSupport.getMBeanDesriptor()", "Returning " + modelMBeanDescriptor.toString()); 863 return((Descriptor ) modelMBeanDescriptor.clone()); 864 } 865 866 867 public void setMBeanDescriptor(Descriptor inMBeanDescriptor) 868 throws MBeanException , RuntimeOperationsException { 869 if (tracing()) 870 { 871 trace("ModelMBeanInfoSupport.setMBeanDescriptor(Descriptor)","Executed"); 872 } 873 874 if (inMBeanDescriptor == null) 875 { 876 if (tracing()) trace("ModelMBeanInfoSupport.setMBeanDescriptor(Descriptor)","MBean Descriptor is not valid"); 877 modelMBeanDescriptor = createDefaultDescriptor(); 878 } else 879 { 880 if (isValidDescriptor(inMBeanDescriptor)) { 881 modelMBeanDescriptor = (Descriptor ) inMBeanDescriptor.clone(); 882 addDefaultFields(); 883 } else { 884 throw new RuntimeOperationsException (new IllegalArgumentException ("Invalid descriptor passed in parameter")); 885 } 886 887 } 888 } 889 890 894 private Descriptor createDefaultDescriptor() 895 { 896 897 Descriptor dftDesc = null; 898 dftDesc = new DescriptorSupport (new String [] {("name=" + this.getClassName()), 899 "descriptorType=mbean", 900 ("displayName=" + this.getClassName()), 901 "persistPolicy=never", 902 "log=F", 903 "visibility=1"}); 904 return dftDesc; 905 } 906 907 916 private boolean isValidDescriptor(Descriptor inDesc) 917 { 918 String badField = null; 919 if (tracing()) 923 trace("isValidDescriptor", 924 "Validating descriptor: " + inDesc.toString()); 925 if (inDesc == null) 926 badField = "nullDescriptor"; 927 else if (!inDesc.isValid()) 928 badField="InvalidDescriptor"; 932 else if ((((String )inDesc.getFieldValue("name")) == null)) 933 badField="name"; 934 else if (! ((String )inDesc.getFieldValue("descriptorType")) 935 .equalsIgnoreCase(MMB)) 936 badField="descriptorType"; 937 else { if (tracing()) 939 trace("isValidDescriptor", "returning true"); 940 return true; 941 } 942 943 if (tracing()) 944 trace("isValidDescriptor", 945 "returning false: invalid field is " + badField); 946 947 return false; 948 } 949 950 private void addDefaultFields() { 951 final Descriptor d = modelMBeanDescriptor; 952 953 if ((d.getFieldValue("displayName")) == null) 954 d.setField("displayName",this.getClassName()); 955 if ((d.getFieldValue("persistPolicy")) == null) 956 d.setField("persistPolicy","never"); 957 if ((d.getFieldValue("log")) == null) 958 d.setField("log","F"); 959 if ((d.getFieldValue("visibility")) == null) 960 d.setField("visibility","1"); 961 } 962 963 private boolean tracing() 965 { 966 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN); 967 } 968 969 private void trace(String inClass, String inMethod, String inText) 970 { 971 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN, inClass, 972 inMethod, inText); 973 } 974 975 private void trace(String inMethod, String inText) 976 { 977 trace(currClass, inMethod, inText); 978 } 979 980 983 private void readObject(ObjectInputStream in) 984 throws IOException , ClassNotFoundException { 985 if (compat) 986 { 987 ObjectInputStream.GetField fields = in.readFields(); 990 modelMBeanDescriptor = (Descriptor ) fields.get("modelMBeanDescriptor", null); 991 if (fields.defaulted("modelMBeanDescriptor")) 992 { 993 throw new NullPointerException ("modelMBeanDescriptor"); 994 } 995 modelMBeanAttributes = (MBeanAttributeInfo []) fields.get("mmbAttributes", null); 996 if (fields.defaulted("mmbAttributes")) 997 { 998 throw new NullPointerException ("mmbAttributes"); 999 } 1000 modelMBeanConstructors = (MBeanConstructorInfo []) fields.get("mmbConstructors", null); 1001 if (fields.defaulted("mmbConstructors")) 1002 { 1003 throw new NullPointerException ("mmbConstructors"); 1004 } 1005 modelMBeanNotifications = (MBeanNotificationInfo []) fields.get("mmbNotifications", null); 1006 if (fields.defaulted("mmbNotifications")) 1007 { 1008 throw new NullPointerException ("mmbNotifications"); 1009 } 1010 modelMBeanOperations = (MBeanOperationInfo []) fields.get("mmbOperations", null); 1011 if (fields.defaulted("mmbOperations")) 1012 { 1013 throw new NullPointerException ("mmbOperations"); 1014 } 1015 } 1016 else 1017 { 1018 in.defaultReadObject(); 1021 } 1022 } 1023 1024 1025 1028 private void writeObject(ObjectOutputStream out) 1029 throws IOException { 1030 if (compat) 1031 { 1032 ObjectOutputStream.PutField fields = out.putFields(); 1035 fields.put("modelMBeanDescriptor", modelMBeanDescriptor); 1036 fields.put("mmbAttributes", modelMBeanAttributes); 1037 fields.put("mmbConstructors", modelMBeanConstructors); 1038 fields.put("mmbNotifications", modelMBeanNotifications); 1039 fields.put("mmbOperations", modelMBeanOperations); 1040 fields.put("currClass", currClass); 1041 out.writeFields(); 1042 } 1043 else 1044 { 1045 out.defaultWriteObject(); 1048 } 1049 } 1050 1051 1052} 1053 1054 1055 | Popular Tags |