Package gs

Deprecated, replaced by wcs.

See:
          Description

Class Summary
JagTask Deprecated. Replaced by JagTask.
JarTask Deprecated. Replaced by JarTask.
JavacTask Deprecated. Replaced by JavacTask.
ProcessTask Deprecated. Replaced by ProcessTask.
RmTask Deprecated. Replaced by RmTask.
Servlet Deprecated. Replaced by Servlet.
Task Deprecated. Replaced by Task.
Task.In generic input source.
Task.In.None empty input as input source.
Task.In.Stream byte stream as input source.
Task.In.String string as input source.
Task.Out generic output sink.
Task.Out.None black hole as output sink.
Task.Out.Stream byte stream as output sink.
 

Exception Summary
Task.Exception wraps any exception during Task.run().
 

Package gs Description

Deprecated, replaced by wcs.

This is the homepage of gs, a servlet to provide preprocessing with jag, compilation with javac, and execution in an applet.

Requests

gs can be accessed with the GET or POST methods of HTTP. It will reply with a request page, Java source resulting from preprocessing with jag, an applet page, or error messages from jag and javac. The expected key/value pairs are documented in Servlet. The table below shows possible queries and responses.

? request page with sample program.
?jag.source=jag-source
&javac.source=javac-source
request page with sources. Either source can also be a HTTP-based URL. A partial URL is resolved against the HTTP referer.
?jag=true
&jag.source=jag-source
page with Java code resulting from preprocessing.
?jag=true
&javac=true
&jag.source=jag-source
&javac.source=javac-source
applet page to execute the main program in the jag source. Both sources must belong to the same package.
?applet=basename.jar archive for applet (once only).

Event Loop

By default gs will return a request page with a sample, editable jag source and a URL for the Java code of a suitable frontend which resulted from preprocessing an annotated grammar with pj. The example can produce stack machine code for arithmetic expressions.

The request page submits jag and Java source texts or URLs as values for the keys jag.source and javac.source and true for jag and (optionally) for javac. Partial URLs would be resolved against the referer which only exists if the submission comes from a page obtained via HTTP. The only protocol supported is HTTP.

If jag.source is not accompanied by true for jag gs replies with a request page presenting the jag source text for editing and submission. This is intended to present tutorial examples for execution within some other course material.

If jag.source is accompanied by true for jag but not for javac, gs replies with an error report or Java code resulting from preprocessing the source. This is intended to demonstrate the effects of preprocessing.

javac.source can contain Java source text or one or more (partial) URLs separated by white space. Multiple sources must be in the same package, however.

If both, jag and javac, have the value true gs sets up a temporary directory and a package path, if any, with the (preprocessed) sources and System placed into the package and executes javac with jay.yydebug and the runtime support of jag on the classpath.

If preprocessing and compilation succeed gs builds a temporary archive file with the class files, jay.yydebug, and the runtime support of jag, and replies with an applet page referencing the archive. If preprocessing or compilation fails gs replies with the relevant error log. All files but the archive file are deleted in either case.

The applet page contains a request with a value for applet so that the archive file will be returned and deleted from the temporary file area.

System Spoofing

Both source texts are searched for the package path, if any, and the name of the first class, which must be public. The search uses pattern matching and accounts for comments and white space but it will fail if package or import paths contain white space or comments. The package may not be java.lang and the class name may not be System. Both source texts must belong to the same package.

The applet class System is placed into the same package as the source texts and is compiled together with the source texts. This means that as long as there is no explicit reference to java.lang.System rather then System and as long as there is no reference from another class, System will take over.

System inserts a fresh yyInputStream and yyPrintStream each time the jag program is started in the applet. These streams emulate a terminal in a text area in the applet. System delegates all other methods to java.lang.System.

Apparently, the Java code has access to whatever libraries are available within the web browser, including, e.g., the AWT, as long as it sticks within the security constraints for an applet. Without a policy setup there can be no local file access and no network activity.

There seems to be no reliable way to really terminate a thread. However, standard i/o is disconnected from the Java program when it is "stopped" in the applet and the web browser will forcibly remove the remains once the applet page is closed.

It should be noted that a class is loaded into an applet only once, i.e., if a program is restarted in the applet, the static items of the program are not initialized again.

Projects

Downloads

Version:
1.0, Pittsford, December 2004.
Author:
Axel T. Schreiner.