edu.rice.cs.drjava.model.compiler
Class CompilerRegistry

java.lang.Object
  |
  +--edu.rice.cs.drjava.model.compiler.CompilerRegistry

public class CompilerRegistry
extends Object

Registry for all CompilerInterface implementations. Allows registration, by class name, of CompilerInterface implementations. Later, the list of these registered compilers (but only those that successfully loaded) can be retrieved.

Version:
$Id: CompilerRegistry.java,v 1.11 2002/09/13 22:55:34 csreis Exp $

Field Summary
private  CompilerInterface _activeCompiler
          The active compiler.
private  ClassLoader _baseClassLoader
          Class loader to use to fetch compiler classes.
private  LinkedList _registeredCompilers
          Linked list of class names of registered compilers.
static String[] DEFAULT_COMPILERS
          The list of compiler interfaces that are distributed with DrJava.
static CompilerRegistry ONLY
          Singleton instance.
 
Constructor Summary
private CompilerRegistry()
          Private constructor due to singleton.
 
Method Summary
private static URL[] _getToolsJarURLs()
          Returns reasonable location guesses for tools jar file.
private  CompilerInterface _instantiateCompiler(String name)
          Instantiate the given compiler.
private  void _registerDefaultCompilers()
           
static CompilerInterface createCompiler(Class clazz)
           
 CompilerInterface getActiveCompiler()
          Gets the compiler is the "active" compiler.
 CompilerInterface[] getAvailableCompilers()
          Returns all registered compilers that are actually available.
 ClassLoader getBaseClassLoader()
          Gets the base class loader used to load compiler classes.
 boolean isNoCompilerAvailable()
           
 void registerCompiler(String name)
          Register the given compiler, adding it to the list of potential compilers.
 void setActiveCompiler(CompilerInterface compiler)
          Sets which compiler is the "active" compiler.
 void setBaseClassLoader(ClassLoader l)
          Sets the base class loader used to load compiler classes.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMPILERS

public static final String[] DEFAULT_COMPILERS
The list of compiler interfaces that are distributed with DrJava.

ONLY

public static final CompilerRegistry ONLY
Singleton instance.

_baseClassLoader

private ClassLoader _baseClassLoader
Class loader to use to fetch compiler classes.

_registeredCompilers

private LinkedList _registeredCompilers
Linked list of class names of registered compilers.

_activeCompiler

private CompilerInterface _activeCompiler
The active compiler. Must never be null.
Constructor Detail

CompilerRegistry

private CompilerRegistry()
Private constructor due to singleton.
Method Detail

setBaseClassLoader

public void setBaseClassLoader(ClassLoader l)
Sets the base class loader used to load compiler classes.

getBaseClassLoader

public ClassLoader getBaseClassLoader()
Gets the base class loader used to load compiler classes.

registerCompiler

public void registerCompiler(String name)
Register the given compiler, adding it to the list of potential compilers. This function adds the compiler to the list, regardless of whether the compiler is actualy available. This method will not add a duplicate instance of the same compiler.
Parameters:
name - Name of the CompilerInterface implementation class.

getAvailableCompilers

public CompilerInterface[] getAvailableCompilers()
Returns all registered compilers that are actually available. That is, for all elements in the returned array, .isAvailable() is true.

This method will never return null or a zero-length array. Instead, if no compiler is registered and available, this will return a one-element array containing an instance of NoCompilerAvailable.


isNoCompilerAvailable

public boolean isNoCompilerAvailable()

setActiveCompiler

public void setActiveCompiler(CompilerInterface compiler)
Sets which compiler is the "active" compiler.
Parameters:
compiler - Compiler to set active.
See Also:
getActiveCompiler()

getActiveCompiler

public CompilerInterface getActiveCompiler()
Gets the compiler is the "active" compiler. If there is no "active" compiler or if the active compiler is not available, this will return NoCompilerAvailable.
See Also:
setActiveCompiler(edu.rice.cs.drjava.model.compiler.CompilerInterface)

_registerDefaultCompilers

private void _registerDefaultCompilers()

_instantiateCompiler

private CompilerInterface _instantiateCompiler(String name)
                                        throws Throwable
Instantiate the given compiler.
Parameters:
name - Fully qualified class name of the compiler to instantiate. This class must implement CompilerInterface.
Returns:
Instance of CompilerInterface. This will either be the value of the .ONLY field of the class (if it exists and is an implementation of CompilerInterface) or a new instance of the given class.
Throws:
Throwable - If the compiler would not load, some type of exception will be thrown. Which particular one depends on how it failed. But either way, it is non-recoverable; the exception is thrown just to indicate failure.

createCompiler

public static CompilerInterface createCompiler(Class clazz)
                                        throws Throwable

_getToolsJarURLs

private static URL[] _getToolsJarURLs()
Returns reasonable location guesses for tools jar file.