Scripted Java Language Definition


<?xml version="1.0" encoding="ISO-8859-1" ?>
<languages>
  <language name="java" source-extension="java" object-extension="class" >
    <version name="0.92" stylesheet="java-0.92.xsl" />

    <init-script><![CDATA[
      var separator = File.separator;
      var classPath = java.lang.System.getProperty("java.class.path");

      var errorStream = File.stderr;
      var Compiler = Packages.sun.tools.javac.Main;
    ]]></init-script>

    <compile-script><![CDATA[
      function compileProgram(baseName, path) {
	var cnt = 0;
        var args = new Array();
        var compiler = new Compiler(errorStream, "javac");
        
        args[cnt++] = "-classpath";
        args[cnt++] = classPath + pathSeparator + path;
        
        args[cnt++] = "-d";
        args[cnt++] = path;
        
        args[cnt++] = "-deprecation";
      
        // args[cnt++] = "-verbose";
      
        args[cnt++] = path + separator + baseName + ".java";
      
        if (!compiler.compile(args)) {
	  throwError("Java Compilation Error");
	}
      }
    ]]></compile-script>

    <load-script><![CDATA[
      function loadProgram(baseName, path) {
        var ps = new RegExp(separator);

	ps.global = true;
        var className = baseName.replace(ps, "."));

        var servletClass = java.lang.Class.forName(className);

        return servletClass.newInstance();
      }
    ]]></load-script>

    <unload-script><![CDATA[
      function unloadProgram(servlet) {
        servlet.destroy();
      }
    ]]></unload-script>

    <execute-script><![CDATA[
      function executeProgram(servlet, request, response) {
        servlet.service(request, response);
      }
    ]]></execute-script>
  </language>
</languages>