FileDocCategorySizeDatePackage
AttributeSetUtilities.javaAPI DocJava SE 5 API16400Fri Aug 26 14:57:42 BST 2005javax.print.attribute

AttributeSetUtilities

public final class AttributeSetUtilities extends Object
Class AttributeSetUtilities provides static methods for manipulating AttributeSets.
  • Methods for creating unmodifiable and synchronized views of attribute sets.
  • operations useful for building implementations of interface {@link AttributeSet AttributeSet}

An unmodifiable view U of an AttributeSet S provides a client with "read-only" access to S. Query operations on U "read through" to S; thus, changes in S are reflected in U. However, any attempt to modify U, results in an UnmodifiableSetException. The unmodifiable view object U will be serializable if the attribute set object S is serializable.

A synchronized view V of an attribute set S provides a client with synchronized (multiple thread safe) access to S. Each operation of V is synchronized using V itself as the lock object and then merely invokes the corresponding operation of S. In order to guarantee mutually exclusive access, it is critical that all access to S is accomplished through V. The synchronized view object V will be serializable if the attribute set object S is serializable.

As mentioned in the package description of javax.print, a null reference parameter to methods is incorrect unless explicitly documented on the method as having a meaningful interpretation. Usage to the contrary is incorrect coding and may result in a run time exception either immediately or at some later time. IllegalArgumentException and NullPointerException are examples of typical and acceptable run time exceptions for such cases.

author
Alan Kaminsky

Fields Summary
Constructors Summary
private AttributeSetUtilities()

    
Methods Summary
public static javax.print.attribute.PrintJobAttributeSetsynchronizedView(javax.print.attribute.PrintJobAttributeSet attributeSet)
Creates a synchronized view of the given print job attribute set.

param
attributeSet Underlying print job attribute set.
return
Synchronized view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new SynchronizedPrintJobAttributeSet(attributeSet);
    
public static javax.print.attribute.PrintServiceAttributeSetsynchronizedView(javax.print.attribute.PrintServiceAttributeSet attributeSet)
Creates a synchronized view of the given print service attribute set.

param
attributeSet Underlying print service attribute set.
return
Synchronized view of attributeSet.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new SynchronizedPrintServiceAttributeSet(attributeSet);
    
public static javax.print.attribute.AttributeSetsynchronizedView(javax.print.attribute.AttributeSet attributeSet)
Creates a synchronized view of the given attribute set.

param
attributeSet Underlying attribute set.
return
Synchronized view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new SynchronizedAttributeSet(attributeSet);
    
public static javax.print.attribute.DocAttributeSetsynchronizedView(javax.print.attribute.DocAttributeSet attributeSet)
Creates a synchronized view of the given doc attribute set.

param
attributeSet Underlying doc attribute set.
return
Synchronized view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new SynchronizedDocAttributeSet(attributeSet);
    
public static javax.print.attribute.PrintRequestAttributeSetsynchronizedView(javax.print.attribute.PrintRequestAttributeSet attributeSet)
Creates a synchronized view of the given print request attribute set.

param
attributeSet Underlying print request attribute set.
return
Synchronized view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new SynchronizedPrintRequestAttributeSet(attributeSet);
    
public static javax.print.attribute.AttributeSetunmodifiableView(javax.print.attribute.AttributeSet attributeSet)
Creates an unmodifiable view of the given attribute set.

param
attributeSet Underlying attribute set.
return
Unmodifiable view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null. Null is never a

	if (attributeSet == null) {
	    throw new NullPointerException();
	}

	return new UnmodifiableAttributeSet(attributeSet);
    
public static javax.print.attribute.DocAttributeSetunmodifiableView(javax.print.attribute.DocAttributeSet attributeSet)
Creates an unmodifiable view of the given doc attribute set.

param
attributeSet Underlying doc attribute set.
return
Unmodifiable view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new UnmodifiableDocAttributeSet(attributeSet);
    
public static javax.print.attribute.PrintRequestAttributeSetunmodifiableView(javax.print.attribute.PrintRequestAttributeSet attributeSet)
Creates an unmodifiable view of the given print request attribute set.

param
attributeSet Underlying print request attribute set.
return
Unmodifiable view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new UnmodifiablePrintRequestAttributeSet(attributeSet);
    
public static javax.print.attribute.PrintJobAttributeSetunmodifiableView(javax.print.attribute.PrintJobAttributeSet attributeSet)
Creates an unmodifiable view of the given print job attribute set.

param
attributeSet Underlying print job attribute set.
return
Unmodifiable view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

    	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new UnmodifiablePrintJobAttributeSet(attributeSet);
    
public static javax.print.attribute.PrintServiceAttributeSetunmodifiableView(javax.print.attribute.PrintServiceAttributeSet attributeSet)
Creates an unmodifiable view of the given print service attribute set.

param
attributeSet Underlying print service attribute set.
return
Unmodifiable view of attributeSet.
exception
NullPointerException Thrown if attributeSet is null.

	if (attributeSet == null) {
	    throw new NullPointerException();
	}
	return new UnmodifiablePrintServiceAttributeSet (attributeSet);
    
public static java.lang.ClassverifyAttributeCategory(java.lang.Object object, java.lang.Class interfaceName)
Verify that the given object is a {@link java.lang.Class Class} that implements the given interface, which is assumed to be interface {@link Attribute Attribute} or a subinterface thereof.

param
object Object to test.
param
interfaceName Interface the object must implement.
return
If object is a {@link java.lang.Class Class} that implements interfaceName, object is returned downcast to type {@link java.lang.Class Class}; otherwise an exception is thrown.
exception
NullPointerException (unchecked exception) Thrown if object is null.
exception
ClassCastException (unchecked exception) Thrown if object is not a {@link java.lang.Class Class} that implements interfaceName.

 

	Class result = (Class) object;
	if (interfaceName.isAssignableFrom (result)) {
	    return result;
	}
	else {
	    throw new ClassCastException();
	}
    
public static javax.print.attribute.AttributeverifyAttributeValue(java.lang.Object object, java.lang.Class interfaceName)
Verify that the given object is an instance of the given interface, which is assumed to be interface {@link Attribute Attribute} or a subinterface thereof.

param
object Object to test.
param
interfaceName Interface of which the object must be an instance.
return
If object is an instance of interfaceName, object is returned downcast to type {@link Attribute Attribute}; otherwise an exception is thrown.
exception
NullPointerException (unchecked exception) Thrown if object is null.
exception
ClassCastException (unchecked exception) Thrown if object is not an instance of interfaceName.


	if (object == null) {
	    throw new NullPointerException();
	}
	else if (interfaceName.isInstance (object)) {
	    return (Attribute) object;
	} else {
	    throw new ClassCastException();
	}
    
public static voidverifyCategoryForValue(java.lang.Class category, javax.print.attribute.Attribute attribute)
Verify that the given attribute category object is equal to the category of the given attribute value object. If so, this method returns doing nothing. If not, this method throws an exception.

param
category Attribute category to test.
param
attribute Attribute value to test.
exception
NullPointerException (unchecked exception) Thrown if the category is null or if the attribute is null.
exception
IllegalArgumentException (unchecked exception) Thrown if the category is not equal to the category of the attribute.


	if (!category.equals (attribute.getCategory())) {
	    throw new IllegalArgumentException();
	}