gate.util
Class Jdk

java.lang.Object
  extended bygate.util.Jdk

public class Jdk
extends Object

Jdk encapsulates some utilities for poking around in your Java environment.


Field Summary
private  sun.toolsx.javac.Main compiler
           
private static boolean DEBUG
          Debug flag
private  String[] toolsLocations
          Possible locations of the tools bin directory.
 
Constructor Summary
Jdk()
          Anonymous construction.
 
Method Summary
 byte[] compile(String javaCode, String className)
          Compile a class from its source code string.
 Class defineClass(String classQualifiedName, byte[] classBytes)
          Define a class from its qualified name and the byte array of its binary.
 File getToolsHome()
          Returns a File specifying the location of the JDK tools, i.e.
 Object instantiateClass(Class theClass)
          Create an instance of a class.
 Class loadActionClass(String classFileName)
          Load a class.
static void main(String[] args)
          main.
 byte[] readClass(String classFileName)
          Read the bytes for a class.
 void testMe()
          Test method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

See Also:
Constant Field Values

toolsLocations

private String[] toolsLocations
Possible locations of the tools bin directory. (relative to "java.home").


compiler

private sun.toolsx.javac.Main compiler
Constructor Detail

Jdk

public Jdk()
Anonymous construction.

Method Detail

main

public static void main(String[] args)
                 throws GateException
main.

Throws:
GateException

testMe

public void testMe()
            throws GateException
Test method. Better to use TestJdk via the TestGate suite instead.

Throws:
GateException

getToolsHome

public File getToolsHome()
                  throws GateException
Returns a File specifying the location of the JDK tools, i.e. the location of programs like java, javac, jar. It assumes that if it finds javac or javac.exe then it found the tools home.

Throws:
GateException

compile

public byte[] compile(String javaCode,
                      String className)
               throws GateException
Compile a class from its source code string.

Parameters:
className - should have the package path to the source, e.g. com/thing/MyClass.java.
Throws:
GateException

readClass

public byte[] readClass(String classFileName)
                 throws GateException
Read the bytes for a class.

Parameters:
classFileName - should have the path to the .class file, e.g. com/thing/MyClass.class.
Throws:
GateException

loadActionClass

public Class loadActionClass(String classFileName)
                      throws GateException
Load a class.

Parameters:
classFileName - is the path to the .class file, e.g. com/thing/MyClass.class.
Throws:
GateException

defineClass

public Class defineClass(String classQualifiedName,
                         byte[] classBytes)
                  throws GateException
Define a class from its qualified name and the byte array of its binary.

Throws:
GateException

instantiateClass

public Object instantiateClass(Class theClass)
                        throws GateException
Create an instance of a class.

Throws:
GateException