groovy.lang
Class GroovyClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended bygroovy.lang.GroovyClassLoader

public class GroovyClassLoader
extends SecureClassLoader

A ClassLoader which can load Groovy classes

Version:
$Revision: 1.60 $
Author:
James Strachan , Guillaume Laforge, Steve Goetze, Bing Ran, Scott Stirling

Nested Class Summary
static class GroovyClassLoader.ClassCollector
           
static class GroovyClassLoader.PARSING
           
 
Constructor Summary
GroovyClassLoader()
          creates a GroovyClassLoader using the current Thread's context Class loader as parent.
GroovyClassLoader(ClassLoader loader)
          creates a GroovyClassLoader using the given ClassLoader as parent
GroovyClassLoader(ClassLoader loader, CompilerConfiguration config)
          creates a GroovyClassLoader using the given ClassLoader as parent.
GroovyClassLoader(GroovyClassLoader parent)
          creates a GroovyClassLoader using the given GroovyClassLoader as parent.
 
Method Summary
 void addClasspath(String path)
           
protected  GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit, SourceUnit su)
           
 Class defineClass(ClassNode classNode, String file)
          Loads the given class node returning the implementation Class
 Class defineClass(ClassNode classNode, String file, String newCodeBase)
          Loads the given class node returning the implementation Class
 Class defineClass(String name, byte[] b)
          open up the super class define that takes raw bytes
protected  Class defineClass(String name, byte[] bytecode, ProtectionDomain domain)
          A helper method to allow bytecode to be loaded.
protected  void expandClassPath(List pathList, String base, String classpath, boolean isManifestClasspath)
           
protected  String[] getClassPath()
          Workaround for Groovy-835
 Class[] getLoadedClasses()
          Returns all Groovy classes loaded by this class loader.
 GroovyResourceLoader getResourceLoader()
           
protected  Class loadClass(String name, boolean resolve)
          Implemented here to check package access prior to returning an already loaded class.
 Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript)
          loads a class from a file or a parent classloader.
 Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)
          loads a class from a file or a parent classloader.
 Class parseClass(File file)
          Parses the given file into a Java class capable of being run
 Class parseClass(GroovyCodeSource codeSource)
           
 Class parseClass(GroovyCodeSource codeSource, boolean shouldCache)
          Parses the given code source into a Java class capable of being run
 Class parseClass(InputStream in)
          Parses the given character stream into a Java class capable of being run
 Class parseClass(InputStream in, String fileName)
           
 Class parseClass(String text)
          Parses the given text into a Java class capable of being run
 Class parseClass(String text, String fileName)
          Parses the given text into a Java class capable of being run
 void removeFromCache(Class aClass)
           
 void setResourceLoader(GroovyResourceLoader resourceLoader)
           
 
Methods inherited from class java.security.SecureClassLoader
defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroovyClassLoader

public GroovyClassLoader()
creates a GroovyClassLoader using the current Thread's context Class loader as parent.


GroovyClassLoader

public GroovyClassLoader(ClassLoader loader)
creates a GroovyClassLoader using the given ClassLoader as parent


GroovyClassLoader

public GroovyClassLoader(GroovyClassLoader parent)
creates a GroovyClassLoader using the given GroovyClassLoader as parent. This loader will get the parent's CompilerConfiguration


GroovyClassLoader

public GroovyClassLoader(ClassLoader loader,
                         CompilerConfiguration config)
creates a GroovyClassLoader using the given ClassLoader as parent.

Method Detail

removeFromCache

public void removeFromCache(Class aClass)

setResourceLoader

public void setResourceLoader(GroovyResourceLoader resourceLoader)

getResourceLoader

public GroovyResourceLoader getResourceLoader()

defineClass

public Class defineClass(ClassNode classNode,
                         String file)
Loads the given class node returning the implementation Class

Parameters:
classNode -
Returns:
a class

defineClass

public Class defineClass(ClassNode classNode,
                         String file,
                         String newCodeBase)
Loads the given class node returning the implementation Class

Parameters:
classNode -
Returns:
a class

parseClass

public Class parseClass(File file)
                 throws CompilationFailedException,
                        IOException
Parses the given file into a Java class capable of being run

Parameters:
file - the file name to parse
Returns:
the main class defined in the given script
Throws:
CompilationFailedException
IOException

parseClass

public Class parseClass(String text,
                        String fileName)
                 throws CompilationFailedException
Parses the given text into a Java class capable of being run

Parameters:
text - the text of the script/class to parse
fileName - the file name to use as the name of the class
Returns:
the main class defined in the given script
Throws:
CompilationFailedException

parseClass

public Class parseClass(String text)
                 throws CompilationFailedException
Parses the given text into a Java class capable of being run

Parameters:
text - the text of the script/class to parse
Returns:
the main class defined in the given script
Throws:
CompilationFailedException

parseClass

public Class parseClass(InputStream in)
                 throws CompilationFailedException
Parses the given character stream into a Java class capable of being run

Parameters:
in - an InputStream
Returns:
the main class defined in the given script
Throws:
CompilationFailedException

parseClass

public Class parseClass(InputStream in,
                        String fileName)
                 throws CompilationFailedException
Throws:
CompilationFailedException

parseClass

public Class parseClass(GroovyCodeSource codeSource)
                 throws CompilationFailedException
Throws:
CompilationFailedException

parseClass

public Class parseClass(GroovyCodeSource codeSource,
                        boolean shouldCache)
                 throws CompilationFailedException
Parses the given code source into a Java class capable of being run

Returns:
the main class defined in the given script
Throws:
CompilationFailedException

getClassPath

protected String[] getClassPath()
Workaround for Groovy-835

Returns:
the classpath as an array of strings, uses the classpath in the CompilerConfiguration object if possible, otherwise defaults to the value of the java.class.path system property

expandClassPath

protected void expandClassPath(List pathList,
                               String base,
                               String classpath,
                               boolean isManifestClasspath)
Parameters:
pathList - an empty list that will contain the elements of the classpath
classpath - the classpath specified as a single string

defineClass

protected Class defineClass(String name,
                            byte[] bytecode,
                            ProtectionDomain domain)
A helper method to allow bytecode to be loaded. spg changed name to defineClass to make it more consistent with other ClassLoader methods


createCollector

protected GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit,
                                                           SourceUnit su)

defineClass

public Class defineClass(String name,
                         byte[] b)
open up the super class define that takes raw bytes


loadClass

public Class loadClass(String name,
                       boolean lookupScriptFiles,
                       boolean preferClassOverScript)
                throws ClassNotFoundException
loads a class from a file or a parent classloader. This method does call @see #loadClass(String, boolean, boolean, boolean) with the last parameter set to false.

Throws:
ClassNotFoundException

loadClass

public Class loadClass(String name,
                       boolean lookupScriptFiles,
                       boolean preferClassOverScript,
                       boolean resolve)
                throws ClassNotFoundException
loads a class from a file or a parent classloader.

Parameters:
name - of the class to be loaded
lookupScriptFiles - if false no lookup at files is done at all
preferClassOverScript - if true the file lookup is only done if there is no class
resolve - @see ClassLoader#loadClass(java.lang.String, boolean)
Returns:
the class found or the class created from a file lookup
Throws:
ClassNotFoundException

loadClass

protected Class loadClass(String name,
                          boolean resolve)
                   throws ClassNotFoundException
Implemented here to check package access prior to returning an already loaded class.

Throws:
ClassNotFoundException
See Also:
ClassLoader.loadClass(java.lang.String, boolean)

addClasspath

public void addClasspath(String path)

getLoadedClasses

public Class[] getLoadedClasses()

Returns all Groovy classes loaded by this class loader.

Returns:
all classes loaded by this class loader


Copyright © 2003-2007 The Codehaus. All Rights Reserved.