Service Page

This page makes also use of the query interpreter and lists the data from the server. For this purpose we provide a service page. This service page is built similarly to the HTML page. It also contains a header with some page directives. In addition, it also includes the access of the page parameters and the setup of the data holder and the query object. We do not repeat the details here and the interested reader might consult the appendix for more information.

The service page will be accessed by our Prolog open/3 built-in. This built-in does URL nor-malization and uses a HEAD access to the server for this purpose. We are currently working on a solution that skips URL normalization and does only a GET, but this improvement is not yet available by us. To avoid initiating a long running job on the server we will check the re-quest method and in case of a HEAD access we will do nothing.

    String method = request.getMethod();
if ("HEAD".equals(method))

To deliver the employee/4 facts in Prolog notation we do not generate them piece wise in the service page. Instead we rebuild the employee/4 facts and then invoke the Prolog un-parser. Rebuilding the employee/4 facts does not fill the heap, since we will do it in a loop. The corre-sponding objects are short lived and will be quickly reclaimed by Java. When rebuilding the employee/4 facts we simply use the rows form the query result and assume that they are already in the correct argument order for the TermCompound constructor:

        for (int j = 0; j < rows.length; j++) {
Object[] args = rows[j];
%><%=new"employee", args).toString(>.

Using the Prolog un-parse will assure that atoms are correctly quoted and escaped, and that spaces and parenthesis are set necessary. The invocation of the Prolog un-parse happens between the <%= and %>. This kind of snippet evaluates the given expression and places the result in the output. In our situation the expression creates the employee/4 compound and thus results in a Term. When a non-primitive type is placed in the output its toString() method is invoked. The toString() method of a Term does a Prolog un-parse.

We have also incorporated exception handling into the service page. An exception might not only be thrown when something goes wrong with the query building or query execution. An exception might also be thrown when there is a problem with setting up the knowledge base the first time. We have decided to return an exception/1 Prolog fact in case an exception occurs. The fact is also generated by a Prolog un-parse. More details about the exception handling can be found in the appendix.