Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.beans

Class PropertyDescriptor

java.lang.Object
|
+--java.beans.FeatureDescriptor
   |
   +--java.beans.PropertyDescriptor


public class PropertyDescriptor

extends FeatureDescriptor

PropertyDescriptor describes information about a JavaBean property, by which we mean a property that has been exposed via a pair of get and set methods. (There may be no get method, which means the property is write-only, or no set method, which means the the property is read-only.)

The constraints put on get and set methods are:

  1. A get method must have signature <propertyType> <getMethodName>()
  2. A set method must have signature void <setMethodName>(<propertyType>)
  3. Either method type may throw any exception.
  4. Both methods must be public.

Since:Author:

Constructor Summary

PropertyDescriptor(java.lang.String name, java.lang.Class beanClass)

Create a new PropertyDescriptor by introspection.
PropertyDescriptor(java.lang.String name, java.lang.Class beanClass, java.lang.String getMethodName, java.lang.String setMethodName)

Create a new PropertyDescriptor by introspection.
PropertyDescriptor(java.lang.String name, java.lang.reflect.Method getMethod, java.lang.reflect.Method setMethod)

Create a new PropertyDescriptor using explicit Methods.

Method Summary

java.lang.ClassgetPropertyEditorClass()

Get the PropertyEditor class.
java.lang.ClassgetPropertyType()

Get the property type.
java.lang.reflect.MethodgetReadMethod()

Get the get method.
java.lang.reflect.MethodgetWriteMethod()

Get the set method.
booleanisBound()

Get whether the property is bound.
booleanisConstrained()

Get whether the property is constrained.
voidsetBound(boolean bound)

Set whether the property is bound.
voidsetConstrained(boolean constrained)

Set whether the property is constrained.
voidsetPropertyEditorClass(java.lang.Class propertyEditorClass)

Set the PropertyEditor class.

Constructor Details

PropertyDescriptor

public PropertyDescriptor(java.lang.String name, java.lang.Class beanClass)

Create a new PropertyDescriptor by introspection. This form of constructor creates the PropertyDescriptor by looking for a getter method named get<name>() (or, optionally, if the property is boolean, is<name>()) and set<name>() in class <beanClass>, where <name> has its first letter capitalized by the constructor.

Implementation note: If there is both are both isXXX and getXXX methods, the former is used in preference to the latter. We do not check that an isXXX method returns a boolean. In both cases, this matches the behaviour of JDK 1.4

Parameters:

Throws:


PropertyDescriptor

public PropertyDescriptor(java.lang.String name, java.lang.Class beanClass, java.lang.String getMethodName, java.lang.String setMethodName)

Create a new PropertyDescriptor by introspection. This form of constructor allows you to specify the names of the get and set methods to search for.

Implementation note: If there is a get method (or boolean isXXX() method), then the return type of that method is used to find the set method. If there is no get method, then the set method is searched for exhaustively.

Spec note: If there is no get method and multiple set methods with the same name and a single parameter (different type of course), then an IntrospectionException is thrown. While Sun's spec does not state this, it can make Bean behavior different on different systems (since method order is not guaranteed) and as such, can be treated as a bug in the spec. I am not aware of whether Sun's implementation catches this.

Parameters:

Throws:


PropertyDescriptor

public PropertyDescriptor(java.lang.String name, java.lang.reflect.Method getMethod, java.lang.reflect.Method setMethod)

Create a new PropertyDescriptor using explicit Methods. Note that the methods will be checked for conformance to standard Property method rules, as described above at the top of this class.

Parameters:

Throws:


Method Details

getPropertyEditorClass

public Class getPropertyEditorClass()

Get the PropertyEditor class. Defaults to null. *


getPropertyType

public Class getPropertyType()

Get the property type. This is the type the get method returns and the set method takes in.


getReadMethod

public Method getReadMethod()

Get the get method. Why they call it readMethod here and get everywhere else is beyond me.


getWriteMethod

public Method getWriteMethod()

Get the set method. Why they call it writeMethod here and set everywhere else is beyond me.


isBound

public boolean isBound()

Get whether the property is bound. Defaults to false. *


isConstrained

public boolean isConstrained()

Get whether the property is constrained. Defaults to false. *


setBound

public void setBound(boolean bound)

Set whether the property is bound. As long as the the bean implements addPropertyChangeListener() and removePropertyChangeListener(), setBound(true) may safely be called.

If these things are not true, then the behavior of the system will be undefined.

When a property is bound, its set method is required to fire the PropertyChangeListener.propertyChange()) event after the value has changed.

Parameters:


setConstrained

public void setConstrained(boolean constrained)

Set whether the property is constrained. If the set method throws java.beans.PropertyVetoException (or subclass thereof) and the bean implements addVetoableChangeListener() and removeVetoableChangeListener(), then setConstrained(true) may safely be called. Otherwise, the system behavior is undefined. Spec note: given those strict parameters, it would be nice if it got set automatically by detection, but oh well.

When a property is constrained, its set method is required to:

  1. Fire the VetoableChangeListener.vetoableChange() event notifying others of the change and allowing them a chance to say it is a bad thing.
  2. If any of the listeners throws a PropertyVetoException, then it must fire another vetoableChange() event notifying the others of a reversion to the old value (though, of course, the change was never made). Then it rethrows the PropertyVetoException and exits.
  3. If all has gone well to this point, the value may be changed.

Parameters:


setPropertyEditorClass

public void setPropertyEditorClass(java.lang.Class propertyEditorClass)

Set the PropertyEditor class. If the class does not implement the PropertyEditor interface, you will likely get an exception late in the game.

Parameters: