JavaTM Platform
Standard Ed. 6

java.beans
类 PropertyDescriptor

java.lang.Object
  继承者 java.beans.FeatureDescriptor
      继承者 java.beans.PropertyDescriptor
直接已知子类:
IndexedPropertyDescriptor

public class PropertyDescriptor
extends FeatureDescriptor

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


构造方法摘要
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)
          此构造方法带有某一简单属性的名称,以及用来读取和写入属性的 Method 对象。
 
方法摘要
 PropertyEditor createPropertyEditor(Object bean)
          使用当前属性编辑器类构造一个属性编辑器实例。
 boolean equals(Object obj)
          将此 PropertyDescriptor 与指定对象进行比较。
 Class<?> getPropertyEditorClass()
          获得已为此属性注册的任何显式 PropertyEditor Class。
 Class<?> getPropertyType()
          获得属性的 Class 对象。
 Method getReadMethod()
          获得应该用于读取属性值的方法。
 Method getWriteMethod()
          获得应该用于写入属性值的方法。
 int hashCode()
          返回对象的哈希码。
 boolean isBound()
          更新 "bound" 属性将导致更改该属性时激发 "PropertyChange" 事件。
 boolean isConstrained()
          试图更新 "Constrained" 属性将导致更改该属性时激发 "VetoableChange" 事件。
 void setBound(boolean bound)
          更新 "bound" 属性将导致更改该属性时激发 "PropertyChange" 事件。
 void setConstrained(boolean constrained)
          试图更新 "Constrained" 属性将导致更改该属性时激发 "VetoableChange" 事件。
 void setPropertyEditorClass(Class<?> propertyEditorClass)
          通常 PropertyEditor 是使用 PropertyEditorManager 找到的。
 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
 
从类 java.lang.Object 继承的方法
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

PropertyDescriptor

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

参数:
propertyName - 属性的编程名称。
beanClass - 目标 bean 的 Class 对象。例如 sun.beans.OurButton.class。
抛出:
IntrospectionException - 如果在内省期间发生异常。

PropertyDescriptor

public PropertyDescriptor(String propertyName,
                          Class<?> beanClass,
                          String readMethodName,
                          String writeMethodName)
                   throws IntrospectionException
此构造方法带有一个简单属性的名称和用于读写属性的方法名称。

参数:
propertyName - 属性的编程名称。
beanClass - 目标 bean 的 Class 对象。例如 sun.beans.OurButton.class。
readMethodName - 用于读取属性值的方法名称。如果属性是只写的,则该参数可能为 null。
writeMethodName - 用于写入属性值的方法名称。如果属性是只读的,则该参数可能为 null。
抛出:
IntrospectionException - 如果在内省期间发生异常。

PropertyDescriptor

public PropertyDescriptor(String propertyName,
                          Method readMethod,
                          Method writeMethod)
                   throws IntrospectionException
此构造方法带有某一简单属性的名称,以及用来读取和写入属性的 Method 对象。

参数:
propertyName - 属性的编程名称。
readMethod - 用于读取属性值的方法。如果属性是只写的,则该参数可能为 null。
writeMethod - 用于写入属性值的方法。如果属性是只读的,则该参数可能为 null。
抛出:
IntrospectionException - 如果在内省期间发生异常。
方法详细信息

getPropertyType

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

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

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


getReadMethod

public Method getReadMethod()
获得应该用于读取属性值的方法。

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

setReadMethod

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

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

getWriteMethod

public Method getWriteMethod()
获得应该用于写入属性值的方法。

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

setWriteMethod

public void setWriteMethod(Method writeMethod)
                    throws IntrospectionException
设置应该用于写入属性值的方法。

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

isBound

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

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

setBound

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

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

isConstrained

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

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

setConstrained

public void setConstrained(boolean constrained)
试图更新 "Constrained" 属性将导致更改该属性时激发 "VetoableChange" 事件。

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

setPropertyEditorClass

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

参数:
propertyEditorClass - 所需 PropertyEditor 的 Class。

getPropertyEditorClass

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

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

createPropertyEditor

public PropertyEditor createPropertyEditor(Object bean)
使用当前属性编辑器类构造一个属性编辑器实例。

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

参数:
bean - 源对象
返回:
属性编辑器实例,如果没有定义或无法创建属性编辑器,则返回 null
从以下版本开始:
1.5

equals

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

覆盖:
Object 中的 equals
参数:
obj - 要与之比较的引用对象。
返回:
如果此对象与 obj 参数相同,则返回 true;否则返回 false
从以下版本开始:
1.4
另请参见:
Object.hashCode(), Hashtable

hashCode

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

覆盖:
Object 中的 hashCode
返回:
此对象的哈希码值。
从以下版本开始:
1.5
另请参见:
Object.equals(java.lang.Object), Hashtable

JavaTM Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策