JavaAPI之PropertyDescriptor

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)

结构

java.beans

类 PropertyDescriptor

java.lang.Object
  java.beans.FeatureDescriptor
      java.beans.PropertyDescriptor

直接已知子类:

IndexedPropertyDescriptor

描述

public class PropertyDescriptor extends FeatureDescriptor
 

PropertyDescriptor 描述 Java Bean 通过一对存储器方法导出的一个属性。

构造方法

1、public PropertyDescriptor(String propertyName, Class<?> beanClass) throwsIntrospectionException

通过调用 getFoo 和 setFoo 存取方法,为符合标准 Java 约定的属性构造一个 PropertyDescriptor。因此如果参数名为 "fred",则假定 writer 方法为 "setFred",reader 方法为 "getFred"(对于 boolean 属性则为 "isFred")。注意,属性名应该以小写字母开头,而方法名称中的首写字母将是大写的。

参数:propertyName - 属性的编程名称。

            beanClass - 目标 bean 的 Class 对象。例如 sun.beans.OurButton.class。

抛出:IntrospectionException - 如果在内省期间发生异常。

2、public PropertyDescriptor(String propertyName, Class<?> beanClass, String readMethodName, String writeMethodName) throwsIntrospectionException

此构造方法带有一个简单属性的名称和用于读写属性的方法名称。

参数:propertyName - 属性的编程名称。

            beanClass - 目标 bean 的 Class 对象。例如 sun.beans.OurButton.class。

            readMethodName - 用于读取属性值的方法名称。如果属性是只写的,则该参数可能为 null。

            writeMethodName - 用于写入属性值的方法名称。如果属性是只读的,则该参数可能为 null。

抛出:IntrospectionException - 如果在内省期间发生异常。

 

3、public PropertyDescriptor(String propertyName,  Method readMethod,Method writeMethod)throwsIntrospectionException

此构造方法带有某一简单属性的名称,以及用来读取和写入属性的 Method 对象。

参数:propertyName - 属性的编程名称。

             readMethod - 用于读取属性值的方法。如果属性是只写的,则该参数可能为 null。

            writeMethod - 用于写入属性值的方法。如果属性是只读的,则该参数可能为 null。

抛出:IntrospectionException - 如果在内省期间发生异常。

方法详细

1、public Class<?>getPropertyType()   获得属性的 Class 对象。

返回:属性的 Java 类型信息。注意,"Class" 对象可以描述内置 Java 类型,比如 "int"。如果此属性是一个不支持非索引访问的索引 (indexed) 属性,则结果可能是 "null"。

而这里的类型是由 ReadMethod 返回的类型。

2、publicMethodgetReadMethod()   获得应该用于读取属性值的方法。

返回:应该用于读取属性值的方法。如果无法读取该属性,则可能返回。

3、public void setReadMethod(Method readMethod) throwsIntrospectionException  设置应该用于读取属性值的方法。

参数:readMethod - 新的读取方法。

抛出:IntrospectionException

4、publicMethodgetWriteMethod()   获得应该用于写入属性值的方法。

返回:应该用于写入属性值的方法。如果无法写入该属性,则可能返回。

5、public void setWriteMethod(Method writeMethod) throwsIntrospectionException

设置应该用于写入属性值的方法。

参数:writeMethod - 新的写入方法。

抛出:IntrospectionException

6、public boolean isBound()   更新 "bound" 属性将导致更改该属性时激发 "PropertyChange" 事件。

返回:如果该属性是绑定 (bound) 属性,则返回 true。

7、public void setBound(boolean bound)

更新 "bound" 属性将导致更改该属性时激发 "PropertyChange" 事件。

参数:bound - 如果该属性是绑定属性,则该属性为 true。

8、public boolean isConstrained()

试图更新 "Constrained" 属性将导致更改该属性时激发 "VetoableChange" 事件。

返回:如果该属性是约束 (constrained) 属性,则返回 true。

9、public void setConstrained(boolean constrained)

试图更新 "Constrained" 属性将导致更改该属性时激发 "VetoableChange" 事件。

参数:constrained - 如果该属性是约束属性,则该属性为 true。

10、public void setPropertyEditorClass(Class<?> propertyEditorClass)

通常 PropertyEditor 是使用 PropertyEditorManager 找到的。不过,如果出于某些原因想将特定 PropertyEditor 与某一给定属性相关联,那么可以使用此方法做到这一点。

参数:propertyEditorClass - 所需 PropertyEditor 的 Class。

11、public Class<?>getPropertyEditorClass()   获得已为此属性注册的任何显式 PropertyEditor Class。

返回:已为此属性注册的任何显式 PropertyEditor Class。通常此方法将返回 "null",指示没有注册特殊编辑器,所以 PropertyEditorManager 应该用于查找合适的 PropertyEditor。

12、public PropertyEditorcreatePropertyEditor(Object bean)

使用当前属性编辑器类构造一个属性编辑器实例。如果属性编辑器类拥有一个带有 Object 参数的公共构造方法,则将通过使用 bean 参数作为变量来调用它。否则将调用默认构造方法。

参数:bean - 源对象

返回:属性编辑器实例,如果没有定义或无法创建属性编辑器,则返回 null

从以下版本开始:1.5

13、public boolean equals(Object obj)

将此 PropertyDescriptor 与指定对象进行比较。如果对象是相同的,则返回 true。如果读取、写入、属性类型、属性编辑器和标记都是等同的,则两个PropertyDescriptor 是相同的。

覆盖:Object 中的 equals

参数:obj - 要与之比较的引用对象。

返回:如果此对象与 obj 参数相同,则返回 true;否则返回false

从以下版本开始:1.4

另请参见:Object.hashCode(), Hashtable

14、public int hashCode()

返回对象的哈希码。关于完整的描述,请参阅 Object.hashCode()

覆盖:Object 中的 hashCode

返回:此对象的哈希码值。

从以下版本开始:1.5

另请参见:Object.equals(java.lang.Object),Hashtable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值