org.tempuri.javacImpl.util
Class MemoryClassFactoryImpl

java.lang.Object
  extended by org.tempuri.javacImpl.util.MemoryClassFactoryImpl
All Implemented Interfaces:
JavaClassReaderFactory, JavaClassWriterFactory, JavaSourceReaderFactory, MemoryClassFactory

public class MemoryClassFactoryImpl
extends java.lang.Object
implements MemoryClassFactory


Nested Class Summary
 class MemoryClassFactoryImpl.ClassReaderImpl
           
 class MemoryClassFactoryImpl.ClassWriterImpl
           
 class MemoryClassFactoryImpl.DefiningClassLoader
           
 class MemoryClassFactoryImpl.SourceReaderImpl
           
 
Constructor Summary
MemoryClassFactoryImpl()
           
 
Method Summary
 JavaClassReader getClassReader(java.lang.String className)
          Returns a JavaClassReader for the specified class name
 JavaClassWriter getClassWriter(java.lang.String className)
          Called by the compiler for each class it compiles, to handle the generated output.
 java.util.Map getOutput()
          Get the compiled output files as a map
 JavaSourceReader getSourceReader(java.lang.String className)
          Get a source reader for a Java class.
 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 class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryClassFactoryImpl

public MemoryClassFactoryImpl()
Method Detail

setInput

public void setInput(java.util.Map sourceMap)
Description copied from interface: MemoryClassFactory
Set the input source files to be compiled.

Specified by:
setInput in interface MemoryClassFactory
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

public java.util.Map getOutput()
Description copied from interface: MemoryClassFactory
Get the compiled output files as a map

Specified by:
getOutput in interface MemoryClassFactory
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[]

getSourceReader

public JavaSourceReader getSourceReader(java.lang.String className)
                                 throws java.io.IOException
Description copied from interface: JavaSourceReaderFactory
Get a source reader for a Java class. Called by the compiler for each class it is instructed to compile

Specified by:
getSourceReader in interface JavaSourceReaderFactory
Returns:
a JavaSourceReader for the specified class or null if the source code cannot be found
Throws:
java.io.IOException - if the source code exists but an error obtaining it occured

getClassReader

public JavaClassReader getClassReader(java.lang.String className)
                               throws java.io.IOException
Description copied from interface: JavaClassReaderFactory
Returns a JavaClassReader for the specified class name

Specified by:
getClassReader in interface JavaClassReaderFactory
Parameters:
className - name of class to be read
Returns:
a JavaClassReader for className or null if the class can't be found
Throws:
java.io.IOException - if an error occurs

getClassWriter

public JavaClassWriter getClassWriter(java.lang.String className)
                               throws java.io.IOException
Description copied from interface: JavaClassWriterFactory
Called by the compiler for each class it compiles, to handle the generated output.

Specified by:
getClassWriter in interface JavaClassWriterFactory
Parameters:
className - name of compiled class
Returns:
JavaClassWriter to handle the compiled class
Throws:
java.io.IOException

setClassLoader

public void setClassLoader(java.lang.ClassLoader cl)
Description copied from interface: MemoryClassFactory
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

Specified by:
setClassLoader in interface MemoryClassFactory
Parameters:
cl - class loader

loadClass

public java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
Description copied from interface: MemoryClassFactory
Convenience method to load a class you just compiled in memory

Specified by:
loadClass in interface MemoryClassFactory
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