org.apache.jdo.impl.model.java.runtime
Class RuntimeJavaModelFactory

java.lang.Object
  extended by org.apache.jdo.impl.model.java.AbstractJavaModelFactory
      extended by org.apache.jdo.impl.model.java.reflection.ReflectionJavaModelFactory
          extended by org.apache.jdo.impl.model.java.runtime.RuntimeJavaModelFactory
All Implemented Interfaces:
JavaModelFactory

public class RuntimeJavaModelFactory
extends ReflectionJavaModelFactory

A reflection based JavaModelFactory 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. This implementation caches JavaModel instance sper ClassLoader.

RuntimeJavaModelFactory implements the singleton pattern; method getInstance() provides access to the singleton factory instance. This method also registers a model listener at the JDOImplHelper to handle the runtime metadata as generated by the enhancer.

Since:
1.0.1
Version:
1.1

Constructor Summary
protected RuntimeJavaModelFactory()
          Creates a new RuntimeJavaModelFactory.
 
Method Summary
 JavaModel createJavaModel(java.lang.Object key)
          Creates a new empty JavaModel instance.
static RuntimeJavaModelFactory getInstance()
          Returns the singleton instance of RuntimeJavaModelFactory.
 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  void setJDOModelInternal(JavaModel javaModel)
          Sets the JDOModel instance for the specified JavaModel.
 
Methods inherited from class org.apache.jdo.impl.model.java.reflection.ReflectionJavaModelFactory
forNamePrivileged, getClassLoaderPrivileged
 
Methods inherited from class org.apache.jdo.impl.model.java.AbstractJavaModelFactory
getJavaModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuntimeJavaModelFactory

protected RuntimeJavaModelFactory()
Creates a new RuntimeJavaModelFactory. This constructor should not be called directly; instead, the singleton access method getInstance() should be used.

Method Detail

getInstance

public static RuntimeJavaModelFactory getInstance()
                                           throws ModelFatalException
Returns the singleton instance of RuntimeJavaModelFactory. On first call it registers a model listener at the JDOImplHelper. This method checks that the caller is authorized for JDOPermission("getMetadata"), and if not, throws ModelFatalException wrapping the SecurityException.

Returns:
RuntimeJavaModelFactory instance
Throws:
ModelFatalException - if the caller does not have the getMetadata permission.

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

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.

setJDOModelInternal

protected void setJDOModelInternal(JavaModel javaModel)
Sets the JDOModel instance for the specified JavaModel.

Parameters:
javaModel - the JavaModel


Copyright © 2005-2009 Apache Software Foundation. All Rights Reserved.