|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.beans.FeatureDescriptor
java.beans.PropertyDescriptor
public class PropertyDescriptor
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:
<propertyType> <getMethodName>()
void <setMethodName>(<propertyType>)
Constructor Summary | |
---|---|
PropertyDescriptor(String name,
Class<?> beanClass)
Create a new PropertyDescriptor by introspection. |
|
PropertyDescriptor(String name,
Class<?> beanClass,
String getMethodName,
String setMethodName)
Create a new PropertyDescriptor by introspection. |
|
PropertyDescriptor(String name,
Method readMethod,
Method writeMethod)
Create a new PropertyDescriptor using explicit Methods. |
Method Summary | |
---|---|
PropertyEditor |
createPropertyEditor(Object bean)
Instantiate a property editor using the property editor class. |
boolean |
equals(Object o)
Compares this PropertyDescriptor against the
given object. |
Class<?> |
getPropertyEditorClass()
Get the PropertyEditor class. |
Class<?> |
getPropertyType()
Get the property type. |
Method |
getReadMethod()
Get the get method. |
Method |
getWriteMethod()
Get the set method. |
int |
hashCode()
Return a hash code for this object, conforming to the contract described in Object.hashCode() . |
boolean |
isBound()
Get whether the property is bound. |
boolean |
isConstrained()
Get whether the property is constrained. |
void |
setBound(boolean bound)
Set whether the property is bound. |
void |
setConstrained(boolean constrained)
Set whether the property is constrained. |
void |
setPropertyEditorClass(Class<?> propertyEditorClass)
Set the PropertyEditor class. |
void |
setReadMethod(Method readMethod)
Sets the read method. |
void |
setWriteMethod(Method writeMethod)
Sets the write method. |
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, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PropertyDescriptor(String name, Class<?> beanClass) throws IntrospectionException
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.
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
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.
IntrospectionException
- if the methods are not found
or invalid.public PropertyDescriptor(String name, Class<?> beanClass, String getMethodName, String setMethodName) throws IntrospectionException
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.
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 or null
if the property is write-only.setMethodName
- the name of the set method or null
if the property is read-only.
IntrospectionException
- if the methods are not found
or invalid.public PropertyDescriptor(String name, Method readMethod, Method writeMethod) throws IntrospectionException
Method
arguments
being null
. In such a case the property type is null
.
name
- the programmatic name of the property, usually
starting with a lowercase letter (e.g. fooManChu
instead of FooManChu).readMethod
- the read method or null
if the property is write-only.writeMethod
- the write method or null
if the property is read-only.
IntrospectionException
- if the methods are not found
or invalid.Method Detail |
---|
public Class<?> getPropertyType()
public Method getReadMethod()
public void setReadMethod(Method readMethod) throws IntrospectionException
void
. If this methods succeeds the property type
is adjusted to the return type of the read method.null
or provide method which have been declared in distinct classes.
readMethod
- The new method to be used or null
.
IntrospectionException
- If the given method is invalid.public Method getWriteMethod()
public void setWriteMethod(Method writeMethod) throws IntrospectionException
null
or provide method which have been declared in distinct classes.
writeMethod
- The new method to be used or null
.
IntrospectionException
- If the given method is invalid.public boolean isBound()
public void setBound(boolean bound)
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.
bound
- whether the property is bound or not.public boolean isConstrained()
public void setConstrained(boolean constrained)
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:
VetoableChangeListener.vetoableChange()
event notifying others of the change and allowing them a chance to
say it is a bad thing.
constrained
- whether the property is constrained or not.public Class<?> getPropertyEditorClass()
public void setPropertyEditorClass(Class<?> propertyEditorClass)
propertyEditorClass
- the PropertyEditor class for this
class to use.public PropertyEditor createPropertyEditor(Object bean)
bean
- the argument to the constructor
public int hashCode()
Object.hashCode()
.
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public boolean equals(Object o)
PropertyDescriptor
against the
given object.
Two PropertyDescriptors are equals if
equals
in class Object
o
- the Object to compare to
Object.hashCode()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |