Source

osworkflow / docs / 3.4.2 BeanShell Functions.html

Full commit
<html>
    <head>
        <title>OSWorkflow - 
        3.4.2 BeanShell Functions
         </title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <ul>
	<li>Back to <a href="3.4.1 Java-based Functions.html" title="3.4.1 Java-based Functions">3.4.1 Java-based Functions</a></li>
	<li>Forward to <a href="3.4.3 BSF Functions.html" title="3.4.3 BSF Functions">3.4.3 BSF Functions</a></li>
</ul>


<p>OSWorkflow supports BeanShell as a scripting language. You can find out more about BeanShell at the <a href="http://www.beanshell.org/" title="Visit page outside Confluence">BeanShell website</a>. Reading the documentation for BeanShell should be more than enough to get started with scripting for your own workflow definition file. There are a few behaviors that you should be aware of before starting, however:</p>

<p>The <b>type</b> that must be chosen for BeanShell functions is <b>beanshell</b>. There is one required argument: <b>script</b>. The value for this argument is the actual script that is to be executed. Example:</p>

<div class="code"><div class="codeContent">
<pre class="code-java">&lt;function type=<span class="code-quote">"beanshell"</span>&gt;
	&lt;arg name=<span class="code-quote">"script"</span>&gt;	
		<span class="code-object">System</span>.out.println(<span class="code-quote">"Hello, World!"</span>);
	&lt;/arg&gt;
&lt;/function&gt;</pre>
</div></div>

<p>There are three variables in the expression scope at all times: <em>entry</em> <em>context</em>, and <em>store</em>. The variable "entry" is an object that implements <em>com.opensymphony.workflow.spi.WorkflowEntry</em> and represents the workflow instance. The variable "context" is an object of type <em>com.opensymphony.workflow.WorkflowContext</em> which allows for BeanShell functions to roll back transactions or determine the caller name. The "store" variable is of type <em>com.opensymphony.workflow.WorkflowStore</em><br/>
 and allows the function to access the underlying workflow persistence store.</p>

<p>Just like <a href="3.4.1 Java-based Functions.html" title="3.4.1 Java-based Functions">3.4.1 Java-based Functions</a>, there are three variables that can be used and are automatically set in the BeanShell scope: <b>transientVars</b>, <b>args</b>, and <b>propertySet</b>. The same rules that apply to Java functions also apply here. Example:</p>

<div class="code"><div class="codeContent">
<pre class="code-java">&lt;function type=<span class="code-quote">"beanshell"</span>&gt;
	&lt;arg name=<span class="code-quote">"script"</span>&gt;	
		propertySet.setString(<span class="code-quote">"world"</span>, <span class="code-quote">"Earth"</span>);
	&lt;/arg&gt;
&lt;/function&gt;
&lt;function type=<span class="code-quote">"beanshell"</span>&gt;
	&lt;arg name=<span class="code-quote">"script"</span>&gt;	
		<span class="code-object">System</span>.out.println(<span class="code-quote">"Hello, "</span>+propertySet.getString(<span class="code-quote">"world"</span>));
	&lt;/arg&gt;
&lt;/function&gt;</pre>
</div></div>

<p>The output of these two scripts would be "Hello, Earth". This is because any variable stored in the <b>propertySet</b> is persisted for use in functions later in the workflow.</p>

<ul>
	<li>Back to <a href="3.4.1 Java-based Functions.html" title="3.4.1 Java-based Functions">3.4.1 Java-based Functions</a></li>
	<li>Forward to <a href="3.4.3 BSF Functions.html" title="3.4.3 BSF Functions">3.4.3 BSF Functions</a></li>
</ul>


                    			    </td>
		    </tr>
	    </table>
    </body>
</html>