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()
Method
getIndexedReadMethod()
Method
getIndexedWriteMethod()
void
setIndexedReadMethod(Method m)
Sets the method that is used to read an indexed property.
void
setIndexedWriteMethod(Method m)
Sets the method that is used to write an indexed property.

Methods inherited from class java.beans.PropertyDescriptor

createPropertyEditor, equals, getPropertyEditorClass, getPropertyType, getReadMethod, getWriteMethod, hashCode, isBound, isConstrained, setBound, setConstrained, setPropertyEditorClass, setReadMethod, setWriteMethod

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

Constructor Details

IndexedPropertyDescriptor

public IndexedPropertyDescriptor(String name,
                                 Class beanClass)
            throws IntrospectionException
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)
            throws IntrospectionException
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)
            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.
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 Details

getIndexedPropertyType

public Class getIndexedPropertyType()

getIndexedReadMethod

public Method getIndexedReadMethod()

getIndexedWriteMethod

public Method getIndexedWriteMethod()

setIndexedReadMethod

public void setIndexedReadMethod(Method m)
            throws IntrospectionException
Sets the method that is used to read an indexed property.
Parameters:
m - the method to set

setIndexedWriteMethod

public void setIndexedWriteMethod(Method m)
            throws IntrospectionException
Sets the method that is used to write an indexed property.
Parameters:
m - the method to set

IndexedPropertyDescriptor.java -- Copyright (C) 1998, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.