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

java.lang.Object
  extended byorg.apache.jdo.impl.model.java.AbstractJavaModelFactory
      extended byorg.apache.jdo.impl.model.java.reflection.ReflectionJavaModelFactory
All Implemented Interfaces:
JavaModelFactory

public abstract class ReflectionJavaModelFactory
extends AbstractJavaModelFactory

A reflection based JavaModelFactory implementation. The implementation takes java.lang.Class and java.lang.reflect.Field instances to get Java related metadata about types and fields. This implementation caches JavaModel instances per ClassLoader.

Since:
JDO 2.0
Author:
Michael Bouschen

Constructor Summary
ReflectionJavaModelFactory()
           
 
Method Summary
 JavaModel createJavaModel(java.lang.Object key)
          Creates a new empty JavaModel instance.
 java.lang.ClassLoader getClassLoaderPrivileged(java.lang.Class clazz)
          Calls getClassLoader on the specified class instance in a doPrivileged block.
 java.lang.Class getJavaClass(JavaType javaType)
          Returns the java.lang.Class wrapped in the specified JavaType.
 JavaModel getJavaModel(java.lang.Object key)
          Returns the JavaModel instance for the specified key.
 JavaType getJavaType(java.lang.Object typeDesc)
          Returns a JavaType instance for the specified type description (optional operation).
protected  JavaModel newJavaModelInstance(java.lang.ClassLoader classLoader)
          Creates a new instance of the JavaModel implementation class.
 
Methods inherited from class org.apache.jdo.impl.model.java.AbstractJavaModelFactory
removeJavaModel, removeJavaModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionJavaModelFactory

public ReflectionJavaModelFactory()
Method Detail

createJavaModel

public JavaModel createJavaModel(java.lang.Object key)
                          throws ModelException
Creates a new empty JavaModel instance. A factory implementation may use the specified key when caching the new JavaModel instance.

This implementation only accepts java.lang.ClassLoader instances as key and does not support null keys. A ModelException indicates an invalid key.

The method automatically sets the parent/child relationship for the created JavaModel according to the parent/child relationship of the ClassLoader passed as key.

Specified by:
createJavaModel in interface JavaModelFactory
Specified by:
createJavaModel in class AbstractJavaModelFactory
Parameters:
key - the key that may be used to cache the returned JavaModel instance.
Returns:
a new JavaModel instance.
Throws:
ModelException - if impossible; the key is of an inappropriate type or the key is null and this JavaModelFactory does not support null keys.

getJavaModel

public JavaModel getJavaModel(java.lang.Object key)
Returns the JavaModel instance for the specified key.

Specified by:
getJavaModel in interface JavaModelFactory
Overrides:
getJavaModel in class AbstractJavaModelFactory
Parameters:
key - the key used to cache the returned JavaModel instance
Returns:
a JavaModel instance for the specified key.

getJavaType

public JavaType getJavaType(java.lang.Object typeDesc)
Returns a JavaType instance for the specified type description (optional operation). This method is a convenience method and a short cut for getJavaModel(key).getJavaType(typeName).

The ReflectionJavaModelFactory supports this short cut and accepts java.lang.Class instances as valid arguments for this method. The method throws a ModelFatalException, if the specified type descriptor is not a java.lang.Class instance.

Specified by:
getJavaType in interface JavaModelFactory
Overrides:
getJavaType in class AbstractJavaModelFactory
Parameters:
typeDesc - the type description
Returns:
a JavaType instance for the specified type.
Throws:
ModelFatalException - the specified type description is not a java.lang.Class instance.

getClassLoaderPrivileged

public java.lang.ClassLoader getClassLoaderPrivileged(java.lang.Class clazz)
Calls getClassLoader on the specified class instance in a doPrivileged block. Any SecurityException is wrapped into a ModelFatalException.

Returns:
the class loader that loaded the specified class instance.
Throws:
ModelFatalException - wraps the SecurityException thrown by getClassLoader.

getJavaClass

public java.lang.Class getJavaClass(JavaType javaType)
Returns the java.lang.Class wrapped in the specified JavaType.

Returns:
the java.lang.Class for the specified JavaType.
Throws:
ModelFatalException - the specified JavaType does not wrap a java.lang.Class instance.

newJavaModelInstance

protected JavaModel newJavaModelInstance(java.lang.ClassLoader classLoader)
Creates a new instance of the JavaModel implementation class.

This implementation returns a ReflectionJavaModel instance.

Returns:
a new JavaModel instance.


Copyright © 2005 Apache Software Foundation. All Rights Reserved.