java.lang.Object
java.beans.FeatureDescriptor
java.beans.PropertyDescriptor
PropertyDescriptor 描述了 Java Bean 通过一对访问器方法导出的一个属性。
- 自从:
- 1.1
-
构造方法总结
构造方法构造方法描述PropertyDescriptor
(String propertyName, Class<?> beanClass) 通过具有 getFoo 和 setFoo 访问器方法,为遵循标准 Java 约定的属性构造一个 PropertyDescriptor。PropertyDescriptor
(String propertyName, Class<?> beanClass, String readMethodName, String writeMethodName) 此构造方法采用简单属性的名称以及用于读取和写入属性的方法名称。PropertyDescriptor
(String propertyName, Method readMethod, Method writeMethod) 此构造方法采用简单属性的名称和用于读取和写入属性的方法对象。 -
方法总结
修饰符和类型方法描述createPropertyEditor
(Object bean) 使用当前属性编辑器类构造属性编辑器的实例。boolean
将此PropertyDescriptor
与指定对象进行比较。Class<?>
获取已为此属性注册的任何显式 PropertyEditor 类。Class<?>
返回属性的 Java 类型信息。获取应该用于读取属性值的方法。获取应该用于写入属性值的方法。int
hashCode()
返回对象的哈希码值。boolean
isBound()
对“绑定”属性的更新将导致在更改属性时触发“PropertyChange”事件。boolean
尝试更新“Constrained”属性将导致在更改属性时触发“VetoableChange”事件。void
setBound
(boolean bound) 对“绑定”属性的更新将导致在更改属性时触发“PropertyChange”事件。void
setConstrained
(boolean constrained) 尝试更新“Constrained”属性将导致在更改属性时触发“VetoableChange”事件。void
setPropertyEditorClass
(Class<?> propertyEditorClass) 通常使用 PropertyEditorManager 可以找到 PropertyEditors。void
setReadMethod
(Method readMethod) 设置应该用于读取属性值的方法。void
setWriteMethod
(Method writeMethod) 设置应该用于写入属性值的方法。在类 java.beans.FeatureDescriptor 中声明的方法
attributeNames, getDisplayName, getName, getShortDescription, getValue, isExpert, isHidden, isPreferred, setDisplayName, setExpert, setHidden, setName, setPreferred, setShortDescription, setValue, toString
-
构造方法详细信息
-
PropertyDescriptor
通过具有 getFoo 和 setFoo 访问器方法,为遵循标准 Java 约定的属性构造一个 PropertyDescriptor。因此,如果参数名称是“fred”,它将假定写入器方法是“setFred”,而读取器方法是“getFred”(或布尔属性的“isFred”)。请注意,属性名称应以小写字符开头,在方法名称中将大写。- 参数:
propertyName
- 属性的编程名称。beanClass
- 目标 bean 的类对象。例如 sun.beans.OurButton.class。- 抛出:
IntrospectionException
- 如果在内省期间发生异常。
-
PropertyDescriptor
public PropertyDescriptor(String propertyName, Class <?> beanClass, String readMethodName, String writeMethodName) throws IntrospectionException 此构造方法采用简单属性的名称以及用于读取和写入属性的方法名称。- 参数:
propertyName
- 属性的编程名称。beanClass
- 目标 bean 的类对象。例如 sun.beans.OurButton.class。readMethodName
- 用于读取属性值的方法的名称。如果属性是只写的,则可能为 null。writeMethodName
- 用于写入属性值的方法的名称。如果属性是只读的,则可能为 null。- 抛出:
IntrospectionException
- 如果在内省期间发生异常。
-
PropertyDescriptor
public PropertyDescriptor(String propertyName, Method readMethod, Method writeMethod) throws IntrospectionException 此构造方法采用简单属性的名称和用于读取和写入属性的方法对象。- 参数:
propertyName
- 属性的编程名称。readMethod
- 用于读取属性值的方法。如果属性是只写的,则可能为 null。writeMethod
- 用于写入属性值的方法。如果属性是只读的,则可能为 null。- 抛出:
IntrospectionException
- 如果在内省期间发生异常。
-
-
方法详情
-
getPropertyType
返回属性的 Java 类型信息。请注意,Class
对象可以描述原始 Java 类型,例如int
。此类型由 read 方法返回或用作 write 方法的参数类型。如果类型是不支持非索引访问的索引属性,则返回null
。- 返回:
-
表示 Java 类型信息的
Class
对象,如果无法确定类型,则为null
-
getReadMethod
获取应该用于读取属性值的方法。- 返回:
- 应该用于读取属性值的方法。如果无法读取该属性,可能会返回 null。
-
setReadMethod
设置应该用于读取属性值的方法。- 参数:
readMethod
- 新的读取方法。- 抛出:
IntrospectionException
- 如果读取方法无效- 自从:
- 1.2
-
getWriteMethod
获取应该用于写入属性值的方法。- 返回:
- 应该用于写入属性值的方法。如果无法写入该属性,则可能会返回 null。
-
setWriteMethod
设置应该用于写入属性值的方法。- 参数:
writeMethod
- 新的写入方法。- 抛出:
IntrospectionException
- 如果写入方法无效- 自从:
- 1.2
-
isBound
public boolean isBound()对“绑定”属性的更新将导致在更改属性时触发“PropertyChange”事件。- 返回:
- 如果这是绑定属性,则为真。
-
setBound
public void setBound(boolean bound) 对“绑定”属性的更新将导致在更改属性时触发“PropertyChange”事件。- 参数:
bound
- 如果这是绑定属性则为真。
-
isConstrained
public boolean isConstrained()尝试更新“Constrained”属性将导致在更改属性时触发“VetoableChange”事件。- 返回:
- 如果这是一个受约束的属性,则为真。
-
setConstrained
public void setConstrained(boolean constrained) 尝试更新“Constrained”属性将导致在更改属性时触发“VetoableChange”事件。- 参数:
constrained
- 如果这是一个受约束的属性,则为真。
-
setPropertyEditorClass
通常使用 PropertyEditorManager 可以找到 PropertyEditors。但是,如果出于某种原因您想要将特定的 PropertyEditor 与给定的属性相关联,那么您可以使用此方法来完成。- 参数:
propertyEditorClass
- 所需 PropertyEditor 的类。
-
getPropertyEditorClass
获取已为此属性注册的任何显式 PropertyEditor 类。- 返回:
- 已为此属性注册的任何显式 PropertyEditor 类。通常这将返回“null”,表示没有注册任何特殊的编辑器,因此应该使用 PropertyEditorManager 来定位合适的 PropertyEditor。
-
createPropertyEditor
使用当前属性编辑器类构造属性编辑器的实例。如果属性编辑器类有一个接受 Object 参数的公共构造方法,那么将使用 bean 参数作为参数调用它。否则,将调用默认构造方法。
- 参数:
bean
- 源对象- 返回:
- 属性编辑器实例;如果属性编辑器尚未定义或无法创建,则为 null
- 自从:
- 1.5
-
equals
将此PropertyDescriptor
与指定对象进行比较。如果对象相同,则返回 true。如果读取、写入、属性类型、属性编辑器和标志等同,则两个PropertyDescriptor
相同。 -
hashCode
public int hashCode()返回对象的哈希码值。有关完整说明,请参阅Object.hashCode()
。
-