<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.:

service {
    seslet int getNumber() { ... }
    seslet void setNumber(int number) { ... }
    . . .
}

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:

abstract class Seslet extends Applet {
    protected static int getNumber();
    protected static void setNumber(int number);
    . . .
}

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.

Seslet Types

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.

Table 1: Types
<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.

Tuples

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

schema Person {
    int age;
    string name;
    bool male;
}

results in the following Java class (as an inner class of Seslet):

class Person {
    int age;
    String name;
    boolean male;

    Person();
    Person(int age, boolean male, String name);
}

Relations and vectors

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

vector vector int matrix

and if this type is used in a seslet following Java classes are generated:

class VectorInt {
    int get(int index);
    void set(int index, int element);
    . . .
}

class VectorVectorInt {
    VectorInt get(int index);
    void set(int index, VectorInt element);
    . . .
}

Methods

The following table shows the correspondence between bigwig and Java methods on relations and vectors.

Table 2: Methods
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
Valid HTML 4.01!