java.beans

Class IndexedPropertyDescriptor

public class IndexedPropertyDescriptor extends PropertyDescriptor

IndexedPropertyDescriptor describes information about a JavaBean indexed property, by which we mean an array-like property that has been exposed via a pair of get and set methods and another pair that allows you to get to the property by an index.

An example property would have four methods like this:

FooBar[] getFoo()
void setFoo(FooBar[])
FooBar getFoo(int)
void setFoo(int,FooBar)

The constraints put on get and set methods are:

  1. There must be at least a get(int) or a set(int,...) method. Nothing else is required. Spec note:One nice restriction would be that if there is a get() there must be a get(int), same with set, but that is not in the spec and is fairly harmless.)
  2. A get array method must have signature <propertyType>[] <getMethodName>()
  3. A set array method must have signature void <setMethodName>(<propertyType>[])
  4. A get index method must have signature <propertyType> <getMethodName>(int)
  5. A set index method must have signature void <setMethodName>(int,<propertyType>)
  6. All these methods may throw any exception.
  7. All these methods must be public.

Since: JDK1.1

Constructor Summary
IndexedPropertyDescriptor(String name, Class<?> beanClass)
Create a new IndexedPropertyDescriptor by introspection.
IndexedPropertyDescriptor(String name, Class<?> beanClass, String getMethodName, String setMethodName, String getIndexName, String setIndexName)
Create a new IndexedPropertyDescriptor by introspection.
IndexedPropertyDescriptor(String name, Method getMethod, Method setMethod, Method getIndex, Method setIndex)
Create a new PropertyDescriptor using explicit Methods.
Method Summary
Class<?>getIndexedPropertyType()
MethodgetIndexedReadMethod()
MethodgetIndexedWriteMethod()
voidsetIndexedReadMethod(Method m)
Sets the method that is used to read an indexed property.
voidsetIndexedWriteMethod(Method m)
Sets the method that is used to write an indexed property.

Constructor Detail

IndexedPropertyDescriptor

public IndexedPropertyDescriptor(String name, Class<?> beanClass)
Create a new IndexedPropertyDescriptor by introspection. This form of constructor creates the PropertyDescriptor by looking for getter methods named get<name>() and setter methods named set<name>() in class <beanClass>, where <name> has its first letter capitalized by the constructor.

Implementation note: If there is a get(int) method, then the return type of that method is used to find the remaining methods. If there is no get method, then the set(int) method is searched for exhaustively and that type is used to find the others.

Spec note: If there is no get(int) method and multiple set(int) methods with the same name and the correct parameters (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.

Throws: IntrospectionException if the methods are not found or invalid.

IndexedPropertyDescriptor

public IndexedPropertyDescriptor(String name, Class<?> beanClass, String getMethodName, String setMethodName, String getIndexName, String setIndexName)
Create a new IndexedPropertyDescriptor 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(int) method, then the return type of that method is used to find the remaining methods. If there is no get method, then the set(int) method is searched for exhaustively and that type is used to find the others.

Spec note: If there is no get(int) method and multiple set(int) methods with the same name and the correct parameters (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 array method. setMethodName the name of the set array method. getIndexName the name of the get index method. setIndexName the name of the set index method.

Throws: IntrospectionException if the methods are not found or invalid.

IndexedPropertyDescriptor

public IndexedPropertyDescriptor(String name, Method getMethod, Method setMethod, Method getIndex, Method setIndex)
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: name the programmatic name of the property, usually starting with a lowercase letter (e.g. fooManChu instead of FooManChu). getMethod the get array method. setMethod the set array method. getIndex the get index method. setIndex the set index method.

Throws: IntrospectionException if the methods are not found or invalid.

Method Detail

getIndexedPropertyType

public Class<?> getIndexedPropertyType()

getIndexedReadMethod

public Method getIndexedReadMethod()

getIndexedWriteMethod

public Method getIndexedWriteMethod()

setIndexedReadMethod

public void setIndexedReadMethod(Method m)
Sets the method that is used to read an indexed property.

Parameters: m the method to set

setIndexedWriteMethod

public void setIndexedWriteMethod(Method m)
Sets the method that is used to write an indexed property.

Parameters: m the method to set