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

java.lang.Object
  extended by org.apache.jdo.impl.model.java.AbstractJavaModelFactory
      extended by org.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:
1.1

Constructor Summary
ReflectionJavaModelFactory()
           
 
Method Summary
 JavaModel createJavaModel(java.lang.Object key)
          Creates a new empty JavaModel instance.
static java.lang.Class forNamePrivileged(java.lang.String name, boolean initialize, java.lang.ClassLoader loader)
          Calls Class.forName in a doPrivileged block.
static 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.
 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
getJavaModel, 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. 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.

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 static 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.

Parameters:
clazz - the class to get the ClassLoader from.
Returns:
the class loader that loaded the specified Class instance.
Throws:
ModelFatalException - wraps the SecurityException thrown by getClassLoader.

forNamePrivileged

public static java.lang.Class forNamePrivileged(java.lang.String name,
                                                boolean initialize,
                                                java.lang.ClassLoader loader)
                                         throws java.lang.ClassNotFoundException
Calls Class.forName in a doPrivileged block. Any SecurityException is wrapped into a ModelFatalException.

Parameters:
name - fully qualified name of the desired class
initialize - whether the class must be initialized
loader - class loader from which the class must be loaded
Returns:
class object representing the desired class.
Throws:
ModelFatalException - wraps the SecurityException thrown by getClassLoader.
java.lang.ClassNotFoundException - if the class cannot be located by the specified class loader.

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-2012 Apache Software Foundation. All Rights Reserved.