org.tempuri.javac.util
Interface MemoryClassFactory

All Superinterfaces:
JavaClassReaderFactory, JavaClassWriterFactory, JavaSourceReaderFactory
All Known Implementing Classes:
MemoryClassFactoryImpl

public interface MemoryClassFactory
extends JavaClassReaderFactory, JavaSourceReaderFactory, JavaClassWriterFactory

Interface to a utility object that supports compiling and loading Java source code in memory

 Example:
 JavaCompiler compiler = ...
 JavaCompilerErrorHandler errorHandler = ...
 MemoryClassFactory factory = ...
 String source = "public class Foo { public void foo() {} }";
 Map map = new HashMap();
 map.put("Foo", source);
 factory.setInput(map);
 compiler.compile(factory, factory, factory, errorHandler);
 Class clazz = factory.loadClass("Foo");
 


Method Summary
 java.util.Map getOutput()
          Get the compiled output files as a map
 java.lang.Class loadClass(java.lang.String className)
          Convenience method to load a class you just compiled in memory
 void setClassLoader(java.lang.ClassLoader cl)
          Set the class loader to use to locate existing classes.
 void setInput(java.util.Map sourceMap)
          Set the input source files to be compiled.
 
Methods inherited from interface org.tempuri.javac.JavaClassReaderFactory
getClassReader
 
Methods inherited from interface org.tempuri.javac.JavaSourceReaderFactory
getSourceReader
 
Methods inherited from interface org.tempuri.javac.JavaClassWriterFactory
getClassWriter
 

Method Detail

setClassLoader

void setClassLoader(java.lang.ClassLoader cl)
Set the class loader to use to locate existing classes. If not set this defaults to the system class loader. The implementation will use cl.getResource() or equivalent to attempt to locate an existing class

Parameters:
cl - class loader

setInput

void setInput(java.util.Map sourceMap)
Set the input source files to be compiled.

Parameters:
sourceMap - a map of {className -> source code} pairs. Both the keys and values of the map must be instances of java.lang.String

getOutput

java.util.Map getOutput()
Get the compiled output files as a map

Returns:
a map of {className -> compiled code} pairs. The keys in this map are instances of java.lang.String and the values are instances of byte[]

loadClass

java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
Convenience method to load a class you just compiled in memory

Parameters:
name - of class to load
Returns:
The loaded class. The implementation will create a new class loader as a child of the class loader assigned in setClassLoader() to load the class.
Throws:
java.lang.ClassNotFoundException