Skip to main content

Script-handler Handler

It ca be used to persist the business objects using BSH scripts. Supports the following attributes:

Attribute
Usage

if

EL expression that must be evaluated to true prior to handler action

unless

 EL expression that must be evaluated to false prior to handler action

Inside the handler, you can use the insert-script, delete-script and update-script tags. Each contains the BSH script that the engine will execute to perform inserts, deletes or updates. Within the BSH script you can refer to the same EL expressions predefined variables:

Variable
Value
self Current DataNode
instance Business object wrapped into current DataNode
parent Parent DataNode
parent.instance Business object wrapped into parent DataNode
datasource DataSoruce the current DataNode belongs to

The following example shows how to save objects in file Country:

<datanode name="country">
    <script-handler >
        <insert-script>
            import java.io.*;
            f = new FileOutputStream ("country."+instance.abbreviation);
            oos = new ObjectOutputStream (f);
            oos.writeObject (instance);
            oos.close ();
            f.close ();
        </insert-script>
        <update-script>
            import java.io.*;
            f = new FileOutputStream ("country."+instance.abbreviation);
            oos = new ObjectOutputStream (f);
            oos.writeObject (instance);
            oos.close ();
            f.close ();
        </update-script>
        <insert-script>
            import java.io.*;
            f = new File ("country."+instance.abbreviation);
            f.delete ();
        </insert-script>
    </script-handler>
        ...
</datanode>