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

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

public abstract class ReflectionJavaModel
extends AbstractJavaModel

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 ReflectionJavaModel implementation will use this ClassLoader to lookup any type by name. This makes sure that the type name is unique.

Since:
1.1

Field Summary
protected  ReflectionJavaModelFactory declaringJavaModelFactory
          The declaring JavaModelFactory.
 
Fields inherited from class org.apache.jdo.impl.model.java.AbstractJavaModel
children, jdoModel, parent, types
 
Constructor Summary
ReflectionJavaModel(java.lang.ClassLoader classLoader, ReflectionJavaModelFactory declaringJavaModelFactory)
          Constructor.
 
Method Summary
protected abstract  JavaType createJavaType(java.lang.Class clazz)
          Creates a new JavaType instance for the specified Class object.
 java.lang.ClassLoader getClassLoader()
          Returns the ClassLoader wrapped by this ReflectionJavaModel instance.
 ReflectionJavaModelFactory getDeclaringJavaModelFactory()
          Returns the declaring ReflectionJavaModelFactory of this ReflectionJavaModel.
 java.io.InputStream getInputStreamForResource(java.lang.String resourceName)
          Finds a resource with a given name.
 JavaType getJavaType(java.lang.Class clazz)
          The method returns the JavaType instance for the type name of the specified class object.
 JavaType getJavaType(java.lang.String name)
          The method returns the JavaType instance for the specified type name.
 JavaType getJavaTypeInternal(java.lang.Class clazz)
          The method returns the JavaType instance for the type name of the specified class object.
 
Methods inherited from class org.apache.jdo.impl.model.java.AbstractJavaModel
getChildren, getJDOModel, getParent, setJDOModel, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

declaringJavaModelFactory

protected final ReflectionJavaModelFactory declaringJavaModelFactory
The declaring JavaModelFactory.

Constructor Detail

ReflectionJavaModel

public ReflectionJavaModel(java.lang.ClassLoader classLoader,
                           ReflectionJavaModelFactory declaringJavaModelFactory)
Constructor.

Method Detail

getJavaType

public 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 JavaModel
Specified by:
getJavaType in class AbstractJavaModel
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 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.

Specified by:
getJavaType in interface JavaModel
Overrides:
getJavaType in class AbstractJavaModel
Parameters:
clazz - the Class instance representing the type
Returns:
a JavaType instance for the name of the specified class object.

getInputStreamForResource

public java.io.InputStream getInputStreamForResource(java.lang.String resourceName)
Finds a resource with a given name. A resource is some data that can be accessed by class code in a way that is independent of the location of the code. The name of a resource is a "/"-separated path name that identifies the resource. The method method opens the resource for reading and returns an InputStream. It returns null if no resource with this name is found or if the caller doesn't have adequate privileges to get the resource.

This implementation delegates the request to the wrapped ClassLoader.

Specified by:
getInputStreamForResource in interface JavaModel
Specified by:
getInputStreamForResource in class AbstractJavaModel
Parameters:
resourceName - the resource name
Returns:
an input stream for reading the resource, or null if the resource could not be found or if the caller doesn't have adequate privileges to get the resource.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the ClassLoader wrapped by this ReflectionJavaModel instance.

Returns:
the ClassLoader

getJavaTypeInternal

public JavaType getJavaTypeInternal(java.lang.Class clazz)
The method returns the JavaType instance for the type name of the specified class object. It first checks the cache and if there is no entry for the type name in the cache then it creates a new JavaType instance for the specified Class object.

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.

getDeclaringJavaModelFactory

public ReflectionJavaModelFactory getDeclaringJavaModelFactory()
Returns the declaring ReflectionJavaModelFactory of this ReflectionJavaModel.

Returns:
the declaring ReflectionJavaModelFactory

createJavaType

protected abstract JavaType createJavaType(java.lang.Class clazz)
Creates a new JavaType instance for the specified Class object. This method provides a hook such that ReflectionJavaModel subclasses can create instances of a different JavaType implementation.

Parameters:
clazz - the Class instance representing the type
Returns:
a new JavaType instance


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