BSF command

From ControlTier

Jump to: navigation, search

This Module Development Guide page describes how to define a command using the "BsfCommand" command-type.

This command type is useful if you want to use one of the Bean Scripting Framework languages to implement your procedure (e.g., using jython, jruby, groovy, bsh, etc).

Contents

Create or choose a type

You can add the command to an existing type definition or you can create a new type. To create a new type run the ProjectBuilder create-type and follow the prompts:

$ ctl -m ProjectBuilder -c create-type -- -type bsfcommands

The create-type command will generate a type.xml file where you can define your command.

Alternatively, you can use the Graphical type editor to create a new type graphically.

Edit type.xml

If you are using ProjectBuilder commands to define the type, it will have generated a type.xml file inside the module's source directory. Commands are defined using the "command" element, specifying the command-type as "BsfCommand". Use the script tag as a nested element to the command tag specifying the BSF language inside the script tag's language attribute. The BSF script code resides in the text area of the script tag.

      <command name="<name>" description="<description>." 
              command-type="BsfCommand" is-static="true">
        <script language="<language>"><![CDATA[
              script statements ...
	]]></script>
        <opts>
        </opts>
      </command>

The ControlTier client distribution includes BSF dependencies supporting: jruby, jython, and groovy.

Here's an example defining a command called "hello-ruby" implemented in the ruby language:

      <command name="hello-ruby" description="ruby BSF command." 
              command-type="BsfCommand" is-static="true">
        <script language="ruby"><![CDATA[
           print 'ruby says ', $project.getProperty('opts.message'), "\n"
	]]></script>
        <opts>
          <opt parameter="message" description="option name" required="false"
	       property="opts.message" type="string" default="Hello"/>
        </opts>
      </command>

... and here another command called "hello-groovy" implemented with groovy:

      <command name="hello-groovy" description="groovy BSF command." 
              command-type="BsfCommand" is-static="true">
        <script language="groovy"><![CDATA[
           println "groovy says ${project.properties['opts.message']} \n"
	]]></script>
        <opts>
          <opt parameter="message" description="option name" required="false"
	       property="opts.message" type="string" default="Hello"/>
        </opts>
      </command>

Build the type

Use the "build-type" command to generate the command files.

$ ctl -m ProjectBuilder -c build-type -- -type bsfcommands -upload -deploy

The -upload and -deploy flag cause the generated type to be uploaded to Workbench and then deployed to the local client.

Run the command

The bsfcommands type is now deployed and the new commands can be run:

$ ctl -m bsfcommands -c hello-ruby
ruby says Hello
$ ctl -m bsfcommands -c hello-groovy
groovy says Hello
Personal tools
Namespaces
Variants
Actions
Navigation
Communication
Development
Toolbox
Print/export