39 |
|
|
40 |
import java.io.Serializable; |
import java.io.Serializable; |
41 |
|
|
42 |
|
/** |
43 |
|
* <code>AttributeSetUtilities</code> provides static methods for working |
44 |
|
* with <code>AttributeSet</code>s. |
45 |
|
* <p> |
46 |
|
* For every type of an attribute set available in the Java Print Service API |
47 |
|
* are methods provided to get an unmodifiable view of an attribute set. |
48 |
|
* This unmodifiable view provides a read-only version of the attribute |
49 |
|
* set which throws {@link javax.print.attribute.UnmodifiableSetException}s |
50 |
|
* if state changing methods are invoked. |
51 |
|
* </p> |
52 |
|
* <p> |
53 |
|
* Methods for getting a synchronized view of an attribute set are also |
54 |
|
* available. This view provides synchronized (thread safe) access to the |
55 |
|
* underlying wrapped attribute set. |
56 |
|
* </P> |
57 |
|
* <p> |
58 |
|
* Three static methods for the implementation of own AttributeSets |
59 |
|
* are provided, which verify that: |
60 |
|
* <ul> |
61 |
|
* <li>the given object is an attribute of the given interface.</li> |
62 |
|
* <li>the category of given attribute is equals to a given category.</li> |
63 |
|
* <li>the given object is a <code>Class</code> that implements the given |
64 |
|
* interface name.</li> |
65 |
|
* </ul> |
66 |
|
* |
67 |
|
*/ |
68 |
public final class AttributeSetUtilities |
public final class AttributeSetUtilities |
69 |
{ |
{ |
70 |
/** |
/** |
71 |
* This class isn't intended to be instantiated. |
* This class isn't intended to be instantiated. |
72 |
*/ |
*/ |
73 |
private AttributeSetUtilities() {} |
private AttributeSetUtilities() |
74 |
|
{ |
75 |
|
// only static methods |
76 |
|
} |
77 |
|
|
78 |
private static class UnmodifiableAttributeSet |
private static class UnmodifiableAttributeSet |
79 |
implements AttributeSet, Serializable |
implements AttributeSet, Serializable |
316 |
/** |
/** |
317 |
* Returns a synchronized view of the given attribute set. |
* Returns a synchronized view of the given attribute set. |
318 |
* |
* |
319 |
* @return the sychronized attribute set |
* @param attributeSet the set to synchronize. |
320 |
|
* @return The sychronized attribute set. |
321 |
*/ |
*/ |
322 |
public static AttributeSet synchronizedView(AttributeSet attributeSet) |
public static AttributeSet synchronizedView(AttributeSet attributeSet) |
323 |
{ |
{ |
327 |
/** |
/** |
328 |
* Returns a synchronized view of the given attribute set. |
* Returns a synchronized view of the given attribute set. |
329 |
* |
* |
330 |
* @return the sychronized attribute set |
* @param attributeSet the set to synchronize. |
331 |
|
* @return The sychronized attribute set. |
332 |
*/ |
*/ |
333 |
public static DocAttributeSet synchronizedView(DocAttributeSet attributeSet) |
public static DocAttributeSet synchronizedView(DocAttributeSet attributeSet) |
334 |
{ |
{ |
338 |
/** |
/** |
339 |
* Returns a synchronized view of the given attribute set. |
* Returns a synchronized view of the given attribute set. |
340 |
* |
* |
341 |
* @return the sychronized attribute set |
* @param attributeSet the set to synchronize. |
342 |
|
* @return The sychronized attribute set. |
343 |
*/ |
*/ |
344 |
public static PrintJobAttributeSet synchronizedView(PrintJobAttributeSet attributeSet) |
public static PrintJobAttributeSet synchronizedView(PrintJobAttributeSet attributeSet) |
345 |
{ |
{ |
349 |
/** |
/** |
350 |
* Returns a synchronized view of the given attribute set. |
* Returns a synchronized view of the given attribute set. |
351 |
* |
* |
352 |
* @return the sychronized attribute set |
* @param attributeSet the set to synchronize. |
353 |
|
* @return The sychronized attribute set. |
354 |
*/ |
*/ |
355 |
public static PrintRequestAttributeSet synchronizedView(PrintRequestAttributeSet attributeSet) |
public static PrintRequestAttributeSet synchronizedView(PrintRequestAttributeSet attributeSet) |
356 |
{ |
{ |
360 |
/** |
/** |
361 |
* Returns a synchronized view of the given attribute set. |
* Returns a synchronized view of the given attribute set. |
362 |
* |
* |
363 |
* @return the sychronized attribute set |
* @param attributeSet the set to synchronize. |
364 |
|
* @return The sychronized attribute set. |
365 |
*/ |
*/ |
366 |
public static PrintServiceAttributeSet synchronizedView(PrintServiceAttributeSet attributeSet) |
public static PrintServiceAttributeSet synchronizedView(PrintServiceAttributeSet attributeSet) |
367 |
{ |
{ |
371 |
/** |
/** |
372 |
* Returns an unmodifiable view of the given attribute set. |
* Returns an unmodifiable view of the given attribute set. |
373 |
* |
* |
374 |
* @return the sychronized attribute set |
* @param attributeSet the set to make unmodifiable. |
375 |
|
* @return The unmodifiable attribute set. |
376 |
*/ |
*/ |
377 |
public static AttributeSet unmodifiableView(AttributeSet attributeSet) |
public static AttributeSet unmodifiableView(AttributeSet attributeSet) |
378 |
{ |
{ |
382 |
/** |
/** |
383 |
* Returns an unmodifiable view of the given attribute set. |
* Returns an unmodifiable view of the given attribute set. |
384 |
* |
* |
385 |
* @return the sychronized attribute set |
* @param attributeSet the set to make unmodifiable. |
386 |
|
* @return The unmodifiable attribute set. |
387 |
*/ |
*/ |
388 |
public static DocAttributeSet unmodifiableView(DocAttributeSet attributeSet) |
public static DocAttributeSet unmodifiableView(DocAttributeSet attributeSet) |
389 |
{ |
{ |
393 |
/** |
/** |
394 |
* Returns an unmodifiable view of the given attribute set. |
* Returns an unmodifiable view of the given attribute set. |
395 |
* |
* |
396 |
* @return the sychronized attribute set |
* @param attributeSet the set to make unmodifiable. |
397 |
|
* @return The unmodifiable attribute set. |
398 |
*/ |
*/ |
399 |
public static PrintJobAttributeSet unmodifiableView(PrintJobAttributeSet attributeSet) |
public static PrintJobAttributeSet unmodifiableView(PrintJobAttributeSet attributeSet) |
400 |
{ |
{ |
404 |
/** |
/** |
405 |
* Returns an unmodifiable view of the given attribute set. |
* Returns an unmodifiable view of the given attribute set. |
406 |
* |
* |
407 |
* @return the sychronized attribute set |
* @param attributeSet the set to make unmodifiable. |
408 |
|
* @return The unmodifiable attribute set. |
409 |
*/ |
*/ |
410 |
public static PrintRequestAttributeSet unmodifiableView(PrintRequestAttributeSet attributeSet) |
public static PrintRequestAttributeSet unmodifiableView(PrintRequestAttributeSet attributeSet) |
411 |
{ |
{ |
415 |
/** |
/** |
416 |
* Returns an unmodifiable view of the given attribute set. |
* Returns an unmodifiable view of the given attribute set. |
417 |
* |
* |
418 |
* @return the sychronized attribute set |
* @param attributeSet the set to make unmodifiable. |
419 |
|
* @return The unmodifiable attribute set. |
420 |
*/ |
*/ |
421 |
public static PrintServiceAttributeSet unmodifiableView(PrintServiceAttributeSet attributeSet) |
public static PrintServiceAttributeSet unmodifiableView(PrintServiceAttributeSet attributeSet) |
422 |
{ |
{ |
425 |
|
|
426 |
/** |
/** |
427 |
* Verifies that the given object is a <code>Class</code> that |
* Verifies that the given object is a <code>Class</code> that |
428 |
* implements the given interface name. |
* implements the given interface name and returns it casted. |
429 |
* |
* |
430 |
|
* @param object the object to test. |
431 |
|
* @param interfaceName the <code>Class</code> to verify against. |
432 |
* @return object casted to <code>Class</code> |
* @return object casted to <code>Class</code> |
433 |
* |
* |
434 |
* @exception ClassCastException if object is not a <code>Class</code> |
* @exception ClassCastException if object is not a <code>Class</code> |
451 |
|
|
452 |
/** |
/** |
453 |
* Verifies that the given object is an attribute of the given interface. |
* Verifies that the given object is an attribute of the given interface. |
454 |
* |
* and returns it casted to the interface type. |
455 |
|
* |
456 |
|
* @param object the object to test. |
457 |
|
* @param interfaceName the <code>Class</code> to verify against. |
458 |
* @return the object casted to <code>Attribute</code> |
* @return the object casted to <code>Attribute</code> |
459 |
* |
* |
460 |
* @exception ClassCastException if object is no instance of interfaceName. |
* @exception ClassCastException if object is no instance of interfaceName. |
473 |
} |
} |
474 |
|
|
475 |
/** |
/** |
476 |
* Verifies that the category of attribute is equals to category. |
* Verifies that the category of attribute is equals to the given category |
477 |
* |
* class. |
478 |
* @param category the category the atteribute should be |
* |
479 |
* @param attribute the attribute to verify |
* @param category the category to test. |
480 |
|
* @param attribute the attribute to verify. |
481 |
* |
* |
482 |
* @exception IllegalArgumentException if the categories are not equal |
* @exception IllegalArgumentException if the categories are not equal |
483 |
* @exception NullPointerException if category is null |
* @exception NullPointerException if category is null |
485 |
public static void verifyCategoryForValue(Class category, |
public static void verifyCategoryForValue(Class category, |
486 |
Attribute attribute) |
Attribute attribute) |
487 |
{ |
{ |
488 |
if (category == null) |
if (category == null || attribute == null) |
489 |
throw new NullPointerException("object may not be null"); |
throw new NullPointerException("category or attribute may not be null"); |
490 |
|
|
491 |
if (category.equals(attribute.getCategory())) |
if (!category.equals(attribute.getCategory())) |
492 |
throw new IllegalArgumentException |
throw new IllegalArgumentException |
493 |
("category of attribute not equal to category"); |
("category of attribute not equal to category"); |
494 |
} |
} |