org.apache.jdo.impl.model.java.reflection
Class ReflectionJavaTypeIntrospector.PropertyStore

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended byorg.apache.jdo.impl.model.java.reflection.ReflectionJavaTypeIntrospector.PropertyStore
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable
Enclosing class:
ReflectionJavaTypeIntrospector

static class ReflectionJavaTypeIntrospector.PropertyStore
extends java.util.HashMap

Helper class to introspect a class in order to find properties. The class provides a public method getPropertyDescriptors() returning an array of PropertyDescriptors. Each PropertyDescriptor represents a public or protected property of the class specified as constructor argument. This code is inspired by the implementation of java.beans.Introspector class.

Class PropertyStore uses the following algorithm to identify the properties:


Nested Class Summary
 
Nested classes inherited from class java.util.HashMap
 
Nested classes inherited from class java.util.AbstractMap
 
Field Summary
private  java.lang.reflect.Method[] declaredMethods
          The declared method instances for the specified class.
private static java.lang.String GET_PREFIX
           
private static int GET_PREFIX_LENGTH
           
private static java.lang.String IS_PREFIX
           
private static int IS_PREFIX_LENGTH
           
private static java.lang.String SET_PREFIX
           
private static int SET_PREFIX_LENGTH
           
 
Fields inherited from class java.util.HashMap
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
ReflectionJavaTypeIntrospector.PropertyStore(java.lang.Class clazz)
          Constructor.
 
Method Summary
private  void addGetter(java.lang.String propName, java.lang.reflect.Method method)
          Adds a getter method to the methods list for the property with the specified name.
private  void addPropertyDescriptor(java.lang.String propName, java.beans.PropertyDescriptor pd)
          Adds a the specified (incomplete) PropertyDescriptor to the list of PropertyDescriptor candidates managed by this PropertyStore.
private  void addSetter(java.lang.String propName, java.lang.reflect.Method method)
          Adds a setter method to the methods list for the property with the specified name.
 java.beans.PropertyDescriptor[] getPropertyDescriptors()
          Returns an array of PropertyDescriptors.
private  java.util.List processProperties()
          The method returns a list of PropertyDescriptors for the properties managed by this PropertyStore.
private  java.beans.PropertyDescriptor processProperty(java.util.List candidates)
          The method analyzes the specified list of candidate PropertyDescriptors and returns a single PropertyDescriptor describing the property.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

GET_PREFIX

private static final java.lang.String GET_PREFIX
See Also:
Constant Field Values

GET_PREFIX_LENGTH

private static final int GET_PREFIX_LENGTH
See Also:
Constant Field Values

SET_PREFIX

private static final java.lang.String SET_PREFIX
See Also:
Constant Field Values

SET_PREFIX_LENGTH

private static final int SET_PREFIX_LENGTH
See Also:
Constant Field Values

IS_PREFIX

private static final java.lang.String IS_PREFIX
See Also:
Constant Field Values

IS_PREFIX_LENGTH

private static final int IS_PREFIX_LENGTH
See Also:
Constant Field Values

declaredMethods

private final java.lang.reflect.Method[] declaredMethods
The declared method instances for the specified class.

Constructor Detail

ReflectionJavaTypeIntrospector.PropertyStore

public ReflectionJavaTypeIntrospector.PropertyStore(java.lang.Class clazz)
Constructor.

Method Detail

getPropertyDescriptors

public java.beans.PropertyDescriptor[] getPropertyDescriptors()
Returns an array of PropertyDescriptors. Each PropertyDescriptor represents a public or protected property of the class specified as constructor argument.

Returns:
array of public and protected properties

addGetter

private void addGetter(java.lang.String propName,
                       java.lang.reflect.Method method)
Adds a getter method to the methods list for the property with the specified name.

Parameters:
propName - the name of the property.
method - the getter method.

addSetter

private void addSetter(java.lang.String propName,
                       java.lang.reflect.Method method)
Adds a setter method to the methods list for the property with the specified name.

Parameters:
propName - the name of the property.
method - the setter method.

addPropertyDescriptor

private void addPropertyDescriptor(java.lang.String propName,
                                   java.beans.PropertyDescriptor pd)
Adds a the specified (incomplete) PropertyDescriptor to the list of PropertyDescriptor candidates managed by this PropertyStore. The method initializes the list of PropertyDescriptors, in case it is the first PropertyDescriptor for the property with the specified name.

Parameters:
propName - the name of the property.
pd - new PropertyDescriptor.

processProperties

private java.util.List processProperties()
The method returns a list of PropertyDescriptors for the properties managed by this PropertyStore. It iterates the all properties and analyzes the candidate PropertyDescriptors (by calling method processProperty(List).

Returns:
list of PropertyDescriptors

processProperty

private java.beans.PropertyDescriptor processProperty(java.util.List candidates)
The method analyzes the specified list of candidate PropertyDescriptors and returns a single PropertyDescriptor describing the property. It iterates the candidate list in order to find a getter PropertyDescriptor. If there is such a PropertyDescriptor it looks for a corresponding setter PropertyDescriptor and updates the getter PropertyDescriptor with the write method of the setter. It then returns the getter PropertyDescriptor. If there is no getter PropertyDescriptor and a single setter PropertyDescriptor it returns the setter PropertyDescriptor. Otherwise it returns null which means the list of candidate PropertyDescriptors does not qualify for a valid property.

Parameters:
candidates - the list of candidate PropertyDescriptors
Returns:
a PropertyDescriptor describing a property or null if the candidate PropertyDescriptors do not qualify for a valid property.