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

java.lang.Object
  extended by org.apache.jdo.impl.model.java.AbstractJavaModel
      extended by org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel
          extended by org.apache.jdo.impl.model.java.runtime.RuntimeJavaModel
All Implemented Interfaces:
org.apache.jdo.model.java.JavaModel
Direct Known Subclasses:
JDK5RuntimeJavaModel

public class RuntimeJavaModel
extends org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel

A reflection based JavaModel 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.

The RuntimeJavaModelFactory caches JavaModel instances per ClassLoader. The RuntimeJavaModel implementation will use this ClassLoader to lookup any type by name. This makes sure that the type name is unique.

Any JavaType instance bound to a RuntimeJavaModel instance wraps a class instance that is loaded by the ClassLoader that corresponds to this RuntimeJavaModel. The only exception are PredefinedType instances (see PredefinedType.getPredefinedTypes() which are present in every RuntimeJavaModel instance.

Since:
1.0.1
Version:
2.0

Field Summary
 
Fields inherited from class org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel
declaringJavaModelFactory
 
Fields inherited from class org.apache.jdo.impl.model.java.AbstractJavaModel
children, jdoModel, parent, types
 
Constructor Summary
RuntimeJavaModel(java.lang.ClassLoader classLoader, RuntimeJavaModelFactory declaringJavaModelFactory)
          Constructor.
 
Method Summary
 org.apache.jdo.model.java.JavaType getJavaType(java.lang.Class clazz)
          The method returns the JavaType instance for the type name of the specified class object.
 org.apache.jdo.model.java.JavaType getJavaType(java.lang.String name)
          The method returns the JavaType instance for the specified type name.
protected  org.apache.jdo.model.java.JavaType newJavaTypeInstance(java.lang.Class clazz)
          Creates a new instance of the JavaType implementation class.
 
Methods inherited from class org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel
getClassLoader, getDeclaringJavaModelFactory, getInputStreamForResource, getJavaTypeInternal, getJDOModel
 
Methods inherited from class org.apache.jdo.impl.model.java.AbstractJavaModel
getChildren, getParent, setJDOModel, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuntimeJavaModel

public RuntimeJavaModel(java.lang.ClassLoader classLoader,
                        RuntimeJavaModelFactory declaringJavaModelFactory)
Constructor.

Method Detail

getJavaType

public org.apache.jdo.model.java.JavaType getJavaType(java.lang.String name)
The method returns the JavaType instance for the specified type name. A type name is unique within one JavaModel instance. The method returns null if this model instance does not know a type with the specified name.

Note, this method calls Class.forName with the wrapped ClassLoader, if it cannot find a JavaType with the specified name in the cache.

Specified by:
getJavaType in interface org.apache.jdo.model.java.JavaModel
Overrides:
getJavaType in class org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel
Parameters:
name - the name of the type
Returns:
a JavaType instance for the specified name or null if not present in this model instance.

getJavaType

public org.apache.jdo.model.java.JavaType getJavaType(java.lang.Class clazz)
The method returns the JavaType instance for the type name of the specified class object. This is a convenience method for getJavaType(clazz.getName()). The major difference between this method and getJavaType taking a type name is that this method is supposed to return a non-null value. The specified class object describes an existing type.

Note, this implementation does not call the overloaded getJavaType method taking a String, because this would retrieve the Class instance for the specified type again. Instead, it checks the cache directly. If not available it creates a new ReflectionJavaType using the specified Class instance.

Specified by:
getJavaType in interface org.apache.jdo.model.java.JavaModel
Overrides:
getJavaType in class org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel
Parameters:
clazz - the Class instance representing the type
Returns:
a JavaType instance for the name of the specified class object or null if not present in this model instance.

newJavaTypeInstance

protected org.apache.jdo.model.java.JavaType newJavaTypeInstance(java.lang.Class clazz)
Creates a new instance of the JavaType implementation class.

This implementation returns a RuntimeJavaType instance.

Overrides:
newJavaTypeInstance in class org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel
Parameters:
clazz - the Class instance representing the type
Returns:
a new JavaType instance


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