1 7 8 9 package javax.print.attribute; 10 11 import java.io.Serializable ; 12 13 50 public final class AttributeSetUtilities { 51 52 54 private AttributeSetUtilities() { 55 } 56 57 60 private static class UnmodifiableAttributeSet 61 implements AttributeSet , Serializable { 62 63 private AttributeSet attrset; 64 65 67 public UnmodifiableAttributeSet(AttributeSet attributeSet) { 68 69 attrset = attributeSet; 70 } 71 72 public Attribute get(Class <?> key) { 73 return attrset.get(key); 74 } 75 76 public boolean add(Attribute attribute) { 77 throw new UnmodifiableSetException (); 78 } 79 80 public synchronized boolean remove(Class <?> category) { 81 throw new UnmodifiableSetException (); 82 } 83 84 public boolean remove(Attribute attribute) { 85 throw new UnmodifiableSetException (); 86 } 87 88 public boolean containsKey(Class <?> category) { 89 return attrset.containsKey(category); 90 } 91 92 public boolean containsValue(Attribute attribute) { 93 return attrset.containsValue(attribute); 94 } 95 96 public boolean addAll(AttributeSet attributes) { 97 throw new UnmodifiableSetException (); 98 } 99 100 public int size() { 101 return attrset.size(); 102 } 103 104 public Attribute [] toArray() { 105 return attrset.toArray(); 106 } 107 108 public void clear() { 109 throw new UnmodifiableSetException (); 110 } 111 112 public boolean isEmpty() { 113 return attrset.isEmpty(); 114 } 115 116 public boolean equals(Object o) { 117 return attrset.equals (o); 118 } 119 120 public int hashCode() { 121 return attrset.hashCode(); 122 } 123 124 } 125 126 129 private static class UnmodifiableDocAttributeSet 130 extends UnmodifiableAttributeSet 131 implements DocAttributeSet , Serializable { 132 133 public UnmodifiableDocAttributeSet(DocAttributeSet attributeSet) { 134 135 super (attributeSet); 136 } 137 } 138 139 142 private static class UnmodifiablePrintRequestAttributeSet 143 extends UnmodifiableAttributeSet 144 implements PrintRequestAttributeSet , Serializable 145 { 146 public UnmodifiablePrintRequestAttributeSet 147 (PrintRequestAttributeSet attributeSet) { 148 149 super (attributeSet); 150 } 151 } 152 153 156 private static class UnmodifiablePrintJobAttributeSet 157 extends UnmodifiableAttributeSet 158 implements PrintJobAttributeSet , Serializable 159 { 160 public UnmodifiablePrintJobAttributeSet 161 (PrintJobAttributeSet attributeSet) { 162 163 super (attributeSet); 164 } 165 } 166 167 170 private static class UnmodifiablePrintServiceAttributeSet 171 extends UnmodifiableAttributeSet 172 implements PrintServiceAttributeSet , Serializable 173 { 174 public UnmodifiablePrintServiceAttributeSet 175 (PrintServiceAttributeSet attributeSet) { 176 177 super (attributeSet); 178 } 179 } 180 181 191 public static AttributeSet unmodifiableView(AttributeSet attributeSet) { 192 if (attributeSet == null) { 193 throw new NullPointerException (); 194 } 195 196 return new UnmodifiableAttributeSet(attributeSet); 197 } 198 199 209 public static DocAttributeSet unmodifiableView 210 (DocAttributeSet attributeSet) { 211 if (attributeSet == null) { 212 throw new NullPointerException (); 213 } 214 return new UnmodifiableDocAttributeSet(attributeSet); 215 } 216 217 227 public static PrintRequestAttributeSet 228 unmodifiableView(PrintRequestAttributeSet attributeSet) { 229 if (attributeSet == null) { 230 throw new NullPointerException (); 231 } 232 return new UnmodifiablePrintRequestAttributeSet(attributeSet); 233 } 234 235 245 public static PrintJobAttributeSet 246 unmodifiableView(PrintJobAttributeSet attributeSet) { 247 if (attributeSet == null) { 248 throw new NullPointerException (); 249 } 250 return new UnmodifiablePrintJobAttributeSet(attributeSet); 251 } 252 253 263 public static PrintServiceAttributeSet 264 unmodifiableView(PrintServiceAttributeSet attributeSet) { 265 if (attributeSet == null) { 266 throw new NullPointerException (); 267 } 268 return new UnmodifiablePrintServiceAttributeSet (attributeSet); 269 } 270 271 274 private static class SynchronizedAttributeSet 275 implements AttributeSet , Serializable { 276 277 private AttributeSet attrset; 278 279 public SynchronizedAttributeSet(AttributeSet attributeSet) { 280 attrset = attributeSet; 281 } 282 283 public synchronized Attribute get(Class <?> category) { 284 return attrset.get(category); 285 } 286 287 public synchronized boolean add(Attribute attribute) { 288 return attrset.add(attribute); 289 } 290 291 public synchronized boolean remove(Class <?> category) { 292 return attrset.remove(category); 293 } 294 295 public synchronized boolean remove(Attribute attribute) { 296 return attrset.remove(attribute); 297 } 298 299 public synchronized boolean containsKey(Class <?> category) { 300 return attrset.containsKey(category); 301 } 302 303 public synchronized boolean containsValue(Attribute attribute) { 304 return attrset.containsValue(attribute); 305 } 306 307 public synchronized boolean addAll(AttributeSet attributes) { 308 return attrset.addAll(attributes); 309 } 310 311 public synchronized int size() { 312 return attrset.size(); 313 } 314 315 public synchronized Attribute [] toArray() { 316 return attrset.toArray(); 317 } 318 319 public synchronized void clear() { 320 attrset.clear(); 321 } 322 323 public synchronized boolean isEmpty() { 324 return attrset.isEmpty(); 325 } 326 327 public synchronized boolean equals(Object o) { 328 return attrset.equals (o); 329 } 330 331 public synchronized int hashCode() { 332 return attrset.hashCode(); 333 } 334 } 335 336 339 private static class SynchronizedDocAttributeSet 340 extends SynchronizedAttributeSet 341 implements DocAttributeSet , Serializable { 342 343 public SynchronizedDocAttributeSet(DocAttributeSet attributeSet) { 344 super(attributeSet); 345 } 346 } 347 348 351 private static class SynchronizedPrintRequestAttributeSet 352 extends SynchronizedAttributeSet 353 implements PrintRequestAttributeSet , Serializable { 354 355 public SynchronizedPrintRequestAttributeSet 356 (PrintRequestAttributeSet attributeSet) { 357 super(attributeSet); 358 } 359 } 360 361 364 private static class SynchronizedPrintJobAttributeSet 365 extends SynchronizedAttributeSet 366 implements PrintJobAttributeSet , Serializable { 367 368 public SynchronizedPrintJobAttributeSet 369 (PrintJobAttributeSet attributeSet) { 370 super(attributeSet); 371 } 372 } 373 374 377 private static class SynchronizedPrintServiceAttributeSet 378 extends SynchronizedAttributeSet 379 implements PrintServiceAttributeSet , Serializable { 380 public SynchronizedPrintServiceAttributeSet 381 (PrintServiceAttributeSet attributeSet) { 382 super(attributeSet); 383 } 384 } 385 386 396 public static AttributeSet synchronizedView 397 (AttributeSet attributeSet) { 398 if (attributeSet == null) { 399 throw new NullPointerException (); 400 } 401 return new SynchronizedAttributeSet(attributeSet); 402 } 403 404 414 public static DocAttributeSet 415 synchronizedView(DocAttributeSet attributeSet) { 416 if (attributeSet == null) { 417 throw new NullPointerException (); 418 } 419 return new SynchronizedDocAttributeSet(attributeSet); 420 } 421 422 432 public static PrintRequestAttributeSet 433 synchronizedView(PrintRequestAttributeSet attributeSet) { 434 if (attributeSet == null) { 435 throw new NullPointerException (); 436 } 437 return new SynchronizedPrintRequestAttributeSet(attributeSet); 438 } 439 440 450 public static PrintJobAttributeSet 451 synchronizedView(PrintJobAttributeSet attributeSet) { 452 if (attributeSet == null) { 453 throw new NullPointerException (); 454 } 455 return new SynchronizedPrintJobAttributeSet(attributeSet); 456 } 457 458 465 public static PrintServiceAttributeSet 466 synchronizedView(PrintServiceAttributeSet attributeSet) { 467 if (attributeSet == null) { 468 throw new NullPointerException (); 469 } 470 return new SynchronizedPrintServiceAttributeSet(attributeSet); 471 } 472 473 474 494 public static Class <?> 495 verifyAttributeCategory(Object object, Class <?> interfaceName) { 496 497 Class result = (Class ) object; 498 if (interfaceName.isAssignableFrom (result)) { 499 return result; 500 } 501 else { 502 throw new ClassCastException (); 503 } 504 } 505 506 525 public static Attribute 526 verifyAttributeValue(Object object, Class <?> interfaceName) { 527 528 if (object == null) { 529 throw new NullPointerException (); 530 } 531 else if (interfaceName.isInstance (object)) { 532 return (Attribute ) object; 533 } else { 534 throw new ClassCastException (); 535 } 536 } 537 538 553 public static void 554 verifyCategoryForValue(Class <?> category, Attribute attribute) { 555 556 if (!category.equals (attribute.getCategory())) { 557 throw new IllegalArgumentException (); 558 } 559 } 560 } 561 | Popular Tags |