Tuscany Tuscany SCA Java Scripting Language Implementation

The Tuscany Java SCA runtime has a script container allowing SCA components to be implemented with a variety of scripting languages.

To use the script container you use the <implementation.script> element in the component SCDL. The <implementation.script> element has two attributes, 'script' and 'class'. The 'script' attribute is required and defines the location of the script program. The 'class' attribute is optional and enables specifying the class or prototype to be used if the script language supports such concepts.

The language the script is implemented in is defined by the suffix of the script attribute value. For example, the '.js' suffix indicates a JavaScript program, or '.py' indicates a Python program. The script container uses the Apache BSF script engine, so any script language supported by BSF can be used as an SCA component implementation.

The following example shows the files necessary to implement a simple HelloWorld style SCA component using the script container and a JavaScript program.

The composite SCDL:

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
    name="HelloWorldComposite">

    <component name="HelloWorldComponent">
        <implementation.script script="HelloWorld.js"/>
    </component>

</composite>

and the associated JavaScript program, 'HelloWorld.js':

function sayHello(s) {
    return "Hello " + s;
}

This next example shows a HelloWorld program using the Ruby language, and the use of the <implementation.script> element 'class' attribute to specifying the class of the component implementation:

The composite SCDL:

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
    name="HelloWorldComposite">

    <component name="HelloWorldComponent">
        <implementation.script script="HelloWorld.rb" class="Helloworld"/>
    </component>

</composite>

and the associated Ruby program, 'HelloWorld.rb':

class Helloworld

   def sayHello(s) 
      return "Hello to " + s + " from the Ruby World!"
   end

end