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 result = (ArrayList ) 859 (((ArrayList )(role.getRoleValue())).clone()); 860 861 } else { 862 result = (Role )(role.clone()); 865 } 866 867 } else { 868 870 if (!(theMultiRoleFlg)) { 871 try { 874 RelationService.throwRoleProblemException(pbType, 875 theRoleName); 876 return null; 878 } catch (InvalidRoleValueException exc) { 879 throw new RuntimeException (exc.getMessage()); 880 } 881 882 } else { 883 result = new RoleUnresolved (theRoleName, null, pbType); 886 } 887 } 888 889 if (isDebugOn()) 890 debug("getRoleInt: exiting", null); 891 return result; 892 } 893 894 RoleResult getRolesInt(String [] theRoleNameArray, 915 boolean theRelServCallFlg, 916 RelationService theRelServ) 917 throws IllegalArgumentException , 918 RelationServiceNotRegisteredException { 919 920 if (theRoleNameArray == null || 921 (theRelServCallFlg && theRelServ == null)) { 922 String excMsg = "Invalid parameter."; 924 throw new IllegalArgumentException (excMsg); 925 } 926 927 if (isDebugOn()) 928 debug("getRolesInt: entering", null); 929 930 RoleList roleList = new RoleList (); 931 RoleUnresolvedList roleUnresList = new RoleUnresolvedList (); 932 933 for (int i = 0; i < theRoleNameArray.length; i++) { 934 String currRoleName = theRoleNameArray[i]; 935 936 Object currResult = null; 937 938 try { 942 currResult = getRoleInt(currRoleName, 943 theRelServCallFlg, 944 theRelServ, 945 true); 946 947 } catch (RoleNotFoundException exc) { 948 return null; } 950 951 if (currResult instanceof Role ) { 952 try { 955 roleList.add((Role )currResult); 956 } catch (IllegalArgumentException exc) { 957 throw new RuntimeException (exc.getMessage()); 958 } 959 960 } else if (currResult instanceof RoleUnresolved ) { 961 try { 964 roleUnresList.add((RoleUnresolved )currResult); 965 } catch (IllegalArgumentException exc) { 966 throw new RuntimeException (exc.getMessage()); 967 } 968 } 969 } 970 971 RoleResult result = new RoleResult (roleList, roleUnresList); 972 if (isDebugOn()) 973 debug("getRolesInt: exiting", null); 974 return result; 975 } 976 977 RoleResult getAllRolesInt(boolean theRelServCallFlg, 988 RelationService theRelServ) 989 throws IllegalArgumentException , 990 RelationServiceNotRegisteredException { 991 992 if (theRelServCallFlg && theRelServ == null) { 993 String excMsg = "Invalid parameter."; 995 throw new IllegalArgumentException (excMsg); 996 } 997 998 if (isDebugOn()) 999 debug("getAllRolesInt: entering", null); 1000 1001 ArrayList roleNameList = null; 1002 synchronized(myRoleName2ValueMap) { 1003 roleNameList = 1004 new ArrayList (myRoleName2ValueMap.keySet()); 1005 } 1006 String [] roleNames = new String [roleNameList.size()]; 1007 int i = 0; 1008 for (Iterator roleNameIter = roleNameList.iterator(); 1009 roleNameIter.hasNext();) { 1010 String currRoleName = (String )(roleNameIter.next()); 1011 roleNames[i] = currRoleName; 1012 i++; 1013 } 1014 1015 RoleResult result = getRolesInt(roleNames, 1016 theRelServCallFlg, 1017 theRelServ); 1018 1019 if (isDebugOn()) 1020 debug("getAllRolesInt: exiting", null); 1021 return result; 1022 } 1023 1024 Object setRoleInt(Role theRole, 1080 boolean theRelServCallFlg, 1081 RelationService theRelServ, 1082 boolean theMultiRoleFlg) 1083 throws IllegalArgumentException , 1084 RoleNotFoundException , 1085 InvalidRoleValueException , 1086 RelationServiceNotRegisteredException , 1087 RelationTypeNotFoundException , 1088 RelationNotFoundException { 1089 1090 if (theRole == null || 1091 (theRelServCallFlg && theRelServ == null)) { 1092 String excMsg = "Invalid parameter."; 1094 throw new IllegalArgumentException (excMsg); 1095 } 1096 1097 if (isDebugOn()) { 1098 String str = 1099 "theRole " + theRole 1100 + ", theRelServCallFlg " + theRelServCallFlg 1101 + ", theMultiRoleFlg " + theMultiRoleFlg; 1102 debug("setRoleInt: entering" , str); 1103 } 1104 1105 String roleName = theRole.getRoleName(); 1106 int pbType = 0; 1107 1108 Role role = null; 1114 synchronized(myRoleName2ValueMap) { 1115 role = (Role )(myRoleName2ValueMap.get(roleName)); 1116 } 1117 1118 ArrayList oldRoleValue = null; 1119 Boolean initFlg = null; 1120 1121 if (role == null) { 1122 initFlg = new Boolean (true); 1123 oldRoleValue = new ArrayList (); 1124 1125 } else { 1126 initFlg = new Boolean (false); 1127 oldRoleValue = (ArrayList )(role.getRoleValue()); 1128 } 1129 1130 try { 1133 Integer status = null; 1134 1135 if (theRelServCallFlg) { 1136 1137 status = theRelServ.checkRoleWriting(theRole, 1142 myRelTypeName, 1143 initFlg); 1144 1145 } else { 1146 1147 Object [] params = new Object [3]; 1151 params[0] = theRole; 1152 params[1] = myRelTypeName; 1153 params[2] = initFlg; 1154 String [] signature = new String [3]; 1155 signature[0] = "javax.management.relation.Role"; 1156 signature[1] = "java.lang.String"; 1157 signature[2] = "java.lang.Boolean"; 1158 status = (Integer ) 1168 (myRelServiceMBeanServer.invoke(myRelServiceName, 1169 "checkRoleWriting", 1170 params, 1171 signature)); 1172 } 1173 1174 pbType = status.intValue(); 1175 1176 } catch (MBeanException exc2) { 1177 1178 Exception wrappedExc = exc2.getTargetException(); 1180 if (wrappedExc instanceof RelationTypeNotFoundException ) { 1181 throw ((RelationTypeNotFoundException )wrappedExc); 1182 1183 } else { 1184 throw new RuntimeException (wrappedExc.getMessage()); 1185 } 1186 1187 } catch (ReflectionException exc3) { 1188 throw new RuntimeException (exc3.getMessage()); 1189 1190 } catch (RelationTypeNotFoundException exc4) { 1191 throw new RuntimeException (exc4.getMessage()); 1192 1193 } catch (InstanceNotFoundException exc5) { 1194 throw new RelationServiceNotRegisteredException (exc5.getMessage()); 1195 } 1196 1197 Object result = null; 1198 1199 if (pbType == 0) { 1200 if (!(initFlg.booleanValue())) { 1202 1203 1210 sendRoleUpdateNotification(theRole, 1213 oldRoleValue, 1214 theRelServCallFlg, 1215 theRelServ); 1216 1217 updateRelationServiceMap(theRole, 1220 oldRoleValue, 1221 theRelServCallFlg, 1222 theRelServ); 1223 1224 } 1225 1226 synchronized(myRoleName2ValueMap) { 1228 myRoleName2ValueMap.put(roleName, 1229 (Role )(theRole.clone())); 1230 } 1231 1232 1234 if (theMultiRoleFlg) { 1235 result = theRole; 1237 } 1238 1239 } else { 1240 1241 1243 if (!(theMultiRoleFlg)) { 1244 RelationService.throwRoleProblemException(pbType, 1249 roleName); 1250 return null; 1252 1253 } else { 1254 result = new RoleUnresolved (roleName, 1257 theRole.getRoleValue(), 1258 pbType); 1259 } 1260 } 1261 1262 if (isDebugOn()) 1263 debug("setRoleInt: exiting", null); 1264 return result; 1265 } 1266 1267 private void sendRoleUpdateNotification(Role theNewRole, 1291 List theOldRoleValue, 1292 boolean theRelServCallFlg, 1293 RelationService theRelServ) 1294 throws IllegalArgumentException , 1295 RelationServiceNotRegisteredException , 1296 RelationNotFoundException { 1297 1298 if (theNewRole == null || 1299 theOldRoleValue == null || 1300 (theRelServCallFlg && theRelServ == null)) { 1301 String excMsg = "Invalid parameter."; 1303 throw new IllegalArgumentException (excMsg); 1304 } 1305 1306 if (isDebugOn()) { 1307 String str = 1308 "theNewRole " + theNewRole 1309 + ", theOldRoleValue " + theOldRoleValue 1310 + ", theRelServCallFlg " + theRelServCallFlg; 1311 debug("sendRoleUpdateNotification: entering", str); 1312 } 1313 1314 if (theRelServCallFlg) { 1315 try { 1319 theRelServ.sendRoleUpdateNotification(myRelId, 1320 theNewRole, 1321 theOldRoleValue); 1322 } catch (RelationNotFoundException exc) { 1323 throw new RuntimeException (exc.getMessage()); 1324 } 1325 1326 } else { 1327 1328 Object [] params = new Object [3]; 1329 params[0] = myRelId; 1330 params[1] = theNewRole; 1331 params[2] = ((ArrayList )theOldRoleValue); 1332 String [] signature = new String [3]; 1333 signature[0] = "java.lang.String"; 1334 signature[1] = "javax.management.relation.Role"; 1335 signature[2] = "java.util.List"; 1336 1337 try { 1346 myRelServiceMBeanServer.invoke(myRelServiceName, 1347 "sendRoleUpdateNotification", 1348 params, 1349 signature); 1350 } catch (ReflectionException exc1) { 1351 throw new RuntimeException (exc1.getMessage()); 1352 } catch (InstanceNotFoundException exc2) { 1353 throw new RelationServiceNotRegisteredException ( 1354 exc2.getMessage()); 1355 } catch (MBeanException exc3) { 1356 Exception wrappedExc = exc3.getTargetException(); 1357 if (wrappedExc instanceof RelationNotFoundException ) { 1358 throw ((RelationNotFoundException )wrappedExc); 1359 } else { 1360 throw new RuntimeException (wrappedExc.getMessage()); 1361 } 1362 } 1363 } 1364 1365 if (isDebugOn()) 1366 debug("sendRoleUpdateNotification: exiting", null); 1367 return; 1368 } 1369 1370 private void updateRelationServiceMap(Role theNewRole, 1393 List theOldRoleValue, 1394 boolean theRelServCallFlg, 1395 RelationService theRelServ) 1396 throws IllegalArgumentException , 1397 RelationServiceNotRegisteredException , 1398 RelationNotFoundException { 1399 1400 if (theNewRole == null || 1401 theOldRoleValue == null || 1402 (theRelServCallFlg && theRelServ == null)) { 1403 String excMsg = "Invalid parameter."; 1405 throw new IllegalArgumentException (excMsg); 1406 } 1407 1408 if (isDebugOn()) { 1409 String str = 1410 "theNewRole " + theNewRole 1411 + ", theOldRoleValue " + theOldRoleValue 1412 + ", theRelServCallFlg " + theRelServCallFlg; 1413 debug("updateRelationServiceMap: entering", str); 1414 } 1415 1416 if (theRelServCallFlg) { 1417 try { 1420 theRelServ.updateRoleMap(myRelId, 1421 theNewRole, 1422 theOldRoleValue); 1423 } catch (RelationNotFoundException exc) { 1424 throw new RuntimeException (exc.getMessage()); 1425 } 1426 1427 } else { 1428 Object [] params = new Object [3]; 1429 params[0] = myRelId; 1430 params[1] = theNewRole; 1431 params[2] = theOldRoleValue; 1432 String [] signature = new String [3]; 1433 signature[0] = "java.lang.String"; 1434 signature[1] = "javax.management.relation.Role"; 1435 signature[2] = "java.util.List"; 1436 try { 1443 myRelServiceMBeanServer.invoke(myRelServiceName, 1444 "updateRoleMap", 1445 params, 1446 signature); 1447 } catch (ReflectionException exc1) { 1448 throw new RuntimeException (exc1.getMessage()); 1449 } catch (InstanceNotFoundException exc2) { 1450 throw new 1451 RelationServiceNotRegisteredException (exc2.getMessage()); 1452 } catch (MBeanException exc3) { 1453 Exception wrappedExc = exc3.getTargetException(); 1454 if (wrappedExc instanceof RelationNotFoundException ) { 1455 throw ((RelationNotFoundException )wrappedExc); 1456 } else { 1457 throw new RuntimeException (wrappedExc.getMessage()); 1458 } 1459 } 1460 } 1461 1462 if (isDebugOn()) 1463 debug("updateRelationServiceMap: exiting", null); 1464 return; 1465 } 1466 1467 RoleResult setRolesInt(RoleList theRoleList, 1500 boolean theRelServCallFlg, 1501 RelationService theRelServ) 1502 throws IllegalArgumentException , 1503 RelationServiceNotRegisteredException , 1504 RelationTypeNotFoundException , 1505 RelationNotFoundException { 1506 1507 if (theRoleList == null || 1508 (theRelServCallFlg && theRelServ == null)) { 1509 String excMsg = "Invalid parameter."; 1511 throw new IllegalArgumentException (excMsg); 1512 } 1513 1514 if (isDebugOn()) { 1515 String str = 1516 "theRoleList " + theRoleList 1517 + ", theRelServCallFlg " + theRelServCallFlg; 1518 debug("setRolesInt: entering", str); 1519 } 1520 1521 RoleList roleList = new RoleList (); 1522 RoleUnresolvedList roleUnresList = new RoleUnresolvedList (); 1523 1524 for (Iterator roleIter = theRoleList.iterator(); 1525 roleIter.hasNext();) { 1526 1527 Role currRole = (Role )(roleIter.next()); 1528 1529 Object currResult = null; 1530 try { 1538 currResult = setRoleInt(currRole, 1539 theRelServCallFlg, 1540 theRelServ, 1541 true); 1542 } catch (RoleNotFoundException exc1) { 1543 } catch (InvalidRoleValueException exc2) { 1545 } 1547 1548 if (currResult instanceof Role ) { 1549 try { 1552 roleList.add((Role )currResult); 1553 } catch (IllegalArgumentException exc) { 1554 throw new RuntimeException (exc.getMessage()); 1555 } 1556 1557 } else if (currResult instanceof RoleUnresolved ) { 1558 try { 1561 roleUnresList.add((RoleUnresolved )currResult); 1562 } catch (IllegalArgumentException exc) { 1563 throw new RuntimeException (exc.getMessage()); 1564 } 1565 } 1566 } 1567 1568 RoleResult result = new RoleResult (roleList, roleUnresList); 1569 1570 if (isDebugOn()) 1571 debug("setRolesInt: exiting", null); 1572 return result; 1573 } 1574 1575 private void initMembers(String theRelId, 1601 ObjectName theRelServiceName, 1602 MBeanServer theRelServiceMBeanServer, 1603 String theRelTypeName, 1604 RoleList theRoleList) 1605 throws InvalidRoleValueException , 1606 IllegalArgumentException { 1607 1608 if (theRelId == null || 1609 theRelServiceName == null || 1610 theRelTypeName == null) { 1611 String excMsg = "Invalid parameter."; 1613 throw new IllegalArgumentException (excMsg); 1614 } 1615 1616 if (isDebugOn()) { 1617 StringBuffer strB = 1618 new StringBuffer ("theRelId " + theRelId 1619 + ", theRelServiceName " 1620 + theRelServiceName.toString() 1621 + ", theRelTypeName " + theRelTypeName); 1622 if (theRoleList != null) { 1623 strB.append(", theRoleList " + theRoleList.toString()); 1624 } 1625 debug("initMembers: entering", strB.toString()); 1626 } 1627 1628 myRelId = theRelId; 1629 myRelServiceName = theRelServiceName; 1630 myRelServiceMBeanServer = theRelServiceMBeanServer; 1631 myRelTypeName = theRelTypeName; 1632 initRoleMap(theRoleList); 1634 myInRelServFlg = new Boolean (false); 1635 1636 if (isDebugOn()) 1637 debug("initMembers: exiting", null); 1638 return; 1639 } 1640 1641 private void initRoleMap(RoleList theRoleList) 1650 throws InvalidRoleValueException { 1651 1652 if (theRoleList == null) { 1653 return; 1654 } 1655 1656 if (isDebugOn()) 1657 debug("initRoleMap: entering", theRoleList.toString()); 1658 1659 synchronized(myRoleName2ValueMap) { 1660 1661 for (Iterator roleIter = theRoleList.iterator(); 1662 roleIter.hasNext();) { 1663 1664 Role currRole = (Role )(roleIter.next()); 1667 String currRoleName = currRole.getRoleName(); 1668 1669 if (myRoleName2ValueMap.containsKey(currRoleName)) { 1670 StringBuffer excMsgStrB = new StringBuffer ("Role name "); 1673 excMsgStrB.append(currRoleName); 1674 excMsgStrB.append(" used for two roles."); 1675 throw new InvalidRoleValueException (excMsgStrB.toString()); 1676 } 1677 1678 myRoleName2ValueMap.put(currRoleName, 1679 (Role )(currRole.clone())); 1680 } 1681 } 1682 1683 if (isDebugOn()) 1684 debug("initRoleMap: exiting", null); 1685 return; 1686 } 1687 1688 void handleMBeanUnregistrationInt(ObjectName theObjName, 1727 String theRoleName, 1728 boolean theRelServCallFlg, 1729 RelationService theRelServ) 1730 throws IllegalArgumentException , 1731 RoleNotFoundException , 1732 InvalidRoleValueException , 1733 RelationServiceNotRegisteredException , 1734 RelationTypeNotFoundException , 1735 RelationNotFoundException { 1736 1737 if (theObjName == null || 1738 theRoleName == null || 1739 (theRelServCallFlg && theRelServ == null)) { 1740 String excMsg = "Invalid parameter."; 1742 throw new IllegalArgumentException (excMsg); 1743 } 1744 1745 if (isDebugOn()) { 1746 String str = 1747 "theObjName " + theObjName 1748 + ", theRoleName " + theRoleName 1749 + ", theRelServCallFlg " + theRelServCallFlg; 1750 debug("handleMBeanUnregistrationInt: entering", str); 1751 } 1752 1753 Role role = null; 1755 synchronized(myRoleName2ValueMap) { 1756 role = (Role )(myRoleName2ValueMap.get(theRoleName)); 1757 } 1758 1759 if (role == null) { 1760 StringBuffer excMsgStrB = new StringBuffer (); 1761 String excMsg = "No role with name "; 1763 excMsgStrB.append(excMsg); 1764 excMsgStrB.append(theRoleName); 1765 throw new RoleNotFoundException (excMsgStrB.toString()); 1766 } 1767 ArrayList currRoleValue = (ArrayList )(role.getRoleValue()); 1768 1769 ArrayList newRoleValue = (ArrayList )(currRoleValue.clone()); 1772 newRoleValue.remove(theObjName); 1773 Role newRole = new Role (theRoleName, newRoleValue); 1774 1775 Object result = 1779 setRoleInt(newRole, theRelServCallFlg, theRelServ, false); 1780 1781 if (isDebugOn()) 1782 debug("handleMBeanUnregistrationInt: exiting", null); 1783 return; 1784 } 1785 1786 1788 private static String localClassName = "RelationSupport"; 1789 1790 private boolean isTraceOn() { 1792 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_RELATION); 1793 } 1794 1795 1799 private void trace(String methodName, String info) { 1800 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, localClassName, methodName, info); 1801 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, "", "", "\n"); 1802 } 1803 1804 1808 1812 private boolean isDebugOn() { 1814 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_RELATION); 1815 } 1816 1817 1821 private void debug(String methodName, String info) { 1822 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, localClassName, methodName, info); 1823 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, "", "", "\n"); 1824 } 1825 1826 1830} 1834 | Popular Tags |