| 1 7 8 package javax.management.relation; 9 10 import javax.management.ObjectName ; 11 import javax.management.MBeanRegistration ; 12 import javax.management.MBeanServer ; 13 import javax.management.InstanceNotFoundException ; 14 import javax.management.ReflectionException ; 15 import javax.management.MBeanException ; 16 17 import java.util.HashMap ; 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 import java.util.List ; 22 23 import com.sun.jmx.trace.Trace; 24 25 48 public class RelationSupport 49 implements RelationSupportMBean , MBeanRegistration { 50 51 55 private String myRelId = null; 58 59 private ObjectName myRelServiceName = null; 66 67 private MBeanServer myRelServiceMBeanServer = null; 78 79 private String myRelTypeName = null; 82 83 private HashMap myRoleName2ValueMap = new HashMap (); 90 91 private Boolean myInRelServFlg = null; 93 94 98 130 public RelationSupport(String theRelId, 131 ObjectName theRelServiceName, 132 String theRelTypeName, 133 RoleList theRoleList) 134 throws InvalidRoleValueException , 135 IllegalArgumentException { 136 137 super(); 138 139 if (isTraceOn()) 140 trace("Constructor: entering", null); 141 142 initMembers(theRelId, 144 theRelServiceName, 145 null, 146 theRelTypeName, 147 theRoleList); 148 149 if (isTraceOn()) 150 trace("Constructor: exiting", null); 151 } 152 153 197 public RelationSupport(String theRelId, 198 ObjectName theRelServiceName, 199 MBeanServer theRelServiceMBeanServer, 200 String theRelTypeName, 201 RoleList theRoleList) 202 throws InvalidRoleValueException , 203 IllegalArgumentException { 204 205 super(); 206 207 if (theRelServiceMBeanServer == null) { 208 String excMsg = "Invalid parameter."; 210 throw new IllegalArgumentException (excMsg); 211 } 212 213 if (isTraceOn()) 214 trace("Constructor: entering", null); 215 216 initMembers(theRelId, 219 theRelServiceName, 220 theRelServiceMBeanServer, 221 theRelTypeName, 222 theRoleList); 223 224 if (isTraceOn()) 225 trace("Constructor: exiting", null); 226 } 227 228 232 250 public List getRole(String theRoleName) 251 throws IllegalArgumentException , 252 RoleNotFoundException , 253 RelationServiceNotRegisteredException { 254 255 if (theRoleName == null) { 256 String excMsg = "Invalid parameter."; 258 throw new IllegalArgumentException (excMsg); 259 } 260 261 if (isTraceOn()) 262 trace("getRole: entering", theRoleName); 263 264 ArrayList result = (ArrayList ) 267 (getRoleInt(theRoleName, false, null, false)); 268 269 if (isTraceOn()) 270 trace("getRole: exiting", null); 271 return result; 272 } 273 274 291 public RoleResult getRoles(String [] theRoleNameArray) 292 throws IllegalArgumentException , 293 RelationServiceNotRegisteredException { 294 295 if (theRoleNameArray == null) { 296 String excMsg = "Invalid parameter."; 298 throw new IllegalArgumentException (excMsg); 299 } 300 301 if (isTraceOn()) 302 trace("getRoles: entering", null); 303 304 RoleResult result = getRolesInt(theRoleNameArray, false, null); 306 307 if (isTraceOn()) 308 trace("getRoles: exiting", null); 309 return result; 310 } 311 312 322 public RoleResult getAllRoles() 323 throws RelationServiceNotRegisteredException { 324 325 if (isTraceOn()) 326 trace("getAllRoles: entering", null); 327 328 RoleResult result = null; 329 try { 330 result = getAllRolesInt(false, null); 331 } catch (IllegalArgumentException exc) { 332 } 334 335 if (isTraceOn()) 336 trace("getAllRoles: exiting", null); 337 return result; 338 } 339 340 345 public RoleList retrieveAllRoles() { 346 347 if (isTraceOn()) 348 trace("retrieveAllRoles: entering", null); 349 350 RoleList result = null; 351 synchronized(myRoleName2ValueMap) { 352 result = 353 new RoleList (new ArrayList (myRoleName2ValueMap.values())); 354 } 355 356 if (isTraceOn()) 357 trace("retrieveAllRoles: exiting", null); 358 return result; 359 } 360 361 371 public Integer getRoleCardinality(String theRoleName) 372 throws IllegalArgumentException , 373 RoleNotFoundException { 374 375 if (theRoleName == null) { 376 String excMsg = "Invalid parameter."; 378 throw new IllegalArgumentException (excMsg); 379 } 380 381 if (isTraceOn()) 382 trace("getRoleCardinality: entering", theRoleName); 383 384 Role role = null; 386 synchronized(myRoleName2ValueMap) { 387 role = (Role )(myRoleName2ValueMap.get(theRoleName)); 389 } 390 if (role == null) { 391 int pbType = RoleStatus.NO_ROLE_WITH_NAME; 392 try { 397 RelationService.throwRoleProblemException(pbType, 398 theRoleName); 399 } catch (InvalidRoleValueException exc) { 400 } 403 } 404 405 ArrayList roleValue = (ArrayList )(role.getRoleValue()); 406 407 if (isTraceOn()) 408 trace("getRoleCardinality: exiting", null); 409 return new Integer (roleValue.size()); 410 } 411 412 443 public void setRole(Role theRole) 444 throws IllegalArgumentException , 445 RoleNotFoundException , 446 RelationTypeNotFoundException , 447 InvalidRoleValueException , 448 RelationServiceNotRegisteredException , 449 RelationNotFoundException { 450 451 if (theRole == null) { 452 String excMsg = "Invalid parameter."; 454 throw new IllegalArgumentException (excMsg); 455 } 456 457 if (isTraceOn()) 458 trace("setRole: entering", theRole.toString()); 459 460 Object result = setRoleInt(theRole, false, null, false); 462 463 if (isTraceOn()) 464 trace("setRole: exiting", null); 465 return; 466 } 467 468 492 public RoleResult setRoles(RoleList theRoleList) 493 throws IllegalArgumentException , 494 RelationServiceNotRegisteredException , 495 RelationTypeNotFoundException , 496 RelationNotFoundException { 497 498 if (theRoleList == null) { 499 String excMsg = "Invalid parameter."; 501 throw new IllegalArgumentException (excMsg); 502 } 503 504 if (isTraceOn()) 505 trace("setRoles: entering", theRoleList.toString()); 506 507 RoleResult result = setRolesInt(theRoleList, false, null); 508 509 if (isTraceOn()) 510 trace("setRoles: exiting", null); 511 return result; 512 } 513 514 540 public void handleMBeanUnregistration(ObjectName theObjName, 541 String theRoleName) 542 throws IllegalArgumentException , 543 RoleNotFoundException , 544 InvalidRoleValueException , 545 RelationServiceNotRegisteredException , 546 RelationTypeNotFoundException , 547 RelationNotFoundException { 548 549 if (theObjName == null || theRoleName == null) { 550 String excMsg = "Invalid parameter."; 552 throw new IllegalArgumentException (excMsg); 553 } 554 555 if (isTraceOn()) 556 trace("handleMBeanUnregistration: entering", 557 "theObjName " + theObjName + ", theRoleName " + theRoleName); 558 559 handleMBeanUnregistrationInt(theObjName, 562 theRoleName, 563 false, 564 null); 565 566 if (isTraceOn()) 567 trace("handleMBeanUnregistration: exiting", null); 568 return; 569 } 570 571 577 public Map getReferencedMBeans() { 578 579 if (isTraceOn()) 580 trace("getReferencedMBeans: entering", null); 581 582 HashMap refMBeanMap = new HashMap (); 583 584 synchronized(myRoleName2ValueMap) { 585 586 for (Iterator roleIter = (myRoleName2ValueMap.values()).iterator(); 587 roleIter.hasNext();) { 588 589 Role currRole = (Role )(roleIter.next()); 590 591 String currRoleName = currRole.getRoleName(); 592 ArrayList currRefMBeanList = (ArrayList ) 594 (currRole.getRoleValue()); 595 596 for (Iterator mbeanIter = currRefMBeanList.iterator(); 597 mbeanIter.hasNext();) { 598 599 ObjectName currRoleObjName = 600 (ObjectName )(mbeanIter.next()); 601 602 ArrayList mbeanRoleNameList = 605 (ArrayList )(refMBeanMap.get(currRoleObjName)); 606 607 boolean newRefFlg = false; 608 if (mbeanRoleNameList == null) { 609 newRefFlg = true; 610 mbeanRoleNameList = new ArrayList (); 611 } 612 mbeanRoleNameList.add(currRoleName); 613 if (newRefFlg) { 614 refMBeanMap.put(currRoleObjName, mbeanRoleNameList); 615 } 616 } 617 } 618 } 619 620 if (isTraceOn()) 621 trace("getReferencedMBeans: exiting", null); 622 return refMBeanMap; 623 } 624 625 628 public String getRelationTypeName() { 629 return myRelTypeName; 630 } 631 632 637 public ObjectName getRelationServiceName() { 638 return myRelServiceName; 639 } 640 641 647 public String getRelationId() { 648 return myRelId; 649 } 650 651 655 public ObjectName preRegister(MBeanServer server, 662 ObjectName name) 663 throws Exception { 664 665 myRelServiceMBeanServer = server; 666 return name; 667 } 668 669 public void postRegister(Boolean registrationDone) { 671 return; 672 } 673 674 public void preDeregister() 676 throws Exception { 677 return; 678 } 679 680 public void postDeregister() { 682 return; 683 } 684 685 689 693 public Boolean isInRelationService() { 694 Boolean result = null; 695 synchronized(myInRelServFlg) { 696 result = new Boolean (myInRelServFlg.booleanValue()); 697 } 698 return result; 699 } 700 701 public void setRelationServiceManagementFlag(Boolean theFlg) 702 throws IllegalArgumentException { 703 704 if (theFlg == null) { 705 String excMsg = "Invalid parameter."; 707 throw new IllegalArgumentException (excMsg); 708 } 709 synchronized(myInRelServFlg) { 710 myInRelServFlg = new Boolean (theFlg.booleanValue()); 711 } 712 return; 713 } 714 715 719 Object getRoleInt(String theRoleName, 766 boolean theRelServCallFlg, 767 RelationService theRelServ, 768 boolean theMultiRoleFlg) 769 throws IllegalArgumentException , 770 RoleNotFoundException , 771 RelationServiceNotRegisteredException { 772 773 if (theRoleName == null || 774 (theRelServCallFlg && theRelServ == null)) { 775 String excMsg = "Invalid parameter."; 777 throw new IllegalArgumentException (excMsg); 778 } 779 780 if (isDebugOn()) { 781 String str = "theRoleName " + theRoleName; 782 debug("getRoleInt: entering", str); 783 } 784 785 int pbType = 0; 786 787 Role role = null; 788 synchronized(myRoleName2ValueMap) { 789 role = (Role )(myRoleName2ValueMap.get(theRoleName)); 791 } 792 793 if (role == null) { 794 pbType = RoleStatus.NO_ROLE_WITH_NAME; 795 796 } else { 797 Integer status = null; 799 800 if (theRelServCallFlg) { 801 802 try { 806 status = theRelServ.checkRoleReading(theRoleName, 807 myRelTypeName); 808 } catch (RelationTypeNotFoundException exc) { 809 throw new RuntimeException (exc.getMessage()); 810 } 811 812 } else { 813 814 Object [] params = new Object [2]; 818 params[0] = theRoleName; 819 params[1] = myRelTypeName; 820 String [] signature = new String [2]; 821 signature[0] = "java.lang.String"; 822 signature[1] = "java.lang.String"; 823 try { 830 status = (Integer ) 831 (myRelServiceMBeanServer.invoke(myRelServiceName, 832 "checkRoleReading", 833 params, 834 signature)); 835 } catch (MBeanException exc1) { 836 throw new RuntimeException ("incorrect relation type"); 837 } catch (ReflectionException exc2) { 838 throw new RuntimeException (exc2.getMessage()); 839 } catch (InstanceNotFoundException exc3) { 840 throw new RelationServiceNotRegisteredException ( 841 exc3.getMessage()); 842 } 843 } 844 845 pbType = status.intValue(); 846 } 847 848 Object result = null; 849 850 if (pbType == 0) { 851 853 if (!(theMultiRoleFlg)) { 854 |