Method and apparatus for generating program code for world wide web service applications5966535Abstract A new application language called the MAWL language and a compiler for the new application language called the MAWL compiler are provided for use by programmers of World Wide Web services. The MAWL language and the MAWL compiler may be used to provide any World Wide Web service, but they are especially useful for programming interactive services. The MAWL language provides an expressive typing capability. Through this expressive ability World Wide Web services that have defined states, sequences and sessions are straightforward where previously such capabilities do not exist. Further, the MAWL compiler performs error checking for common errors and self-consistency before actual compiling so run-time error checking is avoided. Together the MAWL language and the MAWL compiler greatly increase the productivity of the World Wide Web programmer and the complexity of the World Wide Web services that can reliably be provided. Claims What is claimed is: Description TECHNICAL FIELD
______________________________________
%%
session fancyGreeting {
mhtml { } --> { "firstname", "lastname" }: login;
mhtml { "firstname", "lastname" }: greeting;
auto { "firstname", lastname" }: names;
names=mhtml.put [ login, ({ }) ];
mhtml.put [ greeting, names ];
______________________________________
EXAMPLE 1 Service Logic for a Personalized Fancy Greeting Service The first three lines of the source code program are declarations, the last two lines contain the service-logic. The lines beginning with the keyword mhtml declare certain properties about MHTML documents that are found in other files. In this case, two documents are declared, one called "login" and one called "greeting". A variable called "names", which is a record with two fields called "firstname" and "lastname", is also declared. Note that the "login" document is declared with an arrow (.fwdarw.) between two record descriptions. This requires an empty record as its input parameter and produces a record with two fields "firstname" and "lastname" as its output parameter. The "greeting" document is declared to take two inputs "firstname" and "lastname", and produces no output (signified implicitly by the lack of an arrow). The code for the service-logic works as follows: the command: names=mhtml.put [login, ({ })] commands the server to display the "login" document with no input, and put the result (the information entered by the user in fields on this document) into the variable "names". The command thereafter commands the server to display the "greetings" document with the contents of the variable "names" as its input. This completely describes the service-logic for the fancy "greeting" program, what remains is to describe the format of the two pages given by the two MHTML code files "greetings" and "login". Following the description of the fancy "greeting" program and its support files, a description of the MAWL service logic language in general will be given.
______________________________________
<HTML>
<HEAD><TITLE>Login form</TITLE></HEAD>
<BODY>
Please fill in the fields below with the requested info:
<P>
First name: <INPUT NAME="firstname"><P>
Last name: <INPUT NAME="lastname"><P>
</BODY>
</HTML>
______________________________________
EXAMPLE 2 A form File Needed by the Fancy Greeting Program
______________________________________
<HTML>
<HEAD><TITLE>Greeting form</TITLE></HEAD>
<BODY>
Rather than "Hello, World", we now say:<P>
Hello, <MVAR NAME="firstname"><MVAR NAME="lastname">!
</BODY>
</HTML>
______________________________________
EXAMPLE 3 Another Form File Needed by the Fancy Greeting Program In the first mhtml file, example 2 above, the presence of the variables "firstname" and "lastname" within the input tags indicates the MAWL field names in which the results will be stored. In the second mhtml file, example 3 above, the presence of the MVAR tags indicates that that the corresponding input values will be inserted there. This completes the description of the Fancy Greeting service program and its files. Details of the MAWL Service Logic Language Program Structure Immediately below is an annotated skeleton of an example of a MAWL program:
______________________________________
.fwdarw. fun hostLanguageFunction(x) = x // any host (ML) code
could go here
%%
.fwdarw. // one or more sessions could go here
.fwdarw. session test {
// this declares aForm to take anInput and return anOutput
mhtml { anInput } --> { anOutput } : aForm;
// this puts aForm with "aLiteralString" as the anInput argument
mhtml.put [ aForm, ({anInput="aLiteralString"}) ];
______________________________________
Each MHTML form needs to appear in the current directory of a file of the same name with the suffix .mhtm1. In the above case, aForm.mhtrml would need to be in the current directory of file aForm. MAWL makes use of a host programming language for general-purpose computation. This allows the MAWL programmer to make use of any library functions or procedures available through the host language without compromising the correctness guarantees given by MAWL. The host programming language for the MAWL compiler is Standard ML of New Jersey. The lines prior to the delimiter "%%" contain function or procedure declarations from the host language that may be referenced later in host-language fragments. Host language expressions can occur within the body of the MAWL service-logic program, and can be assigned to MAWL variables of the proper type. Syntactically, host-language fragments within the body of the program are introduced with parentheses. The MAWL compiler does not interpret anything within the parentheses, instead, everything within the parenthesis is passed unchanged to the host language compiler. The rules of MAWL's typing scheme place type obligations on all such host language fragments, e.g. assignments of a host-language expression to a MAWL variable require the type of the variable and expression to agree. Fragments which do not meet such obligations are detected at compile-time and reported as errors for correction. Basic Grammar and Features of the MAWL service-logic Language
______________________________________
types (1)
string
integer
boolean
unit (a.k.a. void)
{ name, name : type } (6)
type list
declarations
mhtml type : formName; (2) (3)
mhtml type --> type : formName; (2) (4)
auto type : varName;
auto type: varName = expr; (5)
static type : varName = expr; (5)
typdef type : newTypeName;
statements
statement; statement
while expr { statementlist }
for expr ; expr ; expr { statementlist }
if expr { statementlist } else { statementlist }
break;
expressions
var
(host-language-expression)
expr , expr
var = expr
var = html.get[ expr ] (7)
var = mhtml.put[ form, expr ]
var = mhtml.put[ form, expr ] handle "name" --> [ expr] (8)
var = mhtml.put[ form, expr ] handle any --> [ expr ] (8)
______________________________________
(1) Types can be built from any combination of string, integer, boolean
and unit, plus structures with named members of any type, plus lists of
any type.
(2) Mhtml forms must have inputs and outputs of structure type.
(3) A single type in an MHTML declaration means a form returning the empt
structure.
(4) A form declared to be of type A --> B takes a structure of type A and
returns one of type B.
(5) MAWL variables are declared to be either automatic or static.
Automatic variables persist only for the duration of one userinteraction
(one session), while static variables persist for the life of the service
Automatic (auto) variables may, and static variables must, have an initia
value.
(6) Structure members are of type string by default.
(7) The expression in file html.get is the URL to get (a string), its
result is the data returned by the server (a string).
(8) Handle clauses allow thr program to use special hyperlinks to continu
the current session. These special links are called MEXCEPTION's, and the
two forms of handle clause allow the programmer to respond to particular
exceptions (with the string literal) or to bind an identifier to whatever
MEXCEPTION was selected (with a new variable name). In both cases, the
expression after the arrow is taken as the return value of the form.
Idioms Request/response Responses from forms are almost always assigned to local variables, which need to be of the same type as the form's return value:
______________________________________
mhtml { } --> { name, PIN } : myform;
auto { name, PIN } : ret;
ret = mhtml.put[ myform, ({ }) ];
______________________________________
Response forms may advantageously use the typedef construct. A typedef for the form immediately above is illustrated in the following fragment:
______________________________________
typedef { name, PIN } : personalData;
mhtml { } --> personalData : myform;
auto personalData : ret;
ret = mhtml.put[ myform, ({ }) ];
______________________________________
Following links In order to follow a link, define a variable that gets changed in a exception handler, such as the variable whereToGo in the following example.
______________________________________
mhtml { } --> { } : aform;
auto string: whereToGo =("");
mhtml.put[ aform, ({ }) ]
handle any --> [ whereToGo = any, ({ }) ];
if (whereToGo <> "" ) {
. . . go there . . .
}
______________________________________
Advanced Features OK Functions mhtml type.fwdarw.type:formName!(checkFunction); checkFunction takes a host-language structure and returns a result which is a bool * string in ML. If the argument is "OK", the function ought to return (true,.sub.--) and if not, the function ought to return (false, reason) where reason is the explanation of what is wrong with the input. Server Push mhtml.put [form, (expr1)] pushing (expr2) upon varname This construct puts the form called "form", passing expr1 as the argument, and keeps the connection to the browser open. As long as the connection remains active, the form is replaced every time the variable "varname" changes. The replaced form is "form" with expr2 as the argument. Details of the MAWL Extended HTML Language MHTML contains HTML as a proper subset. The most important marks added to html in the MHTML language are the following: MHTML Mark-ups
__________________________________________________________________________
<MVAR NAME=x> replace this markup with variable "x"
<A MEXCEPTION=name> text</A>: raise exception "name" in the program.
Appears as a link in the HTML
<A MVAREXCEPTION=name> text</A>: raise exception given by the value
of variable name. Appears as a link in the HTML
<A MHREF=name> text</A>: hyperlink to URL given by value of variable
name
<MEXIT>text</MEXIT>: Appears as a link that exits the service
<MITER NAME=x MCURSOR=y> . . . block . . . </MITER>: repeat the
contents of block once for every element of the list "x". The variable
"y" takes
on each value in "x" in turn.
<IMG MVARSRC=varname MVARALT=varname
MVARALIGN=varname>
<INPUT NAME=iname MVARTYPE=varname MVARVALUE=varname>
<TEXTAREA NAME=iname MVARROWS=varname
MVARCOLS=varname>
__________________________________________________________________________
The MVAR mark is for variable replacement; the variable-name is declared separately in the service logic, and is a variable of any scalar printable type. The MITER mark is used to iterate over the list-typed variable specified by the NAME attribute; there is an iteration variable MCURSOR that is set to the value of each element, and the MHTML enclosed by the MITER marks is expanded once for each element. The MVAR mark is legal anywhere ordinary text is legal, and the MITER mark is legal only in places where zero or more of its enclosed MHTML are legal (this restriction guarantees that the resulting HTML document will conform to the standard HTML grammar). Consistency Requirements Between MAWL Programs and MHTML Files In order to eliminate certain HTML programming errors, all MHTML documents used in a MAWL program must be declared according to the syntax in Example 4 shown below on the next page.
______________________________________
declaration:
mhtml record-declaration : doc-name+ ;
.vertline. mhtml record-declaration --> record-declaration : doc-name+ ;
record-declaration:
{ field-decl-comma-list }
field-decl-comma-list:
field-decl
.vertline. field-decl-comma-list , field-decl
field-decl:
field-name : type
.vertline. field-name
______________________________________
EXAMPLE 4 MHTML Declarations The first part of an mhtml declaration declares the type of the form, giving the type (always a MAWL record) of the data passed from the program to the form, and optionally a type for the data coming back from the form. Following the type specification is a list of the form identifiers being declared to have the type. To display a particular form, it must be invoked with a record argument of the appropriate type according to the syntax as shown in Example 5 below; the return value must also correspond to the declaration. Note that the MAWL expression for serving a document has the flavor of a remote procedure call.
______________________________________
expr:
mhtml.put [ doc-name, expr ]
______________________________________
EXAMPLE 5 MHTML Usage The uses of MHTML forms that are found in the body of the mawl service-logic program must be consistent with both the declarations given in that program, and the inputs and outputs found in the corresponding .mhtml files. In Operation Consider operation during a more complex MAWL program such as the one in Example 6 given below. Such a service would be (relatively) unthinkable if written from scratch using prior art html, but such a service is easy to build using the MAWL language. The service in this example is an old guessing game, where the host computer system chooses a number between 1 and 100, and the player/user must figure out which number was chosen. It is probably easy to figure out most of what this program is doing, but take special note of the static variables that keep track of how many users have played the game, and look at the interplay between the host language fragments (the entries in parentheses) and the rest of the language. Note how there are two entry points, one for playing the game and one for looking up some statistics and who has achieved the quickest victory. Also note that MAWL variables can be used within the host language fragments, and the return result of the host language fragments is automatically translated into the appropriate MAWL representation. Any type errors are caught by the MAWL compiler at compile time.
______________________________________
fun number ( ) = let
val s = Time.toSeconds(Time.now( )) in s mod 99 end
%%
static integer: numPlayed=(0), numWon=(0), minGuesses=(0);
static string: bestPlayer=("");
session play {
mhtml { suggestion } --> { guess } : askUser;
mhtml { } --> { name, guess}: initQuestion;
auto integer: mynum=(number( )), guesses=(0), guess=(0);
auto string : suggestion = ("");
auto { name, guess } : initresult;
auto { guess } : result;
auto string: name;
numPlayed = (numPlayed + 1);
initresult = mhtml.put [ initQuestion,
({ guessno=makestring guesses,
suggestion=suggestion}) ];
guess = (jcrlib.atoi (#guess initresult));
while (mynum <> guess) {
suggestion = (if guess<mynum then "higher" else "lower");
result= mhtml.put [
askUser,
({ guessno=makestring guesses,
suggestion=suggestion}) ];
guess = (jcrlib.atoi (#guess result));
guesses = (guesses + 1);
numWon = (numWon + 1);
if (minGuesses < guesses andalso minGuesses <> 0) {
mhtml { best, gamelength } : youWin;
mhtml.put [ youWin,
({ best=bestPlayer,
gamelength=makestring guesses }) ];
} else {
mhtml { } : youBest;
bestPlayer = (#name initresult);
minGuesses = guesses;
mhtml.put [ youBest, ({ }) ];
}
}
session admin {
mhtml { played, won, best }: highScores AndInfo;
mhtml.put [ highScoresAndInfo, ({
played=makestring numPlayed,
won=makestring numWon,
best=bestPlayer }) ];
}
______________________________________
EXAMPLE 6 Service Logic for a Guessing Game The MAWL language also has explicit synchronization constructs; exception handling facilities; server-push constructs, and an MHTML syntax used to specify iteration which the MAWL compiler will analyze for errors and compile into errorless service code when all errors are corrected. Advantages of MAWL System The MAWL system provides the infrastructure for programmers that is lacking in the prior art for creating complex and reliable web services. Programming Abstractions State that is passed from document to document can be expressed in a natural way using MAWL variables. MAWL also provides access to several other important programming abstractions: the ability to control the scope and persistence of information by giving appropriate declarations of MAWL variables, the ability to sequence pages using MAWL's conditional and looping constructs of the MAWL language, and the ability to protect stored state using critical regions. Web-specific Optimization MAWL relieves the programmer of the task of coding many repetitive tasks within a Web service. For example, the MAWL programmer does not need to code HTML pages telling the user that a particular field in a form was not filled out because MAWL automatically supplies such an error message and it also supplies hyperlinks back to the original form for quick correction. Analysis In circumstances where, before MAWL, an entire document would have to be generated dynamically, users of MHTML are able to compose their documents statically. Specifying portions that are run-time variabilities using variables with the MVAR syntax. In this way, the MHTML can be parsed at compile time and analyzed for correctness independent of execution. MHTML is an extension of HTML described within the Standard Generalized Markup Language (SGML). This could enable users to check, if desired, that the HTML documents generated will conform to a particular HTML standard. The MAWL compiler currently detects some classes of errors at compile time. For example, if the mawl program made use of an MHTML document such as:
______________________________________
<HTML>
<HEAD><TITLE>A basic html program </TITLE></HEAD>
<ODY>Hello,world.</BODY>
</HTML>
The MAWL compiler would generate the message:
ERROR: Parse Error : Missing <BODY> markup in file helloerr.
______________________________________
Additional checks to conform to stricter html standards can easily be accommodated as these standards evolve. The MAWL compiler also checks that the fields that are declared in the MAWL service logic program as inputs to a particular MHTML form are actually used by the forms and their declared types are correct with respect to the way they are used in the form. For example, if the MAWL program is as follows:
__________________________________________________________________________
%%
session hello{
mhtml {name:string}: hello
mhtml.put [hello, (name="joe") ];
and the mhtml file hello.mhtml did not make use of the input variable
"name", the
MAWL compiler would give an error message:
ERROR: Type Error: MHTML file "hello" doesn't use declared variable
__________________________________________________________________________
"name"
Platform Independence The MAWL system has been designed to accommodate a number of parameters of variation. Because no construct in the service-logic or MHTML language is specific to a particular browser, the MAWL compiler can easily be extended to deal with changes to popular browsers such as Netscape Navigator, or to new browsers. No construct in the service-logic language is specific to a hypertext setting, hence MAWL allows for the possibility of using the same service-logic program in conjunction with markup languages for other media and other interfaces, such as telephones and television set-top boxes. For telephones and television set top boxes, other interface specifications files would be used instead of specialized interface language MHTML. The strict separation of service-logic and layout into distinct languages makes for a number of other advantages as well: MHTML files used for layout can be changed frequently without touching the service-logic files. The fact that the MHTML documents do not make use of programming constructs enables them to be created and maintained by nonprogrammers. Thus, there has been described a method of generating web service code using the MAWL language to define the desired functionality in an expressive source code and the MAWL compiler to check that source code for common errors and self-inconsistencies and, after all such errors are corrected, compile the source code into web service code. While the invention has been particularly illustrated and described with reference to preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form, details, and applications may be made therein. For instance, the MAWL compiler is written in ML, but any general purpose programming language could be used instead, and a MAWL compiler in some version of the C programming language is contemplated. It is accordingly intended that the appended claims shall cover all such changes in form, details and applications which do not depart from the true spirit and scope of the invention.
|
Same subclass Same class Consider this |
||||||||||
