![]() |
<Seslets> |
Seslets are bigwig functions that can be called from outside a session. Seslets have the same functionality as normal functions, but they are not allowed to use show and exit statements.
A seslet is declared by adding the keyword seslet in front of a function declaration, eg.:
When one or more seslets are declared in a bigwig service, the
compiler will generate source code for a Java class
Seslet. This class will be a sub-class of
java.applet.Applet and will have a static method
corresponding to each declared seslet.
Continuing the example form above the Java class will look like this:
The programmer can now extend Seslet to make his own Java applet that can call the seslet-functions and get results from the service running on the server.
In order to make Java seslets work the need for a mapping between bigwig types and Java types arises. The following table briefly describes how types are mapped and the next sections will describe tuples, relations, and vectors in more detail.
| <bigwig> type | Java type |
|---|---|
| bool | boolean |
| char | char |
| int | int |
| float | double |
| string | String |
| time | java.util.Date |
| tuple Scm | Scm |
| relation scm | RelationScm |
| vector type | VectorType |
Note: Following standard
Java naming conventions tuple types, relation types, and
vector types (and their subtypes) are capitalized, i.e. the
<bigwig> type "vector int" corresponds to the
Java type "VectorInt".
For each non-atomic bigwig type (tuple, relation, and vector) used
as argument to or return type of a seslet, a corresponding inner
class of Seslet is generated.
Marshalling and un-marshalling of arguments and return values are done automatically by the generated Seslet class.
For each bigwig schema scm a Java class Scm is generated. This class has field variables with names and types corresponding to the attributes of the tuple type. Two constructors are provided: one takes no arguments and initialises the field variables to their standard values. The other takes as arguments the values of the attributes ordered alphabetically by name.
Example: The bigwig schema
results in the following Java class (as an inner class of Seslet):
Rather than using generic classes to represent relation and vector types each type is represented explicitly by a class given by Table 1 above. This makes it possible to ensure type safety and prevents the programmer from making (stupid) errors as all operations (eg. getting and setting entries) can be type checked at compile-time.
Example: a matrix of integers is in bigwig declared as
and if this type is used in a seslet following Java classes are generated:
The following table shows the correspondence between bigwig and Java methods on relations and vectors.
| Java type | Java method | <bigwig> expression |
|---|---|---|
| VectorT v | int v.size() |
|v| |
T v.get(i) |
v[i] |
|
T v.set(i, exp) |
v[i] = exp |
|
VectorT v.slice(i, j) |
v[i..j] |
|
VectorT v.concat(VectorT w) |
v+w |
|
| RelationT r | int r.size() |
|r| |
|
bigwig@brics.dk Last updated: November 8, 2001 |
|