/home/projects/magnet/reference/core/scriptHandlerDef

scriptHandlerDef

Overview

The <scriptHandlerDef> element can be used to extend the functionality of Magnet by adding a new scripting engine to execute scripts. Magnet comes with Beanshell integration built-in, but let's say you want to add support for another scripting engine, like Jython. You would first need to implement the ScriptHandlerIF interface. Your class would simply wrap the Jython interpreter, passing it the script to execute. Once this class is coded you need to tell Magnet how to associate the new jython script type to the class you just wrote. To perform the association between the script type and the class that integrates the scripting engine, you configura a so-called script handler definition.

Attributes

Name Description Required Interpolation
type Defines the type of the script for which we provide a handler. yes yes
classname The name of the class that implements the interface ScriptHandlerIF and provides the handling for that script type. yes yes

Rendering Operations

When a <scriptHandlerDef> element is rendered, it performs the following operations in order:

  1. Resolves the type and classname attributes (using variable interpolation).
  2. Registers the new script handler with Magnet's internals.

Examples

This example creates a new script handler for the jython interpreter. The association specifies that the class com.mycorp.magnet.JythonHandler will be used everytime the "jython" script type is used.

<magnet xmlns:magnet="http://schemas.sapia-oss.org/magnet/"
        name="ScriptHandlerDefExample1"
        description="This is a first example.">
...
    <scriptHandlerDef type="jython"
                      classname="com.mycorp.magnet.JythonHandler" />
...
</magnet>