org.dellroad.jc
Class Generate

java.lang.Object
  extended byorg.dellroad.jc.Generate

public final class Generate
extends Object

Singleton class used as the starting point for object file generation. The JC virtual machine will invoke generateObject() on the singleton instance when it needs to create a new ELF object file.

The object file is actually generated by whatever ObjectGenerator is specified by the jc.object.generator system property. By default, a JCObjectGenerator is used.


Field Summary
static char FILE_SEPARATOR
          The system-dependent character used to separate directory names in a path name.
static char PATH_SEPARATOR
          The system-dependent character used to separate individual paths in a search path.
 
Method Summary
static String decode(String s)
          Reverse of encode(java.lang.String).
static String encode(String name)
          Equivalent to encode(name, false).
static String encode(String name, boolean ignoreSlashes)
          Encode a name so that it uses only "safe" 7-bit characters so that it's suitable for use as a file name.
 void generateObject(String className, ClassLoader loader)
          Generate the ELF object file for the named class.
static long hash(InputStream s)
          Return the "JC hash" of some bytes.
static File objectFile(String className)
          Return the file that contains the ELF object for the class.
static File objectFile(String className, File dir)
          Return the file that contains the ELF object for the class, given that dir is the root of the object directory hierarchy.
static Generate v()
          Retrieve the singleton instance of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_SEPARATOR

public static final char FILE_SEPARATOR
The system-dependent character used to separate directory names in a path name.


PATH_SEPARATOR

public static final char PATH_SEPARATOR
The system-dependent character used to separate individual paths in a search path.

Method Detail

v

public static Generate v()
Retrieve the singleton instance of this class.


generateObject

public void generateObject(String className,
                           ClassLoader loader)
                    throws Exception
Generate the ELF object file for the named class. The object file is written into the first directory in the search path specified by the jc.object.path system property.

Parameters:
className - name of class (with slashes not dots).
loader - class loader used to acquire the class file
Throws:
Exception
See Also:
objectFile()

objectFile

public static File objectFile(String className)
Return the file that contains the ELF object for the class. This will be a filename under the first directory in the search path specified by the jc.object.path system property.


objectFile

public static File objectFile(String className,
                              File dir)
Return the file that contains the ELF object for the class, given that dir is the root of the object directory hierarchy.

This method does not depend on the jc.object.path and therefore may be used when running under other Java VM's.


hash

public static long hash(InputStream s)
Return the "JC hash" of some bytes. This is defined to be the last 8 bytes of the MD5 of the input, interpreted as a big-endian Java long value.


encode

public static String encode(String name)
Equivalent to encode(name, false).


encode

public static String encode(String name,
                            boolean ignoreSlashes)
Encode a name so that it uses only "safe" 7-bit characters so that it's suitable for use as a file name. First the string is UTF-8 encoded, then slashes become underscores and all other non alphanumeric characters (UTF-8 bytes really) become two underscores followed by two hex digits.

Parameters:
name - Class name
ignoreSlashes - whether to pass slash characters through unencoded or convert them to underscores.

decode

public static String decode(String s)
Reverse of encode(java.lang.String).

Throws:
IllegalArgumentException - if s is not validly encoded.