org.apache.jdo.impl.model.java.reflection
Class ReflectionJavaType

java.lang.Object
  extended byorg.apache.jdo.impl.model.java.AbstractJavaType
      extended byorg.apache.jdo.impl.model.java.BaseReflectionJavaType
          extended byorg.apache.jdo.impl.model.java.reflection.ReflectionJavaType
All Implemented Interfaces:
JavaElement, JavaType

public class ReflectionJavaType
extends BaseReflectionJavaType

A reflection based JavaType implementation used at runtime. The implementation takes java.lang.Class and java.lang.reflect.Field instances to get Java related metadata about types and fields.

Since:
JDO 1.1
Version:
JDO 2.0
Author:
Michael Bouschen

Field Summary
protected  java.util.Map declaredJavaFields
          Map of JavaField instances, key is the field name.
protected  java.util.Map declaredJavaProperties
          Map of JavaProperty instances, key is the property name.
protected  ReflectionJavaModel declaringJavaModel
          The declaring JavaModel instance.
 
Fields inherited from class org.apache.jdo.impl.model.java.BaseReflectionJavaType
clazz, superclass
 
Constructor Summary
ReflectionJavaType(java.lang.Class clazz, ReflectionJavaModel declaringJavaModel)
          Constructor.
 
Method Summary
 JavaMethod createJavaMethod(java.lang.reflect.Method method)
          Creates a new JavaMethod instance.
 JavaProperty createJavaProperty(java.lang.String name, JavaMethod getter, JavaMethod setter, JavaType type)
          Creates a new JavaProperty instance and adds it to the list of declared properties of this class.
 JavaType getArrayComponentType()
          Returns the JavaType representing the component type of an array.
 JavaField getDeclaredJavaField(java.lang.String fieldName)
          Returns a JavaField instance that reflects the declared field with the specified name of the class or interface represented by this JavaType instance.
 JavaField[] getDeclaredJavaFields()
          Returns an array of JavaField instances representing the declared fields of the class represented by this JavaType instance.
 JavaProperty[] getDeclaredJavaProperties()
          Returns an array of JavaProperty instances representing the declared properties of the class represented by this JavaType instance.
 JavaProperty getDeclaredJavaProperty(java.lang.String name)
          Returns a JavaProperty instance that reflects the declared property with the specified name of the class or interface represented by this JavaType instance.
 JavaField getJavaField(java.lang.String fieldName)
          Returns a JavaField instance that reflects the field with the specified name of the class or interface represented by this JavaType instance.
 JavaProperty getJavaProperty(java.lang.String name)
          Returns a JavaProperty instance that reflects the property with the specified name of the class or interface represented by this JavaType instance.
 JavaType getJavaTypeForClass(java.lang.Class clazz)
          Returns a JavaType instance for the specified Class object.
 JDOClass getJDOClass()
          Returns the JDOClass instance if this JavaType represents a persistence capable class.
 JavaType getSuperclass()
          Returns the JavaType representing the superclass of the entity represented by this JavaType.
protected  void introspectClass()
          Helper method to introspect the class and set the declared fields and properties.
 boolean isArray()
          Determines if this JavaType object represents an array type.
 boolean isPersistenceCapable()
          Returns true if this JavaType represents a persistence capable class.
protected  JavaField newJavaFieldInstance(java.lang.reflect.Field field)
          Creates a new instance of the JavaField implementation class.
protected  JavaField newJavaFieldInstance(java.lang.String fieldName, JavaType type)
          Creates a new instance of the JavaField implementation class.
protected  JavaMethod newJavaMethodInstance(java.lang.reflect.Method method)
          Creates a new instance of the JavaMethod implementation class.
protected  JavaProperty newJavaPropertyInstance(java.lang.String name, JavaMethod getter, JavaMethod setter, JavaType type)
          Creates a new instance of the JavaProperty implementation class.
 
Methods inherited from class org.apache.jdo.impl.model.java.BaseReflectionJavaType
getJavaClass, getModifiers, getName, getUnderlyingObject, isCompatibleWith, isInterface
 
Methods inherited from class org.apache.jdo.impl.model.java.AbstractJavaType
equals, hashCode, isFloatingPoint, isIntegral, isJDOSupportedCollection, isJDOSupportedMap, isOrderable, isPrimitive, isTrackable, isValue, isWrapperClass, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

declaringJavaModel

protected final ReflectionJavaModel declaringJavaModel
The declaring JavaModel instance.


declaredJavaFields

protected java.util.Map declaredJavaFields
Map of JavaField instances, key is the field name.


declaredJavaProperties

protected java.util.Map declaredJavaProperties
Map of JavaProperty instances, key is the property name.

Constructor Detail

ReflectionJavaType

public ReflectionJavaType(java.lang.Class clazz,
                          ReflectionJavaModel declaringJavaModel)
Constructor.

Method Detail

isArray

public boolean isArray()
Determines if this JavaType object represents an array type.

Specified by:
isArray in interface JavaType
Overrides:
isArray in class AbstractJavaType
Returns:
true if this object represents an array type; false otherwise.

isPersistenceCapable

public boolean isPersistenceCapable()
                             throws ModelFatalException
Returns true if this JavaType represents a persistence capable class.

A ModelFatalException indicates a problem accessing the JDO meta data for this JavaType.

Specified by:
isPersistenceCapable in interface JavaType
Overrides:
isPersistenceCapable in class AbstractJavaType
Returns:
true if this JavaType represents a persistence capable class; false otherwise.
Throws:
ModelFatalException - if there is a problem accessing the JDO metadata

getSuperclass

public JavaType getSuperclass()
Returns the JavaType representing the superclass of the entity represented by this JavaType. If this JavaType represents either the Object class, an interface, a primitive type, or void, then null is returned. If this object represents an array class then the JavaType instance representing the Object class is returned.

Specified by:
getSuperclass in interface JavaType
Overrides:
getSuperclass in class BaseReflectionJavaType
Returns:
the superclass of the class represented by this JavaType.

getJDOClass

public JDOClass getJDOClass()
                     throws ModelFatalException
Returns the JDOClass instance if this JavaType represents a persistence capable class. The method returns null, if this JavaType does not represent a persistence capable class.

A ModelFatalException indicates a problem accessing the JDO meta data for this JavaType.

Specified by:
getJDOClass in interface JavaType
Overrides:
getJDOClass in class AbstractJavaType
Returns:
the JDOClass instance if this JavaType represents a persistence capable class; null otherwise.
Throws:
ModelFatalException - if there is a problem accessing the JDO metadata

getArrayComponentType

public JavaType getArrayComponentType()
Returns the JavaType representing the component type of an array. If this JavaType does not represent an array type this method returns null.

Specified by:
getArrayComponentType in interface JavaType
Overrides:
getArrayComponentType in class AbstractJavaType
Returns:
the JavaType representing the component type of this JavaType if this class is an array; null otherwise.

getJavaField

public JavaField getJavaField(java.lang.String fieldName)
Returns a JavaField instance that reflects the field with the specified name of the class or interface represented by this JavaType instance. The method returns null, if the class or interface (or one of its superclasses) does not have a field with that name.

Specified by:
getJavaField in interface JavaType
Overrides:
getJavaField in class BaseReflectionJavaType
Parameters:
fieldName - the name of the field
Returns:
the JavaField instance for the specified field in this class or null if there is no such field.

getDeclaredJavaFields

public JavaField[] getDeclaredJavaFields()
Returns an array of JavaField instances representing the declared fields of the class represented by this JavaType instance. Note, this method does not return JavaField instances representing inherited fields.

Specified by:
getDeclaredJavaFields in interface JavaType
Overrides:
getDeclaredJavaFields in class BaseReflectionJavaType
Returns:
an array of declared JavaField instances.

getJavaProperty

public JavaProperty getJavaProperty(java.lang.String name)
Returns a JavaProperty instance that reflects the property with the specified name of the class or interface represented by this JavaType instance. The method returns null, if the class or interface (or one of its superclasses) does not have a field with that name.

Specified by:
getJavaProperty in interface JavaType
Overrides:
getJavaProperty in class BaseReflectionJavaType
Parameters:
name - the name of the property
Returns:
the JavaProperty instance for the specified property in this class or null if there is no such property.

getDeclaredJavaProperties

public JavaProperty[] getDeclaredJavaProperties()
Returns an array of JavaProperty instances representing the declared properties of the class represented by this JavaType instance. Note, this method does not return JavaField instances representing inherited properties.

Specified by:
getDeclaredJavaProperties in interface JavaType
Overrides:
getDeclaredJavaProperties in class BaseReflectionJavaType
Returns:
an array of declared JavaField instances.

getDeclaredJavaField

public JavaField getDeclaredJavaField(java.lang.String fieldName)
Returns a JavaField instance that reflects the declared field with the specified name of the class or interface represented by this JavaType instance. The method returns null, if the class or interface does not declared a field with that name. It does not check whether one of its superclasses declares such a field.

Parameters:
fieldName - the name of the field
Returns:
the JavaField instance for the specified field in this class

getDeclaredJavaProperty

public JavaProperty getDeclaredJavaProperty(java.lang.String name)
Returns a JavaProperty instance that reflects the declared property with the specified name of the class or interface represented by this JavaType instance. The method returns null, if the class or interface does not declared a property with that name. It does not check whether one of its superclasses declares such a property.

Parameters:
name - the name of the property
Returns:
the JavaField instance for the specified property in this class

getJavaTypeForClass

public JavaType getJavaTypeForClass(java.lang.Class clazz)
Returns a JavaType instance for the specified Class object. This method provides a hook such that ReflectionJavaType subclasses can implement their own mapping of Class objects to JavaType instances.


createJavaProperty

public JavaProperty createJavaProperty(java.lang.String name,
                                       JavaMethod getter,
                                       JavaMethod setter,
                                       JavaType type)
                                throws ModelFatalException
Creates a new JavaProperty instance and adds it to the list of declared properties of this class.

Parameters:
name - the name of the property
getter - the getter method
setter - the setter method
type - the ytpe of the property
Returns:
a new JavaProperty declared by this class
Throws:
ModelFatalException

createJavaMethod

public JavaMethod createJavaMethod(java.lang.reflect.Method method)
Creates a new JavaMethod instance.

Parameters:
method - the java.lang.reflect.Method instance
Returns:
a new JavaMethod declared by this class

newJavaFieldInstance

protected JavaField newJavaFieldInstance(java.lang.String fieldName,
                                         JavaType type)
Creates a new instance of the JavaField implementation class.

This implementation returns a ReflectionJavaField instance.

Returns:
a new JavaField instance.

newJavaFieldInstance

protected JavaField newJavaFieldInstance(java.lang.reflect.Field field)
Creates a new instance of the JavaField implementation class.

This implementation returns a ReflectionJavaField instance.

Returns:
a new JavaField instance.

newJavaPropertyInstance

protected JavaProperty newJavaPropertyInstance(java.lang.String name,
                                               JavaMethod getter,
                                               JavaMethod setter,
                                               JavaType type)
                                        throws ModelFatalException
Creates a new instance of the JavaProperty implementation class.

This implementation returns a JavaPropertyImpl instance.

Returns:
a new JavaProperty instance.
Throws:
ModelFatalException

newJavaMethodInstance

protected JavaMethod newJavaMethodInstance(java.lang.reflect.Method method)
Creates a new instance of the JavaMethod implementation class.

This implementation returns a ReflectionJavaMethod instance.

Returns:
a new JavaMethod instance.

introspectClass

protected void introspectClass()
Helper method to introspect the class and set the declared fields and properties.



Copyright © 2005 Apache Software Foundation. All Rights Reserved.