Package org.h2.util

# Class SourceCompiler

java.lang.Object
org.h2.util.SourceCompiler

public class SourceCompiler extends Object
This class allows to convert source code to a class. It uses one class loader per class.

## Constructor Summary

Constructors
Constructor
Description
`SourceCompiler()`

## Method Summary

Modifier and Type
Method
Description
`Class<?>`
`getClass(String packageAndClassName)`
Get the class object for the given name.
`CompiledScript`
`getCompiledScript(String packageAndClassName)`
Get the compiled script.
`Method`
`getMethod(String className)`
Get the first public static method of the given class.
`static boolean`
`isJavaxScriptSource(String source)`
Whether the passed source can be compiled using `ScriptEngineManager`.
`void`
`setJavaSystemCompiler(boolean enabled)`
Enable or disable the usage of the Java system compiler.
`void`
`setSource(String className, String source)`
Set the source code for the specified class.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SourceCompiler

public SourceCompiler()

## Method Details

### setSource

public void setSource(String className, String source)
Set the source code for the specified class. This will reset all compiled classes.

Parameters:
  `className` - the class name
  `source` - the source code

### setJavaSystemCompiler

public void setJavaSystemCompiler(boolean enabled)
Enable or disable the usage of the Java system compiler.

Parameters:
  `enabled` - true to enable

### getClass

public Class<?> getClass(String packageAndClassName) throws ClassNotFoundException
Get the class object for the given name.

Parameters:
  `packageAndClassName` - the class name
Returns:
  the class
Throws:
  `ClassNotFoundException` - on failure

### isJavaxScriptSource

public static boolean isJavaxScriptSource(String source)
Whether the passed source can be compiled using `ScriptEngineManager`.

Parameters:
  `source` - the source to test.
Returns:
  `true` if `getCompiledScript(String)` can be called.

### getCompiledScript

public CompiledScript getCompiledScript(String packageAndClassName) throws ScriptException
Get the compiled script.

Parameters:
  `packageAndClassName` - the package and class name
Returns:
  the compiled script
Throws:
  `ScriptException` - on failure

### getMethod

public Method getMethod(String className) throws ClassNotFoundException
Get the first public static method of the given class.

Parameters:
  `className` - the class name
Returns:
  the method name
Throws:
  `ClassNotFoundException` - on failure