Package org.h2.util

Class SourceCompiler


  • public class SourceCompiler
    extends java.lang.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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<?> getClass​(java.lang.String packageAndClassName)
      Get the class object for the given name.
      javax.script.CompiledScript getCompiledScript​(java.lang.String packageAndClassName)
      Get the compiled script.
      java.lang.reflect.Method getMethod​(java.lang.String className)
      Get the first public static method of the given class.
      static boolean isJavaxScriptSource​(java.lang.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​(java.lang.String className, java.lang.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 Detail

      • SourceCompiler

        public SourceCompiler()
    • Method Detail

      • setSource

        public void setSource​(java.lang.String className,
                              java.lang.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 java.lang.Class<?> getClass​(java.lang.String packageAndClassName)
                                    throws java.lang.ClassNotFoundException
        Get the class object for the given name.
        Parameters:
        packageAndClassName - the class name
        Returns:
        the class
        Throws:
        java.lang.ClassNotFoundException - on failure
      • isJavaxScriptSource

        public static boolean isJavaxScriptSource​(java.lang.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 javax.script.CompiledScript getCompiledScript​(java.lang.String packageAndClassName)
                                                      throws javax.script.ScriptException
        Get the compiled script.
        Parameters:
        packageAndClassName - the package and class name
        Returns:
        the compiled script
        Throws:
        javax.script.ScriptException - on failure
      • getMethod

        public java.lang.reflect.Method getMethod​(java.lang.String className)
                                           throws java.lang.ClassNotFoundException
        Get the first public static method of the given class.
        Parameters:
        className - the class name
        Returns:
        the method name
        Throws:
        java.lang.ClassNotFoundException - on failure