1 7 8 package javax.management.relation; 9 10 import java.io.IOException ; 11 import java.io.ObjectInputStream ; 12 import java.io.ObjectOutputStream ; 13 import java.io.ObjectStreamField ; 14 import java.io.Serializable ; 15 import java.security.AccessController ; 16 import java.security.PrivilegedAction ; 17 18 import javax.management.NotCompliantMBeanException ; 19 import javax.management.MBeanInfo ; 20 import javax.management.MBeanServer ; 21 import javax.management.loading.ClassLoaderRepository ; 22 23 import com.sun.jmx.mbeanserver.GetPropertyAction; 24 import com.sun.jmx.mbeanserver.Introspector; 25 26 27 32 public class RoleInfo implements Serializable { 33 34 private static final long oldSerialVersionUID = 7227256952085334351L; 42 private static final long newSerialVersionUID = 2504952983494636987L; 45 private static final ObjectStreamField [] oldSerialPersistentFields = 48 { 49 new ObjectStreamField ("myName", String .class), 50 new ObjectStreamField ("myIsReadableFlg", boolean.class), 51 new ObjectStreamField ("myIsWritableFlg", boolean.class), 52 new ObjectStreamField ("myDescription", String .class), 53 new ObjectStreamField ("myMinDegree", int.class), 54 new ObjectStreamField ("myMaxDegree", int.class), 55 new ObjectStreamField ("myRefMBeanClassName", String .class) 56 }; 57 private static final ObjectStreamField [] newSerialPersistentFields = 60 { 61 new ObjectStreamField ("name", String .class), 62 new ObjectStreamField ("isReadable", boolean.class), 63 new ObjectStreamField ("isWritable", boolean.class), 64 new ObjectStreamField ("description", String .class), 65 new ObjectStreamField ("minDegree", int.class), 66 new ObjectStreamField ("maxDegree", int.class), 67 new ObjectStreamField ("referencedMBeanClassName", String .class) 68 }; 69 private static final long serialVersionUID; 72 81 private static final ObjectStreamField [] serialPersistentFields; 82 private static boolean compat = false; 83 static { 84 try { 85 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 86 String form = (String ) AccessController.doPrivileged(act); 87 compat = (form != null && form.equals("1.0")); 88 } catch (Exception e) { 89 } 91 if (compat) { 92 serialPersistentFields = oldSerialPersistentFields; 93 serialVersionUID = oldSerialVersionUID; 94 } else { 95 serialPersistentFields = newSerialPersistentFields; 96 serialVersionUID = newSerialVersionUID; 97 } 98 } 99 102 106 109 public static int ROLE_CARDINALITY_INFINITY = -1; 110 111 115 118 private String name = null; 119 120 123 private boolean isReadable; 124 125 128 private boolean isWritable; 129 130 133 private String description = null; 134 135 138 private int minDegree; 139 140 143 private int maxDegree; 144 145 148 private String referencedMBeanClassName = null; 149 150 154 185 public RoleInfo(String theName, 186 String theRefMBeanClassName, 187 boolean theIsReadable, 188 boolean theIsWritable, 189 int theMinDegree, 190 int theMaxDegree, 191 String theDescription) 192 throws IllegalArgumentException , 193 InvalidRoleInfoException , 194 ClassNotFoundException , 195 NotCompliantMBeanException { 196 197 init(theName, 198 theRefMBeanClassName, 199 theIsReadable, 200 theIsWritable, 201 theMinDegree, 202 theMaxDegree, 203 theDescription); 204 return; 205 } 206 207 231 public RoleInfo(String theName, 232 String theRefMBeanClassName, 233 boolean theIsReadable, 234 boolean theIsWritable) 235 throws IllegalArgumentException , 236 ClassNotFoundException , 237 NotCompliantMBeanException { 238 239 try { 240 init(theName, 241 theRefMBeanClassName, 242 theIsReadable, 243 theIsWritable, 244 1, 245 1, 246 null); 247 } catch (InvalidRoleInfoException exc) { 248 } 251 252 return; 253 } 254 255 276 public RoleInfo(String theName, 277 String theRefMBeanClassName) 278 throws IllegalArgumentException , 279 ClassNotFoundException , 280 NotCompliantMBeanException { 281 282 try { 283 init(theName, 284 theRefMBeanClassName, 285 true, 286 true, 287 1, 288 1, 289 null); 290 } catch (InvalidRoleInfoException exc) { 291 } 294 295 return; 296 } 297 298 305 public RoleInfo(RoleInfo theRoleInfo) 306 throws IllegalArgumentException { 307 308 if (theRoleInfo == null) { 309 String excMsg = "Invalid parameter."; 311 throw new IllegalArgumentException (excMsg); 312 } 313 314 try { 315 init(theRoleInfo.getName(), 316 theRoleInfo.getRefMBeanClassName(), 317 theRoleInfo.isReadable(), 318 theRoleInfo.isWritable(), 319 theRoleInfo.getMinDegree(), 320 theRoleInfo.getMaxDegree(), 321 theRoleInfo.getDescription()); 322 } catch (InvalidRoleInfoException exc3) { 323 } 327 } 328 329 333 338 public String getName() { 339 return name; 340 } 341 342 347 public boolean isReadable() { 348 return isReadable; 349 } 350 351 356 public boolean isWritable() { 357 return isWritable; 358 } 359 360 365 public String getDescription() { 366 return description; 367 } 368 369 374 public int getMinDegree() { 375 return minDegree; 376 } 377 378 383 public int getMaxDegree() { 384 return maxDegree; 385 } 386 387 393 public String getRefMBeanClassName() { 394 return referencedMBeanClassName; 395 } 396 397 405 public boolean checkMinDegree(int theValue) { 406 if (theValue >= ROLE_CARDINALITY_INFINITY && 407 (minDegree == ROLE_CARDINALITY_INFINITY 408 || theValue >= minDegree)) { 409 return true; 410 } else { 411 return false; 412 } 413 } 414 415 423 public boolean checkMaxDegree(int theValue) { 424 if (theValue >= ROLE_CARDINALITY_INFINITY && 425 (maxDegree == ROLE_CARDINALITY_INFINITY || 426 (theValue != ROLE_CARDINALITY_INFINITY && 427 theValue <= maxDegree))) { 428 return true; 429 } else { 430 return false; 431 } 432 } 433 434 439 public String toString() { 440 StringBuffer result = new StringBuffer (); 441 result.append("role info name: " + name); 442 result.append("; isReadable: " + isReadable); 443 result.append("; isWritable: " + isWritable); 444 result.append("; description: " + description); 445 result.append("; minimum degree: " + minDegree); 446 result.append("; maximum degree: " + maxDegree); 447 result.append("; MBean class: " + referencedMBeanClassName); 448 return result.toString(); 449 } 450 451 455 private void init(String theName, 457 String theRefMBeanClassName, 458 boolean theIsReadable, 459 boolean theIsWritable, 460 int theMinDegree, 461 int theMaxDegree, 462 String theDescription) 463 throws IllegalArgumentException , 464 InvalidRoleInfoException { 465 466 if (theName == null || 467 theRefMBeanClassName == null) { 468 String excMsg = "Invalid parameter."; 470 throw new IllegalArgumentException (excMsg); 471 } 472 473 name = theName; 474 isReadable = theIsReadable; 475 isWritable = theIsWritable; 476 if (theDescription != null) { 477 description = theDescription; 478 } 479 480 boolean invalidRoleInfoFlg = false; 481 StringBuffer excMsgStrB = new StringBuffer (); 482 if (theMaxDegree != ROLE_CARDINALITY_INFINITY && 483 (theMinDegree == ROLE_CARDINALITY_INFINITY || 484 theMinDegree > theMaxDegree)) { 485 excMsgStrB.append("Minimum degree "); 487 excMsgStrB.append(theMinDegree); 488 excMsgStrB.append(" is greater than maximum degree "); 489 excMsgStrB.append(theMaxDegree); 490 invalidRoleInfoFlg = true; 491 492 } else if (theMinDegree < ROLE_CARDINALITY_INFINITY || 493 theMaxDegree < ROLE_CARDINALITY_INFINITY) { 494 excMsgStrB.append("Minimum or maximum degree has an illegal value, must be [0, ROLE_CARDINALITY_INFINITY]."); 496 invalidRoleInfoFlg = true; 497 } 498 if (invalidRoleInfoFlg) { 499 throw new InvalidRoleInfoException (excMsgStrB.toString()); 500 } 501 minDegree = theMinDegree; 502 maxDegree = theMaxDegree; 503 504 referencedMBeanClassName = theRefMBeanClassName; 505 506 return; 507 } 508 509 512 private void readObject(ObjectInputStream in) 513 throws IOException , ClassNotFoundException { 514 if (compat) 515 { 516 ObjectInputStream.GetField fields = in.readFields(); 519 name = (String ) fields.get("myName", null); 520 if (fields.defaulted("myName")) 521 { 522 throw new NullPointerException ("myName"); 523 } 524 isReadable = fields.get("myIsReadableFlg", false); 525 if (fields.defaulted("myIsReadableFlg")) 526 { 527 throw new NullPointerException ("myIsReadableFlg"); 528 } 529 isWritable = fields.get("myIsWritableFlg", false); 530 if (fields.defaulted("myIsWritableFlg")) 531 { 532 throw new NullPointerException ("myIsWritableFlg"); 533 } 534 description = (String ) fields.get("myDescription", null); 535 if (fields.defaulted("myDescription")) 536 { 537 throw new NullPointerException ("myDescription"); 538 } 539 minDegree = fields.get("myMinDegree", (int)0); 540 if (fields.defaulted("myMinDegree")) 541 { 542 throw new NullPointerException ("myMinDegree"); 543 } 544 maxDegree = fields.get("myMaxDegree", (int)0); 545 if (fields.defaulted("myMaxDegree")) 546 { 547 throw new NullPointerException ("myMaxDegree"); 548 } 549 referencedMBeanClassName = (String ) fields.get("myRefMBeanClassName", null); 550 if (fields.defaulted("myRefMBeanClassName")) 551 { 552 throw new NullPointerException ("myRefMBeanClassName"); 553 } 554 } 555 else 556 { 557 in.defaultReadObject(); 560 } 561 } 562 563 564 567 private void writeObject(ObjectOutputStream out) 568 throws IOException { 569 if (compat) 570 { 571 ObjectOutputStream.PutField fields = out.putFields(); 574 fields.put("myName", name); 575 fields.put("myIsReadableFlg", isReadable); 576 fields.put("myIsWritableFlg", isWritable); 577 fields.put("myDescription", description); 578 fields.put("myMinDegree", minDegree); 579 fields.put("myMaxDegree", maxDegree); 580 fields.put("myRefMBeanClassName", referencedMBeanClassName); 581 out.writeFields(); 582 } 583 else 584 { 585 out.defaultWriteObject(); 588 } 589 } 590 591 } 592 | Popular Tags |