Seppia Specification Version 1.0 (Draft)

 

Motivation

Recent years have seen the proliferation of many scripting languages for java: rhino (javascript 1.5), jython, beanshell, groovy to name but a few.

The increasing need of highly customizable applications has been an important factor for them to gain popularity within the java community.

But while each scripting language has been fighting to prove it has just that extra feature to make it better than its rivals, developers have been left on the trenches trying to work out on their own best practices on when and how to use them.

Unfortunately this has left a sense of discontent on some developers leaving them convinced that scripting languages are more trouble than a solution.

What they really needed was a framework with clear rules on how the interaction between scripts and code works which encorauges modular design and leads to well-crafted products.

Seppia was envisioned to address this need.

Mission Statement

Seppia's main aim is to make java applications easier to maintain and deploy.
Seppia will change the way we think of Java based component computing.

 

Design Principles

The following design principles are used to guide the development of Seppia

 

Seppia Technology

Seppia is a simple framework to build and deploy any java application.
It gains from the sinergy of java and javascript and a minimum set of clear rules to organize their interaction.
We refer to "Seppia Application" to any application built using the Seppia Technology. Seppia itself is a minimal Seppia application.

 

A Seppia Application

A seppia application is not a single monolithic program, but rather a tiny launcher surrounded by a few modules.
Each module may rely on services provided by another module and may in turn provide services on which yet other modules may rely. This "modular" design  lends itself to discrete chunk of functionality that can be easily adapted to meet new requirements.

The behaviour of each module is split between java code and javascript code.
The java code , stored in jar files provides an API for the javascript code to work with.
The javascript code defines the services provided by the module.

The structure of a Seppia Application

Any Seppia Application is recognizable by its directory structure.

Let SEPPIA be the directory on which a Seppia application has been installed , this is what the structure looks like: 

SEPPIA\StartUp.class
SEPPIA\jars    (folder containing jar files needed by each module of the application)
SEPPIA\modules (folder containing the modules specific to the SEPPIA application)

In the modules folder are found the modules. Each module then has a well defined structure consisting of

\javascripts (folder containing at least one javascript file)
\jars (optional folder containing jar files needed by the javascript code in javascripts)

Depending on the nature of the module it might define additional folders like
\icons , \properties, etcetera.

Seppia Javascript

Javascript code is saved in files with the extension .js
Javascript files are named following the same rules and conventions used for .java files.(e.g.: Sprite.js, ImageObserver.js)

The name of the file omitting its ".js" extension is the name of the javascript (Sprite, ImageObserver)
The files are stored in the javascripts folder where they can interact with any of the module's features.

A javascript in Seppia has access to java objects via the following objects:

and via the keyword this.

java and Packages object lets you access the public methods and fields of an arbitrary Java class from within JavaScript.
Example:


var map = new java.util.HashMap();
var frame = new Packages.javax.swing.JFrame("My Frame");

The Keyword this refers to the current object (i.e.: the current executing javascript itself). The following properties are available to the javascript object:


java.lang.System.out.println("the script is "+id);
java.lang.System.out.println("the script code is "+code);


The function run accepts either one or two arguments. In both cases it is just a shorthand for two common operations:

e.g.:

var logger = run("org.seppia.log4j","Logger");

 

Execution of a Javascript

The execution of the javascript file consists of two phases:

Javascripts always belong to a module and each module is assigned its own Java class loader that is solely responsible for loading the classes visible to the javascript code.
Module classloaders use the jar files in the jars folder of the module.

Understanding How a Seppia Application works

A seppia application is launched by running a JVM against "StartUp.class" on its installation directory.
There is no classpath to set, no system properties to pass and no arguments to pass to its main method.
For example:

SEPPIA> java -cp . StartUp

A batch file or a shell script depending on the system can be easily written. 

When the minimal application StartUp is ran it does the following :

This javascript typically just redirects the application so to execute another javascript.
For example:


function main()
{
    run("org.your-company.notepad","Notepad");
}