Top Description Fields Constructors Methods
org.codehaus.groovy.runtime.metaclass

public Class ReflectorLoader

extends ClassLoader
Class Inheritance
Imports
org.codehaus.groovy.runtime.Reflector, java.security.ProtectionDomain, java.util.HashMap, .Map

Reflector creation helper. This class is used to define the Reflector classes. For each ClassLoader such a loader will be created by MetaClass. Special about this loader is, that it knows the classes form the Groovy Runtime. The Reflector class is resolved in different ways: During the definition of a class Reflector will resolve to the Reflector class of the runtime, even if there is another Reflector class in the parent loader. After the new class is defined Reflector will resolve like other Groovy classes. This loader is able to resolve all Groovy classes even if the parent does not know them, but the parent serves first (Reflector during a class definition is different).

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private boolean
private final Map<K, V>
private static final String

Constructor Summary

AccessConstructor and Description
public
ReflectorLoader(ClassLoader
the parent loader. This should never be null!
parent
)

creates a ReflectorLoader.

Method Summary

Modifier and TypeMethod and Description
public synchronized Class<T>

Returns:

the generated class
defineClass
(String
of the Reflector
name
,
byte[]
the bytecode
bytecode
,
ProtectionDomain
the protection domain
domain
)

helper method to define Reflector classes.

protected Class<T>

Returns:

the class if found
findClass
(String
The binary name of the class
name
)

Overrides java.lang.ClassLoader.findClass.

Tries to find a Groovy class.
public synchronized Class<T>

Returns:

the Reflector class if defined else null.
getLoadedClass
(String
of the Reflector class
name
)

try to load one of the defined Reflector classes by name.

pack-priv static String
getReflectorName(Class<T> theClass)

protected synchronized Class<T>
loadClass(String
of the class to load
name
,
boolean
is true if the class should be resolved
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Loads a class per name.
Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

delegatationLoaderback to summary
private final ClassLoader delegatationLoader
inDefineback to summary
private boolean inDefine
loadedClassesback to summary
private final Map<K, V> loadedClasses
REFLECTORback to summary
private static final String REFLECTOR

Constructor Detail

ReflectorLoaderback to summary
public ReflectorLoader(ClassLoader parent)

creates a ReflectorLoader.

Parameters
parent:ClassLoader

the parent loader. This should never be null!

Method Detail

defineClassback to summary
public synchronized Class<T> defineClass(String name, byte[] bytecode, ProtectionDomain domain)

helper method to define Reflector classes.

Parameters
name:String

of the Reflector

bytecode:byte[]

the bytecode

domain:ProtectionDomain

the protection domain

Returns:Class<T>

the generated class

findClassback to summary
protected Class<T> findClass(String name) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

Tries to find a Groovy class.

Parameters
name:String

Doc from java.lang.ClassLoader.findClass.

The binary name of the class

Returns:Class<T>

the class if found

Exceptions
ClassNotFoundException:
if not found
getLoadedClassback to summary
public synchronized Class<T> getLoadedClass(String name)

try to load one of the defined Reflector classes by name.

Parameters
name:String

of the Reflector class

Returns:Class<T>

the Reflector class if defined else null.

getReflectorNameback to summary
pack-priv static String getReflectorName(Class<T> theClass)
loadClassback to summary
protected synchronized Class<T> loadClass(String name, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Loads a class per name. Unlike a normal loadClass this version behaves different during a class definition. In that case it checks if the class we want to load is Reflector and returns class if the check is successful. If it is not during a class definition it just calls the super class version of loadClass.

Parameters
name:String

of the class to load

resolve:boolean

is true if the class should be resolved

Returns:Class<T>

Doc from java.lang.ClassLoader.loadClass.

The resulting Class object

Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.loadClass.

If the class could not be found

See Also
Reflector, ClassLoader#loadClass(String, boolean)