java.lang.Object
javax.print.attribute.AttributeSetUtilities
类
AttributeSetUtilities提供了用于操作AttributeSets的静态方法。
- 用于创建属性集的不可修改和同步视图的方法。
- 用于构建接口
AttributeSet实现的有用操作
AttributeSet S的客户端提供“只读”访问的方式。对U的查询操作“读取”到S;因此,对S的更改会反映在U中。但是,任何尝试修改U的操作都会导致UnmodifiableSetException。如果属性集对象S是可序列化的,则不可修改视图对象U也将是可序列化的。
属性集的同步视图 V 是属性集S的客户端提供同步(多线程安全)访问的方式。每个V的操作都是使用V本身作为锁对象进行同步,然后仅调用S的相应操作。为了保证互斥访问,所有对S的访问都必须通过V完成。如果属性集对象S是可序列化的,则同步视图对象V也将是可序列化的。
如在javax.print包描述中提到的,将null引用参数传递给方法是不正确的,除非在方法上明确记录了具有有意义解释的情况。反之使用是不正确的编码,可能会导致立即或以后的某个时间发生运行时异常。 IllegalArgumentException和NullPointerException是这类情况的典型和可接受的运行时异常示例。
-
Method Summary
Modifier and TypeMethodDescriptionstatic AttributeSetsynchronizedView(AttributeSet attributeSet) 创建给定属性集的同步视图。static DocAttributeSetsynchronizedView(DocAttributeSet attributeSet) 创建给定文档属性集的同步视图。static PrintJobAttributeSetsynchronizedView(PrintJobAttributeSet attributeSet) 创建给定打印作业属性集的同步视图。static PrintRequestAttributeSetsynchronizedView(PrintRequestAttributeSet attributeSet) 创建给定打印请求属性集的同步视图。static PrintServiceAttributeSetsynchronizedView(PrintServiceAttributeSet attributeSet) 创建给定打印服务属性集的同步视图。static AttributeSetunmodifiableView(AttributeSet attributeSet) 创建给定属性集的不可修改视图。static DocAttributeSetunmodifiableView(DocAttributeSet attributeSet) 创建给定文档属性集的不可修改视图。static PrintJobAttributeSetunmodifiableView(PrintJobAttributeSet attributeSet) 创建给定打印作业属性集的不可修改视图。static PrintRequestAttributeSetunmodifiableView(PrintRequestAttributeSet attributeSet) 创建给定打印请求属性集的不可修改视图。static PrintServiceAttributeSetunmodifiableView(PrintServiceAttributeSet attributeSet) 创建给定打印服务属性集的不可修改视图。static Class<?> verifyAttributeCategory(Object object, Class<?> interfaceName) static AttributeverifyAttributeValue(Object object, Class<?> interfaceName) 验证给定对象是给定接口的实例,假定为接口Attribute或其子接口。static voidverifyCategoryForValue(Class<?> category, Attribute attribute) 验证给定属性类别对象是否等于给定属性值对象的类别。
-
Method Details
-
unmodifiableView
创建给定属性集的不可修改视图。- 参数:
-
attributeSet- 基础属性集 - 返回:
-
attributeSet的不可修改视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
unmodifiableView
创建给定文档属性集的不可修改视图。- 参数:
-
attributeSet- 基础文档属性集 - 返回:
-
attributeSet的不可修改视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
unmodifiableView
创建给定打印请求属性集的不可修改视图。- 参数:
-
attributeSet- 基础打印请求属性集 - 返回:
-
attributeSet的不可修改视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
unmodifiableView
创建给定打印作业属性集的不可修改视图。- 参数:
-
attributeSet- 基础打印作业属性集 - 返回:
-
attributeSet的不可修改视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
unmodifiableView
创建给定打印服务属性集的不可修改视图。- 参数:
-
attributeSet- 基础打印服务属性集 - 返回:
-
attributeSet的不可修改视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
synchronizedView
创建给定属性集的同步视图。- 参数:
-
attributeSet- 基础属性集 - 返回:
-
attributeSet的同步视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
synchronizedView
创建给定文档属性集的同步视图。- 参数:
-
attributeSet- 基础文档属性集 - 返回:
-
attributeSet的同步视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
synchronizedView
创建给定打印请求属性集的同步视图。- 参数:
-
attributeSet- 基础打印请求属性集 - 返回:
-
attributeSet的同步视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
synchronizedView
创建给定打印作业属性集的同步视图。- 参数:
-
attributeSet- 基础打印作业属性集 - 返回:
-
attributeSet的同步视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
synchronizedView
创建给定打印服务属性集的同步视图。- 参数:
-
attributeSet- 基础打印服务属性集 - 返回:
-
attributeSet的同步视图 - 抛出:
-
NullPointerException- 如果attributeSet为null
-
verifyAttributeCategory
- 参数:
-
object- 要测试的Object -
interfaceName- 对象必须实现的接口 - 返回:
-
如果
object是实现interfaceName的Class,则将object向下转型为类型Class;否则将抛出异常 - 抛出:
-
NullPointerException- 如果object为null -
ClassCastException- 如果object不是实现interfaceName的Class
-
verifyAttributeValue
验证给定对象是给定接口的实例,假定为接口Attribute或其子接口。- 参数:
-
object- 要测试的Object -
interfaceName- 对象必须是其实例的接口 - 返回:
-
如果
object是interfaceName的实例,则将object向下转型为类型Attribute;否则将抛出异常 - 抛出:
-
NullPointerException- 如果object为null -
ClassCastException- 如果object不是interfaceName的实例
-
verifyCategoryForValue
验证给定属性类别对象是否等于给定属性值对象的类别。如果是,则此方法返回不执行任何操作。如果不是,则此方法抛出异常。- 参数:
-
category- 要测试的属性类别 -
attribute- 要测试的属性值 - 抛出:
-
NullPointerException- 如果category或attribute为null -
IllegalArgumentException- 如果category不等于attribute的类别
-