FileDocCategorySizeDatePackage
BeanPropertyDescriptor.javaAPI DocApache Axis 1.47908Sat Apr 22 18:57:28 BST 2006org.apache.axis.utils

BeanPropertyDescriptor

public class BeanPropertyDescriptor extends Object
This class represents a field/property in a value type (a class with either bean-style getters/setters or public fields). It is essentially a thin wrapper around the PropertyDescriptor from the JavaBean utilities. We wrap it with this class so that we can create the subclass FieldPropertyDescriptor and access public fields (who wouldn't have PropertyDescriptors normally) via the same interface. There are also some interesting tricks where indexed properties are concerned, mostly involving the fact that we manage the arrays here rather than relying on the value type class to do it itself.
author
Rich Scheuerle
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
protected static Log
log
protected PropertyDescriptor
myPD
protected static final Object[]
noArgs
Constructors Summary
public BeanPropertyDescriptor(PropertyDescriptor pd)
Constructor (takes a PropertyDescriptor)

param
pd


               
       
        myPD = pd;
    
protected BeanPropertyDescriptor()
Protected constructor for use by our children

    
Methods Summary
public java.lang.Objectget(java.lang.Object obj, int i)
Get an indexed property

param
obj is the object
param
i the index
return
the object at the indicated index

        if (!isIndexed()) {
            return Array.get(get(obj), i);
        } else {
            IndexedPropertyDescriptor id = (IndexedPropertyDescriptor)myPD;
            return id.getIndexedReadMethod().invoke(obj,
                                                    new Object[] {
                                                        new Integer(i)});
        }
    
public java.lang.Objectget(java.lang.Object obj)
Get the property value

param
obj is the object
return
the entire propery value

        Method readMethod = myPD.getReadMethod();
        if (readMethod != null) {
            return readMethod.invoke(obj, noArgs);
        } else {
            throw new IllegalAccessException(Messages.getMessage("badGetter00"));
        }
    
public java.lang.ClassgetActualType()

        return myPD.getPropertyType();
    
public java.lang.StringgetName()
Get our property name.

        return myPD.getName();
    
public java.lang.ClassgetType()
Get the type of a property

return
the type of the property

        if (isIndexed()) {
            return ((IndexedPropertyDescriptor)myPD).getIndexedPropertyType();
        } else {
            return myPD.getPropertyType();
        }
    
protected voidgrowArrayToSize(java.lang.Object obj, java.lang.Class componentType, int i)
Grow the array

param
obj
param
componentType
param
i
throws
InvocationTargetException
throws
IllegalAccessException

        // Get the entire array and make sure it is large enough
        Object array = get(obj);
        if (array == null || Array.getLength(array) <= i) {
            // Construct a larger array of the same type            
            Object newArray = Array.newInstance(componentType, i + 1);
            // Copy over the old elements
            if (array != null) {
                System.arraycopy(array, 0, newArray, 0, Array.getLength(array));
            }
            // Set the object to use the larger array
            set(obj, newArray);
        }
    
public booleanisArray()
Query if property is an array (excluded byte[]).

return
true if it's an array (excluded byte[])

        return ((myPD.getPropertyType() != null) && myPD.getPropertyType()
                                   .isArray());
    
public booleanisIndexed()
Query if property is indexed

return
true if indexed methods exist

        return (myPD instanceof IndexedPropertyDescriptor);
    
public booleanisIndexedOrArray()
Query if property is indexed or if it' an array.

return
true if indexed methods exist or if it's an array

        return (isIndexed() || isArray());
    
public booleanisReadable()
Query if property is readable

return
true if readable

        return (myPD.getReadMethod() != null);
    
public booleanisWriteable()
Query if property is writeable

return
true if writeable

        return (myPD.getWriteMethod() != null);
    
public voidset(java.lang.Object obj, java.lang.Object newValue)
Set the property value

param
obj is the object
param
newValue is the new value

        Method writeMethod = myPD.getWriteMethod();
        if (writeMethod != null) {
            writeMethod.invoke(obj, new Object[] {newValue});
        } else {
            throw new IllegalAccessException(Messages.getMessage("badSetter00"));
        }
    
public voidset(java.lang.Object obj, int i, java.lang.Object newValue)
Set an indexed property value

param
obj is the object
param
i the index
param
newValue is the new value

        // Set the new value
        if (isIndexed()) {
            IndexedPropertyDescriptor id = (IndexedPropertyDescriptor)myPD;
            growArrayToSize(obj, id.getIndexedPropertyType(), i);
            id.getIndexedWriteMethod().invoke(obj,
                                              new Object[] {
                                                  new Integer(i), newValue});
        } else {
            // Not calling 'growArrayToSize' to avoid an extra call to the
            // property's setter. The setter will be called at the end anyway.
            // growArrayToSize(obj, myPD.getPropertyType().getComponentType(), i);
            Object array = get(obj);
            if (array == null || Array.getLength(array) <= i) {
                Class componentType = getType().getComponentType();
                Object newArray = Array.newInstance(componentType, i + 1);
                // Copy over the old elements
                if (array != null) {
                    System.arraycopy(array, 0, newArray, 0, Array.getLength(array));
                }
                array = newArray;
            }
            Array.set(array, i, newValue);
            // Fix for non-indempondent array-type propertirs.
            // Make sure we call the property's setter.
            set(obj, array);
        }