Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.beans.FeatureDescriptor
java.beans.PropertyDescriptor
public class PropertyDescriptor
extends FeatureDescriptor
The constraints put on get and set methods are:
<propertyType> <getMethodName>()
void <setMethodName>(<propertyType>)
Constructor Summary | |
| |
| |
|
Method Summary | |
PropertyEditor |
|
boolean | |
Class |
|
Class |
|
Method |
|
Method |
|
int |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.beans.FeatureDescriptor | |
attributeNames , getDisplayName , getName , getShortDescription , getValue , isExpert , isHidden , isPreferred , setDisplayName , setExpert , setHidden , setName , setPreferred , setShortDescription , setValue |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public PropertyDescriptor(String name, Class beanClass) throws IntrospectionException
Create a new PropertyDescriptor by introspection. This form of constructor creates the PropertyDescriptor by looking for a getter method namedget<name>()
(or, optionally, if the property is boolean,is<name>()
) andset<name>()
in class<beanClass>
, where <name> has its first letter capitalized by the constructor.Note that using this constructor the given property must be read- and writeable. If the implementation does not both, a read and a write method, an
IntrospectionException
is thrown. 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:
name
- the programmatic name of the property, usually starting with a lowercase letter (e.g. fooManChu instead of FooManChu).beanClass
- the class the get and set methods live in.
- Throws:
IntrospectionException
- if the methods are not found or invalid.
public PropertyDescriptor(String name, Class beanClass, String getMethodName, String setMethodName) throws IntrospectionException
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:
name
- the programmatic name of the property, usually starting with a lowercase letter (e.g. fooManChu instead of FooManChu).beanClass
- the class the get and set methods live in.getMethodName
- the name of the get method ornull
if the property is write-only.setMethodName
- the name of the set method ornull
if the property is read-only.
- Throws:
IntrospectionException
- if the methods are not found or invalid.
public PropertyDescriptor(String name, Method readMethod, Method writeMethod) throws IntrospectionException
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.
It is possible to call this method with bothMethod
arguments beingnull
. In such a case the property type isnull
.
- Parameters:
name
- the programmatic name of the property, usually starting with a lowercase letter (e.g. fooManChu instead of FooManChu).readMethod
- the read method ornull
if the property is write-only.writeMethod
- the write method ornull
if the property is read-only.
- Throws:
IntrospectionException
- if the methods are not found or invalid.
public PropertyEditor createPropertyEditor(Object bean)
Instantiate a property editor using the property editor class. If no property editor class has been set, this will return null. If the editor class has a public constructor which takes a single argument, that will be used and the bean parameter will be passed to it. Otherwise, a public no-argument constructor will be used, if available. This method will return null if no constructor is found or if construction fails for any reason.
- Parameters:
bean
- the argument to the constructor
- Returns:
- a new PropertyEditor, or null on error
- Since:
- 1.5
public boolean equals(Object o)
Compares thisPropertyDescriptor
against the given object. Two PropertyDescriptors are equals if
- the read methods are equal
- the write methods are equal
- the property types are equals
- the property editor classes are equal
- the flags (constrained and bound) are equal
- Returns:
- Whether both objects are equal according to the rules given above.
- Since:
- 1.4
public Class getPropertyEditorClass()
Get the PropertyEditor class. Defaults to null. *
public Class getPropertyType()
Get the property type. This is the type the get method returns and the set method takes in.
public Method getReadMethod()
Get the get method. Why they call it readMethod here and get everywhere else is beyond me.
public Method getWriteMethod()
Get the set method. Why they call it writeMethod here and set everywhere else is beyond me.
public int hashCode()
Return a hash code for this object, conforming to the contract described inObject.hashCode()
.
- Returns:
- the hash code
- Since:
- 1.5
public boolean isConstrained()
Get whether the property is constrained. Defaults to false. *
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:
bound
- whether the property is bound or not.
public void setConstrained(boolean constrained)
Set whether the property is constrained. If the set method throwsjava.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:
- Fire the
VetoableChangeListener.vetoableChange()
event notifying others of the change and allowing them a chance to say it is a bad thing.- 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.
- If all has gone well to this point, the value may be changed.
- Parameters:
constrained
- whether the property is constrained or not.
public void setPropertyEditorClass(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:
propertyEditorClass
- the PropertyEditor class for this class to use.
public void setReadMethod(Method readMethod) throws IntrospectionException
Sets the read method.
The read method is used to retrieve the value of a property. A legal read method must have no arguments. Its return type must not bevoid
. If this methods succeeds the property type is adjusted to the return type of the read method.
It is legal to set the read and the write method tonull
or provide method which have been declared in distinct classes.
- Parameters:
readMethod
- The new method to be used ornull
.
- Throws:
IntrospectionException
- If the given method is invalid.
- Since:
- 1.2
public void setWriteMethod(Method writeMethod) throws IntrospectionException
Sets the write method.
The write method is used to set the value of a property. A legal write method must have a single argument which can be assigned to the property. If no read method exists the property type changes to the argument type of the write method.
It is legal to set the read and the write method tonull
or provide method which have been declared in distinct classes.
- Parameters:
writeMethod
- The new method to be used ornull
.
- Throws:
IntrospectionException
- If the given method is invalid.
- Since:
- 1.2