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.21 $
Author:
James Strachan, Guillaume Laforge, Steve Goetze

Nested Class Summary
static class GroovyClassLoader.ClassCollector
           
 
Constructor Summary
GroovyClassLoader()
           
GroovyClassLoader(ClassLoader loader)
           
GroovyClassLoader(ClassLoader loader, CompilerConfiguration config)
           
GroovyClassLoader(GroovyClassLoader parent)
           
 
Method Summary
protected  GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit)
           
 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
protected  Class defineClass(String name, byte[] bytecode, ProtectionDomain domain)
          A helper method to allow bytecode to be loaded.
protected  Class findClass(String name)
          Using this classloader you can load groovy classes from the system classpath as though they were already compiled.
protected  Class findGroovyClass(String name)
           
protected  Class loadClass(String name, boolean resolve)
           
 Class parseClass(File file)
          Parses the given file into a Java class capable of being run
 Class parseClass(GroovyCodeSource codeSource)
          Parses the given character stream 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
 
Methods inherited from class java.security.SecureClassLoader
defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, 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()

GroovyClassLoader

public GroovyClassLoader(ClassLoader loader)

GroovyClassLoader

public GroovyClassLoader(GroovyClassLoader parent)

GroovyClassLoader

public GroovyClassLoader(ClassLoader loader,
                         CompilerConfiguration config)
Method Detail

defineClass

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

Parameters:
classNode -
Returns:

defineClass

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

Parameters:
classNode -
Returns:

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,
                        IOException
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
IOException

parseClass

public Class parseClass(String text)
                 throws CompilationFailedException,
                        IOException
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
IOException

parseClass

public Class parseClass(InputStream in)
                 throws CompilationFailedException,
                        IOException
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
IOException

parseClass

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

parseClass

public Class parseClass(GroovyCodeSource codeSource)
                 throws CompilationFailedException,
                        IOException
Parses the given character stream into a Java class capable of being run

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

findClass

protected Class findClass(String name)
                   throws ClassNotFoundException
Using this classloader you can load groovy classes from the system classpath as though they were already compiled. Note that .groovy classes found with this mechanism need to conform to the standard java naming convention - i.e. the public class inside the file must match the filename and the file must be located in a directory structure that matches the package structure.

Throws:
ClassNotFoundException

findGroovyClass

protected Class findGroovyClass(String name)
                         throws ClassNotFoundException
Throws:
ClassNotFoundException

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)

loadClass

protected Class loadClass(String name,
                          boolean resolve)
                   throws ClassNotFoundException
Throws:
ClassNotFoundException


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