189 /** 190 * @serial include 191 */ 192 private static class UnmodifiablePrintServiceAttributeSet 193 extends UnmodifiableAttributeSet 194 implements PrintServiceAttributeSet, Serializable 195 { 196 private static final long serialVersionUID = -7112165137107826819L; 197 public UnmodifiablePrintServiceAttributeSet 198 (PrintServiceAttributeSet attributeSet) { 199 200 super (attributeSet); 201 } 202 } 203 204 /** 205 * Creates an unmodifiable view of the given attribute set. 206 * 207 * @param attributeSet Underlying attribute set. 208 * 209 * @return Unmodifiable view of <CODE>attributeSet</CODE>. 210 * 211 * @exception NullPointerException 212 * Thrown if <CODE>attributeSet</CODE> is null. Null is never a 213 */ 214 public static AttributeSet unmodifiableView(AttributeSet attributeSet) { 215 if (attributeSet == null) { 216 throw new NullPointerException(); 217 } 218 219 return new UnmodifiableAttributeSet(attributeSet); 220 } 221 222 /** 223 * Creates an unmodifiable view of the given doc attribute set. 224 * 225 * @param attributeSet Underlying doc attribute set. 226 * 227 * @return Unmodifiable view of <CODE>attributeSet</CODE>. 228 * 229 * @exception NullPointerException 230 * Thrown if <CODE>attributeSet</CODE> is null. 231 */ 232 public static DocAttributeSet unmodifiableView 233 (DocAttributeSet attributeSet) { 234 if (attributeSet == null) { 235 throw new NullPointerException(); 236 } 237 return new UnmodifiableDocAttributeSet(attributeSet); 238 } 239 240 /** 241 * Creates an unmodifiable view of the given print request attribute set. 242 * 243 * @param attributeSet Underlying print request attribute set. 244 * 245 * @return Unmodifiable view of <CODE>attributeSet</CODE>. 246 * 247 * @exception NullPointerException 248 * Thrown if <CODE>attributeSet</CODE> is null. 249 */ 250 public static PrintRequestAttributeSet 251 unmodifiableView(PrintRequestAttributeSet attributeSet) { 252 if (attributeSet == null) { 253 throw new NullPointerException(); 254 } 255 return new UnmodifiablePrintRequestAttributeSet(attributeSet); 256 } 257 258 /** 259 * Creates an unmodifiable view of the given print job attribute set. 260 * 261 * @param attributeSet Underlying print job attribute set. 262 * 263 * @return Unmodifiable view of <CODE>attributeSet</CODE>. 264 * 265 * @exception NullPointerException 266 * Thrown if <CODE>attributeSet</CODE> is null. 267 */ 268 public static PrintJobAttributeSet 269 unmodifiableView(PrintJobAttributeSet attributeSet) { 270 if (attributeSet == null) { 271 throw new NullPointerException(); 272 } 273 return new UnmodifiablePrintJobAttributeSet(attributeSet); 274 } 275 276 /** 277 * Creates an unmodifiable view of the given print service attribute set. 278 * 279 * @param attributeSet Underlying print service attribute set. 280 * 281 * @return Unmodifiable view of <CODE>attributeSet</CODE>. 282 * 283 * @exception NullPointerException 284 * Thrown if <CODE>attributeSet</CODE> is null. 285 */ 286 public static PrintServiceAttributeSet 287 unmodifiableView(PrintServiceAttributeSet attributeSet) { 288 if (attributeSet == null) { 289 throw new NullPointerException(); 290 } 291 return new UnmodifiablePrintServiceAttributeSet (attributeSet); 292 } 293 294 /** 295 * @serial include 296 */ 297 private static class SynchronizedAttributeSet 298 implements AttributeSet, Serializable { 299 private static final long serialVersionUID = 8365731020128564925L; 300 301 private AttributeSet attrset; 302 303 public SynchronizedAttributeSet(AttributeSet attributeSet) { 304 attrset = attributeSet; 400 401 /** 402 * @serial include 403 */ 404 private static class SynchronizedPrintServiceAttributeSet 405 extends SynchronizedAttributeSet 406 implements PrintServiceAttributeSet, Serializable { 407 private static final long serialVersionUID = -2830705374001675073L; 408 409 public SynchronizedPrintServiceAttributeSet 410 (PrintServiceAttributeSet attributeSet) { 411 super(attributeSet); 412 } 413 } 414 415 /** 416 * Creates a synchronized view of the given attribute set. 417 * 418 * @param attributeSet Underlying attribute set. 419 * 420 * @return Synchronized view of <CODE>attributeSet</CODE>. 421 * 422 * @exception NullPointerException 423 * Thrown if <CODE>attributeSet</CODE> is null. 424 */ 425 public static AttributeSet synchronizedView 426 (AttributeSet attributeSet) { 427 if (attributeSet == null) { 428 throw new NullPointerException(); 429 } 430 return new SynchronizedAttributeSet(attributeSet); 431 } 432 433 /** 434 * Creates a synchronized view of the given doc attribute set. 435 * 436 * @param attributeSet Underlying doc attribute set. 437 * 438 * @return Synchronized view of <CODE>attributeSet</CODE>. 439 * 440 * @exception NullPointerException 441 * Thrown if <CODE>attributeSet</CODE> is null. 442 */ 443 public static DocAttributeSet 444 synchronizedView(DocAttributeSet attributeSet) { 445 if (attributeSet == null) { 446 throw new NullPointerException(); 447 } 448 return new SynchronizedDocAttributeSet(attributeSet); 449 } 450 451 /** 452 * Creates a synchronized view of the given print request attribute set. 453 * 454 * @param attributeSet Underlying print request attribute set. 455 * 456 * @return Synchronized view of <CODE>attributeSet</CODE>. 457 * 458 * @exception NullPointerException 459 * Thrown if <CODE>attributeSet</CODE> is null. 460 */ 461 public static PrintRequestAttributeSet 462 synchronizedView(PrintRequestAttributeSet attributeSet) { 463 if (attributeSet == null) { 464 throw new NullPointerException(); 465 } 466 return new SynchronizedPrintRequestAttributeSet(attributeSet); 467 } 468 469 /** 470 * Creates a synchronized view of the given print job attribute set. 471 * 472 * @param attributeSet Underlying print job attribute set. 473 * 474 * @return Synchronized view of <CODE>attributeSet</CODE>. 475 * 476 * @exception NullPointerException 477 * Thrown if <CODE>attributeSet</CODE> is null. 478 */ 479 public static PrintJobAttributeSet 480 synchronizedView(PrintJobAttributeSet attributeSet) { 481 if (attributeSet == null) { 482 throw new NullPointerException(); 483 } 484 return new SynchronizedPrintJobAttributeSet(attributeSet); 485 } 486 487 /** 488 * Creates a synchronized view of the given print service attribute set. 489 * 490 * @param attributeSet Underlying print service attribute set. 491 * 492 * @return Synchronized view of <CODE>attributeSet</CODE>. 493 */ 494 public static PrintServiceAttributeSet 495 synchronizedView(PrintServiceAttributeSet attributeSet) { 496 if (attributeSet == null) { 497 throw new NullPointerException(); 498 } 499 return new SynchronizedPrintServiceAttributeSet(attributeSet); 500 } 501 502 503 /** 504 * Verify that the given object is a {@link java.lang.Class Class} that 505 * implements the given interface, which is assumed to be interface {@link 506 * Attribute Attribute} or a subinterface thereof. 507 * 508 * @param object Object to test. 509 * @param interfaceName Interface the object must implement. 510 * 511 * @return If <CODE>object</CODE> is a {@link java.lang.Class Class} 512 * that implements <CODE>interfaceName</CODE>, 513 * <CODE>object</CODE> is returned downcast to type {@link 514 * java.lang.Class Class}; otherwise an exception is thrown. 515 * 516 * @exception NullPointerException 517 * (unchecked exception) Thrown if <CODE>object</CODE> is null. 518 * @exception ClassCastException 519 * (unchecked exception) Thrown if <CODE>object</CODE> is not a 520 * {@link java.lang.Class Class} that implements 521 * <CODE>interfaceName</CODE>. 522 */ 523 public static Class<?> 524 verifyAttributeCategory(Object object, Class<?> interfaceName) { 525 526 Class<?> result = (Class<?>) object; 527 if (interfaceName.isAssignableFrom (result)) { 528 return result; 529 } 530 else { 531 throw new ClassCastException(); 532 } 533 } 534 535 /** 536 * Verify that the given object is an instance of the given interface, which 537 * is assumed to be interface {@link Attribute Attribute} or a subinterface 538 * thereof. 539 * 540 * @param object Object to test. 541 * @param interfaceName Interface of which the object must be an instance. 542 * 543 * @return If <CODE>object</CODE> is an instance of 544 * <CODE>interfaceName</CODE>, <CODE>object</CODE> is returned 545 * downcast to type {@link Attribute Attribute}; otherwise an 546 * exception is thrown. 547 * 548 * @exception NullPointerException 549 * (unchecked exception) Thrown if <CODE>object</CODE> is null. 550 * @exception ClassCastException 551 * (unchecked exception) Thrown if <CODE>object</CODE> is not an 552 * instance of <CODE>interfaceName</CODE>. 553 */ 554 public static Attribute 555 verifyAttributeValue(Object object, Class<?> interfaceName) { 556 557 if (object == null) { 558 throw new NullPointerException(); 559 } 560 else if (interfaceName.isInstance (object)) { 561 return (Attribute) object; 562 } else { 563 throw new ClassCastException(); 564 } 565 } 566 567 /** 568 * Verify that the given attribute category object is equal to the 569 * category of the given attribute value object. If so, this method 570 * returns doing nothing. If not, this method throws an exception. 571 * 572 * @param category Attribute category to test. 573 * @param attribute Attribute value to test. 574 * 575 * @exception NullPointerException 576 * (unchecked exception) Thrown if the <CODE>category</CODE> is 577 * null or if the <CODE>attribute</CODE> is null. 578 * @exception IllegalArgumentException 579 * (unchecked exception) Thrown if the <CODE>category</CODE> is not 580 * equal to the category of the <CODE>attribute</CODE>. 581 */ 582 public static void 583 verifyCategoryForValue(Class<?> category, Attribute attribute) { 584 585 if (!category.equals (attribute.getCategory())) { 586 throw new IllegalArgumentException(); 587 } 588 } 589 } | 189 /** 190 * @serial include 191 */ 192 private static class UnmodifiablePrintServiceAttributeSet 193 extends UnmodifiableAttributeSet 194 implements PrintServiceAttributeSet, Serializable 195 { 196 private static final long serialVersionUID = -7112165137107826819L; 197 public UnmodifiablePrintServiceAttributeSet 198 (PrintServiceAttributeSet attributeSet) { 199 200 super (attributeSet); 201 } 202 } 203 204 /** 205 * Creates an unmodifiable view of the given attribute set. 206 * 207 * @param attributeSet Underlying attribute set. 208 * 209 * @return Unmodifiable view of {@code attributeSet}. 210 * 211 * @exception NullPointerException 212 * Thrown if {@code attributeSet} is null. Null is never a 213 */ 214 public static AttributeSet unmodifiableView(AttributeSet attributeSet) { 215 if (attributeSet == null) { 216 throw new NullPointerException(); 217 } 218 219 return new UnmodifiableAttributeSet(attributeSet); 220 } 221 222 /** 223 * Creates an unmodifiable view of the given doc attribute set. 224 * 225 * @param attributeSet Underlying doc attribute set. 226 * 227 * @return Unmodifiable view of {@code attributeSet}. 228 * 229 * @exception NullPointerException 230 * Thrown if {@code attributeSet} is null. 231 */ 232 public static DocAttributeSet unmodifiableView 233 (DocAttributeSet attributeSet) { 234 if (attributeSet == null) { 235 throw new NullPointerException(); 236 } 237 return new UnmodifiableDocAttributeSet(attributeSet); 238 } 239 240 /** 241 * Creates an unmodifiable view of the given print request attribute set. 242 * 243 * @param attributeSet Underlying print request attribute set. 244 * 245 * @return Unmodifiable view of {@code attributeSet}. 246 * 247 * @exception NullPointerException 248 * Thrown if {@code attributeSet} is null. 249 */ 250 public static PrintRequestAttributeSet 251 unmodifiableView(PrintRequestAttributeSet attributeSet) { 252 if (attributeSet == null) { 253 throw new NullPointerException(); 254 } 255 return new UnmodifiablePrintRequestAttributeSet(attributeSet); 256 } 257 258 /** 259 * Creates an unmodifiable view of the given print job attribute set. 260 * 261 * @param attributeSet Underlying print job attribute set. 262 * 263 * @return Unmodifiable view of {@code attributeSet}. 264 * 265 * @exception NullPointerException 266 * Thrown if {@code attributeSet} is null. 267 */ 268 public static PrintJobAttributeSet 269 unmodifiableView(PrintJobAttributeSet attributeSet) { 270 if (attributeSet == null) { 271 throw new NullPointerException(); 272 } 273 return new UnmodifiablePrintJobAttributeSet(attributeSet); 274 } 275 276 /** 277 * Creates an unmodifiable view of the given print service attribute set. 278 * 279 * @param attributeSet Underlying print service attribute set. 280 * 281 * @return Unmodifiable view of {@code attributeSet}. 282 * 283 * @exception NullPointerException 284 * Thrown if {@code attributeSet} is null. 285 */ 286 public static PrintServiceAttributeSet 287 unmodifiableView(PrintServiceAttributeSet attributeSet) { 288 if (attributeSet == null) { 289 throw new NullPointerException(); 290 } 291 return new UnmodifiablePrintServiceAttributeSet (attributeSet); 292 } 293 294 /** 295 * @serial include 296 */ 297 private static class SynchronizedAttributeSet 298 implements AttributeSet, Serializable { 299 private static final long serialVersionUID = 8365731020128564925L; 300 301 private AttributeSet attrset; 302 303 public SynchronizedAttributeSet(AttributeSet attributeSet) { 304 attrset = attributeSet; 400 401 /** 402 * @serial include 403 */ 404 private static class SynchronizedPrintServiceAttributeSet 405 extends SynchronizedAttributeSet 406 implements PrintServiceAttributeSet, Serializable { 407 private static final long serialVersionUID = -2830705374001675073L; 408 409 public SynchronizedPrintServiceAttributeSet 410 (PrintServiceAttributeSet attributeSet) { 411 super(attributeSet); 412 } 413 } 414 415 /** 416 * Creates a synchronized view of the given attribute set. 417 * 418 * @param attributeSet Underlying attribute set. 419 * 420 * @return Synchronized view of {@code attributeSet}. 421 * 422 * @exception NullPointerException 423 * Thrown if {@code attributeSet} is null. 424 */ 425 public static AttributeSet synchronizedView 426 (AttributeSet attributeSet) { 427 if (attributeSet == null) { 428 throw new NullPointerException(); 429 } 430 return new SynchronizedAttributeSet(attributeSet); 431 } 432 433 /** 434 * Creates a synchronized view of the given doc attribute set. 435 * 436 * @param attributeSet Underlying doc attribute set. 437 * 438 * @return Synchronized view of {@code attributeSet}. 439 * 440 * @exception NullPointerException 441 * Thrown if {@code attributeSet} is null. 442 */ 443 public static DocAttributeSet 444 synchronizedView(DocAttributeSet attributeSet) { 445 if (attributeSet == null) { 446 throw new NullPointerException(); 447 } 448 return new SynchronizedDocAttributeSet(attributeSet); 449 } 450 451 /** 452 * Creates a synchronized view of the given print request attribute set. 453 * 454 * @param attributeSet Underlying print request attribute set. 455 * 456 * @return Synchronized view of {@code attributeSet}. 457 * 458 * @exception NullPointerException 459 * Thrown if {@code attributeSet} is null. 460 */ 461 public static PrintRequestAttributeSet 462 synchronizedView(PrintRequestAttributeSet attributeSet) { 463 if (attributeSet == null) { 464 throw new NullPointerException(); 465 } 466 return new SynchronizedPrintRequestAttributeSet(attributeSet); 467 } 468 469 /** 470 * Creates a synchronized view of the given print job attribute set. 471 * 472 * @param attributeSet Underlying print job attribute set. 473 * 474 * @return Synchronized view of {@code attributeSet}. 475 * 476 * @exception NullPointerException 477 * Thrown if {@code attributeSet} is null. 478 */ 479 public static PrintJobAttributeSet 480 synchronizedView(PrintJobAttributeSet attributeSet) { 481 if (attributeSet == null) { 482 throw new NullPointerException(); 483 } 484 return new SynchronizedPrintJobAttributeSet(attributeSet); 485 } 486 487 /** 488 * Creates a synchronized view of the given print service attribute set. 489 * 490 * @param attributeSet Underlying print service attribute set. 491 * 492 * @return Synchronized view of {@code attributeSet}. 493 */ 494 public static PrintServiceAttributeSet 495 synchronizedView(PrintServiceAttributeSet attributeSet) { 496 if (attributeSet == null) { 497 throw new NullPointerException(); 498 } 499 return new SynchronizedPrintServiceAttributeSet(attributeSet); 500 } 501 502 503 /** 504 * Verify that the given object is a {@link java.lang.Class Class} that 505 * implements the given interface, which is assumed to be interface {@link 506 * Attribute Attribute} or a subinterface thereof. 507 * 508 * @param object Object to test. 509 * @param interfaceName Interface the object must implement. 510 * 511 * @return If {@code object} is a {@link java.lang.Class Class} 512 * that implements {@code interfaceName}, 513 * {@code object} is returned downcast to type {@link 514 * java.lang.Class Class}; otherwise an exception is thrown. 515 * 516 * @exception NullPointerException 517 * (unchecked exception) Thrown if {@code object} is null. 518 * @exception ClassCastException 519 * (unchecked exception) Thrown if {@code object} is not a 520 * {@link java.lang.Class Class} that implements 521 * {@code interfaceName}. 522 */ 523 public static Class<?> 524 verifyAttributeCategory(Object object, Class<?> interfaceName) { 525 526 Class<?> result = (Class<?>) object; 527 if (interfaceName.isAssignableFrom (result)) { 528 return result; 529 } 530 else { 531 throw new ClassCastException(); 532 } 533 } 534 535 /** 536 * Verify that the given object is an instance of the given interface, which 537 * is assumed to be interface {@link Attribute Attribute} or a subinterface 538 * thereof. 539 * 540 * @param object Object to test. 541 * @param interfaceName Interface of which the object must be an instance. 542 * 543 * @return If {@code object} is an instance of 544 * {@code interfaceName}, {@code object} is returned 545 * downcast to type {@link Attribute Attribute}; otherwise an 546 * exception is thrown. 547 * 548 * @exception NullPointerException 549 * (unchecked exception) Thrown if {@code object} is null. 550 * @exception ClassCastException 551 * (unchecked exception) Thrown if {@code object} is not an 552 * instance of {@code interfaceName}. 553 */ 554 public static Attribute 555 verifyAttributeValue(Object object, Class<?> interfaceName) { 556 557 if (object == null) { 558 throw new NullPointerException(); 559 } 560 else if (interfaceName.isInstance (object)) { 561 return (Attribute) object; 562 } else { 563 throw new ClassCastException(); 564 } 565 } 566 567 /** 568 * Verify that the given attribute category object is equal to the 569 * category of the given attribute value object. If so, this method 570 * returns doing nothing. If not, this method throws an exception. 571 * 572 * @param category Attribute category to test. 573 * @param attribute Attribute value to test. 574 * 575 * @exception NullPointerException 576 * (unchecked exception) Thrown if the {@code category} is 577 * null or if the {@code attribute} is null. 578 * @exception IllegalArgumentException 579 * (unchecked exception) Thrown if the {@code category} is not 580 * equal to the category of the {@code attribute}. 581 */ 582 public static void 583 verifyCategoryForValue(Class<?> category, Attribute attribute) { 584 585 if (!category.equals (attribute.getCategory())) { 586 throw new IllegalArgumentException(); 587 } 588 } 589 } |