1 7 8 package javax.management.relation; 9 10 import javax.management.Notification ; 11 import javax.management.ObjectName ; 12 13 import java.io.IOException ; 14 import java.io.ObjectInputStream ; 15 import java.io.ObjectOutputStream ; 16 import java.io.ObjectStreamField ; 17 18 import java.security.AccessController ; 19 import java.security.PrivilegedAction ; 20 21 import java.util.ArrayList ; 22 import java.util.Collections ; 23 import java.util.List ; 24 25 import com.sun.jmx.mbeanserver.GetPropertyAction; 26 27 36 public class RelationNotification extends Notification { 37 38 private static final long oldSerialVersionUID = -2126464566505527147L; 46 private static final long newSerialVersionUID = -6871117877523310399L; 49 private static final ObjectStreamField [] oldSerialPersistentFields = 52 { 53 new ObjectStreamField ("myNewRoleValue", ArrayList .class), 54 new ObjectStreamField ("myOldRoleValue", ArrayList .class), 55 new ObjectStreamField ("myRelId", String .class), 56 new ObjectStreamField ("myRelObjName", ObjectName .class), 57 new ObjectStreamField ("myRelTypeName", String .class), 58 new ObjectStreamField ("myRoleName", String .class), 59 new ObjectStreamField ("myUnregMBeanList", ArrayList .class) 60 }; 61 private static final ObjectStreamField [] newSerialPersistentFields = 64 { 65 new ObjectStreamField ("newRoleValue", List .class), 66 new ObjectStreamField ("oldRoleValue", List .class), 67 new ObjectStreamField ("relationId", String .class), 68 new ObjectStreamField ("relationObjName", ObjectName .class), 69 new ObjectStreamField ("relationTypeName", String .class), 70 new ObjectStreamField ("roleName", String .class), 71 new ObjectStreamField ("unregisterMBeanList", List .class) 72 }; 73 private static final long serialVersionUID; 76 87 private static final ObjectStreamField [] serialPersistentFields; 88 private static boolean compat = false; 89 static { 90 try { 91 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 92 String form = (String ) AccessController.doPrivileged(act); 93 compat = (form != null && form.equals("1.0")); 94 } catch (Exception e) { 95 } 97 if (compat) { 98 serialPersistentFields = oldSerialPersistentFields; 99 serialVersionUID = oldSerialVersionUID; 100 } else { 101 serialPersistentFields = newSerialPersistentFields; 102 serialVersionUID = newSerialVersionUID; 103 } 104 } 105 108 112 115 public static final String RELATION_BASIC_CREATION = "jmx.relation.creation.basic"; 116 119 public static final String RELATION_MBEAN_CREATION = "jmx.relation.creation.mbean"; 120 123 public static final String RELATION_BASIC_UPDATE = "jmx.relation.update.basic"; 124 127 public static final String RELATION_MBEAN_UPDATE = "jmx.relation.update.mbean"; 128 131 public static final String RELATION_BASIC_REMOVAL = "jmx.relation.removal.basic"; 132 135 public static final String RELATION_MBEAN_REMOVAL = "jmx.relation.removal.mbean"; 136 137 141 144 private String relationId = null; 145 146 149 private String relationTypeName = null; 150 151 155 private ObjectName relationObjName = null; 156 157 161 private List unregisterMBeanList = null; 162 163 166 private String roleName = null; 167 168 171 private List oldRoleValue = null; 172 173 176 private List newRoleValue = null; 177 178 182 216 public RelationNotification(String theNtfType, 217 Object theSrcObj, 218 long TheSeqNbr, 219 long theTimeStamp, 220 String theMsg, 221 String theRelId, 222 String theRelTypeName, 223 ObjectName theRelObjName, 224 List theUnregMBeanList) 225 throws IllegalArgumentException { 226 227 super(theNtfType, theSrcObj, TheSeqNbr, theTimeStamp, theMsg); 228 229 initMembers(1, 231 theNtfType, 232 theSrcObj, 233 TheSeqNbr, 234 theTimeStamp, 235 theMsg, 236 theRelId, 237 theRelTypeName, 238 theRelObjName, 239 theUnregMBeanList, 240 null, 241 null, 242 null); 243 return; 244 } 245 246 268 public RelationNotification(String theNtfType, 269 Object theSrcObj, 270 long TheSeqNbr, 271 long theTimeStamp, 272 String theMsg, 273 String theRelId, 274 String theRelTypeName, 275 ObjectName theRelObjName, 276 String theRoleName, 277 List theNewRoleValue, 278 List theOldRoleValue 279 ) 280 throws IllegalArgumentException { 281 282 super(theNtfType, theSrcObj, TheSeqNbr, theTimeStamp, theMsg); 283 284 initMembers(2, 286 theNtfType, 287 theSrcObj, 288 TheSeqNbr, 289 theTimeStamp, 290 theMsg, 291 theRelId, 292 theRelTypeName, 293 theRelObjName, 294 null, 295 theRoleName, 296 theNewRoleValue, 297 theOldRoleValue); 298 return; 299 } 300 301 305 310 public String getRelationId() { 311 return relationId; 312 } 313 314 319 public String getRelationTypeName() { 320 return relationTypeName; 321 } 322 323 329 public ObjectName getObjectName() { 330 return relationObjName; 331 } 332 333 339 public List getMBeansToUnregister() { 340 List result = null; 341 if (unregisterMBeanList != null) { 342 result = (List )((ArrayList )unregisterMBeanList).clone(); 343 } else { 344 result = Collections.EMPTY_LIST; 345 } 346 return result; 347 } 348 349 354 public String getRoleName() { 355 String result = null; 356 if (roleName != null) { 357 result = roleName; 358 } 359 return result; 360 } 361 362 367 public List getOldRoleValue() { 368 List result = null; 369 if (oldRoleValue != null) { 370 result = (List )((ArrayList )oldRoleValue).clone(); 371 } else { 372 result = Collections.EMPTY_LIST; 373 } 374 return result; 375 } 376 377 382 public List getNewRoleValue() { 383 List result = null; 384 if (newRoleValue != null) { 385 result = (List )((ArrayList )newRoleValue).clone(); 386 } else { 387 result = Collections.EMPTY_LIST; 388 } 389 return result; 390 } 391 392 396 private void initMembers(int theNtfKind, 435 String theNtfType, 436 Object theSrcObj, 437 long TheSeqNbr, 438 long theTimeStamp, 439 String theMsg, 440 String theRelId, 441 String theRelTypeName, 442 ObjectName theRelObjName, 443 List theUnregMBeanList, 444 String theRoleName, 445 List theNewRoleValue, 446 List theOldRoleValue) 447 throws IllegalArgumentException { 448 449 boolean badInitFlg = false; 450 451 if (theNtfType == null || 452 theSrcObj == null || 453 (!(theSrcObj instanceof RelationService )) || 454 theRelId == null || 455 theRelTypeName == null) { 456 457 badInitFlg = true; 458 } 459 460 if (theNtfKind == 1) { 461 462 if ((!(theNtfType.equals(RelationNotification.RELATION_BASIC_CREATION))) 463 && 464 (!(theNtfType.equals(RelationNotification.RELATION_MBEAN_CREATION))) 465 && 466 (!(theNtfType.equals(RelationNotification.RELATION_BASIC_REMOVAL))) 467 && 468 (!(theNtfType.equals(RelationNotification.RELATION_MBEAN_REMOVAL))) 469 ) { 470 471 badInitFlg = true; 473 } 474 475 } else if (theNtfKind == 2) { 476 477 if (((!(theNtfType.equals(RelationNotification.RELATION_BASIC_UPDATE))) 478 && 479 (!(theNtfType.equals(RelationNotification.RELATION_MBEAN_UPDATE)))) 480 || theRoleName == null || 481 theOldRoleValue == null || 482 theNewRoleValue == null) { 483 484 badInitFlg = true; 486 } 487 } 488 489 if (badInitFlg) { 490 String excMsg = "Invalid parameter."; 492 throw new IllegalArgumentException (excMsg); 493 } 494 495 relationId = theRelId; 496 relationTypeName = theRelTypeName; 497 relationObjName = theRelObjName; 498 if (theUnregMBeanList != null) { 499 unregisterMBeanList = new ArrayList (theUnregMBeanList); 500 } 501 if (theRoleName != null) { 502 roleName = theRoleName; 503 } 504 if (theOldRoleValue != null) { 505 oldRoleValue = new ArrayList (theOldRoleValue); 506 } 507 if (theNewRoleValue != null) { 508 newRoleValue = new ArrayList (theNewRoleValue); 509 } 510 return; 511 } 512 513 516 private void readObject(ObjectInputStream in) 517 throws IOException , ClassNotFoundException { 518 if (compat) 519 { 520 ObjectInputStream.GetField fields = in.readFields(); 523 newRoleValue = (List ) fields.get("myNewRoleValue", null); 524 if (fields.defaulted("myNewRoleValue")) 525 { 526 throw new NullPointerException ("newRoleValue"); 527 } 528 oldRoleValue = (List ) fields.get("myOldRoleValue", null); 529 if (fields.defaulted("myOldRoleValue")) 530 { 531 throw new NullPointerException ("oldRoleValue"); 532 } 533 relationId = (String ) fields.get("myRelId", null); 534 if (fields.defaulted("myRelId")) 535 { 536 throw new NullPointerException ("relationId"); 537 } 538 relationObjName = (ObjectName ) fields.get("myRelObjName", null); 539 if (fields.defaulted("myRelObjName")) 540 { 541 throw new NullPointerException ("relationObjName"); 542 } 543 relationTypeName = (String ) fields.get("myRelTypeName", null); 544 if (fields.defaulted("myRelTypeName")) 545 { 546 throw new NullPointerException ("relationTypeName"); 547 } 548 roleName = (String ) fields.get("myRoleName", null); 549 if (fields.defaulted("myRoleName")) 550 { 551 throw new NullPointerException ("roleName"); 552 } 553 unregisterMBeanList = (List ) fields.get("myUnregMBeanList", null); 554 if (fields.defaulted("myUnregMBeanList")) 555 { 556 throw new NullPointerException ("unregisterMBeanList"); 557 } 558 } 559 else 560 { 561 in.defaultReadObject(); 564 } 565 } 566 567 568 571 private void writeObject(ObjectOutputStream out) 572 throws IOException { 573 if (compat) 574 { 575 ObjectOutputStream.PutField fields = out.putFields(); 578 fields.put("myNewRoleValue", newRoleValue); 579 fields.put("myOldRoleValue", oldRoleValue); 580 fields.put("myRelId", relationId); 581 fields.put("myRelObjName", relationObjName); 582 fields.put("myRelTypeName", relationTypeName); 583 fields.put("myRoleName",roleName); 584 fields.put("myUnregMBeanList", unregisterMBeanList); 585 out.writeFields(); 586 } 587 else 588 { 589 out.defaultWriteObject(); 592 } 593 } 594 } 595 | Popular Tags |